7003006: add option to list directory in deterministic order
authorjjg
Mon, 29 Nov 2010 10:09:48 -0800
changeset 7334 f432af22de29
parent 7333 a9ed6bf644fc
child 7335 8b390fd27190
7003006: add option to list directory in deterministic order Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
--- a/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Tue Nov 23 15:28:34 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Mon Nov 29 10:09:48 2010 -0800
@@ -25,6 +25,7 @@
 
 package com.sun.tools.javac.file;
 
+import java.util.Comparator;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -110,6 +111,20 @@
     protected boolean mmappedIO;
     protected boolean ignoreSymbolFile;
 
+    protected enum SortFiles implements Comparator<File> {
+        FORWARD {
+            public int compare(File f1, File f2) {
+                return f1.getName().compareTo(f2.getName());
+            }
+        },
+        REVERSE {
+            public int compare(File f1, File f2) {
+                return -f1.getName().compareTo(f2.getName());
+            }
+        };
+    };
+    protected SortFiles sortFiles;
+
     /**
      * Register a Context.Factory to create a JavacFileManager.
      */
@@ -152,6 +167,11 @@
 
         mmappedIO = options.isSet("mmappedIO");
         ignoreSymbolFile = options.isSet("ignore.symbol.file");
+
+        String sf = options.get("sortFiles");
+        if (sf != null) {
+            sortFiles = (sf.equals("reverse") ? SortFiles.REVERSE : SortFiles.FORWARD);
+        }
     }
 
     public JavaFileObject getFileForInput(String name) {
@@ -293,6 +313,9 @@
             if (files == null)
                 return;
 
+            if (sortFiles != null)
+                Arrays.sort(files, sortFiles);
+
             for (File f: files) {
                 String fname = f.getName();
                 if (f.isDirectory()) {