Skip to content

Commit 5e8ab89

Browse files
committed
Clean up root build script
1 parent 793943c commit 5e8ab89

1 file changed

Lines changed: 54 additions & 31 deletions

File tree

‎exercises/build.gradle‎

Lines changed: 54 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,67 @@
1-
subprojects { project ->
2-
apply plugin: "java"
3-
4-
sourceSets {
5-
// Verify that the tests are working by running them against the example code.
6-
// By replacing the "main" sourceSet with the example code we avoid any collisions
7-
// with solution code that may have been included as a "starter" (e.g. etl).
8-
main {
9-
java.srcDirs = ["src/example/java"]
10-
}
11-
project["compileJava"].doFirst { compileTask ->
12-
println " (source = ${compileTask.source.asPath})"
13-
}
1+
// This root Gradle project is used for:
2+
//
3+
// - Checking that every test suite compiles against its corresponding example implementation;
4+
// - Checking that every example implementation passes its corresponding test suite;
5+
// - Checking that every provided starter implementation compiles.
6+
//
7+
// This file is never delivered to Exercism users.
148

15-
starterSource {
16-
java.srcDirs = ["src/main/java"]
17-
}
18-
project["compileStarterSourceJava"].doFirst { compileTask ->
19-
println " (source = ${compileTask.source.asPath})"
20-
}
9+
def generatedTestSourceDir = "build/gen/test/java"
2110

22-
// In lieu of being able to disable @Ignore in JUnit tests, we filter
23-
// those annotations, placing the edited tests in the path named here.
24-
test {
25-
java.srcDirs = ["build/gen/test/java"]
26-
}
27-
project["compileTestJava"].doFirst { compileTask ->
28-
println " (source = ${compileTask.source.asPath})"
29-
}
30-
}
11+
subprojects {
3112

13+
// Add a task that copies test source files into a build directory. All @Ignore annotations
14+
// are removed during this copying, so that when we run the copied tests, none are skipped and
15+
// all should execute.
16+
//
3217
// Note that journey-test.sh also strips @Ignore annotations using sed. The
3318
// stripping implementations here and in journey-test.sh should be kept
3419
// consistent.
3520
task copyTestsFilteringIgnores(type: Copy) {
3621
from "src/test/java"
37-
into "build/gen/test/java"
22+
into generatedTestSourceDir
3823
filter { line ->
39-
line.contains("@Ignore") ? "" : line
24+
line.contains("@Ignore") ? null : line
25+
}
26+
}
27+
28+
afterEvaluate { project ->
29+
30+
sourceSets {
31+
// Set the directory containing the example implementation as the default source set. Default
32+
// compile tasks will now run against this source set.
33+
main {
34+
java.srcDirs = ["src/example/java"]
35+
}
36+
37+
// Define a custom source set named "starterSource" that points to the starter implementations
38+
// delivered to users. We can then use the generated "compileStarterSourceJava" task to verify
39+
// that the starter source compiles as-is.
40+
starterSource {
41+
java.srcDirs = ["src/main/java"]
42+
}
43+
44+
// Set the directory containing the @Ignore-stripped tests as the default test source set.
45+
// Default test tasks will now run against this source set.
46+
test {
47+
java.srcDirs = [generatedTestSourceDir]
48+
}
49+
50+
// Log the source paths associated with each source set to verify they are what we expect.
51+
logCompileTaskSourcePath(project, "compileJava") // Corresponds to the "main" source set.
52+
logCompileTaskSourcePath(project, "compileStarterSourceJava")
53+
logCompileTaskSourcePath(project, "compileTestJava")
4054
}
55+
56+
// When running the standard test task, make sure we prepopulate the test source set with the
57+
// @Ignore-stripped tests.
58+
test.dependsOn(copyTestsFilteringIgnores)
4159
}
4260

43-
test.dependsOn(copyTestsFilteringIgnores)
61+
}
62+
63+
def logCompileTaskSourcePath(Project project, String taskName) {
64+
project[taskName].doFirst { compileTask ->
65+
println " (source = ${compileTask.source.asPath})"
66+
}
4467
}

0 commit comments

Comments
 (0)