Skip to content

Commit

Permalink
[MRRESOURCES-150] Ensure reproducible order in bundle (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai authored Dec 19, 2024
1 parent 2cbffc3 commit 3c59569
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
*/
Expand Down Expand Up @@ -88,7 +92,9 @@ public void testNoBundles() throws Exception {
}

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 {
Expand Down Expand Up @@ -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<String> expectedOrder = new ArrayList<>(Arrays.asList(resourceNames));
Collections.sort(expectedOrder);
assertThat(data, stringContainsInOrder(expectedOrder));

if (null != jarName) {
try (OutputStream fos = Files.newOutputStream(jarName.toPath());
Expand Down

0 comments on commit 3c59569

Please sign in to comment.