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;
public static AlignFrame currentAlignFrame;
- public ArgParser argparser = null;
+ private ArgParser argparser = null;
- public BootstrapArgs bootstrapArgs = null;
+ private BootstrapArgs bootstrapArgs = null;
private boolean QUIET = false;
*
*/
{
- System.out.println("not in js");
+ Console.outPrintln("not in js");
}
// BH - for event debugging in JavaScript (Java mode only)
}.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);
}
}
// stop now if only after --version
if (bootstrapArgs.contains(Arg.VERSION))
{
- Jalview.exit(null, 0);
+ Jalview.exit(null, ExitCode.OK);
}
// old ArgsParser
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");
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);
{
List<Map.Entry<Type, String>> 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"))
{
* 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
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");
}
}
}
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),
{
headless = true;
}
- System.setProperty("http.agent",
- "Jalview Desktop/" + Cache.getDefault("VERSION", "Unknown"));
+ System.setProperty("http.agent", HttpUtils.getUserAgent());
try
{
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);
}
desktop = null;
desktop = new Desktop();
desktop.setInBatchMode(true); // indicate we are starting up
+ mixedCliWarning();
+
try
{
JalviewTaskbar.setTaskbar(this);
}
else
{
- System.out.println("CMD [-nousagestats] executed successfully!");
+ Console.outPrintln("CMD [-nousagestats] executed successfully!");
testoutput(argparser, Arg.NOUSAGESTATS);
}
// 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
}
else
{
- System.out
- .println("CMD [-noquestionnaire] executed successfully!");
+ Console.outPrintln(
+ "CMD [-noquestionnaire] executed successfully!");
testoutput(argparser, Arg.QUESTIONNAIRE);
}
}
}
}
+ 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)
}
else
{
- // record usage stats if in headless mode
- if (Cache.getDefault("USAGESTATS", false))
- {
- Cache.initGoogleTracker(headlessArg);
- }
Jalview.exit("Successfully completed commands in headless mode",
- 0);
+ ExitCode.OK);
}
}
Console.info("Successfully completed commands");
{
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");
}
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;
.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())
/**
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 + "'");
}
format);
if (af == null)
{
- System.out.println("error");
+ Console.outPrintln("error");
}
else
{
if (cs != null)
{
- System.out.println(
+ Console.outPrintln(
"CMD [-colour " + data + "] executed successfully!");
}
af.changeColour(cs);
{
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);
{
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!");
}
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.
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"))
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"))
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);
{
try
{
- System.out.println(
+ Console.outPrintln(
"CMD [-tree " + data + "] executed successfully!");
NewickFile nf = new NewickFile(data,
AppletFormatAdapter.checkProtocol(data));
.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);
}
}
{
// 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;
}
if (outputFormat.equalsIgnoreCase("png"))
{
- System.out.println("Creating PNG image: " + file);
+ Console.outPrintln("Creating PNG image: " + file);
af.createPNG(new File(file));
imageName = (new File(file)).getName();
continue;
}
else if (outputFormat.equalsIgnoreCase("svg"))
{
- System.out.println("Creating SVG image: " + file);
+ Console.outPrintln("Creating SVG image: " + file);
File imageFile = new File(file);
imageName = imageFile.getName();
af.createSVG(imageFile);
imageName = imageFile.getName();
HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
- System.out.println("Creating HTML image: " + file);
+ Console.outPrintln("Creating HTML image: " + file);
htmlSVG.exportHTML(file);
continue;
}
{
if (file == null)
{
- System.err.println("The output html file must not be null");
+ jalview.bin.Console.errPrintln(
+ "The output html file must not be null");
return;
}
try
e.printStackTrace();
}
BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
- System.out.println(
+ Console.outPrintln(
"Creating BioJS MSA Viwer HTML file: " + file);
bjs.exportHTML(file);
continue;
}
else if (outputFormat.equalsIgnoreCase("imgMap"))
{
- System.out.println("Creating image map: " + file);
+ Console.outPrintln("Creating image map: " + file);
af.createImageMap(new File(file), imageName);
continue;
}
else if (outputFormat.equalsIgnoreCase("eps"))
{
File outputFile = new File(file);
- System.out.println(
+ Console.outPrintln(
"Creating EPS file: " + outputFile.getAbsolutePath());
af.createEPS(outputFile);
continue;
outFormat = FileFormats.getInstance().forName(outputFormat);
} catch (Exception formatP)
{
- System.out.println("Couldn't parse " + outFormat
+ Console.outPrintln("Couldn't parse " + outFormat
+ " as a valid Jalview format string.");
}
if (outFormat != null)
{
if (!outFormat.isWritable())
{
- System.out.println(
+ Console.outPrintln(
"This version of Jalview does not support alignment export as "
+ outputFormat);
}
af.saveAlignment(file, outFormat);
if (af.isSaveAlignmentSuccessful())
{
- System.out.println("Written alignment in "
+ Console.outPrintln("Written alignment in "
+ outFormat.getName() + " format to " + file);
}
else
{
- System.out.println("Error writing file " + file + " in "
+ Console.outPrintln("Error writing file " + file + " in "
+ outFormat.getName() + " format!!");
}
}
}
} catch (ImageOutputException ioexc)
{
- System.out.println(
+ 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());
}
}
}
{
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);
}
}
desktop.setInBatchMode(false);
}
+
+ cliWarning();
}
private static void setLookAndFeel()
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");
/*
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"
+ "-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,
*/
PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
"USAGESTATS",
- MessageManager.getString("prompt.google_analytics_title"),
- MessageManager.getString("prompt.google_analytics"),
+ 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()
@Override
public void run()
{
- Console.debug("Not enabling Google Tracking.");
+ Console.debug("Not enabling analytics.");
}
}, null, true);
desktop.addDialogThread(prompter);
} 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;
}
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();
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
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;
}
}
} 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);
}
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()
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!
{
if (exitcode == 0)
{
- System.out.println(message);
+ Console.outPrintln(message);
}
else
{
- System.err.println(message);
+ jalview.bin.Console.errPrintln(message);
}
}
}
}
}
+ 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;
+ }
+
/******************************
*
* 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.
+ *
******************************/
/**
- * method for reporting string values parsed/processed during tests
+ * 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)
}
/**
- * method for reporting string values parsed/processed during tests
+ * 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,
}
/**
- * report value set for string values parsed/processed during tests
+ * 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");
}
}
{
message = a.argString() + (yes ? " was set" : " was not set");
}
- System.out.println("[TESTOUTPUT] arg " + message);
+ 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, quit,
+ JvOptionPane.WARNING_MESSAGE, false, true);
+
+ 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 = "<a href=\"https://www.jalview.org/help/html/features/commandline.html\">https://www.jalview.org/help/html/features/commandline.html</a>";
+ if (Desktop.instance != null)
+ {
+ String cont = MessageManager.getString("label.continue");
+
+ Desktop.instance.nonBlockingDialog(32, 2, title, warning, url, cont,
+ JvOptionPane.WARNING_MESSAGE, false, true, true);
+ }
+ }
+ 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<String> 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);
+ }
+ }
}
+
}