JAL-629 sort files from java glob for predictability. reduce maxdepth of walkfiletree
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 3 Apr 2023 22:31:28 +0000 (23:31 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 3 Apr 2023 22:31:28 +0000 (23:31 +0100)
src/jalview/bin/argparser/BootstrapArgs.java
src/jalview/util/FileUtils.java
test/jalview/bin/CommandsTest.java

index 0d648a4..a327197 100644 (file)
@@ -77,9 +77,14 @@ public class BootstrapArgs
           else
           {
             if (a.hasOption(Opt.GLOB))
+            {
+              System.out.println("##### VAL='" + val + "'");
               addAll(a, FileUtils.getFilenamesFromGlob(val));
+            }
             else
+            {
               add(a, val);
+            }
           }
         }
         else
index b6f4e90..f5b3701 100644 (file)
@@ -12,6 +12,7 @@ import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -67,10 +68,11 @@ public class FileUtils
           String glob = "glob:" + parentDir.toString() + File.separator
                   + rest;
           PathMatcher pm = FileSystems.getDefault().getPathMatcher(glob);
-          int maxDepth = rest.contains("**") ? Integer.MAX_VALUE
+          int maxDepth = rest.contains("**") ? 1028
                   : (int) (rest.chars()
                           .filter(ch -> ch == File.separatorChar).count())
                           + 1;
+
           Files.walkFileTree(parentDir,
                   EnumSet.of(FileVisitOption.FOLLOW_LINKS), maxDepth,
                   new SimpleFileVisitor<Path>()
@@ -108,6 +110,7 @@ public class FileUtils
         files.add(f);
       }
     }
+    Collections.sort(files);
 
     return files;
   }
index 2597e2a..f7805fe 100644 (file)
@@ -24,9 +24,9 @@ public class CommandsTest
 {
   private static final String testfiles = "test/jalview/bin/argparser/testfiles";
 
-  private static final String png1 = testfiles + "/dir1/test2.png";
+  private static final String png1 = testfiles + "/dir1/test1.png";
 
-  private static final String png2 = testfiles + "/dir2/test2.png";
+  private static final String png2 = testfiles + "/dir2/test1.png";
 
   @BeforeClass(alwaysRun = true)
   public static void setUpBeforeClass() throws Exception