diff --git a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml index f2b6696192..3230b5945f 100644 --- a/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml +++ b/.github/workflows/composites/maven-build-with-dry-run-for-tests/action.yaml @@ -21,7 +21,7 @@ runs: shell: bash run: | cd spring-cloud-kubernetes-test-support - .././mvnw -q exec:java -Dexec.mainClass="org.springframework.cloud.kubernetes.tests.discovery.TestsDiscovery" > /tmp/tests.txt + .././mvnw -q exec:java -Prun-on-github-actions -Dexec.mainClass="org.springframework.cloud.kubernetes.tests.discovery.TestsDiscovery" > /tmp/tests.txt cd .. - name: show result diff --git a/spring-cloud-kubernetes-test-support/pom.xml b/spring-cloud-kubernetes-test-support/pom.xml index 653e690628..cf2a394ebd 100644 --- a/spring-cloud-kubernetes-test-support/pom.xml +++ b/spring-cloud-kubernetes-test-support/pom.xml @@ -49,24 +49,33 @@ - - - - org.codehaus.mojo - exec-maven-plugin - 3.1.0 - - - - java - - - - - org.springframework.cloud.kubernetes.tests.discovery.TestsDiscovery - - - - + + + + run-on-github-actions + + false + + + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + + + java + + + + + org.springframework.cloud.kubernetes.tests.discovery.TestsDiscovery + + + + + + diff --git a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/tests/discovery/TestsDiscovery.java b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/tests/discovery/TestsDiscovery.java index 528613c37b..22ebd00ccf 100644 --- a/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/tests/discovery/TestsDiscovery.java +++ b/spring-cloud-kubernetes-test-support/src/main/java/org/springframework/cloud/kubernetes/tests/discovery/TestsDiscovery.java @@ -31,6 +31,7 @@ import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.launcher.Launcher; import org.junit.platform.launcher.LauncherDiscoveryRequest; +import org.junit.platform.launcher.LauncherSession; import org.junit.platform.launcher.TestIdentifier; import org.junit.platform.launcher.TestPlan; import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder; @@ -57,12 +58,15 @@ public static void main(String[] args) throws Exception { LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request() .selectors(DiscoverySelectors.selectClasspathRoots(paths)).build(); - Launcher launcher = LauncherFactory.openSession().getLauncher(); - TestPlan testPlan = launcher.discover(request); - testPlan.getRoots().stream().flatMap(x -> testPlan.getChildren(x).stream()) + try (LauncherSession session = LauncherFactory.openSession()) { + Launcher launcher = session.getLauncher(); + TestPlan testPlan = launcher.discover(request); + testPlan.getRoots().stream().flatMap(x -> testPlan.getChildren(x).stream()) .map(TestIdentifier::getLegacyReportingName).sorted().forEach(test -> { System.out.println("spring.cloud.k8s.test.to.run -> " + test); }); + } + } private static void replaceClassloader(List classpathURLs) { @@ -73,7 +77,9 @@ private static void replaceClassloader(List classpathURLs) { // /tmp/deps.txt are created by the pipeline private static List entireClasspath() throws Exception { - return Files.lines(Paths.get("/tmp/deps.txt")).distinct().collect(Collectors.toList()); + try (Stream lines = Files.lines(Paths.get("/tmp/deps.txt"))) { + return lines.distinct().collect(Collectors.toList()); + } } private static URL toURL(URI uri) {