From: Ben Soares Date: Tue, 4 Apr 2023 10:36:50 +0000 (+0100) Subject: JAL-629 --initsubstitutions as a bootstrap arg, new tests X-Git-Tag: Release_2_11_4_0~409 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=404d5b51a7a7781ad6924df6a7ce63c754370f16;p=jalview.git JAL-629 --initsubstitutions as a bootstrap arg, new tests --- diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index 0870ecb..d0e76f2 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -432,12 +432,14 @@ public class Jalview // --argfile=... -- OVERRIDES ALL NON-BOOTSTRAP ARGS if (bootstrapArgs.contains(Arg.ARGFILE)) { - argparser = ArgParser - .parseArgFiles(bootstrapArgs.getList(Arg.ARGFILE)); + argparser = ArgParser.parseArgFiles( + bootstrapArgs.getList(Arg.ARGFILE), + bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS)); } else { - argparser = new ArgParser(args); + argparser = new ArgParser(args, + bootstrapArgs.getBoolean(Arg.INITSUBSTITUTIONS)); } if (!Platform.isJS()) diff --git a/src/jalview/bin/argparser/Arg.java b/src/jalview/bin/argparser/Arg.java index e658434..8207996 100644 --- a/src/jalview/bin/argparser/Arg.java +++ b/src/jalview/bin/argparser/Arg.java @@ -14,7 +14,7 @@ public enum Arg SSANNOTATION, NOTEMPFAC, TEMPFAC, TEMPFAC_LABEL, TEMPFAC_DESC, TEMPFAC_SHADING, TITLE, PAEMATRIX, WRAP, NOSTRUCTURE, STRUCTURE, IMAGE, QUIT, CLOSE, DEBUG("d"), QUIET("q"), ARGFILE, INCREMENT, NPP("n++"), - SUBSTITUTIONS, NIL, SPLASH, SETARGFILE, UNSETARGFILE; + SUBSTITUTIONS, INITSUBSTITUTIONS, NIL, SPLASH, SETARGFILE, UNSETARGFILE; protected static enum Opt { @@ -86,6 +86,7 @@ public enum Arg INCREMENT.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION); NPP.setOptions(Opt.UNARY, Opt.MULTI, Opt.NOACTION); SUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.MULTI, Opt.NOACTION); + INITSUBSTITUTIONS.setOptions(Opt.BOOLEAN, Opt.BOOTSTRAP, Opt.NOACTION); NIL.setOptions(Opt.UNARY, Opt.LINKED, Opt.MULTI, Opt.NOACTION); SETARGFILE.setOptions(Opt.STRING, Opt.MULTI, Opt.PRIVATE, Opt.NOACTION); UNSETARGFILE.setOptions(Opt.MULTI, Opt.PRIVATE, Opt.NOACTION); diff --git a/src/jalview/bin/argparser/ArgParser.java b/src/jalview/bin/argparser/ArgParser.java index c2568bb..7d4f187 100644 --- a/src/jalview/bin/argparser/ArgParser.java +++ b/src/jalview/bin/argparser/ArgParser.java @@ -125,21 +125,27 @@ public class ArgParser public ArgParser(String[] args) { + this(args, false); + } + + public ArgParser(String[] args, boolean initsubstitutions) + { // Make a mutable new ArrayList so that shell globbing parser works. // (When shell file globbing is used, there are a sequence of non-Arg // arguments (which are the expanded globbed filenames) that need to be // consumed by the --open/--argfile/etc Arg which is most easily done by // removing these filenames from the list one at a time. This can't be done // with an ArrayList made with only Arrays.asList(String[] args). ) - this(new ArrayList<>(Arrays.asList(args))); + this(new ArrayList<>(Arrays.asList(args)), initsubstitutions); } - public ArgParser(List args) + public ArgParser(List args, boolean initsubstitutions) { - this(args, false); + this(args, initsubstitutions, false); } - public ArgParser(List args, boolean allowPrivate) + public ArgParser(List args, boolean initsubstitutions, + boolean allowPrivate) { // do nothing if there are no "--" args and some "-" args boolean d = false; @@ -159,14 +165,16 @@ public class ArgParser if (d && !dd) { // leave it to the old style -- parse an empty list - parse(new ArrayList(), allowPrivate); + parse(new ArrayList(), false, false); return; } - parse(args, allowPrivate); + parse(args, initsubstitutions, allowPrivate); } - private void parse(List args, boolean allowPrivate) + private void parse(List args, boolean initsubstitutions, + boolean allowPrivate) { + this.substitutions = initsubstitutions; int argIndex = 0; boolean openEachInitialFilenames = true; for (int i = 0; i < args.size(); i++) @@ -628,7 +636,8 @@ public class ArgParser return new SubVals(item); } - public static ArgParser parseArgFiles(List argFilenameGlobs) + public static ArgParser parseArgFiles(List argFilenameGlobs, + boolean initsubstitutions) { List argFiles = new ArrayList<>(); @@ -638,10 +647,11 @@ public class ArgParser argFiles.addAll(FileUtils.getFilesFromGlob(pattern)); } - return parseArgFileList(argFiles); + return parseArgFileList(argFiles, initsubstitutions); } - public static ArgParser parseArgFileList(List argFiles) + public static ArgParser parseArgFileList(List argFiles, + boolean initsubstitutions) { List argsList = new ArrayList<>(); for (File argFile : argFiles) @@ -670,9 +680,9 @@ public class ArgParser Jalview.exit(message, 3); } } - // Second param "true" uses Opt.PRIVATE args --setargile=argfile and + // Third param "true" uses Opt.PRIVATE args --setargile=argfile and // --unsetargfile - return new ArgParser(argsList, true); + return new ArgParser(argsList, initsubstitutions, true); } } \ No newline at end of file diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java index f7805fe..30c5e4e 100644 --- a/test/jalview/bin/CommandsTest.java +++ b/test/jalview/bin/CommandsTest.java @@ -108,26 +108,53 @@ public class CommandsTest lookForSequenceName("THIS_SEQUENCE_ID_DOESN'T_EXIST")); } - @Test(groups = "Functional") - public void argFilesGlobAndSubstitutionsTest() throws IOException + @Test(groups = "Functional", dataProvider = "argfileOutputFiles") + public void argFilesGlobAndSubstitutionsTest(String cmdLine, + String[] filenames) throws IOException { - cleanupArgfilesImages(); - String cmdLine = "--argfile=" + testfiles + "/dir*/argfile.txt"; + cleanupFiles(filenames); String[] args = cmdLine.split("\\s+"); Jalview.main(args); Commands cmds = Jalview.getInstance().getCommands(); - File file1 = new File(png1); - File file2 = new File(png2); - Assert.assertTrue(file1.exists(), - "Did not make file " + png1 + " from argfile"); - Assert.assertTrue(file2.exists(), - "Did not make file " + png2 + " from argfile"); - long size1 = Files.size(file1.toPath()); - long size2 = Files.size(file2.toPath()); - Assert.assertTrue(file1.isFile() && size1 > 0); - Assert.assertTrue(file2.isFile() && size2 > 0); - Assert.assertTrue(size2 > size1); // png2 has three sequences, png1 has 2 - cleanupArgfilesImages(); + Assert.assertNotNull(cmds); + File lastFile = null; + for (String filename : filenames) + { + File file = new File(filename); + Assert.assertTrue(file.exists(), "File '" + filename + + "' was not created by '" + cmdLine + "'"); + Assert.assertTrue(file.isFile(), "File '" + filename + + "' is not a file from '" + cmdLine + "'"); + Assert.assertTrue(Files.size(file.toPath()) > 0, "File '" + filename + + "' has no content from '" + cmdLine + "'"); + // make sure the successive output files get bigger! + if (lastFile != null) + Assert.assertTrue( + Files.size(file.toPath()) > Files.size(lastFile.toPath())); + } + cleanupFiles(filenames); + tearDown(); + } + + @DataProvider(name = "argfileOutputFiles") + public Object[][] argfileOutputFiles() + { + return new Object[][] { + { "--argfile=" + testfiles + "/**/*.txt", new String[] + { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png", + testfiles + "/dir3/subdir/test0.png" } }, + { "--argfile=" + testfiles + "/**/argfile.txt", new String[] + { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } }, + { "--argfile=" + testfiles + "/dir*/argfile.txt", new String[] + { testfiles + "/dir1/test1.png", testfiles + "/dir2/test1.png" } }, + { "--initsubstitutions --open examples/uniref50.fa --image " + + testfiles + "/{basename}.png", + new String[] + { testfiles + "/uniref50.png" } }, + { "--open examples/uniref50.fa --image " + testfiles + + "/{basename}.png", + new String[] + { testfiles + "/{basename}.png" } } }; } @DataProvider(name = "cmdLines") @@ -175,17 +202,15 @@ public class CommandsTest return false; } - public static void cleanupArgfilesImages() + public static void cleanupFiles(String[] filenames) { - File png1File = new File(png1); - File png2File = new File(png2); - if (png1File.exists()) - { - png1File.delete(); - } - if (png2File.exists()) + for (String filename : filenames) { - png2File.delete(); + File file = new File(filename); + if (file.exists()) + { + file.delete(); + } } } diff --git a/test/jalview/bin/argparser/testfiles/dir3/subdir/subdirfile.txt b/test/jalview/bin/argparser/testfiles/dir3/subdir/subdirfile.txt new file mode 100644 index 0000000..cd6b31b --- /dev/null +++ b/test/jalview/bin/argparser/testfiles/dir3/subdir/subdirfile.txt @@ -0,0 +1,6 @@ +--substitutions +--increment +--open={argfiledirname}/*.fa +--colour=gecos:flower +--image={argfiledirname}/{basename}.png +--close diff --git a/test/jalview/bin/argparser/testfiles/dir3/subdir/test0.fa b/test/jalview/bin/argparser/testfiles/dir3/subdir/test0.fa new file mode 100644 index 0000000..c9fae78 --- /dev/null +++ b/test/jalview/bin/argparser/testfiles/dir3/subdir/test0.fa @@ -0,0 +1,2 @@ +>TEST0 +AAAA diff --git a/test/jalview/bin/argparser/testfiles/dir3/subdir/test1.fa b/test/jalview/bin/argparser/testfiles/dir3/subdir/test1.fa new file mode 100644 index 0000000..c9e687f --- /dev/null +++ b/test/jalview/bin/argparser/testfiles/dir3/subdir/test1.fa @@ -0,0 +1,2 @@ +>TEST1 +AAAA diff --git a/test/jalview/bin/argparser/testfiles/dir3/subdir/test2.fa b/test/jalview/bin/argparser/testfiles/dir3/subdir/test2.fa new file mode 100644 index 0000000..fbd15c3 --- /dev/null +++ b/test/jalview/bin/argparser/testfiles/dir3/subdir/test2.fa @@ -0,0 +1,2 @@ +>TEST2 +LLLL diff --git a/test/jalview/bin/argparser/testfiles/dir3/subdir/test3.fa b/test/jalview/bin/argparser/testfiles/dir3/subdir/test3.fa new file mode 100644 index 0000000..f9503d4 --- /dev/null +++ b/test/jalview/bin/argparser/testfiles/dir3/subdir/test3.fa @@ -0,0 +1,2 @@ +>TEST3 +AAARG