From 560b04c9edddce9ccc69b59b5e7db934cf1e0cf0 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 17 Mar 2023 21:15:30 +0000 Subject: [PATCH] JAL-629 All applications System.exits going through Jalview.exit --- src/jalview/bin/ArgParser.java | 12 +++++----- src/jalview/bin/Commands.java | 3 +-- src/jalview/bin/Jalview.java | 49 ++++++++++++++++++++++++-------------- src/jalview/bin/Launcher.java | 1 - src/jalview/gui/Desktop.java | 3 +-- src/jalview/io/NewickFile.java | 18 +++++++------- src/jalview/util/AWTConsole.java | 5 ++-- 7 files changed, 51 insertions(+), 40 deletions(-) diff --git a/src/jalview/bin/ArgParser.java b/src/jalview/bin/ArgParser.java index 14785ea..fca2320 100644 --- a/src/jalview/bin/ArgParser.java +++ b/src/jalview/bin/ArgParser.java @@ -1199,20 +1199,20 @@ public class ArgParser { if (!argFile.exists()) { - System.err.println(DOUBLEDASH + String message = DOUBLEDASH + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + "=\"" - + argFile.getPath() + "\": File does not exist."); - System.exit(2); + + argFile.getPath() + "\": File does not exist."; + Jalview.exit(message, 2); } try { argsList.addAll(Files.readAllLines(Paths.get(argFile.getPath()))); } catch (IOException e) { - System.err.println(DOUBLEDASH + String message = DOUBLEDASH + Arg.ARGFILE.name().toLowerCase(Locale.ROOT) + "=\"" - + argFile.getPath() + "\": File could not be read."); - System.exit(3); + + argFile.getPath() + "\": File could not be read."; + Jalview.exit(message, 3); } } return new ArgParser(argsList); diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 26ce8c3..f71ebf3 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -374,8 +374,7 @@ public class Commands { if (headless) { - Console.error("Could not open any files in headless mode"); - System.exit(1); + Jalview.exit("Could not open any files in headless mode", 1); } else { diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index a728bc8..fbbb16c 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -365,9 +365,9 @@ public class Jalview } catch (NoClassDefFoundError error) { error.printStackTrace(); - System.out.println("\nEssential logging libraries not found." - + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"); - System.exit(0); + String message = "\nEssential logging libraries not found." + + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"; + Jalview.exit(message, 0); } // register SIGTERM listener @@ -427,7 +427,7 @@ public class Jalview || argparser.getBool(Arg.HELP)) { showUsage(); - System.exit(0); + Jalview.exit(null, 0); } if (bootstrapArgs.contains(Arg.HEADLESS)) @@ -501,9 +501,9 @@ public class Jalview NoClassDefFoundError error) { error.printStackTrace(); - System.out.println("\nEssential logging libraries not found." - + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"); - System.exit(0); + String message = "\nEssential logging libraries not found." + + "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview"; + Jalview.exit(message, 0); } desktop = null; @@ -647,18 +647,19 @@ public class Jalview boolean commandsSuccess = cmds.argsWereParsed(); if (commandsSuccess) { - Console.info("Successfully completed commands"); if (headlessArg) { - System.out.println("#### EXITING"); - System.exit(0); + Jalview.exit("Successfully completed commands in headless mode", 0); } + Console.info("Successfully completed commands"); } else { - Console.warn("Error when running commands"); if (headlessArg) - System.exit(1); + { + Jalview.exit("Error when running Commands in headless mode", 1); + } + Console.warn("Error when running commands"); } // Check if JVM and compile version might cause problems and log if it @@ -706,8 +707,7 @@ public class Jalview if (file == null && desktop == null) { - System.out.println("No files to open!"); - System.exit(1); + Jalview.exit("No files to open!", 1); } long progress = -1; @@ -734,11 +734,12 @@ public class Jalview { if (!(new File(file)).exists()) { - System.out.println("Can't find " + file); if (headless) { - System.exit(1); + Jalview.exit( + "Can't find file '" + file + "' in headless mode", 1); } + Console.warn("Can't find file'" + file + "'"); } } } @@ -1578,8 +1579,7 @@ public class Jalview public void quit() { // System.exit will run the shutdownHook first - System.out.println("Quitting now. Bye!"); - System.exit(0); + Jalview.exit("Quitting now. Bye!", 0); } public static AlignFrame getCurrentAlignFrame() @@ -1596,4 +1596,17 @@ public class Jalview { return cmds; } + + public static void exit(String message, int exitcode) + { + System.err.println("####### EXITING HERE!"); + Console.debug("Using Jalview.exit"); + if (message != null) + if (exitcode == 0) + Console.info(message); + else + Console.error(message); + if (exitcode > -1) + System.exit(exitcode); + } } diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index 9e1fb51..cab2c00 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -254,7 +254,6 @@ public class Launcher { e.printStackTrace(); } - // System.exit(0); } } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index ba7665b..981a060 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -1436,8 +1436,7 @@ public class Desktop extends jalview.jbgui.GDesktop // this will run the shutdownHook but QuitHandler.getQuitResponse() should // not run a second time if gotQuitResponse flag has been set (i.e. user // confirmed quit of some kind). - System.out.println("Desktop exiting."); - System.exit(0); + Jalview.exit("Desktop exiting.", 0); } private void storeLastKnownDimensions(String string, Rectangle jc) diff --git a/src/jalview/io/NewickFile.java b/src/jalview/io/NewickFile.java index 027390a..98978d0 100755 --- a/src/jalview/io/NewickFile.java +++ b/src/jalview/io/NewickFile.java @@ -26,19 +26,19 @@ // TODO: Extended SequenceNodeI to hold parsed NHX strings package jalview.io; -import java.util.Locale; - -import jalview.datamodel.SequenceNode; -import jalview.util.MessageManager; - import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.util.Locale; import java.util.StringTokenizer; import com.stevesoft.pat.Regex; +import jalview.bin.Jalview; +import jalview.datamodel.SequenceNode; +import jalview.util.MessageManager; + /** * Parse a new hanpshire style tree Caveats: NHX files are NOT supported and the * tree distances and topology are unreliable when they are parsed. TODO: on @@ -487,7 +487,8 @@ public class NewickFile extends FileParse { try { - distance = (Double.valueOf(ndist.stringMatched(1))).floatValue(); + distance = (Double.valueOf(ndist.stringMatched(1))) + .floatValue(); HasDistances = true; nodehasdistance = true; } catch (Exception e) @@ -944,9 +945,8 @@ public class NewickFile extends FileParse { if (args == null || args.length != 1) { - System.err.println( - "Takes one argument - file name of a newick tree file."); - System.exit(0); + Jalview.exit( + "Takes one argument - file name of a newick tree file.", 0); } File fn = new File(args[0]); diff --git a/src/jalview/util/AWTConsole.java b/src/jalview/util/AWTConsole.java index ab049a3..cf44dcb 100644 --- a/src/jalview/util/AWTConsole.java +++ b/src/jalview/util/AWTConsole.java @@ -48,6 +48,8 @@ import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.io.PrintStream; +import jalview.bin.Jalview; + public class AWTConsole extends WindowAdapter implements WindowListener, ActionListener, Runnable { @@ -174,8 +176,7 @@ public class AWTConsole extends WindowAdapter } catch (Exception e) { } - System.out.println("Window closing. Bye!"); - System.exit(0); + Jalview.exit("Window closing. Bye!", 0); } @Override -- 1.7.10.2