-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
379 lines (332 loc) · 14.1 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
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.nio.file.Files
plugins {
id "java"
id "application"
id "com.gradleup.shadow" version "8.3.3"
id "com.google.osdetector" version "1.7.3"
id "org.openjfx.javafxplugin" version "0.1.0"
}
project.group = "de.hhu.stups"
project.version = "1.2.2-SNAPSHOT"
final isSnapshot = project.version.endsWith("-SNAPSHOT")
if (project != rootProject) {
throw new GradleException(
"""\
The prob2-ui Gradle build cannot be included as a subproject.
If you are writing a plugin and need to reference the prob2-ui code as a dependency, replace the include statement in your settings.gradle with an includeBuild statement:
includeBuild "${rootProject.relativePath(project.projectDir)}"
And replace the project(":prob2-ui") dependency in your build.gradle with a compileOnly dependency:
dependencies {
compileOnly group: "${project.group}", name: "${project.name}", version: "${project.version}"
}
""".stripIndent()
)
}
test {
useJUnitPlatform()
systemProperty("logback.configurationFile", "de/prob/logging/production.xml")
testLogging {
exceptionFormat = 'full'
}
}
repositories {
mavenCentral()
if (isSnapshot) {
maven {
name "sonatype snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots"
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_17
}
// Module export/open declarations for Java 9+
def exports = [
// So the documentation generator Velocity templates can call JavaFX collection methods
"javafx.base/com.sun.javafx.collections",
]
def opens = []
// Uncomment when getting WebView console messages with com.sun.javafx.webkit.WebConsoleListener
// (see the corresponding commented out code in StageManager.initWebView).
//exports += ["javafx.web/com.sun.javafx.webkit"]
application {
// Our actual application class is de.prob2.ui.ProB2.
// See the Javadoc of de.prob2.ui.Main for an explanation of why this extra class is necessary.
mainClass = "de.prob2.ui.Main"
applicationDefaultJvmArgs += exports.collect { "--add-exports=${it}=ALL-UNNAMED".toString() }
applicationDefaultJvmArgs += opens.collect { "--add-opens=${it}=ALL-UNNAMED".toString() }
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = Integer.parseInt(java.sourceCompatibility.toString())
}
configurations {
// These configurations are used by the multi-platform jar build.
// Each OS needs its own configuration - otherwise Gradle complains about conflicts between different OS versions of the same dependency.
javafxWin {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, OperatingSystemFamily.WINDOWS))
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, MachineArchitecture.X86_64))
}
}
javafxMac {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, OperatingSystemFamily.MACOS))
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, MachineArchitecture.X86_64))
}
}
javafxMacArm {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, OperatingSystemFamily.MACOS))
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, MachineArchitecture.ARM64))
}
}
javafxLinux {
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME))
attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, OperatingSystemFamily.LINUX))
attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, MachineArchitecture.X86_64))
}
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor(0, 'seconds')
resolutionStrategy.cacheDynamicVersionsFor(0, 'seconds')
}
dependencies {
implementation group: "ch.qos.logback", name: "logback-classic", version: "1.4.14"
implementation group: "com.fatboyindustrial.gson-javatime-serialisers", name: "gson-javatime-serialisers", version: "1.1.2"
implementation group: "com.google.code.gson", name: "gson", version: "2.11.0"
implementation group: "com.google.guava", name: "guava", version: "33.3.1-jre"
implementation group: "io.github.java-diff-utils", name: "java-diff-utils", version: "4.12"
implementation group: "commons-cli", name: "commons-cli", version: "1.9.0"
implementation group: "de.jangassen", name: "nsmenufx", version: "3.1.0"
implementation(platform(group: "de.hhu.stups", name: "prob-java-bom", version: "4.13.2-SNAPSHOT"))
implementation group: "de.hhu.stups", name: "de.prob2.kernel"
implementation group: "de.hhu.stups", name: "voparser", version: "0.3.0-SNAPSHOT"
// cannot update to 1.2.2 as this breaks nsmenufx due to a transitive dependency on jna
implementation group: "net.harawata", name: "appdirs", version: "1.2.1"
implementation group: "org.controlsfx", name: "controlsfx", version: "11.2.1"
implementation group: "org.fxmisc.richtext", name: "richtextfx", version: "0.11.3"
implementation group: "org.pf4j", name: "pf4j", version: "3.12.0"
implementation group: "se.sawano.java", name: "alphanumeric-comparator", version: "1.4.1"
implementation group: "org.apache.commons", name: "commons-csv", version: "1.12.0"
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
implementation group: 'org.apache.velocity', name: 'velocity-engine-core', version: '2.4'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-guava'
testImplementation platform('org.junit:junit-bom:5.11.1')
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter'
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-launcher'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.14.1'
}
final osArch = System.getProperty("os.arch")
final javafxVersion = "22.0.2"
final javafxModules = [
"javafx.base",
"javafx.controls",
"javafx.fxml",
"javafx.graphics",
"javafx.media",
"javafx.swing",
"javafx.web",
]
javafx {
version = javafxVersion
modules = javafxModules
configurations += ["javafxWin", "javafxMac", "javafxMacArm", "javafxLinux"]
}
final generatedResourcesDir = layout.buildDirectory.dir("generated-src/main/resources").get().asFile
sourceSets {
main {
resources {
srcDir(generatedResourcesDir)
}
}
}
final helpSourceDir = file("src/main/helpsources")
final helpSourceFiles = fileTree(dir: helpSourceDir, include: ["**/*.md"])
final helpOutputDir = new File(generatedResourcesDir, "de/prob2/ui/helpsystem/helppages")
final helpFilterLuaScript = "pandoc_links_to_html.lua"
task createHelp {
inputs.file(helpFilterLuaScript)
inputs.files(helpSourceFiles)
outputs.dir(helpOutputDir)
doLast {
delete(helpOutputDir)
helpSourceFiles.each {inputFile ->
final title = inputFile.name.replaceAll(/\.md$/, '')
final relativePath = helpSourceDir.toPath().relativize(inputFile.toPath())
final relativePathWithNewExtension = relativePath.parent.resolve(relativePath.fileName.toString().replaceAll(/\.md$/, ".html"))
final outputFile = helpOutputDir.toPath().resolve(relativePathWithNewExtension).toFile()
outputFile.parentFile.mkdirs()
exec {
executable = "pandoc"
args = [
"--from=gfm",
"--to=html",
"--metadata=title=${title}",
"--standalone",
"--lua-filter=${helpFilterLuaScript}",
"--output=${outputFile}",
"${inputFile}",
]
}
}
}
}
processResources.dependsOn(createHelp)
def readCurrentGitBranch() {
def proc = ["git", "rev-parse", "--abbrev-ref", "HEAD"].execute(null, project.projectDir)
def exitCode = proc.waitFor()
if (exitCode != 0) {
throw new IllegalStateException("git rev-parse command exited with status code ${exitCode}:\n" + proc.err.readLines().join("\n"))
}
return proc.in.readLines()[0]
}
def readCurrentGitCommit() {
def proc = ["git", "rev-parse", "HEAD"].execute(null, project.projectDir)
def exitCode = proc.waitFor()
if (exitCode != 0) {
throw new IllegalStateException("git rev-parse command exited with status code ${exitCode}:\n" + proc.err.readLines().join("\n"))
}
return proc.in.readLines()[0]
}
processResources {
filesMatching("de/prob2/ui/build.properties") {
expand(version: project.version, branch: readCurrentGitBranch(), commit: readCurrentGitCommit())
}
}
jar {
manifest {
attributes([
"Add-Exports": exports.join(" "),
"Add-Opens": opens.join(" "),
])
}
}
final probBinariesByOs = [
"windows": "windows64",
"osx": "macos",
"linux": "linux64",
].collectEntries {k, v -> [(k): "de/prob/cli/binaries/probcli_${v}.zip".toString()]}
shadowJar {
// Set the classifier depending on the current OS to make it clear that this jar is platform-specific.
// This code converts the OS names to the format used by the OpenJFX Maven artifacts (this isn't necessary, but it's more consistent this way).
if (osdetector.os == "osx") {
// Include architecture for Mac builds to distinguish x86_64 and aarch64.
archiveClassifier = "mac-" + osArch
} else if (osdetector.os == "windows") {
archiveClassifier = "win"
} else {
archiveClassifier = osdetector.os
}
// Exclude all probcli zips that are not for the current platform.
// It's safer to do this with an exclude rule that lists all resources that we know we don't want.
// This way nothing will break if ProB 2 adds new resources that shouldn't be excluded.
exclude(probBinariesByOs.findAll {k, v -> k != osdetector.os}.values())
}
task multiPlatformShadowJar(type: ShadowJar) {
manifest {
inheritFrom(jar.manifest)
attributes([
"Main-Class": application.mainClass.get(),
"Multi-Release": "true",
])
}
archiveClassifier = "multi"
from(sourceSets.main.output)
configurations = [
project.configurations.runtimeClasspath,
project.configurations.javafxWin,
project.configurations.javafxMac,
project.configurations.javafxMacArm,
project.configurations.javafxLinux,
]
}
if (project.hasProperty("probHome")) {
allprojects {
tasks.withType(JavaForkOptions) {
delegate.systemProperties["prob.home"] = project.probHome
}
}
}
// Assumes that the correct version of jpackage is on the PATH.
// This task does not respect JAVA_HOME or other non-default JDK locations!
task jpackage(type: Exec) {
// Use single-platform shadowJar
dependsOn 'shadowJar'
// Show jpackage --verbose output only if running Gradle with --info (or higher)
logging.captureStandardOutput(LogLevel.INFO)
final applicationName = "ProB 2 UI"
final applicationNameNoSpaces = "ProB2-UI"
// Some platforms (Windows, macOS) require that versions follow a strict x.y.z format and don't allow string components like SNAPSHOT.
final applicationVersion = project.version.replaceAll(/-SNAPSHOT/, "")
final jpackageFilesDir = file("src/main/jpackage")
final jpackageIconsDir = new File(jpackageFilesDir, "icons")
final jpackageLaunchersDir = new File(jpackageFilesDir, "launchers")
final shadowJarFile = shadowJar.archiveFile.get().asFile
final destinationDir = base.distsDirectory.get().asFile
executable = "jpackage"
args = [
"--verbose",
"--dest", destinationDir,
"--input", shadowJarFile.parent,
"--main-jar", shadowJarFile.name, // file name given to --main-jar is relative to the path given to --input
'--main-class', application.mainClass.get(),
// When targetting Linux, jpackage doesn't handle spaces in the application name correctly.
"--name", osdetector.os == "linux" ? applicationNameNoSpaces : applicationName,
"--app-version", applicationVersion,
"--copyright", "Heinrich-Heine-University, Institut für Softwaretechnik und Programmiersprachen 2023",
"--vendor", "Heinrich-Heine-University, Institut für Softwaretechnik und Programmiersprachen",
"--license-file", "LICENSE",
]
if (osdetector.os == "windows") {
args += [
"--icon", new File(jpackageIconsDir, "prob2-ui.ico"),
"--win-dir-chooser",
"--win-menu",
"--win-menu-group", applicationName,
"--win-upgrade-uuid", "9e004b84-41c5-4c95-8aca-32ac44063ef9",
// The Windows application by default runs without a console,
// which makes it impossible to see stdout/stderr output
// (even when launched from an existing console window).
// There is an option to make the launcher a console application,
// which make stdout/stderr visible,
// but this also makes a console window appear when the application is launched from the GUI,
// which is usually not the desired behavior.
// So we leave the main launcher as a non-console application
// and add an alternative console launcher that can be used to see stdout/stderr output.
"--add-launcher", "${applicationName} (with console)=" + new File(jpackageLaunchersDir, "windows_console.properties"),
]
} else if (osdetector.os == "osx") {
args += [
//"--mac-sign", "--mac-signing-key-user-name", "Michael Leuschel (794LFG5T52)",
//"--mac-package-signing-prefix", "de.prob2.ui",
"--icon", new File(jpackageIconsDir, "prob2-ui.icns")
]
doLast {
// Include architecture in file name for Mac builds to distinguish x86_64 and aarch64.
// This needs to be done manually afterwards,
// because jpackage doesn't allow changing the output file name without also changing the displayed application name.
final originalPath = destinationDir.toPath().resolve("${applicationName}-${applicationVersion}.dmg")
final renamedPath = originalPath.resolveSibling("${applicationName}-${osArch}-${applicationVersion}.dmg")
Files.move(originalPath, renamedPath)
}
} else if (osdetector.os == "linux") {
args += [
"--icon", new File(jpackageIconsDir, "prob2-ui.png"),
// This corresponds to the Categories key in the generated .desktop file.
// For a list of standard categories, see:
// https://specifications.freedesktop.org/menu-spec/latest/apa.html
"--linux-menu-group", "ComputerScience;Development;IDE;Java;Science;",
"--linux-deb-maintainer", "Michael.Leuschel@hhu.de",
]
} else {
throw new GradleException("Unsupported OS: ${osdetector.os} (expected windows, osx, or linux)")
}
}