-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.gradle
352 lines (304 loc) · 13 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
plugins {
id 'org.openstreetmap.josm' version '0.8.2'
id 'java'
id 'groovy'
id 'eclipse'
}
repositories {
mavenLocal()
mavenCentral()
}
configurations {
graalvm
}
dependencies {
implementation group: 'org.apache.groovy', name: 'groovy-all', version: project.property('dep.groovy')
implementation group: 'javax.activation', name: 'activation', version: '1.1.1'
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: project.property('dep.mustache')
implementation group: 'com.fifesoft', name: 'rsyntaxtextarea', version: project.property("dep.rsyntaxtextarea")
implementation group: 'org.apache.commons', name: 'commons-compress', version: project.property("dep.commons-compress")
// graalvm
implementation group: 'org.graalvm.sdk', name: 'graal-sdk', version: project.property("dep.graalvm-sdk")
implementation group: 'org.graalvm.truffle', name: 'truffle-api', version: project.property("dep.graalvm-sdk")
implementation group: 'org.graalvm.js', name: 'js', version: project.property("dep.graalvm-sdk")
graalvm group: 'org.graalvm.sdk', name: 'graal-sdk', version: project.property("dep.graalvm-sdk")
graalvm group: 'org.graalvm.truffle', name: 'truffle-api', version: project.property("dep.graalvm-sdk")
graalvm group: 'org.graalvm.js', name: 'js', version: project.property("dep.graalvm-sdk")
packIntoJar group: 'javax.validation', name: 'validation-api', version: '1.0.0.GA'
packIntoJar group: 'javax.activation', name: 'activation', version: '1.1.1'
packIntoJar group: 'com.github.spullara.mustache.java', name: 'compiler', version: project.property('dep.mustache')
packIntoJar group: 'com.fifesoft', name: 'rsyntaxtextarea', version: project.property("dep.rsyntaxtextarea")
packIntoJar group: 'org.apache.commons', name: 'commons-compress', version: project.property("dep.commons-compress")
testImplementation('org.openstreetmap.josm:josm-unittest:latest'){changing=true}
testImplementation group: 'org.jmockit', name: 'jmockit', version: '1.49'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: project.property('dep.jupiter')
testImplementation group: 'org.apache.groovy', name: 'groovy-all', version: project.property('dep.groovy')
testImplementation group: 'org.apache.groovy', name: 'groovy-test', version: project.property('dep.groovy')
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: project.property('dep.jupiter')
testRuntimeOnly group: "org.python", name: "jython", version: "2.7.3"
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
def releases = Releases.fromFile(file("releases.yml"))
def deriveJosmCompileVersion(releases) {
final value = project.hasProperty("plugin.josmCompileVersion")
? project.property("plugin.josmCompileVersion")
: null
def josmCompileVersion
//noinspection GroovyFallthrough
switch (value) {
case null:
josmCompileVersion = "latest"
break
case "latest":
case "tested":
josmCompileVersion = value
break
case "release":
josmCompileVersion = releases.getLastCompatibleJosmVersion()
break
default:
josmCompileVersion = value.isInteger() ? value as Integer : "latest"
}
return josmCompileVersion
}
def configuredJosmCompileVersion = deriveJosmCompileVersion(releases)
logger.info("Compiling for JOSM ${configuredJosmCompileVersion}")
version = releases.currentPluginLabel
base {
archivesName = "scripting"
}
tasks.register('dumpGraalVMJars') {
doLast {
println "GRAALVM_CLASS_PATH=" + configurations.graalvm.asPath
}
}
josm {
josmCompileVersion = configuredJosmCompileVersion
manifest {
minJosmVersion = releases.highestJosmVersion
minJavaVersion = 17
// Old releases up to v0.2.0 have a numeric ID and are available as raw asset from the github repo.
// Newer releases starting from v0.2.0 use semantic versioning and are available as asset from
// a github release.
releases.josmVersions.each {josmVersion ->
final label = releases.highestPluginLabelForJosmVersion(josmVersion)
if (label.isNumber()) {
oldVersionDownloadLink josmVersion, label,
new URL("https://raw.github.com/Gubaer/josm-scripting-plugin/for-josm-$josmVersion/dist/scripting.jar")
} else {
oldVersionDownloadLink josmVersion, label,
new URL("https://github.com/Gubaer/josm-scripting-plugin/releases/download/$label/scripting.jar")
}
}
}
i18n {
copyrightHolder = "Gubaer"
//pathTransformer = getGithubPathTransformer('Gubaer/josm-scripting-plugin')
}
github {
repositoryOwner = project.property("josm.github.user")
repositoryName = project.property("josm.github.repository")
targetCommitish = "master"
}
}
jar {
from("src/main/javascript/v3") {
into("js/v3")
include("**/*.js")
include("**/*.mjs")
}
}
compileJava {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" << "-Werror"
}
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.openstreetmap.josm.plugins.scripting.CheckDownloadUrlsInManifestTask
import org.openstreetmap.josm.plugins.scripting.build.GraalVMDownloadTask
import org.openstreetmap.josm.plugins.scripting.build.Releases
import org.openstreetmap.josm.plugins.scripting.release.PublishToAwsS3Task
import org.openstreetmap.josm.plugins.scripting.release.ShowPublishedPluginTask
import java.nio.file.Files
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
/**
* Replies the 'josm.home' directories used in tests
*/
File josmHomeForTests() {
return new File(project.projectDir, "build/josm.home")
}
final JVM_ARGS = [
'--add-opens', 'java.prefs/java.util.prefs=ALL-UNNAMED',
'--add-exports', 'java.base/sun.security.action=ALL-UNNAMED',
'--add-exports', 'java.desktop/com.sun.imageio.plugins.jpeg=ALL-UNNAMED',
'--add-exports', 'java.desktop/com.sun.imageio.spi=ALL-UNNAMED'
]
/**
* Run unit tests that only depend on the JDK, JOSM, and the plugin.
* Runs on the current stock Java VM and JDK.
*/
test {
useJUnitPlatform()
jvmArgs JVM_ARGS
environment "JOSM_SCRIPTING_PLUGIN_HOME", project.projectDir
systemProperty "josm.home", josmHomeForTests().absolutePath
scanForTestClasses = false
include "org/openstreetmap/josm/plugins/scripting/js/**/*.class"
include "org/openstreetmap/josm/plugins/scripting/model/*.class"
include "org/openstreetmap/josm/plugins/scripting/preferences/graalvm/GraalVMPrivilegesModelTest.class"
include "org/openstreetmap/josm/plugins/scripting/ui/console/*.class"
include "org/openstreetmap/josm/plugins/scripting/esmodules/PathTests.class"
testLogging.events TestLogEvent.FAILED, TestLogEvent.PASSED
}
def getGraalVMHome() {
if (!project.hasProperty("graalvm.jdk")) {
throw new GradleException("Missing mandatory project property 'graalvm.jdk'")
}
def jdk = project.property("graalvm.jdk")
return new File(project.projectDir, "software/graalvm-$jdk")
}
def getGraalVMJavaExecutable() {
return System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows")
? new File(getGraalVMHome(), "bin/java.exe").absolutePath
: new File(getGraalVMHome(), "bin/java").absolutePath
}
/**
* Runs the API V2 JavaScript unit tests with JOSM and GraalJS
* present. The tests are run with a GraalVM 'java' binary.
*/
tasks.register('testScriptApiV3', Test) {
dependsOn "downloadGraalVM"
useJUnitPlatform()
jvmArgs JVM_ARGS
environment "JOSM_SCRIPTING_PLUGIN_HOME", project.projectDir
environment "TEST_COMMONJS_MODULE_REPO",
"${project.projectDir}/src/test/resources/require/modules"
environment "OSM_DEV_API_PASSWORD", System.getenv('OSM_DEV_API_PASSWORD')
executable getGraalVMJavaExecutable()
environment "JAVA_HOME", getGraalVMHome().absolutePath
systemProperty "java.util.logging.config.file", "${project.projectDir}/src/test/resources/logging.properties"
scanForTestClasses = false
include "org/openstreetmap/josm/plugins/scripting/graalvm/api/*.class"
testLogging {
outputs.upToDateWhen { false }
showStandardStreams = true
events TestLogEvent.FAILED, TestLogEvent.PASSED
exceptionFormat = TestExceptionFormat.FULL
}
}
/**
* Runs tests for functionality that tests whether GraalJS is
* present or not. Runs with the current stock Java VM and JDK and makes
* sure that GraalJS/GraalVM isn't present on the classpath.
*/
tasks.register('testGraalVMSupportNotPresent', Test) {
// remove GraalVM from classpath under test
classpath = classpath.filter { !it.toString().toLowerCase().contains("graalvm") }
useJUnitPlatform()
jvmArgs JVM_ARGS
scanForTestClasses = false
include "**/graalvm/GraalVMNotPresentTest.class"
testLogging {
events TestLogEvent.FAILED, TestLogEvent.PASSED
exceptionFormat = TestExceptionFormat.FULL
}
}
/**
* Run unit tests for GraalJS functionality. Run it with the GraalVM java
* executable.
*/
tasks.register('testWithGraalVMJDK', Test) {
dependsOn "downloadGraalVM"
doFirst {
// prepare a suitable 'preferences.xml' for the test cases in this
// executed by this task
def josmHome = josmHomeForTests()
josmHome.mkdirs()
Files.copy(
Paths.get("${project.projectDir}/src/test/resources/josm-test-environments/env01/preferences.xml"),
Paths.get("${josmHome.absolutePath}/preferences.xml"),
StandardCopyOption.REPLACE_EXISTING
)
}
useJUnitPlatform()
jvmArgs JVM_ARGS
environment "JOSM_SCRIPTING_PLUGIN_HOME", project.projectDir
environment "TEST_COMMONJS_MODULE_REPO",
"${project.projectDir}/src/test/resources/require/modules"
systemProperty "josm.home", josmHomeForTests().absolutePath
systemProperty "java.util.logging.config.file", "${project.projectDir}/src/test/resources/logging.properties"
scanForTestClasses = false
// configuration to use GraalVM
executable getGraalVMJavaExecutable()
environment "JAVA_HOME", getGraalVMHome()
scanForTestClasses = false
include "org/openstreetmap/josm/plugins/scripting/graalvm/with_graalvm/*.class"
include "org/openstreetmap/josm/plugins/scripting/graalvm/esmodule/*.class"
include "org/openstreetmap/josm/plugins/scripting/graalvm/*.class"
exclude "org/openstreetmap/josm/plugins/scripting/graalvm/GraalVMNotPresentTest.class"
include "org/openstreetmap/josm/plugins/scripting/esmodules/ESModuleUsageTest.class"
testLogging {
events TestLogEvent.FAILED, TestLogEvent.PASSED
exceptionFormat = TestExceptionFormat.FULL
}
}
/**
* Run tests on a stock JDK with the groovy and python scripting
* engines present.
*/
tasks.register('testJSR223EnginePresent', Test) {
useJUnitPlatform()
jvmArgs JVM_ARGS
// groovy and python are on the classpath
scanForTestClasses = false
include "org/openstreetmap/josm/plugins/scripting/jsr223/JSR223CompatibleEnginePresentTest.class"
testLogging {
events TestLogEvent.FAILED, TestLogEvent.PASSED
exceptionFormat = TestExceptionFormat.FULL
}
}
//tasks.check.dependsOn(tasks.testScriptApiV1)
tasks.check.dependsOn(tasks.testScriptApiV3)
tasks.check.dependsOn(tasks.testGraalVMSupportNotPresent)
tasks.check.dependsOn(tasks.testJSR223EnginePresent)
tasks.check.dependsOn(tasks.testWithGraalVMJDK)
sourceSets {
test {
java.srcDirs = [
"src/test/unit/java",
"src/test/functional/java",
"src/test/common/java"
]
groovy.srcDirs = [
"src/test/unit/groovy",
"src/test/functional/groovy"
]
}
}
processResources {
from "$projectDir/README.md"
from "$projectDir/LICENSE"
}
tasks.register("downloadGraalVM", GraalVMDownloadTask)
tasks.register("checkDownloadUrls", CheckDownloadUrlsInManifestTask)
tasks.register("showPublishedPluginInfo", ShowPublishedPluginTask)
tasks.register("publishToAwsS3", PublishToAwsS3Task)
publishToGithubRelease {
remoteJarName = "scripting.jar"
}
// tasks.withType(Test).configureEach {
// def testJdkVersion = System.getenv("TEST_JDK_VERSION") ?: "17"
// if (testJdkVersion == "17") {
// javaLauncher = javaToolchains.launcherFor {
// languageVersion = JavaLanguageVersion.of(17)
// }
// } else if (testJdkVersion == "21") {
// javaLauncher = javaToolchains.launcherFor {
// languageVersion = JavaLanguageVersion.of(21)
// }
// } else {
// throw new GradleException("Invalid TEST_JDK_VERSION: ${testJdkVersion}. Must be 17 or 21.")
// }
// }