You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/12/19 21:39:53 UTC
(maven-remote-resources-plugin) branch master updated: [MRRESOURCES-150] Ensure reproducible order in bundle (#69)
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 3c59569 [MRRESOURCES-150] Ensure reproducible order in bundle (#69)
3c59569 is described below
commit 3c59569aa17b8e45250eaf0309d7808ad0cf49a2
Author: Doroszlai, Attila <64...@users.noreply.github.com>
AuthorDate: Thu Dec 19 22:39:48 2024 +0100
[MRRESOURCES-150] Ensure reproducible order in bundle (#69)
---
pom.xml | 12 ++++++++++++
.../resources/remote/BundleRemoteResourcesMojo.java | 2 ++
.../plugin/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.
</dependency>
<!-- test -->
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest</artifactId>
+ <version>3.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>3.0</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
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.IOException;
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 class BundleRemoteResourcesMojo extends AbstractMojo {
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.ArrayList;
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.DefaultRepositorySystemSession;
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 class RemoteResourcesMojoTest extends AbstractMojoTestCase {
}
public void testCreateBundle() throws Exception {
- buildResourceBundle("default-createbundle", null, new String[] {"SIMPLE.txt"}, null);
+ List<String> 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 @@ public class RemoteResourcesMojoTest extends AbstractMojoTestCase {
assertTrue(xmlFile.exists());
String data = FileUtils.fileRead(xmlFile);
- for (String resourceName1 : resourceNames) {
- assertTrue(data.contains(resourceName1));
- }
+
+ List<String> expectedOrder = new ArrayList<>(Arrays.asList(resourceNames));
+ Collections.sort(expectedOrder);
+ assertThat(data, stringContainsInOrder(expectedOrder));
if (null != jarName) {
try (OutputStream fos = Files.newOutputStream(jarName.toPath());