-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
198 lines (173 loc) · 7.35 KB
/
build.gradle
File metadata and controls
198 lines (173 loc) · 7.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import groovy.json.JsonSlurper
import org.jooq.codegen.DefaultGeneratorStrategy
import org.jooq.codegen.GenerationTool
import org.jooq.meta.Definition
import org.jooq.meta.DefaultDataTypeDefinition
import org.jooq.meta.jaxb.*
import org.jooq.tools.StringUtils
apply plugin: "java"
apply plugin: "maven-publish"
group = "stellar.database"
version = "1.5.0"
sourceCompatibility = 16
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
}
return stdout.toString().trim()
}
ext {
mindustryVersion = "v146"
lombokVersion = "1.18.24"
mysqlVersion = "8.0.30"
postresqlVersion = "42.7.3"
jooqVersion = "3.17.0"
hikariVersion = "5.0.1"
jacksonVersion = "2.17.2"
}
repositories {
mavenCentral()
maven { url "https://www.jitpack.io" }
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jooq:jooq:3.17.0" // older version due to older MySQL version on the host
classpath "org.jooq:jooq-codegen:3.17.0"
classpath "org.jooq:jooq-meta:3.17.0"
classpath "org.postgresql:postgresql:42.7.3"
}
}
dependencies {
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
compileOnly "org.projectlombok:lombok:$lombokVersion"
/*compileOnly("com.github.Anuken.MindustryJitpack:core:$mindustryVersion") {
exclude module: "flabel"
exclude module: "arcnet"
exclude module: "g3d"
exclude module: "freetype"
exclude module: "fx"
}*/
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
implementation "org.jooq:jooq:$jooqVersion"
runtimeOnly "org.postgresql:postgresql:$postresqlVersion"
implementation "com.zaxxer:HikariCP:$hikariVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
implementation "org.jetbrains:annotations:16.0.1"
}
publishing {
publications {
maven(MavenPublication) {
from components.java
}
}
}
task codegen {
doLast {
def host, schema, user, password
if (!project.hasProperty("dbhost") || !project.hasProperty("dbschema") || !project.hasProperty("dbuser") || !project.hasProperty("dbpassword")) {
if (file("./database.json").exists()) {
println("Using local JSON config")
def json = new JsonSlurper()
def dbFile = file("./database.json")
def db = json.parseText(dbFile.text)
host = db.host
schema = db.schema
user = db.username
password = db.password
} else {
println("\u001B[33;1mWARNING!\u001B[0m No DB config. Compiling may fail due to lack of `gen` packet")
return
}
} else {
host = project.property("dbhost")
schema = project.property("dbschema")
user = project.property("dbuser")
password = project.property("dbpassword")
}
println(sourceSets.main.java.srcDirs.first().path)
Configuration configuration = new Configuration()
.withJdbc(new Jdbc()
.withDriver("org.postgresql.Driver")
.withUrl("jdbc:postgresql://$host:5432/$schema")
.withUser("$user")
.withPassword("$password")
)
.withGenerator(new Generator()
.withDatabase(new Database()
.withName("org.jooq.meta.postgres.PostgresDatabase")
.withIncludes(".*")
.withExcludes("")
.withInputSchema("${schema}")
.withForcedTypes(
new ForcedType()
.withUserType("stellar.database.enums.MessageType")
.withEnumConverter(true)
.withIncludeExpression("mindustry\\.messages\\.type"),
new ForcedType()
.withUserType("stellar.database.enums.PlayerStatus")
.withEnumConverter(true)
.withIncludeExpression("mindustry\\.users\\.status"),
new ForcedType()
.withUserType("stellar.database.enums.PvpMode")
.withEnumConverter(true)
.withIncludeExpression("mindustry\\.matches\\.mode"),
new ForcedType()
.withUserType("java.util.List<stellar.database.types.UnitSnapshot>")
.withConverter("stellar.database.converters.UnitSnapshotConverter")
.withIncludeExpression("mindustry\\.hex_snapshots\\.units")
)
)
.withTarget(new Target()
.withPackageName("stellar.database.gen")
.withDirectory(sourceSets.main.java.srcDirs.first().path)
)
.withStrategy(new Strategy()
.withName(CamelCaseGeneratorStrategy.name)
)
.withGenerate(new Generate()
.withFluentSetters(true)
)
)
GenerationTool.generate(configuration)
}
}
javadoc {
options.links "https://www.jooq.org/javadoc/3.17.0/"
destinationDir = file("${buildDir}/docs/javadoc")
}
jar {
println("Make sure you are using the latest database version. Do `./gradle codegen` to generate code")
duplicatesStrategy = DuplicatesStrategy.INCLUDE
archiveFileName = "${project.archivesBaseName}.jar"
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
processResources {
def build = (project.hasProperty("buildVersion") ? project.property("buildVersion") : "snapshot")
println("Compiling with build: '$version $build - $getGitHash'")
filesMatching("**/version.properties") {
from it.file
filter { line -> line.replace("%verType%", build).replace("%verNum%", version).replace("%gitHash%", getGitHash()) }
}
}
class CamelCaseGeneratorStrategy extends DefaultGeneratorStrategy {
String getJavaIdentifier(Definition definition) {
StringUtils.toCamelCaseLC(super.getJavaIdentifier(definition))
}
String getJavaGetterName(Definition definition, Mode mode) {
if (mode == Mode.RECORD) {
if (((DefaultDataTypeDefinition) definition.getProperties().get("definedType")).type.equalsIgnoreCase("boolean")) {
return "is" + StringUtils.toCamelCase(definition.getOutputName())
}
}
return "get" + StringUtils.toCamelCase(definition.getOutputName())
}
}