forked from PCGen/pcgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
980 lines (851 loc) · 36.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
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
/*
* PCGen build using the Gradle tool. This file specifies the core build tasks
* and refers to other files in the code/gradle directory for additional tasks
* for specific output.
*
* Developer build: gradle
* Incremental dev build: gradle build
* Full build: gradle allTasks
* Build and run all tests: gradle clean build slowtest
* Run the data tests: gradle datatest
* Run the character integration tests: gradle inttest
*/
// import Ant helper static values to differ system families
import org.apache.commons.lang3.StringUtils
import org.apache.tools.ant.filters.FixCrLfFilter
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.plugins.ide.idea.model.ProjectLibrary
/**
* Plugins without versions are ones that are bundled with Gradle at the version
* being used (should be through gradlew).
*/
plugins {
id 'application' // Creating application bundles
id 'build-dashboard' // Produces a build report
id 'checkstyle' // Checkstyle for Java, configured further below
id 'com.github.spotbugs' version '6.0.24' // Spotbugs for Java
id 'java' // Core java / javac
id 'maven-publish' // Publishing to Maven Central
id 'pmd' // PMD for Java, configured further below
id 'idea' // For IntelliJ IDEA users
id 'de.undercouch.download' version '5.6.0' // Shows download percentage
id 'edu.sc.seis.launch4j' version '3.0.6' // Creates launch4j
id 'com.github.ben-manes.versions' version '0.51.0' // Checks versions for plugins and dependencies
id 'com.dorongold.task-tree' version '4.0.0' // Prints the task dependency tree
id 'org.openjfx.javafxplugin' version '0.1.0' // JavaFX support
id 'org.beryx.runtime' version '1.13.1' // Creates custom runtimes
}
/**
* Set the version and the modules we want from JavaFX (not everything)
*/
javafx {
version = "21"
modules = [ 'javafx.controls', 'javafx.web', 'javafx.swing', 'javafx.fxml', 'javafx.graphics' ]
}
// Set the groupId as it helps with Maven
group = 'net.sourceforge.pcgen'
// Description of this project
description = """PCGen"""
// Default task if you just run ./gradlew
defaultTasks 'build'
// Configure Java, in particular the version to test/compile/run with
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
// Define properties for the build (directories)
ext {
// Where code gets compiled to
binDir = "code/bin"
// Folder where exe / jar files are placed.
outputDir = layout.projectDirectory.dir("output")
// Folder where the JREs are downloaded for building releases
jresDir = layout.projectDirectory.dir("jre")
// Folder where the JavaFX mods are downloaded for building releases
modsDir = layout.projectDirectory.dir("mods")
// Installers are placed here
releaseDir = layout.projectDirectory.dir("build/release")
// JavaFX version
javaFXVersion = "21.0.4"
}
application {
mainClass.set('pcgen.system.Main')
}
/*
* Which binary repositories this build uses.
*/
repositories {
// Maven Central as a default
mavenCentral()
// Use Ant Ivy Plugin to reference our own hosted repos
// for PCGen Base and PCGen Formula JARs
//ivy {
// TODO Enable HTTPS (e.g., add letsencrypt) for that location
//url "http://pcgen.sourceforge.net/mvnrepo"
//allowInsecureProtocol = true
//patternLayout {
//artifact "[organisation]/jars/[artifact]-[revision].[ext]"
//}
//}
ivy {
// TODO Enable HTTPS (e.g., add letsencrypt) for that location
name "fileRepo"
url 'http://pc-gen.org/librepo/'
allowInsecureProtocol = true
}
// Use Maven plugin to reference freehep (https://java.freehep.org/) artifact repository
// TODO Which libs do we pull from here?
maven {
name = 'free'
url = 'https://java.freehep.org/maven2'
}
maven {
name = 'local'
url = 'installers'
}
// Use Maven plugin to reference JBoss artifact repository
// TODO Which libs do we pull from here?
maven {
name = 'jboss'
url "https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/"
}
}
// Define the source sets for each task/module
// TODO even though we have the idea plugin, IntelliJ doesn't reference
// these source sets whether you run that task or not.
sourceSets {
// The main build
main {
java {
srcDirs 'code/src/java'
}
resources {
srcDirs = ['code/src/resources']
}
}
// Running regular tests
test {
java {
srcDirs = ['code/src/utest', 'code/src/testcommon']
}
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
resources {
srcDirs = ['code/src/testResources']
}
}
// Integration Tests
itest {
java {
srcDirs = ['code/src/itest', 'code/src/testcommon']
}
resources {
srcDirs = ['code/src/testResources']
}
compileClasspath += sourceSets.test.compileClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
// Running Slow Tests
slowtest {
java {
srcDirs = ['code/src/test', 'code/src/testcommon']
}
resources {
srcDirs = ['code/src/testResources']
}
compileClasspath += sourceSets.test.compileClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
/* Copy 'master' outputsheets into different genre folders */
tasks.register("copyMasterSheets", Copy) {
def filesToCopy = copySpec {
include 'eqsheet_fantasy_std.htm', 'psheet_fantasy_std.htm'
from 'outputsheets/d20/fantasy/htmlxml'
}
into(layout.projectDirectory.dir('outputsheets/d20'))
into('historical/htmlxml') { with filesToCopy }
into('horror/htmlxml') { with filesToCopy }
into('sciencefiction/htmlxml') { with filesToCopy }
into('western/htmlxml') { with filesToCopy }
}
/* Delete 'master' outputsheets from different genre folders */
tasks.register("cleanMasterSheets", Delete) {
delete layout.projectDirectory.file("outputsheets/d20/historical/htmlxml/eqsheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/historical/htmlxml/psheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/horror/htmlxml/eqsheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/horror/htmlxml/psheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/sciencefiction/htmlxml/eqsheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/sciencefiction/htmlxml/psheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/western/htmlxml/eqsheet_fantasy_std.htm"),
layout.projectDirectory.file("outputsheets/d20/western/htmlxml/psheet_fantasy_std.htm")
}
/*
* Dependencies for this project.
*
* implementation means both compile and runtime
* testImplementation means both compile and runtime for test phase only
*
* For information on the exclude group items in this section, and why these are necessary to have Eclipse properly compile PCGen, please see the following items:
* https://bugs.openjdk.java.net/browse/JDK-8215739
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=536928
* https://stackoverflow.com/questions/51094274/eclipse-cant-find-xml-related-classes-after-switching-build-path-to-jdk-10/53824670#53824670
* https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html
*/
dependencies {
implementation group: 'commons-io', name: 'commons-io', version: '2.17.0'
implementation group: 'commons-io', name: 'commons-io', version:'2.17.0'
implementation group: 'org.springframework', name: 'spring-web', version:'6.1.13'
implementation group: 'org.springframework', name: 'spring-beans', version:'6.1.13'
implementation group: 'org.springframework', name: 'spring-core', version:'6.1.13'
implementation group: 'org.apache.commons', name: 'commons-lang3', version:'3.17.0'
implementation group: 'xalan', name: 'serializer', version: '2.7.3'
implementation('org.apache.xmlgraphics:fop:2.9')
{
exclude group: 'xml-apis', module: 'xml-apis'
}
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.5.0-M2'
implementation group: 'org.scijava', name: 'jep', version: '2.4.2'
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.33'
implementation group: 'org.jdom', name: 'jdom2', version: '2.0.6.1'
implementation('xalan:xalan:2.7.3')
{
exclude group: 'xml-apis', module: 'xml-apis'
}
implementation group: 'net.sourceforge.argparse4j', name: 'argparse4j', version: '0.9.0'
implementation group: 'org.xmlunit', name: 'xmlunit-core', version: '2.10.0'
implementation group: 'org.controlsfx', name: 'controlsfx', version: '11.2.1'
implementation group: 'net.sourceforge.pcgen', name: 'PCGen-base', version: '1.0.170'
// The latest Base, but pcgen core would need refactoring to support it.
//implementation group: 'net.sourceforge.pcgen', name: 'PCGen-base', version:'1.0.237'
// Use this if you're working from your local PCGen Base
//implementation files("../pcgen-base/PCGen-base/build/libs/PCgen-base-1.0.jar")
implementation group: 'net.sourceforge.pcgen', name: 'PCGen-Formula', version: '1.0.200'
// The latest Formula, but pcgen core would need refactoring to support it.
//implementation group: 'net.sourceforge.pcgen', name: 'PCGen-Formula', version:'1.0.266'
// Use if you're working from your local PCGen Formula
//implementation files("../pcgen-formula/PCGen-formula/build/libs/PCgen-formula-1.0.jar")
compileOnly group: 'org.jetbrains', name: 'annotations', version:'26.0.0'
compileOnly group: 'com.yuvimasory', name: 'orange-extensions', version: '1.3.0'
compileOnly group: 'com.github.spotbugs', name: 'spotbugs-annotations', version: '4.8.6'
testImplementation group: 'org.junit.platform', name: 'junit-platform-runner', version: '1.11.2'
testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.11.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.11.2'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.11.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.11.2'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '3.0'
testImplementation group: 'org.testfx', name: 'testfx-junit5', version: '4.0.18'
testImplementation group: 'org.testfx', name: 'openjfx-monocle', version: '21.0.2'
testImplementation group: 'org.xmlunit', name: 'xmlunit-matchers', version: '2.10.0'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.13.0'
pmd 'net.sourceforge.pmd:pmd-ant:7.6.0'
pmd 'net.sourceforge.pmd:pmd-java:7.6.0'
}
// Properties to support Ant builds
def antPluginTasks = []
ant.importBuild('build-gradle.xml') {
def (projectName, taskName) = it.tokenize('.')
if (taskName == null && projectName.startsWith("jar") &&
(projectName.endsWith("plugins") || projectName.endsWith("plugin"))) {
antPluginTasks.push(projectName)
}
return it
}
ant.properties['src.java.dir']="code/src/java"
ant.properties['build.classes.dir']="build/classes/java/main"
// All plugins depend on compiled .class files
antPluginTasks.each {
tasks.named(it) {
dependsOn tasks.named("compileJava")
}
}
// Configuration for creating JARs from all of the plugins
configure('jar-all-plugins') {
group = BasePlugin.BUILD_GROUP // Or use 'build'
description = 'Create the plugin jars'
}
ext {
classpath = ""
configurations.runtimeClasspath.each { lib -> classpath += " libs/${lib.name} "}
}
jar {
// Pick up some configuration to JAR up the plugins
it.dependsOn 'jar-all-plugins'
// If we detect duplicate JARs ignore the subsequent ones
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// Create the manifest for the main JAR
manifest {
attributes 'Implementation-Title': 'PCGen', 'Implementation-Version': archiveVersion,
'Main-Class': 'pcgen.system.Main', 'Class-Path': classpath
}
from {
configurations.runtimeClasspath.collect {
it.directory ? it : zipTree(it)
}
}
}
/**
* Create a Java runtime built from Java modules
*/
runtime {
options = ['--compress', 'zip-6'] // Equivalent to the old '2' value pre Java 21
modules = [
'jdk.httpserver',
'java.management',
'java.rmi',
'java.desktop',
'java.xml',
'java.sql',
'jdk.unsupported',
'java.prefs',
'java.logging',
'java.naming',
'jdk.xml.dom',
'jdk.unsupported.desktop',
'java.datatransfer',
'java.scripting',
'jdk.jfr',
'jdk.jsobject',
'javafx.controls',
'javafx.web',
'javafx.swing',
'javafx.fxml',
'javafx.graphics'
]
// We support Mac/Win/Linux x86-64, Mac/Linux aarch64
targetPlatform('linux-x64', layout.projectDirectory.dir("jre/linux/jre_x64").asFile.absolutePath)
targetPlatform('linux-aarch64', layout.projectDirectory.dir("jre/linux/jre_aarch64").asFile.absolutePath)
targetPlatform('windows-x64', layout.projectDirectory.dir("jre/windows/jre_x64").asFile.absolutePath)
targetPlatform('mac-x64', layout.projectDirectory.dir("jre/mac/jre_x64/Contents/Home").asFile.absolutePath)
targetPlatform('mac-aarch64', layout.projectDirectory.dir("jre/mac/jre_aarch64/Contents/Home").asFile.absolutePath)
// Use the jpackage tool that comes with Java to build native installers
jpackage {
def licenseFile = layout.projectDirectory.file("code/LICENSE")
installerOptions = ["--app-version", "${version.replaceAll('-SNAPSHOT', '')}", "--license-file", licenseFile.asFile.absolutePath]
def hostArchitecture = System.getProperty("os.arch")
def osFamily = (Os.isFamily(Os.FAMILY_MAC)
? "mac"
: (Os.isFamily(Os.FAMILY_UNIX)
? "linux"
: (Os.isFamily(Os.FAMILY_WINDOWS) ? "win" : "unknown")))
def targetPlatform = ["x86_64" : "x64",
"amd64" : "x64",
"aarch64" : "aarch64"]
// formats a string such as "mac-aarch64", or "linux-x64"
targetPlatformName = "${osFamily}-${targetPlatform.get(hostArchitecture, "NOT SUPPORTED")}"
if (osFamily == "mac") {
installerOptions += ["--mac-package-identifier", "PcGen", "--mac-package-name", "PcGen"]
resourceDir = layout.projectDirectory.dir("installers/mac-installer").asFile
}
// This may seem weird but there's no LINUX family detection in the OS lib
else if (osFamily == "linux") {
installerOptions += ['--linux-shortcut']
}
imageName = "PcGen"
}
}
// Package up other files with the main program
tasks.named("jpackageImage") {
dependsOn tasks.named("runtime")
doLast {
copy {
includeEmptyDirs = false
from layout.buildDirectory.dir("install/pcgen")
exclude "**/*.exe"
exclude "**/*.bat"
exclude "pcgen"
exclude "**/lib/**"
if (Os.isFamily(Os.FAMILY_MAC)) {
into layout.buildDirectory.dir("jpackage/PcGen.app/Contents/app")
} else {
into layout.buildDirectory.dir("jpackage/PcGen/bin")
}
}
// Mac OS X specific config for jpackage
if (Os.isFamily(Os.FAMILY_MAC)) {
copy {
from layout.projectDirectory.dir("installers/mac-installer")
include "MacDirLauncher"
fileMode 0755
into layout.buildDirectory.dir("jpackage/PcGen.app/Contents/MacOS")
}
ant.replace(file: layout.buildDirectory.file("jpackage/PcGen.app/Contents/Info.plist").get(),
token: "<key>CFBundleExecutable</key>\n <string>PcGen</string>",
value: "<key>CFBundleExecutable</key>\n <string>MacDirLauncher</string>")
}
}
}
// Create the Data Convertor JAR
tasks.register("converterJar", Jar) {
dependsOn jar
manifest {
attributes 'Implementation-Title': 'PCGen Data Converter', 'Implementation-Version': archiveVersion,
'Main-Class': 'pcgen.gui2.converter.PCGenDataConvert', 'Class-Path': 'pcgen.jar' + classpath
}
archiveClassifier.set('batch-convert')
from {
configurations.runtimeClasspath.collect { it.directory ? it : zipTree(it) }
}
from sourceSets.main.output
include 'none'
}
artifacts {
archives converterJar
}
tasks.register("copyToLibs", Copy) {
dependsOn startScripts, distTar, distZip, installDist
mustRunAfter createExe
doFirst {
println("IN copyToLibs")
}
into layout.buildDirectory.dir("libs")
from configurations.runtimeClasspath
}
tasks.register("copyToOutput", Copy) {
dependsOn copyToLibs, createExe, converterJar, jar
doFirst {
println("IN copyToOutput")
}
from layout.buildDirectory.file("libs/pcgen-${version}.jar"),
layout.buildDirectory.file("libs/pcgen-${version}-batch-convert.jar"),
layout.buildDirectory.file("launch4j/pcgen.exe"),
layout.projectDirectory.file("code/pcgen.bat")
from(layout.projectDirectory.file("code/pcgen.sh")) {
filter(FixCrLfFilter, eol:FixCrLfFilter.CrLf.newInstance("lf"))
filePermissions {
unix(0755)
}
}
into outputDir
rename "(.+)-$version(.+)", '$1$2'
}
tasks.register("qbuild", Copy) {
dependsOn copyToOutput, jar
description = "Copy the executable file into 'output' to create a working environment"
from layout.buildDirectory.file("libs/pcgen-${version}.jar")
into outputDir
rename "(.+)-$version(.+)", '$1$2'
mustRunAfter clean
}
tasks.register("cleanOutput", Delete) {
description = "Clean up things copied to the output folder by the build"
delete outputDir
}
// TODO - Hook this into a clean phase properly
tasks.register("cleanJre", Delete) {
description = "Clean up things copied to the jre folder by the build"
delete jresDir
}
// TODO - Hook this into a clean phase properly
tasks.register("cleanMods", Delete) {
description="Clean up things copied to the mods folder by the build"
delete modsDir
}
// Alias tasks
tasks.register("buildonly") {
doFirst {
println("IN buildonly")
}
dependsOn copyToOutput
}
tasks.register("quickbuild") {
dependsOn copyToOutput, test
}
tasks.named("build") {
// TODO reverts the commit f00f99c, because we don't have to generate all artifacts during the build
// dependsOn copyToOutput
// Ensures that clean is never run after build and when clean is called it is
// run before build so it doesn't delete the new build folder.
mustRunAfter clean
}
tasks.register("downloadJRE") {
def major = 21
def archs = ['x64', 'aarch64']
def osList = ['windows', 'mac', 'linux']
doLast {
println("Downloading JDKs for use in creating the runtime bundles.")
osList.each {
def os = "${it}"
def extension = (os == "windows" ? "zip" : "tar.gz")
archs.each {
def arch = "${it}"
// TODO We don't currently support Windows aarch64, but once Eclipse Adoptium does we should remove this line
if (arch == "aarch64" && os == "windows") return
def url = "https://api.adoptium.net/v3/binary/latest/${major}/ga/${os}/${arch}/jdk/hotspot/normal/eclipse"
def jreDownloadDest = layout.projectDirectory.file("jre/${os}/jre_${arch}.${extension}")
def jreDir = layout.projectDirectory.dir("jre/${os}/jre_${arch}").asFile
def jreRelease = (os == "mac"
? layout.projectDirectory.dir("jre/${os}/jre_${arch}/Contents/Home/release").asFile
: layout.projectDirectory.dir("jre/${os}/jre_${arch}/release").asFile)
def outputDir = layout.projectDirectory.dir("jre/${os}/jre_${arch}")
def shouldDownloadJDK = true;
try {
if (jreRelease.exists()) {
def props = new Properties()
jreRelease.withInputStream { props.load(it) }
def javaVersion = StringUtils.strip((String)props.get("JAVA_VERSION"), "\"")
shouldDownloadJDK = !javaVersion.startsWith(major.toString())
println "JDK ${major} ${arch.padLeft(7)} for ${os.padLeft(7)} found with version ${javaVersion} at ${jreDir}, ${shouldDownloadJDK ? "starting" : "skipping"} downloading"
}
} catch (e) {
throw new GradleException("There was an error in :downloadJRE", e)
}
if (!shouldDownloadJDK) {
return
} else if (jreDir.exists()) {
println "Delete the previously downloaded JDK at ${jreDir} as outdated. JavaFX modules will be deleted from jdkDir/jmods."
project.delete(jreDir)
}
println("Downloading Java ${major} ${arch} for ${os} from ${url}")
download.run {
src url
dest jreDownloadDest.asFile.absolutePath
overwrite false
}
layout.projectDirectory.dir("jre/${os}")
.asFileTree
.matching { include "*.${extension}" }
.each { simLib ->
def archFile = layout.projectDirectory.file("jre/${os}/${simLib.name}")
copy {
println "* Unpack $simLib.name to ${outputDir}"
if (extension == "zip") {
from zipTree(archFile)
} else {
from tarTree(archFile)
}
into outputDir
eachFile { FileCopyDetails fcd ->
def relPath = fcd.relativePath
def segments = relPath.segments
fcd.relativePath = new RelativePath(!fcd.isDirectory(), segments[1..-1] as String[])
}
}
project.delete(archFile)
}
file("${projectDir}/jre/${os}/jre_${arch}").list().each { f ->
if (f.startsWith("jdk")) {
file("${projectDir}/jre/${os}/jre_${arch}/" + f).deleteDir()
}
}
}
}
}
}
tasks.register("downloadJavaFXModules") {
mustRunAfter downloadJRE
// We support Windows/Mac/Linux - x64, and Mac/Linux - aarch64
// (JavaFX doesn't support Linux/aarch64 in 21 LTS, use 21.0.1 instead)
def major = project.ext.javaFXVersion
def archs = ['x64', 'aarch64']
def osList = ["windows", "mac", "linux"]
inputs.property("major", major)
doLast {
println("Downloading JavaFX modules (.mods) for use in the runtime bundles.")
// Downloads javafx .mods for custom runtime image. All platforms downloaded
osList.each { os ->
// Build the os part of the filename string. Gluon renamed the mac package to osx
def osPackage = (os == "mac") ? "osx" : os
archs.each { arch ->
// build the architecture part of the download filename string
def archAppend
if (arch == "x64") {
archAppend = "-x64"
} else if (arch == "aarch64" && os != "windows") {
archAppend = "-aarch64"
if (os == "linux") {
major = "21.0.1" // TODO other versions don't supply aarch64 for Linux, use 21.0.1 instead
}
} else {
return
}
// URLs look like this: https://download2.gluonhq.com/openjfx/21.0.2/openjfx-21.0.2_osx-aarch64_bin-jmods.zip
def url = "https://download2.gluonhq.com/openjfx/${major}/openjfx-${major}_${osPackage}${archAppend}_bin-jmods.zip"
def jmodsZip = layout.projectDirectory.file("jre/${os}/jmods${arch}.zip")
// If we don't already have the jmods, download them and unzip them to the correct place.
if (!jmodsZip.asFile.exists()) {
println("Downloading JavaFX mods ${major} ${arch} for ${os} from ${url} to ${projectDir}/jre/${os}/")
download.run {
src url
dest jmodsZip
overwrite false
}
copy {
def zipFile = jmodsZip
def outputDir = (os == "mac")
? "${projectDir}/jre/${os}/jre_${arch}/Contents/Home/jmods"
: "${projectDir}/jre/${os}/jre_${arch}/jmods"
println "Unzipping ${zipFile} to ${outputDir}"
from zipTree(zipFile)
into outputDir
eachFile { fcd ->
def relPath = fcd.relativePath
def segments = relPath.segments
fcd.relativePath = new RelativePath(!fcd.isDirectory(), (segments[1..-1]) as String[])
}
includeEmptyDirs = false
}
} else {
println("* ${jmodsZip} already exists")
}
}
}
}
}
tasks.register("downloadJavaFXLocal", Download) {
description = "Downloads the JavaFX modules for the current platform to the 'mods' directory for local testing"
def supportedOS = [(Os.FAMILY_WINDOWS): "windows",
(Os.FAMILY_MAC) : "osx",
(Os.FAMILY_UNIX) : "linux"]
def osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
def currentOS = supportedOS
.entrySet()
.stream()
.filter(i -> Os.isFamily(i.key))
.map { it.value }
.findFirst()
.orElseThrow { new GradleException("Unsupported OS detected: '${osName}'. Supported families are: ${Os.FAMILY_WINDOWS}, ${Os.FAMILY_MAC} and ${Os.FAMILY_UNIX}") }
def supportedArch = ["x86_64" : "-x64",
"amd64" : "-x64",
"aarch64": "-aarch64"];
def hostArchitecture = System.getProperty("os.arch")
def archAppend = supportedArch[hostArchitecture]
if (archAppend == null) {
throw new GradleException("Unsupported arch detected: '${hostArchitecture}'. Supported architectures are: x86_64, amd64 and aarch64")
}
doFirst {
println("Downloading JavaFX SDK for use in local testing.")
}
def fileName = "openjfx-${project.ext.javaFXVersion}_${currentOS}${archAppend}_bin-sdk.zip"
src "https://download2.gluonhq.com/openjfx/${project.ext.javaFXVersion}/${fileName}"
dest layout.projectDirectory.file("mods/${fileName}")
overwrite false
useETag true
tempAndMove true
}
tasks.register("extractJavaFXLocal", Copy) {
description = "Extracts the JavaFX modules for the current platform to the 'mods' directory for local testing"
dependsOn downloadJavaFXLocal
doFirst {
println "Extracting JavaFX SDK for use in local testing."
}
from zipTree(downloadJavaFXLocal.dest)
into layout.projectDirectory.dir("mods")
eachFile { fcd ->
def relPath = fcd.relativePath
def segments = relPath.segments
fcd.relativePath = new RelativePath(!fcd.isDirectory(), (segments[1..-1]) as String[])
}
includeEmptyDirs = false
}
tasks.named("compileJava") {
dependsOn copyMasterSheets
}
tasks.named("jre") {
dependsOn downloadJRE, downloadJavaFXModules
}
tasks.named("test", Test) {
exclude 'pcgen/testsupport/**'
useJUnitPlatform()
}
tasks.register("itest", Test) {
dependsOn jar
useJUnitPlatform()
testClassesDirs = sourceSets.itest.output.classesDirs
classpath = sourceSets.itest.runtimeClasspath
systemProperties['jar.path'] = jar.getArchiveFile().get().getAsFile()
}
tasks.register("slowtest", Test) {
dependsOn jar, itest
useJUnitPlatform()
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
systemProperties['jar.path'] = jar.getArchiveFile().get().getAsFile()
forkEvery = 1
// Exclude the two suites to avoid duplicate test runs.
exclude 'AllJUnitTests.class'
exclude 'pcgen/core/AllJUnitTests.class'
}
tasks.register("datatest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
include 'pcgen/persistence/lst/DataTest.class'
include 'pcgen/persistence/lst/DataLoadTest.class'
}
tasks.register("inttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/**/*Test.class'
}
tasks.register("sfinttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/game_starfinder/*Test.class'
}
tasks.register("pfinttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/game_pathfinder/*Test.class'
}
tasks.register("rsrdinttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/game_35e/*Test.class'
}
tasks.register("srdinttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/game_3e/*Test.class'
}
tasks.register("msrdinttest", Test) {
dependsOn jar
testClassesDirs = sourceSets.slowtest.output.classesDirs
classpath = sourceSets.slowtest.runtimeClasspath
forkEvery = 1
include 'pcgen/inttest/game_modern/*Test.class'
}
allprojects {
tasks.withType(Javadoc).configureEach {
options.addBooleanOption('Xdoclint:none', true)
}
tasks.withType(Test).configureEach {
maxHeapSize = "1024m"
maxParallelForks = 1
enableAssertions = true
testLogging {
exceptionFormat = 'full'
events 'failed', 'skipped'
}
jvmArgs += [
'-Djava.awt.headless=true',
'-Dtestfx.robot=glass',
'-Dtestfx.headless=true',
'-Dprism.order=sw',
'-Dprism.verbose=true',
'-Djavafx.macosx.embedded=true',
"--module-path", layout.projectDirectory.dir("mods/lib"),
"--add-modules", "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics",
// Needed to fix issue with testfx test crashing due to issue with modularity of whole program. Slightly related issue. https://github.com/TestFX/TestFX/issues/638
'--add-exports', 'javafx.graphics/com.sun.javafx.application=ALL-UNNAMED',
// Next two needed to support monocle testing
'--add-exports', 'javafx.graphics/com.sun.javafx.util=ALL-UNNAMED',
'--add-exports', 'javafx.base/com.sun.javafx.logging=ALL-UNNAMED',
'--add-opens', 'javafx.graphics/com.sun.glass.ui=ALL-UNNAMED',
]
}
tasks.withType(JavaCompile).configureEach {
dependsOn extractJavaFXLocal
options.fork = true
doFirst {
if (name.toLowerCase().contains("test")) {
options.compilerArgs << "--module-path" << layout.projectDirectory.dir("mods/lib").asFile.absolutePath
//options.compilerArgs << "--add-modules" << "javafx.controls,javafx.web,javafx.swing,javafx.fxml" // Not sure why no javafx.graphics here
options.compilerArgs << "--add-modules" << "javafx.controls,javafx.web,javafx.swing,javafx.fxml,javafx.graphics"
}
println "Args for for $name are $options.allCompilerArgs"
}
}
// https://youtrack.jetbrains.com/issue/KT-46165
tasks.withType(Jar).configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
tasks.withType(JavaExec).configureEach {
maxHeapSize = "2048m"
}
}
tasks.named("dependencyUpdates") {
revision = 'release'
resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
if (['atlassian'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
}) {
selection.reject('unofficial release')
}
boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'b', 'ea'].any { qualifier ->
selection.candidate.version ==~ /(?i).*[.-]$qualifier[.\d-+]*/
}
if (rejected) {
selection.reject('Release candidate')
}
if (selection.candidate.version == '2.0.2' && selection.candidate.name == 'xml-apis') {
selection.reject('older than current')
}
if (selection.candidate.version == '2.24' && selection.candidate.name == 'jep') {
selection.reject('older than current')
}
if (selection.candidate.version == '1.8.0_20' && selection.candidate.name == 'openjfx-monocle') {
selection.reject('older than current')
}
}
}
}
}
// Support for creating IntelliJ IDEA files.
idea {
project {
def javafxLib = layout.projectDirectory.dir("mods/lib")
.asFileTree.matching { include "*.jar" }
.files
def projectLibrary = new ProjectLibrary()
projectLibrary.name = "lib"
projectLibrary.classes += javafxLib
projectLibraries += [ projectLibrary ]
}
module {
testSources.from(project.sourceSets.itest.java.srcDirs,
project.sourceSets.slowtest.java.srcDirs)
iml.withXml {
def module = asNode()
def component = module.find {it.@name == 'NewModuleRootManager'}
def orderEntry = component.appendNode('orderEntry', [ type: 'library', scope: 'RUNTIME', name:'lib', level:'project'])
}
}
}
// Use the gradle wrapper
tasks.named("wrapper") {
distributionType = Wrapper.DistributionType.ALL
}
// Bring in the rest of the gradle build config
apply from: 'code/gradle/distribution.gradle'
apply from: 'code/gradle/autobuild.gradle' // depends on distribution.gradle
apply from: 'code/gradle/reporting.gradle'
apply from: 'code/gradle/release.gradle'
tasks.register("allTasks") {
dependsOn build, slowtest, javadoc, buildNsis, allReports
description = "Runs tasks build, slowtest, javadoc, buildNsis and allReports"
}
// TODO This clean is not as nuclear as it perhaps should be.
// For jlink and friends to work when you get odd Zip errors
// you will also need to clean out output/ bin/
// This task is in the end, because other scripts contribute to the building process
tasks.named("clean") {
dependsOn tasks.named("clean-plugins"), cleanOutput, cleanJre, cleanMods, cleanNsis, cleanMasterSheets
doLast {
// Delete a file generated by pluginbuild.xml
project.delete(layout.projectDirectory.file("code/manifest"))
// Delete plugin folders
project.delete(
layout.projectDirectory.dir("plugins/bonusplugins"),
layout.projectDirectory.dir("plugins/converterplugins"),
layout.projectDirectory.dir("plugins/jepplugins"),
layout.projectDirectory.dir("plugins/lstplugins"),
layout.projectDirectory.dir("plugins/outputplugins"),
layout.projectDirectory.dir("plugins/preplugins"),
layout.projectDirectory.dir("plugins/systemlstplugins")
)
}
}