JAL-629 Move more stdout messages to stderr when outputting file to stdout
[jalview.git] / src / jalview / bin / Jalview.java
index 57f2575..e2b5bfb 100755 (executable)
@@ -274,7 +274,7 @@ public class Jalview
      * 
      */
     {
-      System.out.println("not in js");
+      Console.outputMessage("not in js");
     }
 
     // BH - for event debugging in JavaScript (Java mode only)
@@ -383,29 +383,31 @@ public class Jalview
       }.start();
     }
 
-    if (!quiet() || bootstrapArgs.contains(Arg.VERSION))
+    if (!quiet() || !bootstrapArgs.outputToStdout()
+            || bootstrapArgs.contains(Arg.VERSION))
     {
-      System.out.println(
+      Console.outputMessage(
               "Java version: " + System.getProperty("java.version"));
-      System.out.println("Java home: " + System.getProperty("java.home"));
-      System.out.println("Java arch: " + System.getProperty("os.arch") + " "
-              + System.getProperty("os.name") + " "
+      Console.outputMessage(
+              "Java home: " + System.getProperty("java.home"));
+      Console.outputMessage("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.outputMessage("Install4j version: " + val);
       }
       val = System.getProperty("installer_template_version");
       if (val != null)
       {
-        System.out.println("Install4j template version: " + val);
+        Console.outputMessage("Install4j template version: " + val);
       }
       val = System.getProperty("launcher_version");
       if (val != null)
       {
-        System.out.println("Launcher version: " + val);
+        Console.outputMessage("Launcher version: " + val);
       }
     }
 
@@ -463,6 +465,7 @@ public class Jalview
     // register SIGTERM listener
     Runtime.getRuntime().addShutdownHook(new Thread()
     {
+      @Override
       public void run()
       {
         Console.debug("Running shutdown hook");
@@ -509,7 +512,7 @@ public class Jalview
     Cache.loadProperties(usrPropsFile);
     if (usrPropsFile != null)
     {
-      System.out.println(
+      Console.outputMessage(
               "CMD [-props " + usrPropsFile + "] executed successfully!");
       testoutput(bootstrapArgs, Arg.PROPS,
               "test/jalview/bin/testProps.jvprops", usrPropsFile);
@@ -541,8 +544,8 @@ public class Jalview
       {
         List<Map.Entry<Type, String>> helpArgs = bootstrapArgs
                 .getList(Arg.HELP);
-        System.out.println(Arg.usage(helpArgs.stream().map(e -> e.getKey())
-                .collect(Collectors.toList())));
+        Console.outputMessage(Arg.usage(helpArgs.stream()
+                .map(e -> e.getKey()).collect(Collectors.toList())));
         Jalview.exit(null, 0);
       }
       if (aparser.contains("help") || aparser.contains("h"))
@@ -551,7 +554,7 @@ public class Jalview
          * Now using new usage statement.
         showUsage();
         */
-        System.out.println(Arg.usage());
+        Console.outputMessage(Arg.usage());
         Jalview.exit(null, 0);
       }
 
@@ -581,7 +584,7 @@ public class Jalview
         try
         {
           Jws2Discoverer.getDiscoverer().setPreferredUrl(jabawsUrl);
-          System.out.println(
+          Console.outputMessage(
                   "CMD [-jabaws " + jabawsUrl + "] executed successfully!");
           testoutput(bootstrapArgs, Arg.JABAWS,
                   "http://www.compbio.dundee.ac.uk/jabaws", jabawsUrl);
@@ -617,7 +620,7 @@ public class Jalview
       }
       else
       {
-        System.out.println("Executing setprop argument: " + setprop);
+        System.err.println("Executing setprop argument: " + setprop);
         if (Platform.isJS())
         {
           Cache.setProperty(setprop.substring(0, p),
@@ -749,7 +752,8 @@ public class Jalview
         }
         else
         {
-          System.out.println("CMD [-nousagestats] executed successfully!");
+          Console.outputMessage(
+                  "CMD [-nousagestats] executed successfully!");
           testoutput(argparser, Arg.NOUSAGESTATS);
         }
 
@@ -765,7 +769,7 @@ public class Jalview
             // questionnaire
             Console.debug("Starting questionnaire url at " + url);
             desktop.checkForQuestionnaire(url);
-            System.out.println("CMD questionnaire[-" + url
+            Console.outputMessage("CMD questionnaire[-" + url
                     + "] executed successfully!");
           }
           else
@@ -786,8 +790,8 @@ public class Jalview
         }
         else
         {
-          System.out
-                  .println("CMD [-noquestionnaire] executed successfully!");
+          Console.outputMessage(
+                  "CMD [-noquestionnaire] executed successfully!");
           testoutput(argparser, Arg.QUESTIONNAIRE);
         }
 
@@ -877,7 +881,8 @@ public class Jalview
                         .getString("status.processing_commandline_args"),
                 progress = System.currentTimeMillis());
       }
-      System.out.println("CMD [-open " + file + "] executed successfully!");
+      Console.outputMessage(
+              "CMD [-open " + file + "] executed successfully!");
 
       if (!Platform.isJS())
       /**
@@ -914,7 +919,7 @@ public class Jalview
               format);
       if (af == null)
       {
-        System.out.println("error");
+        Console.outputMessage("error");
       }
       else
       {
@@ -929,7 +934,7 @@ public class Jalview
 
           if (cs != null)
           {
-            System.out.println(
+            Console.outputMessage(
                     "CMD [-colour " + data + "] executed successfully!");
           }
           af.changeColour(cs);
@@ -941,8 +946,8 @@ public class Jalview
         {
           af.parseFeaturesFile(data,
                   AppletFormatAdapter.checkProtocol(data));
-          // System.out.println("Added " + data);
-          System.out.println(
+          // Console.outputMessage("Added " + data);
+          Console.outputMessage(
                   "CMD groups[-" + data + "]  executed successfully!");
         }
         data = aparser.getValue("features", true);
@@ -950,8 +955,8 @@ public class Jalview
         {
           af.parseFeaturesFile(data,
                   AppletFormatAdapter.checkProtocol(data));
-          // System.out.println("Added " + data);
-          System.out.println(
+          // Console.outputMessage("Added " + data);
+          Console.outputMessage(
                   "CMD [-features " + data + "]  executed successfully!");
         }
 
@@ -959,8 +964,8 @@ public class Jalview
         if (data != null)
         {
           af.loadJalviewDataFile(data, null, null, null);
-          // System.out.println("Added " + data);
-          System.out.println(
+          // Console.outputMessage("Added " + data);
+          Console.outputMessage(
                   "CMD [-annotations " + data + "] executed successfully!");
         }
         // set or clear the sortbytree flag.
@@ -969,7 +974,8 @@ public class Jalview
           af.getViewport().setSortByTree(true);
           if (af.getViewport().getSortByTree())
           {
-            System.out.println("CMD [-sortbytree] executed successfully!");
+            Console.outputMessage(
+                    "CMD [-sortbytree] executed successfully!");
           }
         }
         if (aparser.contains("no-annotation"))
@@ -977,7 +983,8 @@ public class Jalview
           af.getViewport().setShowAnnotation(false);
           if (!af.getViewport().isShowAnnotation())
           {
-            System.out.println("CMD no-annotation executed successfully!");
+            Console.outputMessage(
+                    "CMD no-annotation executed successfully!");
           }
         }
         if (aparser.contains("nosortbytree"))
@@ -985,8 +992,8 @@ public class Jalview
           af.getViewport().setSortByTree(false);
           if (!af.getViewport().getSortByTree())
           {
-            System.out
-                    .println("CMD [-nosortbytree] executed successfully!");
+            Console.outputMessage(
+                    "CMD [-nosortbytree] executed successfully!");
           }
         }
         data = aparser.getValue("tree", true);
@@ -994,7 +1001,7 @@ public class Jalview
         {
           try
           {
-            System.out.println(
+            Console.outputMessage(
                     "CMD [-tree " + data + "] executed successfully!");
             NewickFile nf = new NewickFile(data,
                     AppletFormatAdapter.checkProtocol(data));
@@ -1011,9 +1018,9 @@ public class Jalview
         {
           // 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.outputMessage("Executing script " + groovyscript);
           executeGroovyScript(groovyscript, af);
-          System.out.println("CMD groovy[" + groovyscript
+          Console.outputMessage("CMD groovy[" + groovyscript
                   + "] executed successfully!");
           groovyscript = null;
         }
@@ -1027,14 +1034,14 @@ public class Jalview
 
             if (outputFormat.equalsIgnoreCase("png"))
             {
-              System.out.println("Creating PNG image: " + file);
+              Console.outputMessage("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.outputMessage("Creating SVG image: " + file);
               File imageFile = new File(file);
               imageName = imageFile.getName();
               af.createSVG(imageFile);
@@ -1046,7 +1053,7 @@ public class Jalview
               imageName = imageFile.getName();
               HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
 
-              System.out.println("Creating HTML image: " + file);
+              Console.outputMessage("Creating HTML image: " + file);
               htmlSVG.exportHTML(file);
               continue;
             }
@@ -1066,21 +1073,21 @@ public class Jalview
                 e.printStackTrace();
               }
               BioJsHTMLOutput bjs = new BioJsHTMLOutput(af.alignPanel);
-              System.out.println(
+              Console.outputMessage(
                       "Creating BioJS MSA Viwer HTML file: " + file);
               bjs.exportHTML(file);
               continue;
             }
             else if (outputFormat.equalsIgnoreCase("imgMap"))
             {
-              System.out.println("Creating image map: " + file);
+              Console.outputMessage("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.outputMessage(
                       "Creating EPS file: " + outputFile.getAbsolutePath());
               af.createEPS(outputFile);
               continue;
@@ -1092,14 +1099,14 @@ public class Jalview
               outFormat = FileFormats.getInstance().forName(outputFormat);
             } catch (Exception formatP)
             {
-              System.out.println("Couldn't parse " + outFormat
+              Console.outputMessage("Couldn't parse " + outFormat
                       + " as a valid Jalview format string.");
             }
             if (outFormat != null)
             {
               if (!outFormat.isWritable())
               {
-                System.out.println(
+                Console.outputMessage(
                         "This version of Jalview does not support alignment export as "
                                 + outputFormat);
               }
@@ -1108,19 +1115,19 @@ public class Jalview
                 af.saveAlignment(file, outFormat);
                 if (af.isSaveAlignmentSuccessful())
                 {
-                  System.out.println("Written alignment in "
+                  Console.outputMessage("Written alignment in "
                           + outFormat.getName() + " format to " + file);
                 }
                 else
                 {
-                  System.out.println("Error writing file " + file + " in "
-                          + outFormat.getName() + " format!!");
+                  Console.outputMessage("Error writing file " + file
+                          + " in " + outFormat.getName() + " format!!");
                 }
               }
             }
           } catch (ImageOutputException ioexc)
           {
-            System.out.println(
+            Console.outputMessage(
                     "Unexpected error whilst exporting image to " + file);
             ioexc.printStackTrace();
           }
@@ -1129,7 +1136,7 @@ public class Jalview
 
         while (aparser.getSize() > 0)
         {
-          System.out.println("Unknown arg: " + aparser.nextValue());
+          Console.outputMessage("Unknown arg: " + aparser.nextValue());
         }
       }
     }
@@ -1197,7 +1204,7 @@ public class Jalview
     {
       if (Cache.groovyJarsPresent())
       {
-        System.out.println("Executing script " + groovyscript);
+        Console.outputMessage("Executing script " + groovyscript);
         executeGroovyScript(groovyscript, startUpAlframe);
       }
       else
@@ -1786,7 +1793,7 @@ public class Jalview
       {
         if (exitcode == 0)
         {
-          System.out.println(message);
+          Console.outputMessage(message);
         }
         else
         {
@@ -1882,7 +1889,7 @@ public class Jalview
     if (yes && ((s1 == null && s2 == null)
             || (s1 != null && s1.equals(s2))))
     {
-      System.out.println("[TESTOUTPUT] arg " + a.argString() + "='" + s1
+      Console.outputMessage("[TESTOUTPUT] arg " + a.argString() + "='" + s1
               + "' was set");
     }
   }
@@ -1940,6 +1947,6 @@ public class Jalview
     {
       message = a.argString() + (yes ? " was set" : " was not set");
     }
-    System.out.println("[TESTOUTPUT] arg " + message);
+    Console.outputMessage("[TESTOUTPUT] arg " + message);
   }
 }