From 3c59569aa17b8e45250eaf0309d7808ad0cf49a2 Mon Sep 17 00:00:00 2001 From: "Doroszlai, Attila" <6454655+adoroszlai@users.noreply.github.com> Date: Thu, 19 Dec 2024 22:39:48 +0100 Subject: [PATCH] [MRRESOURCES-150] Ensure reproducible order in bundle (#69) --- pom.xml | 12 ++++++++++++ .../remote/BundleRemoteResourcesMojo.java | 2 ++ .../resources/remote/RemoteResourcesMojoTest.java | 15 +++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e0a98ad..d342ad0 100644 --- a/pom.xml +++ b/pom.xml @@ -198,6 +198,18 @@ under the License. + + org.hamcrest + hamcrest + 3.0 + test + + + org.hamcrest + hamcrest-library + 3.0 + test + junit junit 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 bcf6c81..591d080 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 @@ -24,6 +24,7 @@ import java.io.Writer; import java.nio.charset.Charset; 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) { 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..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 @@ -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; @@ -51,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.Matchers.stringContainsInOrder; + /** * RemoteResources plugin Test Case */ @@ -88,7 +92,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 +305,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); + assertThat(data, stringContainsInOrder(expectedOrder)); if (null != jarName) { try (OutputStream fos = Files.newOutputStream(jarName.toPath());