Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRRESOURCES-150] Ensure reproducible order in bundle #69

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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 Down Expand Up @@ -88,7 +89,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 +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<String> expectedOrder = new ArrayList<>(Arrays.asList(resourceNames));
Collections.sort(expectedOrder);
assertContainsAllInOrder(expectedOrder, data);

if (null != jarName) {
try (OutputStream fos = Files.newOutputStream(jarName.toPath());
Expand All @@ -322,6 +326,15 @@ protected void buildResourceBundle(String id, String sourceEncoding, String[] re
}
}

private static void assertContainsAllInOrder(Iterable<String> items, String data) {
slawekjaranowski marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading