You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2019/12/18 15:31:35 UTC
[avro] branch branch-1.9 updated: AVRO-2644: Fix deterministic
directory compilation
This is an automated email from the ASF dual-hosted git repository.
rskraba pushed a commit to branch branch-1.9
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/branch-1.9 by this push:
new c0638c8 AVRO-2644: Fix deterministic directory compilation
c0638c8 is described below
commit c0638c8e4f329752064b016929b470c15c0b2f3b
Author: austin ce <au...@gmail.com>
AuthorDate: Mon Dec 2 11:39:11 2019 -0500
AVRO-2644: Fix deterministic directory compilation
---
.../org/apache/avro/tool/SpecificCompilerTool.java | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java b/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
index 9f04ec9..df88038 100644
--- a/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
+++ b/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
@@ -25,6 +25,8 @@ import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.LinkedHashSet;
@@ -151,8 +153,23 @@ public class SpecificCompilerTool implements Tool {
}
/**
+ * For an Array of files, sort using {@link String#compareTo(String)} for each
+ * filename.
+ *
+ * @param files Array of File objects to sort
+ * @return the sorted File array
+ */
+ private static File[] sortFiles(File[] files) {
+ Objects.requireNonNull(files, "files cannot be null");
+ Arrays.sort(files, Comparator.comparing(File::getName));
+ return files;
+ }
+
+ /**
* For a List of files or directories, returns a File[] containing each file
* passed as well as each file with a matching extension found in the directory.
+ * Each directory is sorted using {@link String#compareTo(String)} for each
+ * filename.
*
* @param inputs List of File objects that are files or directories
* @param filter File extension filter to match on when fetching files from a
@@ -166,7 +183,9 @@ public class SpecificCompilerTool implements Tool {
// if directory, look at contents to see what files match extension
if (file.isDirectory()) {
File[] files = file.listFiles(filter);
- Collections.addAll(fileSet, files != null ? files : new File[0]);
+ // sort files in directory to compile deterministically
+ // independent of system/ locale
+ Collections.addAll(fileSet, files != null ? sortFiles(files) : new File[0]);
}
// otherwise, just add the file.
else {