From e902384715b497e78d94fc8fd915c63d4fbfff38 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Fri, 10 Nov 2023 08:23:57 -0600 Subject: [PATCH] [SUREFIRE-2210] - Restore ordering of additional class path elements --- .../plugin/surefire/AbstractSurefireMojo.java | 2 +- .../extraResource/order-test.txt | 1 + .../extraResource2/order-test.txt | 1 + .../java/additionalClasspath/BasicTest.java | 26 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 surefire-its/src/test/resources/additional-classpath/extraResource/order-test.txt create mode 100644 surefire-its/src/test/resources/additional-classpath/extraResource2/order-test.txt diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java index 7cbe8bbb2b..7c337818ad 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java @@ -2569,7 +2569,7 @@ private TestClassPath generateTestClasspath() throws MojoFailureException { Map dependencyConflictIdsProjectArtifacts = classpathArtifacts.stream() .collect(Collectors.toMap(Artifact::getDependencyConflictId, Function.identity())); - Set additionalClasspathElements = new HashSet<>(); + Set additionalClasspathElements = new LinkedHashSet<>(); if (getAdditionalClasspathElements() != null) { Arrays.stream(getAdditionalClasspathElements()).forEach(additionalClasspathElements::add); } diff --git a/surefire-its/src/test/resources/additional-classpath/extraResource/order-test.txt b/surefire-its/src/test/resources/additional-classpath/extraResource/order-test.txt new file mode 100644 index 0000000000..56a6051ca2 --- /dev/null +++ b/surefire-its/src/test/resources/additional-classpath/extraResource/order-test.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/surefire-its/src/test/resources/additional-classpath/extraResource2/order-test.txt b/surefire-its/src/test/resources/additional-classpath/extraResource2/order-test.txt new file mode 100644 index 0000000000..d8263ee986 --- /dev/null +++ b/surefire-its/src/test/resources/additional-classpath/extraResource2/order-test.txt @@ -0,0 +1 @@ +2 \ No newline at end of file diff --git a/surefire-its/src/test/resources/additional-classpath/src/test/java/additionalClasspath/BasicTest.java b/surefire-its/src/test/resources/additional-classpath/src/test/java/additionalClasspath/BasicTest.java index 1cc4cad9c5..3e02270821 100644 --- a/surefire-its/src/test/resources/additional-classpath/src/test/java/additionalClasspath/BasicTest.java +++ b/surefire-its/src/test/resources/additional-classpath/src/test/java/additionalClasspath/BasicTest.java @@ -1,5 +1,12 @@ package additionalClasspath; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Enumeration; + import junit.framework.TestCase; public class BasicTest @@ -12,4 +19,23 @@ public void testExtraResource() assertNotNull( BasicTest.class.getResourceAsStream( "/test2.txt" ) ); } + public void testExtraResourceOrder() throws IOException + { + Enumeration resources = BasicTest.class.getClassLoader().getResources("/order-test.txt"); + assertTrue( resources.hasMoreElements() ); + URL url = resources.nextElement(); + InputStream is = url.openStream(); + assertNotNull( is ); + try ( InputStream i = is; InputStreamReader r = new InputStreamReader(is); BufferedReader br = new BufferedReader(r) ) { + assertEquals("1", br.readLine()); + } + assertTrue( resources.hasMoreElements() ); + url = resources.nextElement(); + is = url.openStream(); + assertNotNull( is ); + try ( InputStream i = is; InputStreamReader r = new InputStreamReader(is); BufferedReader br = new BufferedReader(r) ) { + assertEquals("2", br.readLine()); + } + assertFalse( resources.hasMoreElements() ); + } }