-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
314 lines (276 loc) · 11.3 KB
/
Copy pathbuild.gradle
File metadata and controls
314 lines (276 loc) · 11.3 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
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
import java.nio.file.Files
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.openjfx.gradle.JavaFXPlatform
plugins {
id "java"
id "application"
id "com.gradleup.shadow" version "9.4.2"
id "org.openjfx.javafxplugin" version "0.1.0"
}
project.group = "de.hhu.stups"
project.version = "1.4.0-SNAPSHOT"
final isSnapshot = project.version.endsWith("-SNAPSHOT")
tasks.named("test", Test) {
useJUnitPlatform()
systemProperty("logback.configurationFile", "de/prob/logging/production.xml")
testLogging {
exceptionFormat = 'full'
}
}
final snapshotsRepoUrl = "https://central.sonatype.com/repository/maven-snapshots/"
repositories {
mavenCentral()
if (isSnapshot) {
maven {
name = "Sonatype snapshots"
url = snapshotsRepoUrl
}
}
}
java {
sourceCompatibility = JavaVersion.VERSION_21
}
// 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).configureEach {
options.encoding = "UTF-8"
options.release = Integer.parseInt(java.sourceCompatibility.toString())
}
configurations.configureEach {
resolutionStrategy.cacheChangingModulesFor(0, 'seconds')
resolutionStrategy.cacheDynamicVersionsFor(0, 'seconds')
}
dependencies {
implementation("ch.qos.logback:logback-classic:1.6.3")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-guava")
implementation("com.google.guava:guava:33.7.1-jre")
implementation("commons-cli:commons-cli:1.11.0")
implementation(platform("de.hhu.stups:prob-java-bom:4.16.1"))
implementation("de.hhu.stups:de.prob2.kernel")
implementation("de.hhu.stups:voparser:0.3.0")
implementation("de.hhu.stups:xml2b:1.2.0")
implementation("de.hhu.stups:railml2b:1.0.0")
implementation("io.github.java-diff-utils:java-diff-utils:4.17")
implementation("jakarta.annotation:jakarta.annotation-api:3.0.0")
implementation("org.apache.commons:commons-csv:1.14.1")
implementation("org.apache.commons:commons-math3:3.6.1")
implementation("org.apache.velocity:velocity-engine-core:2.4.1")
implementation("org.controlsfx:controlsfx:11.2.4")
implementation("org.fxmisc.richtext:richtextfx:0.11.4")
implementation("se.sawano.java:alphanumeric-comparator:2.0.0")
// nsmenufx indirectly requires the jna:5.9.0:jpms dependency
// appdirs 1.2.2+ indirectly requires jna:5.13+, but the jpms classifier does not exist for jna 5.13+
// so we manually fix that
implementation("net.harawata:appdirs:1.5.0") {
exclude(group: "net.java.dev.jna")
}
implementation("de.jangassen:nsmenufx:3.1.0") {
exclude(group: "net.java.dev.jna")
}
implementation("net.java.dev.jna:jna-platform:5.19.1")
testImplementation(platform("org.junit:junit-bom:5.14.4"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
final osArch = System.getProperty("os.arch")
javafx {
version = "23.0.2"
modules = [
"javafx.base",
"javafx.controls",
"javafx.fxml",
"javafx.graphics",
"javafx.swing",
"javafx.web",
]
}
final generatedResourcesDir = layout.buildDirectory.dir("generated-src/main/resources").get().asFile
sourceSets {
main {
resources {
srcDir(generatedResourcesDir)
}
}
}
// This is the shortest recommended way to access ExecOperations.exec :(
// The other alternative is to create a dedicated class for each task that needs exec,
// which is even less convenient...
// https://docs.gradle.org/current/userguide/service_injection.html#execoperations
interface InjectedExecOperations {
@Inject
ExecOperations getExecOperations()
}
final execOperations = objects.newInstance(InjectedExecOperations).execOperations
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"
tasks.register("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()
execOperations.exec {
executable = "pandoc"
args = [
"--from=gfm",
"--to=html",
"--metadata=title=${title}",
"--standalone",
"--lua-filter=${helpFilterLuaScript}",
"--output=${outputFile}",
"${inputFile}",
]
}
}
}
}
final firstLineOfProcessOutput = {ExecOutput execOutput ->
return execOutput.standardOutput.asText.map {it.split('\n')[0]}
}
tasks.named("processResources", ProcessResources) {
dependsOn("createHelp")
inputs.property("version", project.version)
inputs.property("currentGitBranch", firstLineOfProcessOutput(providers.exec {
executable = "git"
args = ["rev-parse", "--abbrev-ref", "HEAD"]
}))
inputs.property("currentGitCommit", firstLineOfProcessOutput(providers.exec {
executable = "git"
args = ["rev-parse", "HEAD"]
}))
filesMatching("de/prob2/ui/build.properties") {
expand(
version: inputs.properties["version"],
branch: inputs.properties["currentGitBranch"],
commit: inputs.properties["currentGitCommit"],
)
}
}
tasks.named("jar", Jar) {
manifest {
attributes([
"Add-Exports": exports.join(" "),
"Add-Opens": opens.join(" "),
])
}
}
final probBinariesByOs = [
(OperatingSystemFamily.WINDOWS): "windows64",
(OperatingSystemFamily.MACOS): "macos",
(OperatingSystemFamily.LINUX): "linux64",
].collectEntries {k, v -> [(k): "de/prob/cli/binaries/probcli_${v}.zip".toString()]}
tasks.named("shadowJar", ShadowJar) {
// Set the classifier depending on the current platform to make it clear that this jar is platform-specific.
if (javafx.platform == JavaFXPlatform.OSX) { // This is x86_64 macOS specifically! aarch64 macOS would be JavaFXPlatform.OSX_AARCH64.
// The JavaFX classifier for x86_64 Mac builds is simply "mac".
// Change it to "mac-x86_64" to be explicit and for consistency with "mac-aarch64".
archiveClassifier = "mac-" + osArch
} else {
archiveClassifier = javafx.platform.classifier
}
// 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 != javafx.platform.osFamily}.values())
}
if (project.hasProperty("probHome")) {
allprojects {
tasks.withType(JavaForkOptions).configureEach {
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!
tasks.register("jpackage", Exec) {
dependsOn 'shadowJar'
// Show jpackage --verbose output only if running Gradle with --info (or higher)
logging.captureStandardOutput(LogLevel.INFO)
final applicationName = "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(),
"--name", applicationName,
"--app-version", applicationVersion,
"--copyright", "Heinrich Heine University Düsseldorf, Lehrstuhl für Softwaretechnik und Programmiersprachen 2025",
"--vendor", "Heinrich Heine University Düsseldorf, Lehrstuhl für Softwaretechnik und Programmiersprachen",
"--license-file", "LICENSE",
]
if (javafx.platform.osFamily == OperatingSystemFamily.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 (javafx.platform.osFamily == OperatingSystemFamily.MACOS) {
args += [
//"--mac-sign", "--mac-signing-key-user-name", "Michael Leuschel (794LFG5T52)",
//"--mac-package-identifier", "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 (javafx.platform.osFamily == OperatingSystemFamily.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: ${javafx.platform.osFamily} (expected WINDOWS, MACOS, or LINUX)")
}
}