changeset 808:d44d6d8493ad

7003006: add option to list directory in deterministic order Reviewed-by: mcimadamore
author jjg
date Mon, 29 Nov 2010 10:09:48 -0800
parents 79d0c48d361e
children c44234f680da
files src/share/classes/com/sun/tools/javac/file/JavacFileManager.java
diffstat 1 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Tue Nov 23 15:28:34 2010 -0800
+++ b/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()) {