-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle.kts
87 lines (82 loc) · 2.91 KB
/
build.gradle.kts
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
import java.awt.GraphicsEnvironment
plugins {
java
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(
file("Dockerfile")
.readLines()
.first { it.contains("FROM") }
.substringAfter("eclipse-temurin:")
.toInt()
)
}
}
repositories { mavenCentral() }
dependencies {
implementation(libs.bundles.alchemist.sapere.tutorial)
}
val alchemistGroup = "Run Alchemist"
/*
* This task creates a Jar file containing a description of the classpath, in order to prevent the java command
* to be too long for the host OS to be executed.
*/
val classpathJar by tasks.register<Jar>("classpathJar") {
group = alchemistGroup
description = "Creates a jar file with a manifest pointing to all the jar resources needed for the runtime"
archiveClassifier.set("classpath")
doFirst {
manifest {
val classpath = sourceSets["main"].runtimeClasspath.files
.filter { it.isFile && it.extension == "jar" }
.joinToString(separator = " ", prefix = " ") { it.absolutePath }
attributes("Class-Path" to classpath)
}
}
}
/*
* This task is used to run all experiments in sequence
*/
val runAll by tasks.register<DefaultTask>("runAll") {
group = alchemistGroup
description = "Launches all simulations"
}
val isInCI = System.getenv("CI") == "true"
/*
* Scan the folder with the simulation files, and create a task for each one of them.
*/
File(rootProject.rootDir.path + "/src/main/yaml").listFiles()
?.filter { it.name.matches(Regex("""\d{2}-.*\.yml""")) }
?.sortedBy { it.nameWithoutExtension }
?.forEach {
val task by tasks.register<JavaExec>(it.nameWithoutExtension) {
group = alchemistGroup
description = "Launches simulation ${it.nameWithoutExtension}"
mainClass.set("it.unibo.alchemist.Alchemist")
classpath = sourceSets["main"].runtimeClasspath
args("run", it.absolutePath)
// checks if the environment is headless
if (!(GraphicsEnvironment.isHeadless() || isInCI)) {
args(
"--override",
"""
monitors:
type: SwingGUI
parameters:
graphics: effects/${it.nameWithoutExtension}.json
failOnHeadless: true
launcher:
parameters:
auto-start: $isInCI
""".trimIndent()
)
}
if (isInCI) {
args("--override", "terminate: { type: AfterTime, parameters: 10 }")
}
}
// task.dependsOn(classpathJar) // Uncomment to switch to jar-based cp resolution
runAll.dependsOn(task)
}
?: error("Cannot list simulation files")