Skip to content

Commit c547629

Browse files
author
John Burns
committed
add support for non-java sources to TestKitDsl
add support for configuration cache property in TestKitDsl
1 parent 34caecb commit c547629

File tree

11 files changed

+157
-14
lines changed

11 files changed

+157
-14
lines changed

gradle.lockfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Manual edits can break the build and are not advised.
33
# This file is expected to be part of source control.
44
cglib:cglib-nodep:3.2.2=archRulesTestRuntimeClasspath,integTestRuntimeClasspath,runtimeClasspath,testRuntimeClasspath
5-
com.netflix.nebula:nebula-archrules-core:0.5.2=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
5+
com.netflix.nebula:nebula-archrules-core:0.5.3=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
66
com.tngtech.archunit:archunit:1.4.1=archRulesCompileClasspath,archRulesRuntimeClasspath,archRulesTestCompileClasspath,archRulesTestRuntimeClasspath
77
junit:junit:4.13.2=compileClasspath,integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath
88
net.bytebuddy:byte-buddy-agent:1.11.13=integTestCompileClasspath,integTestRuntimeClasspath,testCompileClasspath,testRuntimeClasspath

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
systemProp.nebula.features.coreLockingSupport=true
2-
2+
org.gradle.configuration-cache=true
33
org.gradle.caching=true
4+
org.gradle.parallel=true

src/main/groovy/nebula/test/dsl/GroovyDsl.groovy

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ class GroovyDsl {
7171
self.test().with(config)
7272
}
7373

74-
static void java(SourceSetBuilder self, String name, Supplier<String> source) {
75-
self.java(name, source.get())
76-
}
77-
7874
/**
7975
* Run a build with expectation of success.
8076
* This method will throw an exception if the build fails.

src/main/java/nebula/test/TestKitOutputUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package nebula.test;
22

3+
import org.jspecify.annotations.NullMarked;
4+
35
import java.util.List;
46
import java.util.Objects;
57
import java.util.concurrent.atomic.AtomicBoolean;
68
import java.util.stream.Collectors;
79
import java.util.stream.Stream;
810

11+
@NullMarked
912
public class TestKitOutputUtil {
1013
private TestKitOutputUtil() {
1114
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package nebula.test.dsl;
22

3+
import org.jspecify.annotations.NullMarked;
4+
5+
@NullMarked
36
public enum BuildscriptLanguage {
47
GROOVY, KOTLIN
58
}

src/main/java/nebula/test/dsl/ProjectProperties.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nebula.test.dsl;
22

33
import org.jetbrains.annotations.Contract;
4+
import org.jspecify.annotations.NullMarked;
45

56
import java.io.File;
67
import java.io.IOException;
@@ -11,6 +12,7 @@
1112
import java.util.List;
1213

1314
@NebulaTestKitDsl
15+
@NullMarked
1416
public class ProjectProperties {
1517
private final File projectDir;
1618

@@ -27,12 +29,29 @@ public ProjectProperties property(String property, String value) {
2729
return this;
2830
}
2931

32+
/**
33+
*
34+
* @deprecated Use {@link #buildCache(boolean)} instead
35+
*/
3036
@NebulaTestKitDsl
3137
@Contract("_ -> this")
38+
@Deprecated
3239
public ProjectProperties gradleCache(boolean enabled) {
3340
return property("org.gradle.caching", String.valueOf(enabled).toLowerCase());
3441
}
3542

