X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fbin%2FJalview.java;h=ba418fea51e49088d8db149ec45d125637d15c92;hb=1213d49ca3df8f48360da857121805d088c13aab;hp=dc97549fa2056d5c7664d1e29d9f810ae10b5a36;hpb=d6e308f41ea1bc57434911e47ac01a19f76e8895;p=jalview.git diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index dc97549..ba418fe 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -76,6 +76,7 @@ import jalview.bin.argparser.BootstrapArgs; import jalview.ext.so.SequenceOntology; import jalview.gui.AlignFrame; import jalview.gui.Desktop; +import jalview.gui.JvOptionPane; import jalview.gui.PromptUserConfig; import jalview.gui.QuitHandler; import jalview.gui.QuitHandler.QResponse; @@ -91,6 +92,7 @@ import jalview.io.FileLoader; import jalview.io.HtmlSvgOutput; import jalview.io.IdentifyFile; import jalview.io.NewickFile; +import jalview.io.exceptions.ImageOutputException; import jalview.io.gff.SequenceOntologyFactory; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; @@ -138,9 +140,9 @@ public class Jalview public static AlignFrame currentAlignFrame; - public ArgParser argparser = null; + private ArgParser argparser = null; - public BootstrapArgs bootstrapArgs = null; + private BootstrapArgs bootstrapArgs = null; private boolean QUIET = false; @@ -273,7 +275,7 @@ public class Jalview * */ { - System.out.println("not in js"); + Console.outPrintln("not in js"); } // BH - for event debugging in JavaScript (Java mode only) @@ -343,6 +345,25 @@ public class Jalview } } + // set individual session preferences + if (bootstrapArgs.contains(Arg.P)) + { + for (String kev : bootstrapArgs.getValueList(Arg.P)) + { + if (kev == null) + { + continue; + } + int equalsIndex = kev.indexOf(ArgParser.EQUALS); + if (equalsIndex > -1) + { + String key = kev.substring(0, equalsIndex); + String val = kev.substring(equalsIndex + 1); + Cache.setSessionProperty(key, val); + } + } + } + // Move any new getdown-launcher-new.jar into place over old // getdown-launcher.jar String appdirString = System.getProperty("getdownappdir"); @@ -363,29 +384,30 @@ public class Jalview }.start(); } - if (!quiet() || bootstrapArgs.contains(Arg.VERSION)) + if (!quiet() || !bootstrapArgs.outputToStdout() + || bootstrapArgs.contains(Arg.VERSION)) { - System.out.println( + Console.outPrintln( "Java version: " + System.getProperty("java.version")); - System.out.println("Java home: " + System.getProperty("java.home")); - System.out.println("Java arch: " + System.getProperty("os.arch") + " " + Console.outPrintln("Java home: " + System.getProperty("java.home")); + Console.outPrintln("Java arch: " + System.getProperty("os.arch") + " " + System.getProperty("os.name") + " " + System.getProperty("os.version")); String val = System.getProperty("sys.install4jVersion"); if (val != null) { - System.out.println("Install4j version: " + val); + Console.outPrintln("Install4j version: " + val); } val = System.getProperty("installer_template_version"); if (val != null) { - System.out.println("Install4j template version: " + val); + Console.outPrintln("Install4j template version: " + val); } val = System.getProperty("launcher_version"); if (val != null) { - System.out.println("Launcher version: " + val); + Console.outPrintln("Launcher version: " + val); } } @@ -405,7 +427,7 @@ public class Jalview // stop now if only after --version if (bootstrapArgs.contains(Arg.VERSION)) { - Jalview.exit(null, 0); + Jalview.exit(null, ExitCode.OK); } // old ArgsParser @@ -437,12 +459,13 @@ public class Jalview error.printStackTrace(); String message = "\nEssential logging libraries not found." + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"; - Jalview.exit(message, 0); + Jalview.exit(message, ExitCode.OK); } // register SIGTERM listener Runtime.getRuntime().addShutdownHook(new Thread() { + @Override public void run() { Console.debug("Running shutdown hook"); @@ -489,7 +512,7 @@ public class Jalview Cache.loadProperties(usrPropsFile); if (usrPropsFile != null) { - System.out.println( + Console.outPrintln( "CMD [-props " + usrPropsFile + "] executed successfully!"); testoutput(bootstrapArgs, Arg.PROPS, "test/jalview/bin/testProps.jvprops", usrPropsFile); @@ -521,9 +544,9 @@ public class Jalview { List> helpArgs = bootstrapArgs .getList(Arg.HELP); - System.out.println(Arg.usage(helpArgs.stream().map(e -> e.getKey()) + Console.outPrintln(Arg.usage(helpArgs.stream().map(e -> e.getKey()) .collect(Collectors.toList()))); - Jalview.exit(null, 0); + Jalview.exit(null, ExitCode.OK); } if (aparser.contains("help") || aparser.contains("h")) { @@ -531,8 +554,8 @@ public class Jalview * Now using new usage statement. showUsage(); */ - System.out.println(Arg.usage()); - Jalview.exit(null, 0); + Console.outPrintln(Arg.usage()); + Jalview.exit(null, ExitCode.OK); } // new CLI @@ -561,13 +584,13 @@ public class Jalview try { Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl); - System.out.println( + Console.outPrintln( "CMD [-jabaws " + jabawsUrl + "] executed successfully!"); testoutput(bootstrapArgs, Arg.JABAWS, "http://www.compbio.dundee.ac.uk/jabaws", jabawsUrl); } catch (MalformedURLException e) { - System.err.println( + jalview.bin.Console.errPrintln( "Invalid jabaws parameter: " + jabawsUrl + " ignored"); } } @@ -597,7 +620,8 @@ public class Jalview } else { - System.out.println("Executing setprop argument: " + setprop); + jalview.bin.Console + .errPrintln("Executing setprop argument: " + setprop); if (Platform.isJS()) { Cache.setProperty(setprop.substring(0, p), @@ -613,20 +637,17 @@ public class Jalview { headless = true; } - System.setProperty("http.agent", - "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown")); + System.setProperty("http.agent", HttpUtils.getUserAgent()); try { Console.initLogger(); - } catch ( - - NoClassDefFoundError error) + } catch (NoClassDefFoundError error) { error.printStackTrace(); String message = "\nEssential logging libraries not found." + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"; - Jalview.exit(message, 0); + Jalview.exit(message, ExitCode.NO_LOGGING); } desktop = null; @@ -651,6 +672,8 @@ public class Jalview desktop = new Desktop(); desktop.setInBatchMode(true); // indicate we are starting up + mixedCliWarning(); + try { JalviewTaskbar.setTaskbar(this); @@ -720,18 +743,18 @@ public class Jalview testoutput(argparser, Arg.WEBSERVICEDISCOVERY); } - boolean usagestats = bootstrapArgs.getBoolean(Arg.USAGESTATS); + boolean usagestats = !bootstrapArgs.getBoolean(Arg.NOUSAGESTATS); if (aparser.contains("nousagestats")) usagestats = false; if (usagestats) { startUsageStats(desktop); - testoutput(argparser, Arg.USAGESTATS); + testoutput(argparser, Arg.NOUSAGESTATS); } else { - System.out.println("CMD [-nousagestats] executed successfully!"); - testoutput(argparser, Arg.USAGESTATS); + Console.outPrintln("CMD [-nousagestats] executed successfully!"); + testoutput(argparser, Arg.NOUSAGESTATS); } boolean questionnaire = bootstrapArgs.getBoolean(Arg.QUESTIONNAIRE); @@ -746,7 +769,7 @@ public class Jalview // questionnaire Console.debug("Starting questionnaire url at " + url); desktop.checkForQuestionnaire(url); - System.out.println("CMD questionnaire[-" + url + Console.outPrintln("CMD questionnaire[-" + url + "] executed successfully!"); } else @@ -767,8 +790,8 @@ public class Jalview } else { - System.out - .println("CMD [-noquestionnaire] executed successfully!"); + Console.outPrintln( + "CMD [-noquestionnaire] executed successfully!"); testoutput(argparser, Arg.QUESTIONNAIRE); } @@ -787,9 +810,35 @@ public class Jalview } } } + else + { + + if (getArgParser().isMixedStyle()) + { + String warning = MessageManager.formatMessage( + "warning.using_mixed_command_line_arguments", + getArgParser().getMixedExamples()); + Console.warn(warning); + Jalview.exit( + "Exiting due to mixed old and new command line arguments", + ExitCode.INVALID_ARGUMENT); + } + if (getArgParser().isOldStyle()) + { + String warning = MessageManager + .getString("warning.using_old_command_line_arguments") + .replace("\n", " ") + + "https://www.jalview.org/help/html/features/commandline.html"; + Console.warn(warning); + } + + } + // Run Commands from cli cmds = new Commands(argparser, headlessArg); + cmds.processArgs(); boolean commandsSuccess = cmds.argsWereParsed(); + if (commandsSuccess) { if (headlessArg) @@ -803,7 +852,7 @@ public class Jalview else { Jalview.exit("Successfully completed commands in headless mode", - 0); + ExitCode.OK); } } Console.info("Successfully completed commands"); @@ -812,7 +861,8 @@ public class Jalview { if (headlessArg) { - Jalview.exit("Error when running Commands in headless mode", 1); + Jalview.exit("Error when running Commands in headless mode", + ExitCode.ERROR_RUNNING_COMMANDS); } Console.warn("Error when running commands"); } @@ -843,7 +893,7 @@ public class Jalview if (file == null && desktop == null && !commandsSuccess) { - Jalview.exit("No files to open!", 1); + Jalview.exit("No files to open!", ExitCode.NO_FILES); } long progress = -1; @@ -857,7 +907,7 @@ public class Jalview .getString("status.processing_commandline_args"), progress = System.currentTimeMillis()); } - System.out.println("CMD [-open " + file + "] executed successfully!"); + Console.outPrintln("CMD [-open " + file + "] executed successfully!"); if (!Platform.isJS()) /** @@ -873,7 +923,8 @@ public class Jalview if (headless) { Jalview.exit( - "Can't find file '" + file + "' in headless mode", 1); + "Can't find file '" + file + "' in headless mode", + ExitCode.FILE_NOT_FOUND); } Console.warn("Can't find file'" + file + "'"); } @@ -894,7 +945,7 @@ public class Jalview format); if (af == null) { - System.out.println("error"); + Console.outPrintln("error"); } else { @@ -909,7 +960,7 @@ public class Jalview if (cs != null) { - System.out.println( + Console.outPrintln( "CMD [-colour " + data + "] executed successfully!"); } af.changeColour(cs); @@ -921,8 +972,8 @@ public class Jalview { af.parseFeaturesFile(data, AppletFormatAdapter.checkProtocol(data)); - // System.out.println("Added " + data); - System.out.println( + // Console.outPrintln("Added " + data); + Console.outPrintln( "CMD groups[-" + data + "] executed successfully!"); } data = aparser.getValue("features", true); @@ -930,8 +981,8 @@ public class Jalview { af.parseFeaturesFile(data, AppletFormatAdapter.checkProtocol(data)); - // System.out.println("Added " + data); - System.out.println( + // Console.outPrintln("Added " + data); + Console.outPrintln( "CMD [-features " + data + "] executed successfully!"); } @@ -939,8 +990,8 @@ public class Jalview if (data != null) { af.loadJalviewDataFile(data, null, null, null); - // System.out.println("Added " + data); - System.out.println( + // Console.outPrintln("Added " + data); + Console.outPrintln( "CMD [-annotations " + data + "] executed successfully!"); } // set or clear the sortbytree flag. @@ -949,7 +1000,7 @@ public class Jalview af.getViewport().setSortByTree(true); if (af.getViewport().getSortByTree()) { - System.out.println("CMD [-sortbytree] executed successfully!"); + Console.outPrintln("CMD [-sortbytree] executed successfully!"); } } if (aparser.contains("no-annotation")) @@ -957,7 +1008,7 @@ public class Jalview af.getViewport().setShowAnnotation(false); if (!af.getViewport().isShowAnnotation()) { - System.out.println("CMD no-annotation executed successfully!"); + Console.outPrintln("CMD no-annotation executed successfully!"); } } if (aparser.contains("nosortbytree")) @@ -965,8 +1016,8 @@ public class Jalview af.getViewport().setSortByTree(false); if (!af.getViewport().getSortByTree()) { - System.out - .println("CMD [-nosortbytree] executed successfully!"); + Console.outPrintln( + "CMD [-nosortbytree] executed successfully!"); } } data = aparser.getValue("tree", true); @@ -974,7 +1025,7 @@ public class Jalview { try { - System.out.println( + Console.outPrintln( "CMD [-tree " + data + "] executed successfully!"); NewickFile nf = new NewickFile(data, AppletFormatAdapter.checkProtocol(data)); @@ -982,127 +1033,135 @@ public class Jalview .setCurrentTree(af.showNewickTree(nf, data).getTree()); } catch (IOException ex) { - System.err.println("Couldn't add tree " + data); + jalview.bin.Console.errPrintln("Couldn't add tree " + data); ex.printStackTrace(System.err); } } - // TODO - load PDB structure(s) to alignment JAL-629 - // (associate with identical sequence in alignment, or a specified - // sequence) + if (groovyscript != null) { // Execute the groovy script after we've done all the rendering stuff // and before any images or figures are generated. - System.out.println("Executing script " + groovyscript); + Console.outPrintln("Executing script " + groovyscript); executeGroovyScript(groovyscript, af); - System.out.println("CMD groovy[" + groovyscript + Console.outPrintln("CMD groovy[" + groovyscript + "] executed successfully!"); groovyscript = null; } String imageName = "unnamed.png"; while (aparser.getSize() > 1) { - String outputFormat = aparser.nextValue(); - file = aparser.nextValue(); - - if (outputFormat.equalsIgnoreCase("png")) - { - af.createPNG(new File(file)); - imageName = (new File(file)).getName(); - System.out.println("Creating PNG image: " + file); - continue; - } - else if (outputFormat.equalsIgnoreCase("svg")) - { - File imageFile = new File(file); - imageName = imageFile.getName(); - af.createSVG(imageFile); - System.out.println("Creating SVG image: " + file); - continue; - } - else if (outputFormat.equalsIgnoreCase("html")) + try { - File imageFile = new File(file); - imageName = imageFile.getName(); - HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel); - htmlSVG.exportHTML(file); + String outputFormat = aparser.nextValue(); + file = aparser.nextValue(); - System.out.println("Creating HTML image: " + file); - continue; - } - else if (outputFormat.equalsIgnoreCase("biojsmsa")) - { - if (file == null) + if (outputFormat.equalsIgnoreCase("png")) { - System.err.println("The output html file must not be null"); - return; + Console.outPrintln("Creating PNG image: " + file); + af.createPNG(new File(file)); + imageName = (new File(file)).getName(); + continue; } - try + else if (outputFormat.equalsIgnoreCase("svg")) { - BioJsHTMLOutput.refreshVersionInfo( - BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY); - } catch (URISyntaxException e) + Console.outPrintln("Creating SVG image: " + file); + File imageFile = new File(file); + imageName = imageFile.getName(); + af.createSVG(imageFile); + continue; + } + else if (outputFormat.equalsIgnoreCase("html")) { - e.printStackTrace(); + File imageFile = new File(file); + imageName = imageFile.getName(); + HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel); + + Console.outPrintln("Creating HTML image: " + file); + htmlSVG.exportHTML(file); + continue; } - BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel); - bjs.exportHTML(file); - System.out - .println("Creating BioJS MSA Viwer HTML file: " + file); - continue; - } - else if (outputFormat.equalsIgnoreCase("imgMap")) - { - af.createImageMap(new File(file), imageName); - System.out.println("Creating image map: " + file); - continue; - } - else if (outputFormat.equalsIgnoreCase("eps")) - { - File outputFile = new File(file); - System.out.println( - "Creating EPS file: " + outputFile.getAbsolutePath()); - af.createEPS(outputFile); - continue; - } - FileFormatI outFormat = null; - try - { - outFormat = FileFormats.getInstance().forName(outputFormat); - } catch (Exception formatP) - { - System.out.println("Couldn't parse " + outFormat - + " as a valid Jalview format string."); - } - if (outFormat != null) - { - if (!outFormat.isWritable()) + else if (outputFormat.equalsIgnoreCase("biojsmsa")) + { + if (file == null) + { + jalview.bin.Console.errPrintln( + "The output html file must not be null"); + return; + } + try + { + BioJsHTMLOutput.refreshVersionInfo( + BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY); + } catch (URISyntaxException e) + { + e.printStackTrace(); + } + BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel); + Console.outPrintln( + "Creating BioJS MSA Viwer HTML file: " + file); + bjs.exportHTML(file); + continue; + } + else if (outputFormat.equalsIgnoreCase("imgMap")) + { + Console.outPrintln("Creating image map: " + file); + af.createImageMap(new File(file), imageName); + continue; + } + else if (outputFormat.equalsIgnoreCase("eps")) + { + File outputFile = new File(file); + Console.outPrintln( + "Creating EPS file: " + outputFile.getAbsolutePath()); + af.createEPS(outputFile); + continue; + } + + FileFormatI outFormat = null; + try { - System.out.println( - "This version of Jalview does not support alignment export as " - + outputFormat); + outFormat = FileFormats.getInstance().forName(outputFormat); + } catch (Exception formatP) + { + Console.outPrintln("Couldn't parse " + outFormat + + " as a valid Jalview format string."); } - else + if (outFormat != null) { - af.saveAlignment(file, outFormat); - if (af.isSaveAlignmentSuccessful()) + if (!outFormat.isWritable()) { - System.out.println("Written alignment in " - + outFormat.getName() + " format to " + file); + Console.outPrintln( + "This version of Jalview does not support alignment export as " + + outputFormat); } else { - System.out.println("Error writing file " + file + " in " - + outFormat.getName() + " format!!"); + af.saveAlignment(file, outFormat); + if (af.isSaveAlignmentSuccessful()) + { + Console.outPrintln("Written alignment in " + + outFormat.getName() + " format to " + file); + } + else + { + Console.outPrintln("Error writing file " + file + " in " + + outFormat.getName() + " format!!"); + } } } + } catch (ImageOutputException ioexc) + { + Console.outPrintln( + "Unexpected error whilst exporting image to " + file); + ioexc.printStackTrace(); } } while (aparser.getSize() > 0) { - System.out.println("Unknown arg: " + aparser.nextValue()); + Console.outPrintln("Unknown arg: " + aparser.nextValue()); } } } @@ -1114,7 +1173,8 @@ public class Jalview if (!Platform.isJS() && !headless && file == null && Cache.getDefault("SHOW_STARTUP_FILE", true) - && !cmds.commandArgsProvided()) + && !cmds.commandArgsProvided() + && !bootstrapArgs.getBoolean(Arg.NOSTARTUPFILE)) // don't open the startup file if command line args have been processed // (&& !Commands.commandArgsProvided()) /** @@ -1169,12 +1229,12 @@ public class Jalview { if (Cache.groovyJarsPresent()) { - System.out.println("Executing script " + groovyscript); + Console.outPrintln("Executing script " + groovyscript); executeGroovyScript(groovyscript, startUpAlframe); } else { - System.err.println( + jalview.bin.Console.errPrintln( "Sorry. Groovy Support is not available, so ignoring the provided groovy script " + groovyscript); } @@ -1188,97 +1248,108 @@ public class Jalview } desktop.setInBatchMode(false); } + + cliWarning(); } private static void setLookAndFeel() { - // property laf = "crossplatform", "system", "gtk", "metal", "nimbus", - // "mac" or "flat" - // If not set (or chosen laf fails), use the normal SystemLaF and if on Mac, - // try Quaqua/Vaqua. - String lafProp = System.getProperty("laf"); - String lafSetting = Cache.getDefault("PREFERRED_LAF", null); - String laf = "none"; - if (lafProp != null) - { - laf = lafProp; - } - else if (lafSetting != null) - { - laf = lafSetting; - } - boolean lafSet = false; - switch (laf) + if (!Platform.isJS()) + /** + * Java only + * + * @j2sIgnore + */ { - case "crossplatform": - lafSet = setCrossPlatformLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); - } - break; - case "system": - lafSet = setSystemLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); + // property laf = "crossplatform", "system", "gtk", "metal", "nimbus", + // "mac" or "flat" + // If not set (or chosen laf fails), use the normal SystemLaF and if on + // Mac, + // try Quaqua/Vaqua. + String lafProp = System.getProperty("laf"); + String lafSetting = Cache.getDefault("PREFERRED_LAF", null); + String laf = "none"; + if (lafProp != null) + { + laf = lafProp; } - break; - case "gtk": - lafSet = setGtkLookAndFeel(); - if (!lafSet) + else if (lafSetting != null) { - Console.error("Could not set requested laf=" + laf); + laf = lafSetting; } - break; - case "metal": - lafSet = setMetalLookAndFeel(); - if (!lafSet) + boolean lafSet = false; + switch (laf) { - Console.error("Could not set requested laf=" + laf); - } - break; - case "nimbus": - lafSet = setNimbusLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); - } - break; - case "flat": - lafSet = setFlatLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); - } - break; - case "mac": - lafSet = setMacLookAndFeel(); - if (!lafSet) - { - Console.error("Could not set requested laf=" + laf); + case "crossplatform": + lafSet = setCrossPlatformLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "system": + lafSet = setSystemLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "gtk": + lafSet = setGtkLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "metal": + lafSet = setMetalLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "nimbus": + lafSet = setNimbusLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "flat": + lafSet = setFlatLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "mac": + lafSet = setMacLookAndFeel(); + if (!lafSet) + { + Console.error("Could not set requested laf=" + laf); + } + break; + case "none": + break; + default: + Console.error("Requested laf=" + laf + " not implemented"); } - break; - case "none": - break; - default: - Console.error("Requested laf=" + laf + " not implemented"); - } - if (!lafSet) - { - // Flatlaf default for everyone! - lafSet = setFlatLookAndFeel(); if (!lafSet) { - setSystemLookAndFeel(); - } - if (Platform.isLinux()) - { - setLinuxLookAndFeel(); - } - if (Platform.isMac()) - { - setMacLookAndFeel(); + // Flatlaf default for everyone! + lafSet = setFlatLookAndFeel(); + if (!lafSet) + { + setSystemLookAndFeel(); + } + if (Platform.isLinux()) + { + setLinuxLookAndFeel(); + } + if (Platform.isMac()) + { + setMacLookAndFeel(); + } } } } @@ -1460,7 +1531,7 @@ public class Jalview UIManager.put("TabbedPane.tabType", "card"); UIManager.put("TabbedPane.showTabSeparators", true); UIManager.put("TabbedPane.showContentSeparator", true); - UIManager.put("TabbedPane.tabSeparatorsFullHeight", true); + // UIManager.put("TabbedPane.tabSeparatorsFullHeight", true); UIManager.put("TabbedPane.tabsOverlapBorder", true); UIManager.put("TabbedPane.hasFullBorder", true); UIManager.put("TabbedPane.tabLayoutPolicy", "scroll"); @@ -1510,7 +1581,7 @@ public class Jalview /* private static void showUsage() { - System.out.println( + jalview.bin.Console.outPrintln( "Usage: jalview -open [FILE] [OUTPUT_FORMAT] [OUTPUT_FILE]\n\n" + "-nodisplay\tRun Jalview without User Interface.\n" + "-props FILE\tUse the given Jalview properties file instead of users default.\n" @@ -1536,7 +1607,7 @@ public class Jalview + "-questionnaire URL\tQueries the given URL for information about any Jalview user questionnaires.\n" + "-noquestionnaire\tTurn off questionnaire check.\n" + "-nonews\tTurn off check for Jalview news.\n" - + "-nousagestats\tTurn off google analytics tracking for this session.\n" + + "-nousagestats\tTurn off analytics tracking for this session.\n" + "-sortbytree OR -nosortbytree\tEnable or disable sorting of the given alignment by the given tree\n" // + // "-setprop PROPERTY=VALUE\tSet the given Jalview property, @@ -1558,18 +1629,15 @@ public class Jalview * start a User Config prompt asking if we can log usage statistics. */ PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop, - "USAGESTATS", "Jalview Usage Statistics", - "Do you want to help make Jalview better by enabling " - + "the collection of usage statistics with Google Analytics ?" - + "\n\n(you can enable or disable usage tracking in the preferences)", - new Runnable() + "USAGESTATS", + MessageManager.getString("prompt.analytics_title"), + MessageManager.getString("prompt.analytics"), new Runnable() { @Override public void run() { - Console.debug( - "Initialising googletracker for usage stats."); - Cache.initGoogleTracker(); + Console.debug("Initialising analytics for usage stats."); + Cache.initAnalytics(); Console.debug("Tracking enabled."); } }, new Runnable() @@ -1577,7 +1645,7 @@ public class Jalview @Override public void run() { - Console.debug("Not enabling Google Tracking."); + Console.debug("Not enabling analytics."); } }, null, true); desktop.addDialogThread(prompter); @@ -1623,9 +1691,10 @@ public class Jalview } catch (Exception ex) { - System.err.println("Failed to read from STDIN into tempfile " - + ((tfile == null) ? "(tempfile wasn't created)" - : tfile.toString())); + jalview.bin.Console + .errPrintln("Failed to read from STDIN into tempfile " + + ((tfile == null) ? "(tempfile wasn't created)" + : tfile.toString())); ex.printStackTrace(); return; } @@ -1634,7 +1703,7 @@ public class Jalview sfile = tfile.toURI().toURL(); } catch (Exception x) { - System.err.println( + jalview.bin.Console.errPrintln( "Unexpected Malformed URL Exception for temporary file created from STDIN: " + tfile.toURI()); x.printStackTrace(); @@ -1651,17 +1720,20 @@ public class Jalview tfile = new File(groovyscript); if (!tfile.exists()) { - System.err.println("File '" + groovyscript + "' does not exist."); + jalview.bin.Console.errPrintln( + "File '" + groovyscript + "' does not exist."); return; } if (!tfile.canRead()) { - System.err.println("File '" + groovyscript + "' cannot be read."); + jalview.bin.Console.errPrintln( + "File '" + groovyscript + "' cannot be read."); return; } if (tfile.length() < 1) { - System.err.println("File '" + groovyscript + "' is empty."); + jalview.bin.Console + .errPrintln("File '" + groovyscript + "' is empty."); return; } try @@ -1669,7 +1741,7 @@ public class Jalview sfile = tfile.getAbsoluteFile().toURI().toURL(); } catch (Exception ex) { - System.err.println("Failed to create a file URL for " + jalview.bin.Console.errPrintln("Failed to create a file URL for " + tfile.getAbsoluteFile()); return; } @@ -1694,8 +1766,9 @@ public class Jalview } } catch (Exception e) { - System.err.println("Exception Whilst trying to execute file " + sfile - + " as a groovy script."); + jalview.bin.Console + .errPrintln("Exception Whilst trying to execute file " + sfile + + " as a groovy script."); e.printStackTrace(System.err); } @@ -1724,7 +1797,7 @@ public class Jalview public void quit() { // System.exit will run the shutdownHook first - Jalview.exit("Quitting now. Bye!", 0); + Jalview.exit("Quitting now. Bye!", ExitCode.OK); } public static AlignFrame getCurrentAlignFrame() @@ -1737,13 +1810,14 @@ public class Jalview Jalview.currentAlignFrame = currentAlignFrame; } - protected Commands getCommands() + public Commands getCommands() { return cmds; } - public static void exit(String message, int exitcode) + public static void exit(String message, ExitCode ec) { + int exitcode = ec == ExitCode.OK ? 0 : ec.ordinal() + 1; if (Console.log == null) { // Don't start the logger just to exit! @@ -1751,11 +1825,11 @@ public class Jalview { if (exitcode == 0) { - System.out.println(message); + Console.outPrintln(message); } else { - System.err.println(message); + jalview.bin.Console.errPrintln(message); } } } @@ -1780,8 +1854,35 @@ public class Jalview } } - /* - * testoutput for string values + public enum ExitCode + { + // only add new ones to the end of the list (to preserve ordinal values) + OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT, + INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS, + ERROR_RUNNING_COMMANDS, NO_LOGGING; + } + + /****************************** + * + * TEST OUTPUT METHODS + * + * these operate only when Arg.TESTOUTPUT has been passed, and variously check + * if an expected value / arg was set and report it to the test framework. + * + ******************************/ + /** + * report string values parsed/processed during tests When the Bootstrap + * argument Arg.TESTOUTPUT is present - reports on debug if given s1 is not + * null and not equals s2, warns if given argument is not set, and calls + * testoutput(true,a,s1,s2) to report processing progress. + * + * @param ap + * - ArgParser handling parsing + * @param a + * - Arg currently being processed + * @param s1 + * - expected + * @param s2 */ protected static void testoutput(ArgParser ap, Arg a, String s1, String s2) @@ -1805,6 +1906,12 @@ public class Jalview testoutput(true, a, s1, s2); } + /** + * report values passed via bootstrap arguments + * + * TODO: significant code duplication with testouput(Argparser...) - move it + */ + protected static void testoutput(BootstrapArgs bsa, Arg a, String s1, String s2) { @@ -1829,18 +1936,22 @@ public class Jalview testoutput(true, a, s1, s2); } + /** + * conditionally (on @param yes) report that expected value s1 was set during + * CommandsTest tests + */ private static void testoutput(boolean yes, Arg a, String s1, String s2) { if (yes && ((s1 == null && s2 == null) || (s1 != null && s1.equals(s2)))) { - System.out.println("[TESTOUTPUT] arg " + a.argString() + "='" + s1 + Console.outPrintln("[TESTOUTPUT] arg " + a.argString() + "='" + s1 + "' was set"); } } /* - * testoutput for boolean values + * testoutput for boolean and unary values */ protected static void testoutput(ArgParser ap, Arg a) { @@ -1883,7 +1994,99 @@ public class Jalview private static void testoutput(boolean yes, Arg a) { - System.out.println("[TESTOUTPUT] arg " - + (yes ? a.argString() : a.negateArgString()) + " was set"); + String message = null; + if (a.hasOption(Opt.BOOLEAN)) + { + message = (yes ? a.argString() : a.negateArgString()) + " was set"; + } + else if (a.hasOption(Opt.UNARY)) + { + message = a.argString() + (yes ? " was set" : " was not set"); + } + Console.outPrintln("[TESTOUTPUT] arg " + message); + } + + public ArgParser getArgParser() + { + return argparser; } + + public BootstrapArgs getBootstrapArgs() + { + return bootstrapArgs; + } + + public static boolean isBatchMode() + { + return getInstance() != null && (getInstance().desktop == null + || getInstance().desktop.isInBatchMode()); + } + + /** + * Warning about old or mixed command line arguments + */ + private void mixedCliWarning() + { + Jalview j = Jalview.getInstance(); + boolean mixedStyle = j.getArgParser() != null + && j.getArgParser().isMixedStyle(); + String title = MessageManager.getString("label.command_line_arguments"); + if (mixedStyle) + { + String warning = MessageManager.formatMessage( + "warning.using_mixed_command_line_arguments", + j.getArgParser().getMixedExamples()); + String quit = MessageManager.getString("action.quit"); + + Desktop.instance.nonBlockingDialog(title, warning, null, quit, + JvOptionPane.WARNING_MESSAGE, false, false, true, 30000); + + Jalview.exit( + "Exiting due to mixed old and new command line arguments.", + ExitCode.MIXED_CLI_ARGUMENTS); + } + } + + private void cliWarning() + { + Jalview j = Jalview.getInstance(); + Commands c = j.getCommands(); + boolean oldStyle = j.getArgParser() != null + && j.getArgParser().isOldStyle(); + String title = MessageManager.getString("label.command_line_arguments"); + if (oldStyle) + { + String warning = MessageManager + .getString("warning.using_old_command_line_arguments"); + String url = "https://www.jalview.org/help/html/features/commandline.html"; + if (Desktop.instance != null) + { + String cont = MessageManager.getString("label.continue"); + + Desktop.instance.nonBlockingDialog(title, warning, url, cont, + JvOptionPane.WARNING_MESSAGE, false, true, true, 2000); + } + } + if (j.getCommands() != null && j.getCommands().getErrors().size() > 0) + { + if (Desktop.instance != null) + { + String message = MessageManager + .getString("warning.the_following_errors"); + String ok = MessageManager.getString("action.ok"); + int shortest = 60; + List errors = j.getCommands().getErrors(); + for (int i = 0; i < errors.size(); i++) + { + shortest = Math.min(shortest, errors.get(i).length()); + } + Desktop.instance.nonBlockingDialog( + Math.max(message.length(), Math.min(60, shortest)), + Math.min(errors.size(), 20), title, message, + j.getCommands().errorsToString(), ok, + JvOptionPane.WARNING_MESSAGE, true, false, true, -1); + } + } + } + }