JAL-629 Change all stdout and stderr output to use Console.outPrintln and Console...
[jalview.git] / src / jalview / bin / Jalview.java
index e2b5bfb..e229079 100755 (executable)
@@ -274,7 +274,7 @@ public class Jalview
      * 
      */
     {
-      Console.outputMessage("not in js");
+      Console.outPrintln("not in js");
     }
 
     // BH - for event debugging in JavaScript (Java mode only)
@@ -386,28 +386,27 @@ public class Jalview
     if (!quiet() || !bootstrapArgs.outputToStdout()
             || bootstrapArgs.contains(Arg.VERSION))
     {
-      Console.outputMessage(
+      Console.outPrintln(
               "Java version: " + System.getProperty("java.version"));
-      Console.outputMessage(
-              "Java home: " + System.getProperty("java.home"));
-      Console.outputMessage("Java arch: " + System.getProperty("os.arch")
-              + " " + System.getProperty("os.name") + " "
+      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)
       {
-        Console.outputMessage("Install4j version: " + val);
+        Console.outPrintln("Install4j version: " + val);
       }
       val = System.getProperty("installer_template_version");
       if (val != null)
       {
-        Console.outputMessage("Install4j template version: " + val);
+        Console.outPrintln("Install4j template version: " + val);
       }
       val = System.getProperty("launcher_version");
       if (val != null)
       {
-        Console.outputMessage("Launcher version: " + val);
+        Console.outPrintln("Launcher version: " + val);
       }
     }
 
@@ -512,7 +511,7 @@ public class Jalview
     Cache.loadProperties(usrPropsFile);
     if (usrPropsFile != null)
     {
-      Console.outputMessage(
+      Console.outPrintln(
               "CMD [-props " + usrPropsFile + "] executed successfully!");
       testoutput(bootstrapArgs, Arg.PROPS,
               "test/jalview/bin/testProps.jvprops", usrPropsFile);
@@ -544,8 +543,8 @@ public class Jalview
       {
         List<Map.Entry<Type, String>> helpArgs = bootstrapArgs
                 .getList(Arg.HELP);
-        Console.outputMessage(Arg.usage(helpArgs.stream()
-                .map(e -> e.getKey()).collect(Collectors.toList())));
+        Console.outPrintln(Arg.usage(helpArgs.stream().map(e -> e.getKey())
+                .collect(Collectors.toList())));
         Jalview.exit(null, 0);
       }
       if (aparser.contains("help") || aparser.contains("h"))
@@ -554,7 +553,7 @@ public class Jalview
          * Now using new usage statement.
         showUsage();
         */
-        Console.outputMessage(Arg.usage());
+        Console.outPrintln(Arg.usage());
         Jalview.exit(null, 0);
       }
 
@@ -584,13 +583,13 @@ public class Jalview
         try
         {
           Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
-          Console.outputMessage(
+          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");
         }
       }
@@ -620,7 +619,8 @@ public class Jalview
       }
       else
       {
-        System.err.println("Executing setprop argument: " + setprop);
+        jalview.bin.Console
+                .errPrintln("Executing setprop argument: " + setprop);
         if (Platform.isJS())
         {
           Cache.setProperty(setprop.substring(0, p),
@@ -752,8 +752,7 @@ public class Jalview
         }
         else
         {
-          Console.outputMessage(
-                  "CMD [-nousagestats] executed successfully!");
+          Console.outPrintln("CMD [-nousagestats] executed successfully!");
           testoutput(argparser, Arg.NOUSAGESTATS);
         }
 
@@ -769,7 +768,7 @@ public class Jalview
             // questionnaire
             Console.debug("Starting questionnaire url at " + url);
             desktop.checkForQuestionnaire(url);
-            Console.outputMessage("CMD questionnaire[-" + url
+            Console.outPrintln("CMD questionnaire[-" + url
                     + "] executed successfully!");
           }
           else
@@ -790,7 +789,7 @@ public class Jalview
         }
         else
         {
-          Console.outputMessage(
+          Console.outPrintln(
                   "CMD [-noquestionnaire] executed successfully!");
           testoutput(argparser, Arg.QUESTIONNAIRE);
         }
@@ -881,8 +880,7 @@ public class Jalview
                         .getString("status.processing_commandline_args"),
                 progress = System.currentTimeMillis());
       }
-      Console.outputMessage(
-              "CMD [-open " + file + "] executed successfully!");
+      Console.outPrintln("CMD [-open " + file + "] executed successfully!");
 
       if (!Platform.isJS())
       /**
@@ -919,7 +917,7 @@ public class Jalview
               format);
       if (af == null)
       {
-        Console.outputMessage("error");
+        Console.outPrintln("error");
       }
       else
       {
@@ -934,7 +932,7 @@ public class Jalview
 
           if (cs != null)
           {
-            Console.outputMessage(
+            Console.outPrintln(
                     "CMD [-colour " + data + "] executed successfully!");
           }
           af.changeColour(cs);
@@ -946,8 +944,8 @@ public class Jalview
         {
           af.parseFeaturesFile(data,
                   AppletFormatAdapter.checkProtocol(data));
-          // Console.outputMessage("Added " + data);
-          Console.outputMessage(
+          // Console.outPrintln("Added " + data);
+          Console.outPrintln(
                   "CMD groups[-" + data + "]  executed successfully!");
         }
         data = aparser.getValue("features", true);
@@ -955,8 +953,8 @@ public class Jalview
         {
           af.parseFeaturesFile(data,
                   AppletFormatAdapter.checkProtocol(data));
-          // Console.outputMessage("Added " + data);
-          Console.outputMessage(
+          // Console.outPrintln("Added " + data);
+          Console.outPrintln(
                   "CMD [-features " + data + "]  executed successfully!");
         }
 
@@ -964,8 +962,8 @@ public class Jalview
         if (data != null)
         {
           af.loadJalviewDataFile(data, null, null, null);
-          // Console.outputMessage("Added " + data);
-          Console.outputMessage(
+          // Console.outPrintln("Added " + data);
+          Console.outPrintln(
                   "CMD [-annotations " + data + "] executed successfully!");
         }
         // set or clear the sortbytree flag.
@@ -974,8 +972,7 @@ public class Jalview
           af.getViewport().setSortByTree(true);
           if (af.getViewport().getSortByTree())
           {
-            Console.outputMessage(
-                    "CMD [-sortbytree] executed successfully!");
+            Console.outPrintln("CMD [-sortbytree] executed successfully!");
           }
         }
         if (aparser.contains("no-annotation"))
@@ -983,8 +980,7 @@ public class Jalview
           af.getViewport().setShowAnnotation(false);
           if (!af.getViewport().isShowAnnotation())
           {
-            Console.outputMessage(
-                    "CMD no-annotation executed successfully!");
+            Console.outPrintln("CMD no-annotation executed successfully!");
           }
         }
         if (aparser.contains("nosortbytree"))
@@ -992,7 +988,7 @@ public class Jalview
           af.getViewport().setSortByTree(false);
           if (!af.getViewport().getSortByTree())
           {
-            Console.outputMessage(
+            Console.outPrintln(
                     "CMD [-nosortbytree] executed successfully!");
           }
         }
@@ -1001,7 +997,7 @@ public class Jalview
         {
           try
           {
-            Console.outputMessage(
+            Console.outPrintln(
                     "CMD [-tree " + data + "] executed successfully!");
             NewickFile nf = new NewickFile(data,
                     AppletFormatAdapter.checkProtocol(data));
@@ -1009,7 +1005,7 @@ 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);
           }
         }
@@ -1018,9 +1014,9 @@ public class Jalview
         {
           // Execute the groovy script after we've done all the rendering stuff
           // and before any images or figures are generated.
-          Console.outputMessage("Executing script " + groovyscript);
+          Console.outPrintln("Executing script " + groovyscript);
           executeGroovyScript(groovyscript, af);
-          Console.outputMessage("CMD groovy[" + groovyscript
+          Console.outPrintln("CMD groovy[" + groovyscript
                   + "] executed successfully!");
           groovyscript = null;
         }
@@ -1034,14 +1030,14 @@ public class Jalview
 
             if (outputFormat.equalsIgnoreCase("png"))
             {
-              Console.outputMessage("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"))
             {
-              Console.outputMessage("Creating SVG image: " + file);
+              Console.outPrintln("Creating SVG image: " + file);
               File imageFile = new File(file);
               imageName = imageFile.getName();
               af.createSVG(imageFile);
@@ -1053,7 +1049,7 @@ public class Jalview
               imageName = imageFile.getName();
               HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
 
-              Console.outputMessage("Creating HTML image: " + file);
+              Console.outPrintln("Creating HTML image: " + file);
               htmlSVG.exportHTML(file);
               continue;
             }
@@ -1061,7 +1057,8 @@ public class Jalview
             {
               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
@@ -1073,21 +1070,21 @@ public class Jalview
                 e.printStackTrace();
               }
               BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
-              Console.outputMessage(
+              Console.outPrintln(
                       "Creating BioJS MSA Viwer HTML file: " + file);
               bjs.exportHTML(file);
               continue;
             }
             else if (outputFormat.equalsIgnoreCase("imgMap"))
             {
-              Console.outputMessage("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);
-              Console.outputMessage(
+              Console.outPrintln(
                       "Creating EPS file: " + outputFile.getAbsolutePath());
               af.createEPS(outputFile);
               continue;
@@ -1099,14 +1096,14 @@ public class Jalview
               outFormat = FileFormats.getInstance().forName(outputFormat);
             } catch (Exception formatP)
             {
-              Console.outputMessage("Couldn't parse " + outFormat
+              Console.outPrintln("Couldn't parse " + outFormat
                       + " as a valid Jalview format string.");
             }
             if (outFormat != null)
             {
               if (!outFormat.isWritable())
               {
-                Console.outputMessage(
+                Console.outPrintln(
                         "This version of Jalview does not support alignment export as "
                                 + outputFormat);
               }
@@ -1115,19 +1112,19 @@ public class Jalview
                 af.saveAlignment(file, outFormat);
                 if (af.isSaveAlignmentSuccessful())
                 {
-                  Console.outputMessage("Written alignment in "
+                  Console.outPrintln("Written alignment in "
                           + outFormat.getName() + " format to " + file);
                 }
                 else
                 {
-                  Console.outputMessage("Error writing file " + file
-                          + " in " + outFormat.getName() + " format!!");
+                  Console.outPrintln("Error writing file " + file + " in "
+                          + outFormat.getName() + " format!!");
                 }
               }
             }
           } catch (ImageOutputException ioexc)
           {
-            Console.outputMessage(
+            Console.outPrintln(
                     "Unexpected error whilst exporting image to " + file);
             ioexc.printStackTrace();
           }
@@ -1136,7 +1133,7 @@ public class Jalview
 
         while (aparser.getSize() > 0)
         {
-          Console.outputMessage("Unknown arg: " + aparser.nextValue());
+          Console.outPrintln("Unknown arg: " + aparser.nextValue());
         }
       }
     }
@@ -1204,12 +1201,12 @@ public class Jalview
     {
       if (Cache.groovyJarsPresent())
       {
-        Console.outputMessage("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);
       }
@@ -1554,7 +1551,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"
@@ -1665,9 +1662,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;
       }
@@ -1676,7 +1674,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();
@@ -1693,17 +1691,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
@@ -1711,7 +1712,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;
         }
@@ -1736,8 +1737,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);
 
     }
@@ -1793,11 +1795,11 @@ public class Jalview
       {
         if (exitcode == 0)
         {
-          Console.outputMessage(message);
+          Console.outPrintln(message);
         }
         else
         {
-          System.err.println(message);
+          jalview.bin.Console.errPrintln(message);
         }
       }
     }
@@ -1889,7 +1891,7 @@ public class Jalview
     if (yes && ((s1 == null && s2 == null)
             || (s1 != null && s1.equals(s2))))
     {
-      Console.outputMessage("[TESTOUTPUT] arg " + a.argString() + "='" + s1
+      Console.outPrintln("[TESTOUTPUT] arg " + a.argString() + "='" + s1
               + "' was set");
     }
   }
@@ -1947,6 +1949,6 @@ public class Jalview
     {
       message = a.argString() + (yes ? " was set" : " was not set");
     }
-    Console.outputMessage("[TESTOUTPUT] arg " + message);
+    Console.outPrintln("[TESTOUTPUT] arg " + message);
   }
 }