From 6d08745a94e4f76d4b124afa83b858be8d843005 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Mon, 3 Apr 2023 23:31:28 +0100 Subject: [PATCH] JAL-629 sort files from java glob for predictability. reduce maxdepth of walkfiletree --- src/jalview/bin/argparser/BootstrapArgs.java | 5 +++++ src/jalview/util/FileUtils.java | 5 ++++- test/jalview/bin/CommandsTest.java | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/jalview/bin/argparser/BootstrapArgs.java b/src/jalview/bin/argparser/BootstrapArgs.java index 0d648a4..a327197 100644 --- a/src/jalview/bin/argparser/BootstrapArgs.java +++ b/src/jalview/bin/argparser/BootstrapArgs.java @@ -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 diff --git a/src/jalview/util/FileUtils.java b/src/jalview/util/FileUtils.java index b6f4e90..f5b3701 100644 --- a/src/jalview/util/FileUtils.java +++ b/src/jalview/util/FileUtils.java @@ -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() @@ -108,6 +110,7 @@ public class FileUtils files.add(f); } } + Collections.sort(files); return files; } diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index 2597e2a..f7805fe 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -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 -- 1.7.10.2