|
38 | 38 |
|
39 | 39 | import javax.inject.Inject; |
40 | 40 |
|
| 41 | +import static java.util.Objects.requireNonNull; |
41 | 42 | import static org.elasticsearch.gradle.internal.util.ParamsUtils.loadBuildParams; |
42 | 43 | import static org.elasticsearch.gradle.util.FileUtils.mkdirs; |
43 | 44 | import static org.elasticsearch.gradle.util.GradleUtils.maybeConfigure; |
@@ -174,25 +175,29 @@ public void execute(Task t) { |
174 | 175 | // we use 'temp' relative to CWD since this is per JVM and tests are forbidden from writing to CWD |
175 | 176 | nonInputProperties.systemProperty("java.io.tmpdir", test.getWorkingDir().toPath().resolve("temp")); |
176 | 177 |
|
177 | | - String projectName = project.getName(); |
178 | 178 | SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class); |
179 | | - FileCollection mainRuntime = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath(); |
180 | | - FileCollection testRuntime = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getRuntimeClasspath(); |
181 | | - FileCollection testOnlyFiles = testRuntime.minus(mainRuntime); |
182 | | - // Configuration compileOnly = project.getConfigurations() |
183 | | - // .findByName(RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME); |
184 | | - // if (compileOnly != null) { |
185 | | - // testOnlyFiles = testOnlyFiles.minus(compileOnly); |
186 | | - // } |
187 | | - nonInputProperties.systemProperty("es.entitlement.testOnlyPath", () -> { |
188 | | - String asPath = testOnlyFiles.getAsPath(); |
189 | | - String[] pathEntries = asPath.split(File.pathSeparator); |
190 | | - Arrays.sort(pathEntries); |
191 | | - // System.err.println( |
192 | | - // "PATDOYLE - for " + project.getName() + " " + test.getName() + " using testOnlyPath:\n" + String.join("\n", pathEntries) |
193 | | - // ); |
194 | | - return asPath; |
195 | | - }); |
| 179 | + SourceSet mainSourceSet = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME); |
| 180 | + SourceSet testSourceSet = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME); |
| 181 | + if (mainSourceSet != null && testSourceSet != null) { |
| 182 | + FileCollection mainRuntime = mainSourceSet.getRuntimeClasspath(); |
| 183 | + FileCollection testRuntime = testSourceSet.getRuntimeClasspath(); |
| 184 | + FileCollection testOnlyFiles = testRuntime.minus(mainRuntime); |
| 185 | + // Configuration compileOnly = project.getConfigurations() |
| 186 | + // .findByName(RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME); |
| 187 | + // if (compileOnly != null) { |
| 188 | + // testOnlyFiles = testOnlyFiles.minus(compileOnly); |
| 189 | + // } |
| 190 | + nonInputProperties.systemProperty("es.entitlement.testOnlyPath", () -> { |
| 191 | + String asPath = testOnlyFiles.getAsPath(); |
| 192 | + String[] pathEntries = asPath.split(File.pathSeparator); |
| 193 | + Arrays.sort(pathEntries); // For readability during troubleshooting. Consumers don't care about order. |
| 194 | + // System.err.println( |
| 195 | + // "PATDOYLE - for " + project.getName() + " " + test.getName() + " using testOnlyPath:\n" + String.join("\n", |
| 196 | + // pathEntries) |
| 197 | + // ); |
| 198 | + return asPath; |
| 199 | + }); |
| 200 | + } |
196 | 201 |
|
197 | 202 | test.systemProperties(getProviderFactory().systemPropertiesPrefixedBy("tests.").get()); |
198 | 203 | test.systemProperties(getProviderFactory().systemPropertiesPrefixedBy("es.").get()); |
@@ -236,6 +241,8 @@ public void execute(Task t) { |
236 | 241 | Configuration shadowConfig = project.getConfigurations().getByName(ShadowBasePlugin.CONFIGURATION_NAME); |
237 | 242 | // Add the shadow JAR artifact itself |
238 | 243 | FileCollection shadowJar = project.files(project.getTasks().named("shadowJar")); |
| 244 | + FileCollection mainRuntime = requireNonNull(mainSourceSet).getRuntimeClasspath(); |
| 245 | + FileCollection testRuntime = requireNonNull(testSourceSet).getRuntimeClasspath(); |
239 | 246 | test.setClasspath(testRuntime.minus(mainRuntime).plus(shadowConfig).plus(shadowJar)); |
240 | 247 | } |
241 | 248 | }); |
|
0 commit comments