From f0b35b8ceab74bb128f88487444ebaed0d91b26a Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Tue, 17 Dec 2024 12:30:16 +0100 Subject: [PATCH 1/5] MRESOURCES-311. Ensure reproducible order in bundle --- .../plugin/resources/remote/BundleRemoteResourcesMojo.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java index 4007dca..335faf7 100644 --- a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.Writer; import java.util.Arrays; +import java.util.Comparator; import java.util.List; import org.apache.maven.plugin.AbstractMojo; @@ -106,6 +107,7 @@ public void execute() throws MojoExecutionException { remoteResourcesBundle.setSourceEncoding(sourceEncoding); DirectoryScanner scanner = new DirectoryScanner(); + scanner.setFilenameComparator(Comparator.naturalOrder()); scanner.setBasedir(resourcesDirectory); if (includes != null && includes.length != 0) { From eb9681e1b8655f956475fd09e983f7be24875a3d Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Wed, 18 Dec 2024 22:04:24 +0100 Subject: [PATCH 2/5] add test --- .../remote/RemoteResourcesMojoTest.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java index 7a2ca0f..4d75aba 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java @@ -28,6 +28,7 @@ import java.util.Arrays; import java.util.Calendar; import java.util.Collections; +import java.util.List; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; @@ -88,7 +89,9 @@ public void testNoBundles() throws Exception { } public void testCreateBundle() throws Exception { - buildResourceBundle("default-createbundle", null, new String[] {"SIMPLE.txt"}, null); + List resources = + Arrays.asList("FILTER.txt.vm", "ISO-8859-1.bin.vm", "PROPERTIES.txt.vm", "SIMPLE.txt", "UTF-8.bin.vm"); + buildResourceBundle("default-createbundle", null, resources.toArray(new String[0]), null); } public void testSimpleBundles() throws Exception { @@ -299,9 +302,10 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re assertTrue(xmlFile.exists()); String data = FileUtils.fileRead(xmlFile); - for (String resourceName1 : resourceNames) { - assertTrue(data.contains(resourceName1)); - } + + List expectedOrder = new ArrayList<>(Arrays.asList(resourceNames)); + Collections.sort(expectedOrder); + assertContainsAllInOrder(expectedOrder, data); if (null != jarName) { try (OutputStream fos = Files.newOutputStream(jarName.toPath()); @@ -322,6 +326,15 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re } } + private static void assertContainsAllInOrder(Iterable items, String data) { + int prevIndex = -1; + for (String resourceName : items) { + int index = data.indexOf(resourceName); + assertTrue("Expected order " + items + ", but was " + data, index > prevIndex); + prevIndex = index; + } + } + protected MavenProjectResourcesStub createTestProject(final String testName) throws Exception { // this will automatically create the isolated // test environment From f88c0fd7628c03e392cdb1312600252873232968 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Wed, 18 Dec 2024 22:49:07 +0100 Subject: [PATCH 3/5] use hamcrest --- pom.xml | 6 ++++++ .../resources/remote/RemoteResourcesMojoTest.java | 14 ++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 7fd1264..e258d64 100644 --- a/pom.xml +++ b/pom.xml @@ -211,6 +211,12 @@ under the License. ${mavenVersion} test + + org.hamcrest + hamcrest-library + 1.3 + test + org.slf4j diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java index 4d75aba..2baad20 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java @@ -52,6 +52,9 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder; + /** * RemoteResources plugin Test Case */ @@ -305,7 +308,7 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re List expectedOrder = new ArrayList<>(Arrays.asList(resourceNames)); Collections.sort(expectedOrder); - assertContainsAllInOrder(expectedOrder, data); + assertThat(data, stringContainsInOrder(expectedOrder)); if (null != jarName) { try (OutputStream fos = Files.newOutputStream(jarName.toPath()); @@ -326,15 +329,6 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re } } - private static void assertContainsAllInOrder(Iterable items, String data) { - int prevIndex = -1; - for (String resourceName : items) { - int index = data.indexOf(resourceName); - assertTrue("Expected order " + items + ", but was " + data, index > prevIndex); - prevIndex = index; - } - } - protected MavenProjectResourcesStub createTestProject(final String testName) throws Exception { // this will automatically create the isolated // test environment From 00c11d20feb358c641d7a678bba382d5f5489811 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Thu, 19 Dec 2024 03:01:39 +0100 Subject: [PATCH 4/5] use assertj-core --- pom.xml | 6 +++--- .../plugin/resources/remote/RemoteResourcesMojoTest.java | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e258d64..e0b4274 100644 --- a/pom.xml +++ b/pom.xml @@ -212,9 +212,9 @@ under the License. test - org.hamcrest - hamcrest-library - 1.3 + org.assertj + assertj-core + 3.26.3 test diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java index 2baad20..0f66948 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java @@ -52,8 +52,7 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.text.StringContainsInOrder.stringContainsInOrder; +import static org.assertj.core.api.Assertions.assertThat; /** * RemoteResources plugin Test Case @@ -308,7 +307,7 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re List expectedOrder = new ArrayList<>(Arrays.asList(resourceNames)); Collections.sort(expectedOrder); - assertThat(data, stringContainsInOrder(expectedOrder)); + assertThat(data).containsSubsequence(expectedOrder); if (null != jarName) { try (OutputStream fos = Files.newOutputStream(jarName.toPath()); From 19916ff5fad9c1d9a144ed0738b083a340f01472 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" Date: Thu, 19 Dec 2024 13:36:21 +0100 Subject: [PATCH 5/5] use hamcrest 3.0 --- pom.xml | 18 ++++++++++++------ .../remote/RemoteResourcesMojoTest.java | 5 +++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e0b4274..5b82b7f 100644 --- a/pom.xml +++ b/pom.xml @@ -186,6 +186,18 @@ under the License. + + org.hamcrest + hamcrest + 3.0 + test + + + org.hamcrest + hamcrest-library + 3.0 + test + junit junit @@ -211,12 +223,6 @@ under the License. ${mavenVersion} test - - org.assertj - assertj-core - 3.26.3 - test - org.slf4j diff --git a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java index 0f66948..b8333c4 100644 --- a/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java +++ b/src/test/java/org/apache/maven/plugin/resources/remote/RemoteResourcesMojoTest.java @@ -52,7 +52,8 @@ import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory; import org.eclipse.aether.repository.LocalRepository; -import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; /** * RemoteResources plugin Test Case @@ -307,7 +308,7 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re List expectedOrder = new ArrayList<>(Arrays.asList(resourceNames)); Collections.sort(expectedOrder); - assertThat(data).containsSubsequence(expectedOrder); + assertThat(data, stringContainsInOrder(expectedOrder)); if (null != jarName) { try (OutputStream fos = Files.newOutputStream(jarName.toPath());