11package nebula .test .dsl ;
22
3+ import org .jspecify .annotations .NullMarked ;
4+
35import java .io .File ;
46import java .io .IOException ;
57import java .nio .charset .StandardCharsets ;
68import java .nio .file .Files ;
79import java .nio .file .Path ;
10+ import java .util .function .Supplier ;
811
12+ @ NullMarked
913public 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 ));
0 commit comments