forked from ion-fusion/fusion-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
345 lines (268 loc) · 10.4 KB
/
build.gradle.kts
File metadata and controls
345 lines (268 loc) · 10.4 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
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
// Copyright Ion Fusion contributors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
version = "0.38a1-SNAPSHOT"
// Docs for how Maven compares version labels:
// https://maven.apache.org/pom.html#Dependency_Version_Requirement_Specification
// I find that nearly incomprehensible, while this blog post is more useful:
// https://octopus.com/blog/maven-versioning-explained
// Gradle's algorithm is different, and easier to understand:
// https://docs.gradle.org/8.10.2/userguide/single_versions.html#version_ordering
// https://docs.gradle.org/8.10.2/userguide/dependency_resolution.html#sec:base-version-comparison
// WARNING: replacing -SNAPSHOT with -a1 (or even -rc) gives an *earlier*
// version according to both algorithms. Proactively including the `a1` preserves
// our ability to release an alpha that will properly sort *after* its snapshots.
plugins {
java
application
jacoco
}
repositories {
mavenCentral()
}
dependencies {
implementation("com.amazon.ion:ion-java:1.11.9")
// TODO This shouldn't be needed when consumers embed Fusion.
// It's a build-time dependency, but here b/c consumers use the CLI to
// generate their docs. That should be handled by a plugin instead.
implementation("org.markdownj:markdownj:0.3.0-1.0.2b4")
// https://junit.org/junit5/docs/current/user-guide/#running-tests-build-gradle-bom
testImplementation(platform("org.junit:junit-bom:5.11.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.hamcrest:hamcrest:3.0")
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
withJavadocJar()
}
// Default output paths, hard-coded because the DSL doesn't seem to expose them.
val docsDir = layout.buildDirectory.dir("docs")
val libsDir = layout.buildDirectory.dir("libs")
val reportsDir = layout.buildDirectory.dir("reports")
// New output paths for Fusion code coverage.
val fcovDataDir = layout.buildDirectory.dir("fcov")
val fcovReportDir = reportsDir.get().dir("fcov")
// Various resources refer to the current version label.
tasks.processResources {
// Embed our version in the jar so the CLI can print it.
expand("project_version" to project.version.toString())
}
// Bundle the Fusion bootstrap repository in our jar.
tasks.jar {
// It might be better if these were modeled as resources in the main
// sourceSet, so they are automatically added to the classpath when testing.
// It's unclear how to change the parent directory that way.
into("FUSION-REPO") {
from(layout.projectDirectory.dir("fusion"))
exclude("**/*.md")
includeEmptyDirs = true
}
}
//=============================================================================
// Tests
tasks.test {
// dev.ionfusion.fusion.ClassLoaderModuleRepositoryTest uses ftst-repo.jar.
dependsOn(ftstRepo)
useJUnitPlatform()
// Collect Fusion coverage data IFF a report is being generated.
mustRunAfter(fcovConfigure)
inputs.dir(layout.projectDirectory.dir("ftst"))
jvmArgumentProviders.add {
if (fcovRunning) {
logger.lifecycle("Enabling Fusion code coverage instrumentation")
listOf("-Ddev.ionfusion.fusion.coverage.DataDir=" + fcovDataDir.get().asFile.path)
}
else {
listOf()
}
}
}
val ftstRepo = tasks.register<Jar>("ftstRepo") {
destinationDirectory = libsDir
archiveFileName = "ftst-repo.jar"
into("FUSION-REPO") {
from(layout.projectDirectory.dir("ftst/repo"))
includeEmptyDirs = true
}
}
// We rely on Gradle defaults to invoke unit tests in the `test` suite.
// Here, we define a separate test suite for checking the content of our
// distribution archives. This is effectively testing our Gradle build logic.
// This approach is incubating; expect changes.
// https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html
testing {
suites {
// This test suite ensures the distribution is functional.
register<JvmTestSuite>("testDist") {
dependencies {
// Docs claim that Jupiter is configured by default, but these
// are all necessary.
implementation(platform("org.junit:junit-bom:5.11.3"))
implementation("org.junit.jupiter:junit-jupiter")
implementation("org.hamcrest:hamcrest:3.0")
implementation("org.htmlunit:htmlunit:4.12.0")
// Provide access to utility classes from src/test
implementation(sourceSets.test.get().runtimeClasspath)
}
// "Future iterations of the plugin will allow defining multiple
// targets based other attributes, such as a particular JDK runtime."
targets {
all {
testTask.configure {
// Install the tarball so we can test it.
dependsOn(tasks.installDist)
// If unit tests are running, complete them first.
shouldRunAfter(tasks.test)
}
}
}
}
}
}
tasks.named("check") {
dependsOn(testing.suites.named("testDist"))
}
//=============================================================================
// Code Coverage
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
jacoco {
// Do this to keep JaCoCo version stable when updating Gradle.
// As of Gradle 8.10, the default is:
// toolVersion = "0.8.12"
}
tasks.test {
configure<JacocoTaskExtension> {
// When running in IDEA, JaCoCo instruments HTMLUnit (and fails).
// I don't know why it's instrumenting libraries, but this avoids it.
includes = listOf("dev.ionfusion.*")
}
}
tasks.jacocoTestReport {
// We don't dependOn distTest; that tests the packaging not the product.
dependsOn(tasks.test)
}
tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.75".toBigDecimal()
}
}
}
}
tasks.check {
dependsOn(tasks.jacocoTestCoverageVerification)
}
// TODO Clean fcovDataDir somewhere
val fcovConfigure = tasks.register<WriteProperties>("fcovConfigure") {
destinationFile = fcovDataDir.get().file("config.properties")
property("IncludedModules", "/fusion")
// Enable this if you want to check that tests are being run.
// TODO Figure out why this causes report generation to fail.
// property("IncludedSources", "ftst")
}
// Name is ick but mirrors jacocoTestReport
val fcovTestReport = tasks.register<JavaExec>("fcovTestReport") {
dependsOn(fcovConfigure, tasks.test)
group = "verification"
description = "Generates Fusion code coverage report"
classpath = sourceSets["main"].runtimeClasspath
mainClass = "dev.ionfusion.fusion.cli.Cli"
args = listOf("report_coverage",
fcovDataDir.get().asFile.path,
fcovReportDir.asFile.path)
enableAssertions = true
}
// Signal to test task to collect coverage data.
var fcovRunning = false
gradle.taskGraph.whenReady {
fcovRunning = hasTask(fcovTestReport.get())
}
//=============================================================================
// Documentation
tasks.javadoc {
exclude("**/_Private_*",
"**/_private/**",
"dev/ionfusion/fusion/cli",
"dev/ionfusion/fusion/util/hamt/**")
title = "FusionJava API Reference"
options {
// https://github.com/gradle/gradle/issues/7038
this as StandardJavadocDocletOptions
docEncoding = "UTF-8"
overview = "$projectDir/src/main/java/overview.html"
header = "FusionJava API Reference"
bottom = "<center>Copyright Ion Fusion contributors. All Rights Reserved.</center>"
}
}
val fusiondocDir = docsDir.get().dir("fusiondoc")
tasks.register<JavaExec>("fusiondocGen") {
classpath = sourceSets["main"].runtimeClasspath
mainClass = "dev.ionfusion.fusion.cli.Cli"
args = listOf("document", fusiondocDir.asFile.path, "fusion")
enableAssertions = true
inputs.dir(layout.projectDirectory.dir("fusion"))
outputs.dir(fusiondocDir)
}
val fusiondoc by tasks.register<Copy>("fusiondoc") {
group = "Documentation"
description = "Generates Fusion language and library documentation."
dependsOn("fusiondocGen")
// Copy Favicon and CSS from `doc` directory.
into(fusiondocDir)
from(layout.projectDirectory.dir("doc"))
exclude("**/*.md")
includeEmptyDirs = false
}
//=============================================================================
// Distribution
// https://docs.gradle.org/current/userguide/application_plugin.html#sec:the_distribution
distributions {
main {
contents {
tasks.distTar {
dependsOn("fusiondoc", "javadoc")
}
tasks.distZip {
dependsOn("fusiondoc", "javadoc")
}
tasks.installDist {
dependsOn("fusiondoc", "javadoc")
}
// TODO JavaDocs should be beside, not inside, the Fusion docs.
// https://github.com/ion-fusion/fusion-java/issues/204
into("docs") {
from(fusiondocDir)
}
into("docs") {
from(docsDir).include("javadoc/**")
}
}
}
}
tasks {
// It took a loooong time to figure out how to access APP_HOME.
// https://discuss.gradle.org/t/42870/4
// https://stackoverflow.com/questions/22153041?rq=3
// It's still not entirely working: `gradle run` doesn't see the replaced script.
startScripts {
doLast {
unixScript.writeText(unixScript.readText().replace("{{APP_HOME}}", "'\${APP_HOME}'"))
windowsScript.writeText(windowsScript.readText().replace("{{APP_HOME}}", "%APP_HOME%"))
}
}
}
application {
applicationName = "fusion"
mainClass.set("dev.ionfusion.fusion.cli.Cli")
// This is unused today, but is likely to be useful and it was hard to do.
applicationDefaultJvmArgs = listOf("-Ddev.ionfusion.fusion.Home={{APP_HOME}}/fusion")
}
// Gradle doesn't seem to have an equivalent "do everything" task.
tasks.register("release") {
group = "Build"
description = "Build all artifacts and reports"
dependsOn(tasks.build, tasks.jacocoTestReport, fcovTestReport)
}