-
Notifications
You must be signed in to change notification settings - Fork 79
/
build.gradle
534 lines (456 loc) · 20.8 KB
/
build.gradle
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import com.install4j.gradle.Install4jTask
// Some useful commands:
//
// `./gradlew tasks` lists the available tasks
// `./gradlew run` runs HO locally
// `./gradlew tiTree <task>` shows the task graph for the task <task>
// Temporary workaround for #2116
// Thx to https://github.com/kordamp/markdown-gradle-plugin/issues/36#issuecomment-2277317737
buildscript {
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("com.overzealous:remark:1.1.0") \
using module("com.wavefront:remark:2023-07.07") \
because "not available on maven central anymore"
}
}
}
plugins {
id "java"
id "groovy"
id "org.jetbrains.kotlin.jvm" version "1.9.21"
id "application"
id "org.kordamp.gradle.markdown" version "2.2.0"
id "com.github.breadmoirai.github-release" version "2.5.2"
id "com.install4j.gradle" version "9.0.6"
id "org.barfuin.gradle.taskinfo" version "2.1.0"
id "io.freefair.lombok" version "8.10"
}
apply plugin: de.jansauer.poeditor.POEditorPlugin
version = '9.0'
ext {
// Development_stage (DEV:0 BETA:1 STABLE:2)
development_stage = project.properties['DEV_STAGE'] as Integer ?: 0
version_type = ["-DEV", "-BETA", ""].get(development_stage)
target_dir = "${buildDir}/artefacts"
}
repositories {
mavenCentral()
maven { url 'https://maven.ej-technologies.com/repository' }
}
dependencies {
implementation "com.install4j:install4j-runtime:10.0.7"
implementation "com.github.scribejava:scribejava-core:8.3.3"
implementation 'org.hsqldb:hsqldb:2.7.3'
implementation 'com.google.code.gson:gson:2.10'
implementation "com.squareup.okhttp3:okhttp:4.12.0"
implementation "com.squareup.okhttp3:okhttp-tls:4.12.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.12.0"
implementation "com.github.weisj:darklaf-core:3.0.2"
implementation "com.github.weisj:darklaf-theme:3.0.2"
implementation "com.github.weisj:darklaf-property-loader:3.0.2"
implementation "org.javatuples:javatuples:1.2"
implementation "org.apache.commons:commons-text:1.12.0"
implementation "org.knowm.xchart:xchart:3.8.7"
implementation 'org.jsoup:jsoup:1.18.1'
implementation "org.jetbrains:annotations:24.1.0"
implementation 'org.codehaus.groovy:groovy-all:3.0.21'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation "org.junit.jupiter:junit-jupiter:5.10.2"
testImplementation "org.assertj:assertj-core:3.26.3"
}
test {
useJUnitPlatform()
}
// configure application plugin --------------------------------
application {
mainClass = "core.HOLauncher"
}
// configure java plugin --------------------------------
java {
compileJava.options.encoding = "UTF-8"
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
sourceSets {
main {
java {
srcDirs = ["src/main/java"]
}
resources {
srcDirs = ["src/main/java", "src/main/resources"]
}
}
test {
java {
srcDirs = ["src/test/java"]
}
resources {
srcDirs = ["src/test/resources"]
}
}
}
// region configuration ==============================================================================================
ext.callGit = { param ->
def p = param.execute()
p.waitFor()
//println "error: " + p.errorStream.text
return p.text.trim()
}
// Used to filter contributors
ext.filter = { string, filters ->
def lines = string.split('\n')
String res = ""
lines.each{ l->
for ( String f in filters ) {
if ( l.contains(f) ) return
}
res = res + l + "\n"
}
return res
}
// configure markdownToHtml --------------------------------
markdownToHtml {
markdownToHtml.tables = true // Configuration
}
// Configure poeditor plugin ================================
poeditor {
apiKey = System.getenv('POEDITOR_APIKEY') ?: 'xxx'
projectId = '206221'
trans.add type:'properties', lang: 'bg', file: "${projectDir}/src/main/resources/language/Bulgarian.properties"
trans.add type:'properties', lang: 'ca', file: "${projectDir}/src/main/resources/language/Catalan.properties"
trans.add type:'properties', lang: 'hr', file: "${projectDir}/src/main/resources/language/Hrvatski(Croatian).properties"
trans.add type:'properties', lang: 'cs', file: "${projectDir}/src/main/resources/language/Czech.properties"
trans.add type:'properties', lang: 'da', file: "${projectDir}/src/main/resources/language/Danish.properties"
trans.add type:'properties', lang: 'nl', file: "${projectDir}/src/main/resources/language/Nederlands.properties"
trans.add type:'properties', lang: 'fi', file: "${projectDir}/src/main/resources/language/Finnish.properties"
trans.add type:'properties', lang: 'fr', file: "${projectDir}/src/main/resources/language/French.properties"
trans.add type:'properties', lang: 'de', file: "${projectDir}/src/main/resources/language/German.properties"
trans.add type:'properties', lang: 'el', file: "${projectDir}/src/main/resources/language/Greeklish.properties"
trans.add type:'properties', lang: 'he', file: "${projectDir}/src/main/resources/language/Hebrew.properties" //Hebrew
trans.add type:'properties', lang: 'hu', file: "${projectDir}/src/main/resources/language/Magyar.properties" //Hungarian
trans.add type:'properties', lang: 'it', file: "${projectDir}/src/main/resources/language/Italiano.properties"
trans.add type:'properties', lang: 'ko', file: "${projectDir}/src/main/resources/language/Hangul(Korean).properties"
trans.add type:'properties', lang: 'lv', file: "${projectDir}/src/main/resources/language/Latvija.properties" //Lettonie
trans.add type:'properties', lang: 'lt', file: "${projectDir}/src/main/resources/language/Lithuanian.properties"
trans.add type:'properties', lang: 'fa', file: "${projectDir}/src/main/resources/language/Persian.properties"
trans.add type:'properties', lang: 'pl', file: "${projectDir}/src/main/resources/language/Polish.properties"
trans.add type:'properties', lang: 'pt', file: "${projectDir}/src/main/resources/language/Portugues.properties"
trans.add type:'properties', lang: 'pt-br', file: "${projectDir}/src/main/resources/language/PortuguesBrasil.properties"
trans.add type:'properties', lang: 'ro', file: "${projectDir}/src/main/resources/language/Romanian.properties"
trans.add type:'properties', lang: 'ru', file: "${projectDir}/src/main/resources/language/Russian.properties"
trans.add type:'properties', lang: 'sr-cyrl', file: "${projectDir}/src/main/resources/language/Serbian(Cyrillic).properties"
trans.add type:'properties', lang: 'sk', file: "${projectDir}/src/main/resources/language/Slovak.properties" //Slovak
trans.add type:'properties', lang: 'es', file: "${projectDir}/src/main/resources/language/Spanish.properties"
trans.add type:'properties', lang: 'sv', file: "${projectDir}/src/main/resources/language/Svenska.properties" //Swedish
trans.add type:'properties', lang: 'tr', file: "${projectDir}/src/main/resources/language/Turkish.properties"
trans.add type:'properties', lang: 'no', file: "${projectDir}/src/main/resources/language/Norsk.properties" // Norwegian
trans.add type:'properties', lang: 'id', file: "${projectDir}/src/main/resources/language/Indonesian.properties"
trans.add type:'properties', lang: 'ja', file: "${projectDir}/src/main/resources/language/Japanese.properties"
trans.add type:'properties', lang: 'sl', file: "${projectDir}/src/main/resources/language/Slovenian.properties"
trans.add type:'properties', lang: 'uk', file: "${projectDir}/src/main/resources/language/Ukranian.properties"
trans.add type:'properties', lang: 'ka', file: "${projectDir}/src/main/resources/language/Georgian.properties"
trans.add type:'properties', lang: 'zh-CN', file: "${projectDir}/src/main/resources/language/Chinese.properties"
trans.add type:'properties', lang: 'gl', file: "${projectDir}/src/main/resources/language/Galego.properties" // Galician
trans.add type:'properties', lang: 'nl-be', file: "${projectDir}/src/main/resources/language/Vlaams.properties" // Flemish
trans.add type:'properties', lang: 'es-ar', file: "${projectDir}/src/main/resources/language/Spanish(AR).properties" // Argentina
}
// Configure jar task ================================
jar {
archiveFileName = "HO.jar"
manifest {
attributes 'Manifest-Version': 1.0,
'Implementation-Title': 'HO',
'Implementation-Version': project.version,
'Main-Class': 'core.HOLauncher',
"Class-Path": configurations.runtimeClasspath.collect { it.getName() }.join(' ')
}
exclude "/*.jar", "/*.ico", "/*.png", "/*.md", "/*.html"
}
// Configure distribution task =======================
distributions {
main {
distributionBaseName = 'XXX'
}
}
install4j {
if (install4jHomeDir != null && install4jHomeDir != "") {
installDir = file(install4jHomeDir)
} else if (System.getenv('INSTALL4J_HOME')) {
installDir = file(System.getenv('INSTALL4J_HOME')) as File
}
disableSigning = true
license = System.getenv('INSTALL4J_LICENSE')
}
poeditorPull {
outputs.upToDateWhen { false }
}
markdownToHtml {
// create html from md sources for both release notes and changelog
sourceDir = new File("${projectDir}/docs/md")
outputDir = new File("${projectDir}/docs/html")
markdownToHtml.hardwraps = true
}
//endregion ======================================================================================================================
// region my tasks ================================================================================================
tasks.register("createVersion") {
description "Creates the version file required by the GitHub Actions release process."
doLast {
def coords = project.version.split(/\./)
def major = coords[0]
def minor = coords[1]
def developmentStage = project.ext.development_stage
println "development stage: ${project.ext.development_stage}"
def currentBranch = callGit('git branch --show-current')
Properties versionProps = new Properties()
def buildNumber = System.getenv("RUN_NUMBER") ?: "0"
project.version = "${major}.${minor}.${buildNumber}.${developmentStage}".toString()
// Version in jar extension is set eagerly, override after computing version.
jar.manifest {
attributes('Implementation-Version': project.version)
}
versionProps['buildNumber'] = buildNumber
versionProps['version'] = project.version.toString()
versionProps['shortVersion'] = "${major}.${minor}".toString()
versionProps['tag'] = ['dev', 'beta', 'tag_stable'].get(developmentStage)
versionProps['branch'] = currentBranch
// Write to version.properties file
def versionPropsFile = new File('version.properties')
versionProps.store(versionPropsFile.newWriter(), null)
println "Project: $project.name $project.version ....................."
}
}
tasks.register("media", Install4jTask) {
group 'sub tasks'
dependsOn tasks.createDistribution
projectFile = file("${projectDir}/utils/buildResources/HO.install4j")
// 60 -> Windows Setup
// 1203 -> Windows Setup (32 bits)
// 485 -> Windows JRE
// 1206 -> Windows JRE (32 bits)
// 64 -> Windows archive
// 481 -> Windows archive JRE
// 1208 -> Windows archive (32bits)
// 1211 -> Windows archive JRE (32bits)
// 172 -> macOS Single Bundle
// 473 -> macOS Single Bundle JRE
// 173 -> Unix Archive
// 477 -> Unix Archive JRE
// 1062 -> Unix installer
// 1064 -> Unix installer JRE
// 62 -> Linux rpm
// 63 -> Linux deb
// 464 -> Linux rpm JRE
// 471 -> Linux deb JRE
buildIds = [60, 485, 64, 481, 172, 473, 173, 477, 1062, 1064, 1203, 1206, 1208, 1211]
//buildIds = [60]
variables = [HO_version: project.version, projectDir: projectDir, versionType: project.ext.version_type]
doFirst {
// Ensures that the project.version used for HO_version
// is the expanded version computed in `createVersion` task.
var mediaTask = tasks.findByName("media") as Install4jTask
mediaTask.configure {
variables.HO_version = project.version
}
}
}
tasks.register("makeAllMedias") {
dependsOn tasks.media
doLast {
delete "${projectDir}/build/artefacts/output.txt"
println("copy version.properties into ${project.ext.target_dir}") // ensures version.properties.html en up with the artefacts in the release
copy {
from "${projectDir}/version.properties"
into "${project.ext.target_dir}"
}
// to ensure changelog.html ends up within the distribution
println("copy release_notes.html") // ensures release_notes.html en up with the artefacts in the release
copy {
from "${projectDir}/docs/html/release_notes.html"
into "${project.ext.target_dir}"
}
// compatibility to HO3 Updater
// which used other zip file name
def versionType = project.ext.version_type ?: '-DEV'
println("copy ${project.ext.target_dir}/HO-${project.version}-portable-win${versionType}.zip -> HO_${project.version}.zip")
copy {
from "${project.ext.target_dir}/HO-${project.version}-portable-win${versionType}.zip"
rename "HO-${project.version}-portable-win${versionType}.zip", "HO_${project.version}.zip"
into "${project.ext.target_dir}"
}
}
}
tasks.register("preparingBuild") {
group 'sub tasks'
doLast {
// Deleting build project ---------------------------------------------------------------------
println("Deleting build and execution files ....")
project.delete(files("${projectDir}/db"))
project.delete(files("${projectDir}/logs"))
project.delete(files("${projectDir}/themes"))
project.delete(files("${projectDir}/user.xml"))
// Creating Target directory ... ---------------------------------------------------------------------
mkdir project.ext.target_dir
}
}
tasks.register("pushmd") {
group 'sub tasks'
dependsOn tasks.preparingBuild
doLast {
def coords = project.version.split(/\./)
def major = coords[0]
def minor = coords[1]
// create release notes ========
// list the contributors that don't want to be mentioned in release notes
def contributorFilter = ["Che"]
def commitCount = callGit('git rev-list 8.0..HEAD --count')
def diff = callGit('git diff --shortstat 8.0..HEAD')
def contributors = filter(callGit('git shortlog -s -n 8.0..HEAD'), contributorFilter)
def latestCommit = callGit('git log -1 --pretty=format:"%s"')
println("create release-notes")
def development_message = [
"Latest alpha release – planned features are still missing and the version might be unstable, so don't use it without backups of your database and program directories",
"Latest beta release – the version is feature complete – feedback from early users is welcome",
"Latest stable release"
]
List<String> intro = [
"# HO! $major.$minor Release Notes",
"",
development_message[project.ext.development_stage],
"",
"latest commit: ${latestCommit}",
"",
"## Some numbers",
"* ${commitCount} commits",
"* ${diff}",
"* Contributors: \n${contributors}",
""
]
def mdDir = new File("${projectDir}/docs/md") // create directory for MD source
mdDir.mkdirs()
new File(mdDir.getAbsolutePath() + "/release_notes.md").text=intro.join("\n") + file("${projectDir}/src/main/resources/release_notes.md").getText() //release notes + intro copied in md source folder
// create changelog
println("create changelog")
List<String> changelogIntro = [
"# Changelist HO! $major.$minor",
""
]
File changeLog = new File(mdDir.getAbsolutePath()+ "/changelog.md")
changeLog.text=changelogIntro.join("\n")
def toConcatenate = files("${projectDir}/src/main/resources/release_notes.md", "${projectDir}/src/main/resources/changelog.md")
toConcatenate.each { f -> changeLog << f.text }
}
}
tasks.register("createDistribution") {
group 'sub tasks'
dependsOn tasks.installDist
outputs.upToDateWhen { false }
def distribDir = file("${buildDir}/install/XXX")
doLast {
// to ensure changelog.html ends up within the distribution
copy {
from "${projectDir}/docs/html/changelog.html"
into "${distribDir}"
}
if (project.ext.development_stage == '0') {
copy {
from "${projectDir}/utils/buildResources/Logo_dev.png"
into "${projectDir}/utils/buildResources"
rename "Logo_dev.png", "Logo.png"
}
} else if (project.ext.development_stage == '1') {
copy {
from "${projectDir}/utils/buildResources/Logo_beta.png"
into "${projectDir}/utils/buildResources"
rename "Logo_beta.png", "Logo.png"
}
} else {
copy {
from "${projectDir}/utils/buildResources/Logo_stable.png"
into distribDir
rename "Logo_stable.png", "Logo.png"
}
}
copy {
from "${projectDir}/prediction"
into "${distribDir}/prediction"
}
copy {
from "${distribDir}/lib"
include "**/*.jar"
into "${distribDir}"
}
copy {
from "${projectDir}/src/main/resources/truststore.jks"
into "${distribDir}"
}
delete "${distribDir}/bin"
delete "${distribDir}/lib"
}
}
tasks.register("createLanguageFileList") {
group 'sub tasks'
dependsOn tasks.poeditorPull
outputs.upToDateWhen { false }
def lTranslationFiles = []
fileTree(dir: "${projectDir}/src/main/resources/language", include: '*.properties').visit {
FileVisitDetails details -> lTranslationFiles << details.file.name
}
doLast {
println("listing available translation in ${projectDir}/src/main/resources/language")
lTranslationFiles = lTranslationFiles.collect { it.take(it.lastIndexOf('.'))}
lTranslationFiles.each {out.println it}
File lstFile = new File("${projectDir}/src/main/resources/language/ListLanguages.txt")
lstFile.withWriter{ out -> lTranslationFiles.each {out.println it} }
}
}
tasks.register("resetDB") {
group 'tool'
description 'copy the database from existing install into project'
doLast {
try {
println("Resetting DB: copying DB from `${resetDir}` into ${projectDir}")
project.delete(files("${projectDir}/db"))
copy {
from "${resetDir}/"
into "${projectDir}/db/"
exclude "**/logs/**"
}
println("Resetting DB: done !")
} catch (Exception ignored) {
println("Resetting DB: CANNOT copy DB from `${resetDir}` into ${projectDir}"); return false
}
}
}
tasks.register("pushDB") {
group 'tool'
description 'copy the database from project to temp folder for analysis'
doLast {
try {
println("Pushing DB: copying DB from ${projectDir} into `${tempDir}/db/`")
project.delete(files("${tempDir}/db"))
copy {
from"${projectDir}/db"
into "${tempDir}/db"
exclude "**/logs/**"
}
println("Pushing DB: done !")
} catch (Exception ignored) {
println("Pushing DB: CANNOT copy DB from ${projectDir} into `${tempDir}db/"); return false
}
}
}
tasks.register("release", GradleBuild) {
tasks = ['clean', 'createVersion', 'poeditorPull', 'processResources', 'createLanguageFileList', 'makeAllMedias']
}
markdownToHtml.dependsOn(pushmd)
poeditorPull.dependsOn(markdownToHtml)
processResources.dependsOn(poeditorPull)
compileJava.dependsOn(clean)
compileJava.dependsOn(processResources)
// endregion ======================================================================================================================