avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rskr...@apache.org
Subject [avro] branch master updated: AVRO-2644: Fix deterministic directory compilation
Date Wed, 18 Dec 2019 14:26:31 GMT
This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new a4a0bcc  AVRO-2644: Fix deterministic directory compilation
a4a0bcc is described below

commit a4a0bccfaebcecce429acc78e7aab0b68cccaa45
Author: austin ce <austin.cawley@gmail.com>
AuthorDate: Mon Dec 2 11:39:11 2019 -0500

    AVRO-2644: Fix deterministic directory compilation
---
 .../org/apache/avro/tool/SpecificCompilerTool.java | 22 +++++++++++++++++++++-
 1 file changed, 21 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 a2dd60f..7791627 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
@@ -23,7 +23,10 @@ import java.io.IOException;
 import java.io.InputStream;
 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;
@@ -132,8 +135,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
@@ -147,7 +165,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 {


Mime
View raw message