43+
@NebulaTestKitDsl
44+
@Contract("_ -> this")
45+
public ProjectProperties buildCache(boolean enabled) {
46+
return property("org.gradle.caching", String.valueOf(enabled).toLowerCase());
47+
}
48+
49+
@NebulaTestKitDsl
50+
@Contract("_ -> this")
51+
public ProjectProperties configurationCache(boolean enabled) {
52+
return property("org.gradle.configuration-cache", String.valueOf(enabled).toLowerCase());
53+
}
54+
3655
void build() {
3756
Path propsFile = projectDir.toPath().resolve("gradle.properties");
3857
String fileContents = String.join("\n", properties);

src/main/java/nebula/test/dsl/SourceSetBuilder.java

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package nebula.test.dsl;
22

3+
import org.jspecify.annotations.NullMarked;
4+
35
import java.io.File;
46
import java.io.IOException;
57
import java.nio.charset.StandardCharsets;
68
import java.nio.file.Files;
79
import java.nio.file.Path;
10+
import java.util.function.Supplier;
811

12+
@NullMarked
913
public class SourceSetBuilder {
1014
private final File sourcesDir;
1115

@@ -19,8 +23,84 @@ public class SourceSetBuilder {
1923
* @param file the relative path to the java file
2024
* @param contents the contents of the file
2125
*/
26+
@NebulaTestKitDsl
2227
public void java(String file, String contents) {
23-
final Path pathToSourceFile = sourcesDir.toPath().resolve("java").resolve(file);
28+
language("java", file, contents);
29+
}
30+
31+
/**
32+
* write a java file
33+
*
34+
* @param file the relative path to the java file
35+
* @param contents the contents of the file. uses a supplier for more ideomatic DSL usage in groovy and kotlin
36+
*/
37+
@NebulaTestKitDsl
38+
public void java(String file, Supplier<String> contents) {
39+
language("java", file, contents.get());
40+
}
41+
42+
/**
43+
* write a groovy file
44+
*
45+
* @param file the relative path to the groovy file
46+
* @param contents the contents of the file
47+
*/
48+
@NebulaTestKitDsl
49+
public void groovy(String file, String contents) {
50+
language("groovy", file, contents);
51+
}
52+
53+
/**
54+
* write a groovy file
55+
*
56+
* @param file the relative path to the groovy file
57+
* @param contents the contents of the file. uses a supplier for more ideomatic DSL usage in groovy and kotlin
58+
*/
59+
@NebulaTestKitDsl
60+
public void groovy(String file, Supplier<String> contents) {
61+
language("groovy", file, contents.get());
62+
}
63+
64+
/**
65+
* write a kotlin file
66+
*
67+
* @param file the relative path to the kotlin file
68+
* @param contents the contents of the file
69+
*/
70+
public void kotlin(String file, String contents) {
71+
language("kotlin", file, contents);
72+
}
73+
74+
/**
75+
* write a kotlin file
76+
*
77+
* @param file the relative path to the kotlin file
78+
* @param contents the contents of the file. uses a supplier for more ideomatic DSL usage in groovy and kotlin
79+
*/
80+
@NebulaTestKitDsl
81+
public void kotlin(String file, Supplier<String> contents) {
82+
language("kotlin", file, contents.get());
83+
}
84+
85+
/**
86+
* write a file for specified language
87+
*
88+
* @param file the relative path to the java file
89+
* @param contents the contents of the file. uses a supplier for more ideomatic DSL usage in groovy and kotlin
90+
*/
91+
@NebulaTestKitDsl
92+
public void language(String language, String file, Supplier<String> contents) {
93+
language(language, file, contents.get());
94+
}
95+
96+
/**
97+
* write a file for specified language
98+
*
99+
* @param file the relative path to the file
100+
* @param contents the contents of the file
101+
*/
102+
public void language(String language, String file, String contents) {
103+
final Path pathToSourceFile = sourcesDir.toPath().resolve(language).resolve(file);
24104
pathToSourceFile.getParent().toFile().mkdirs();
25105
try {
26106
Files.write(pathToSourceFile, contents.getBytes(StandardCharsets.UTF_8));

src/main/kotlin/nebula/test/dsl/KotlinDsl.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ fun TestProjectBuilder.subProject(name: String, config: ProjectBuilder.() -> Uni
8888
subProject(name).apply(config)
8989
}
9090

91-
@NebulaTestKitDsl
92-
fun SourceSetBuilder.java(fileName: String, source: () -> String) {
93-
java(fileName, source())
94-
}
95-
9691
/**
9792
* Run a build with expectation of success.
9893
* This method will throw an exception if the build fails.

src/test/java/nebula/test/SupportedGradleVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package nebula.test;
22

33
public enum SupportedGradleVersion {
4-
MIN("8.14.3"), MAX("9.2.0");
4+
MIN("8.14.3"), MAX("9.2.1");
55
public final String version;
66
SupportedGradleVersion(String version) {
77
this.version = version;

src/test/java/nebula/test/dsl/ProjectPropertiesTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import static org.assertj.core.api.Assertions.assertThat;
99

10-
public class ProjectPropertiesTest {
10+
class ProjectPropertiesTest {
1111
@Test
1212
public void testProjectProperty(@TempDir File testProjectDir) {
1313
final var instance = new ProjectProperties(testProjectDir);
@@ -31,4 +31,28 @@ public void testGradleCache(@TempDir File testProjectDir) {
3131
.content()
3232
.contains("org.gradle.caching=true");
3333
}
34+
35+
@Test
36+
public void testBuildCache(@TempDir File testProjectDir) {
37+
final var instance = new ProjectProperties(testProjectDir);
38+
instance.buildCache(true);
39+
instance.build();
40+
41+
assertThat(testProjectDir.toPath().resolve("gradle.properties"))
42+
.exists()
43+
.content()
44+
.contains("org.gradle.caching=true");
45+
}
46+
47+
@Test
48+
public void testConfigurationCache(@TempDir File testProjectDir) {
49+
final var instance = new ProjectProperties(testProjectDir);
50+
instance.configurationCache(true);
51+
instance.build();
52+
53+
assertThat(testProjectDir.toPath().resolve("gradle.properties"))
54+
.exists()
55+
.content()
56+
.contains("org.gradle.configuration-cache=true");
57+
}
3458
}

0 commit comments

Comments
 (0)