Merge branch 'develop' into releases/Release_2_11_2_Branch
[jalview.git] / src / jalview / bin / Cache.java
index 1a4f341..e10c9eb 100755 (executable)
@@ -50,7 +50,6 @@ import javax.swing.UIManager;
 import jalview.datamodel.PDBEntry;
 import jalview.gui.Preferences;
 import jalview.gui.UserDefinedColours;
-import jalview.log.JLogger;
 import jalview.log.JLoggerLog4j;
 import jalview.schemes.ColourSchemeLoader;
 import jalview.schemes.ColourSchemes;
@@ -59,7 +58,6 @@ import jalview.structure.StructureImportSettings;
 import jalview.urls.IdOrgSettings;
 import jalview.util.ChannelProperties;
 import jalview.util.ColorUtils;
-import jalview.util.Log4j;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.ws.sifts.SiftsSettings;
@@ -173,6 +171,8 @@ import jalview.ws.sifts.SiftsSettings;
  * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
  * respond to selections made in other alignments containing the same sequences.
  * </li>
+ * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
+ * auto-discover JABAWS services</li>
  * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
  * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
  * warning dialog box is displayed.</li>
@@ -200,7 +200,13 @@ import jalview.ws.sifts.SiftsSettings;
  * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
  * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
  * </li>
- * 
+ * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
+ * <li>NOHTMLTEMPLATES - when set, the
+ * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
+ * not downloaded automatically</li>
+ * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
+ * available URL linkouts via www.jalview.org/services/identifiers</li>
+ * <li>
  * </ul>
  * Deprecated settings:
  * <ul>
@@ -276,8 +282,6 @@ public class Cache
 
   public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
 
-  public static JLoggerLog4j log;
-
   // save the proxy properties set at startup
   public final static String[] startupProxyProperties = {
       System.getProperty("http.proxyHost"),
@@ -321,61 +325,6 @@ public class Cache
 
   private final static String JS_PROPERTY_PREFIX = "jalview_";
 
-  public final static String LOGGING_TEST_MESSAGE = "Logging to STDERR";
-
-  public static JLogger.LogLevel getCachedLogLevel()
-  {
-    return getCachedLogLevel(JALVIEWLOGLEVEL);
-  }
-
-  public static JLogger.LogLevel getCachedLogLevel(String key)
-  {
-    return JLogger.toLevel(Cache.getDefault(key, "INFO"));
-  }
-
-  public static boolean initLogger()
-  {
-    if (log != null)
-    {
-      return true;
-    }
-    try
-    {
-      JLogger.LogLevel cachedLevel = getCachedLogLevel();
-      if (!Platform.isJS())
-      {
-        Log4j.init(cachedLevel);
-      }
-      // log output
-      // is laxis used? Does getLogger do anything without a Logger object?
-      // Logger laxis = Log4j.getLogger("org.apache.axis", myLevel);
-      JLoggerLog4j.getLogger("org.apache.axis", cachedLevel);
-
-      // The main application logger
-      log = JLoggerLog4j.getLogger(JALVIEW_LOGGER_NAME, cachedLevel);
-    } catch (NoClassDefFoundError e)
-    {
-      System.err.println("Could not initialise the logger framework");
-      e.printStackTrace();
-    }
-
-    // Test message
-    if (log != null)
-    {
-      // Logging test message should got through the logger object
-      if (log.loggerExists())
-        log.debug(LOGGING_TEST_MESSAGE);
-      // Tell the user that debug is enabled
-      Cache.debug(ChannelProperties.getProperty("app_name")
-              + " Debugging Output Follows.");
-      return true;
-    }
-    else
-    {
-      return false;
-    }
-  }
-
   /**
    * Loads properties from the given properties file. Any existing properties
    * are first cleared.
@@ -486,7 +435,7 @@ public class Cache
     default:
       String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
               + proxyType;
-      Cache.warn(message);
+      Console.warn(message);
     }
 
     // LOAD THE AUTHORS FROM THE authors.props file
@@ -859,11 +808,11 @@ public class Cache
         if (jalview.jbgui.GDesktop.class.getClassLoader()
                 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
         {
-          debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
+          Console.debug("Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
           vamsasJarsArePresent = 1;
           JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
-                  getCachedLogLevel("logs.Vamsas.Level"));
-          JLoggerLog4j.addAppender(lvclient, log, JALVIEW_LOGGER_NAME);
+                  Console.getCachedLogLevel("logs.Vamsas.Level"));
+          JLoggerLog4j.addAppender(lvclient, Console.log, JALVIEW_LOGGER_NAME);
           // Tell the user that debug is enabled
           lvclient.debug(ChannelProperties.getProperty("app_name")
                   + " Vamsas Client Debugging Output Follows.");
@@ -871,7 +820,7 @@ public class Cache
       } catch (Exception e)
       {
         vamsasJarsArePresent = 0;
-        debug("Vamsas Classes are not present");
+        Console.debug("Vamsas Classes are not present");
       }
     }
     return (vamsasJarsArePresent > 0);
@@ -896,11 +845,11 @@ public class Cache
         if (Cache.class.getClassLoader()
                 .loadClass("groovy.lang.GroovyObject") != null)
         {
-          debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
+          Console.debug("Found Groovy (groovy.lang.GroovyObject can be loaded)");
           groovyJarsArePresent = 1;
           JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
-                  getCachedLogLevel("logs.Groovy.Level"));
-          JLoggerLog4j.addAppender(lgclient, log, JALVIEW_LOGGER_NAME);
+                  Console.getCachedLogLevel("logs.Groovy.Level"));
+          JLoggerLog4j.addAppender(lgclient, Console.log, JALVIEW_LOGGER_NAME);
           // Tell the user that debug is enabled
           lgclient.debug(ChannelProperties.getProperty("app_name")
                   + " Groovy Client Debugging Output Follows.");
@@ -908,11 +857,11 @@ public class Cache
       } catch (Error e)
       {
         groovyJarsArePresent = 0;
-        debug("Groovy Classes are not present", e);
+        Console.debug("Groovy Classes are not present", e);
       } catch (Exception e)
       {
         groovyJarsArePresent = 0;
-        debug("Groovy Classes are not present");
+        Console.debug("Groovy Classes are not present");
       }
     }
     return (groovyJarsArePresent > 0);
@@ -946,7 +895,7 @@ public class Cache
                   .loadClass("com.boxysystems.jgoogleanalytics.FocusPoint");
         } catch (Exception e)
         {
-          debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
+          Console.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
           tracker = null;
           jgoogleanalyticstracker = null;
           trackerfocus = null;
@@ -989,22 +938,22 @@ public class Cache
       {
         if (re != null)
         {
-          debug("Caught runtime exception in googletracker init:", re);
+          Console.debug("Caught runtime exception in googletracker init:", re);
         }
         if (ex != null)
         {
-          warn("Failed to initialise GoogleTracker for Jalview Desktop with version "
+          Console.warn("Failed to initialise GoogleTracker for Jalview Desktop with version "
                   + vrs, ex);
         }
         if (err != null)
         {
-          error("Whilst initing GoogleTracker for Jalview Desktop version "
+          Console.error("Whilst initing GoogleTracker for Jalview Desktop version "
                   + vrs, err);
         }
       }
       else
       {
-        debug("Successfully initialised tracker.");
+        Console.debug("Successfully initialised tracker.");
       }
     }
   }
@@ -1026,7 +975,7 @@ public class Cache
     Color col = ColorUtils.parseColourString(colprop);
     if (col == null)
     {
-      warn("Couldn't parse '" + colprop + "' as a colour for " + property);
+      Console.warn("Couldn't parse '" + colprop + "' as a colour for " + property);
     }
     return (col == null) ? defcolour : col;
   }
@@ -1306,7 +1255,7 @@ public class Cache
                             ? " [" + startupProxyProperties[6] + "]"
                             : "");
 
-    Cache.debug(sb.toString());
+    Console.debug(sb.toString());
   }
 
   public static void setProxyPropertiesFromPreferences()
@@ -1332,7 +1281,7 @@ public class Cache
     case Cache.PROXYTYPE_NONE:
       if (!previousProxyType.equals(proxyType))
       {
-        Cache.info("Setting no proxy settings");
+        Console.info("Setting no proxy settings");
         Cache.setProxyProperties(null, null, null, null, null, null, null,
                 null, null);
       }
@@ -1340,7 +1289,7 @@ public class Cache
     case Cache.PROXYTYPE_CUSTOM:
       // always re-set a custom proxy -- it might have changed, particularly
       // password
-      Cache.info("Setting custom proxy settings");
+      Console.info("Setting custom proxy settings");
       boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
       Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
               Cache.getDefault("PROXY_PORT", null),
@@ -1354,7 +1303,7 @@ public class Cache
               proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
       break;
     default: // system proxy settings by default
-      Cache.info("Setting system proxy settings");
+      Console.info("Setting system proxy settings");
       Cache.resetProxyProperties();
     }
   }
@@ -1406,7 +1355,7 @@ public class Cache
         char[] displayHttpPw = new char[httpPassword == null ? 0
                 : httpPassword.length];
         Arrays.fill(displayHttpPw, '*');
-        Cache.debug("CACHE Proxy: setting new Authenticator with httpUser='"
+        Console.debug("CACHE Proxy: setting new Authenticator with httpUser='"
                 + httpUser + "' httpPassword='" + displayHttpPw + "'");
         if (!Platform.isJS())
         /* *
@@ -1456,7 +1405,7 @@ public class Cache
                             && getRequestingPort() == Integer
                                     .valueOf(httpPort))
                     {
-                      Cache.debug(
+                      Console.debug(
                               "AUTHENTICATOR returning PasswordAuthentication(\""
                                       + httpUser + "\", '"
                                       + new String(displayHttpPw) + "')");
@@ -1471,7 +1420,7 @@ public class Cache
                     {
                       char[] displayHttpsPw = new char[httpPassword.length];
                       Arrays.fill(displayHttpsPw, '*');
-                      Cache.debug(
+                      Console.debug(
                               "AUTHENTICATOR returning PasswordAuthentication(\""
                                       + httpsUser + "\", '" + displayHttpsPw
                                       + "'");
@@ -1480,15 +1429,15 @@ public class Cache
                     }
                   } catch (NumberFormatException e)
                   {
-                    Cache.error("Problem with proxy port values [http:"
+                    Console.error("Problem with proxy port values [http:"
                             + httpPort + ", https:" + httpsPort + "]");
                   }
-                  Cache.debug(
+                  Console.debug(
                           "AUTHENTICATOR after trying to get PasswordAuthentication");
                 }
               }
               // non proxy request
-              Cache.debug("AUTHENTICATOR returning null");
+              Console.debug("AUTHENTICATOR returning null");
               return null;
             }
           });
@@ -1496,13 +1445,13 @@ public class Cache
 
         // required to re-enable basic authentication (should be okay for a
         // local proxy)
-        Cache.debug(
+        Console.debug(
                 "AUTHENTICATOR setting property 'jdk.http.auth.tunneling.disabledSchemes' to \"\"");
         System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
       } catch (SecurityException e)
       {
-        Cache.error("Could not set default Authenticator");
-        Cache.debug(getStackTraceString(e));
+        Console.error("Could not set default Authenticator");
+        Console.debug(getStackTraceString(e));
       }
     }
     else
@@ -1520,13 +1469,13 @@ public class Cache
        * 
        */
       {
-        Cache.debug("AUTHENTICATOR setting default Authenticator to null");
+        Console.debug("AUTHENTICATOR setting default Authenticator to null");
         Authenticator.setDefault(null);
       }
     }
 
     // nonProxyHosts not currently configurable in Preferences
-    Cache.debug("AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
+    Console.debug("AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
             + nonProxyHosts + "\"");
     setOrClearSystemProperty("http.nonProxyHosts", nonProxyHosts);
   }
@@ -1553,176 +1502,6 @@ public class Cache
     }
   }
 
-  public static void trace(String message)
-  {
-    if (initLogger())
-    {
-      log.trace(message, null);
-    }
-    else
-    {
-      System.out.println(message);
-    }
-  }
-
-  public static void trace(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.trace(message, t);
-    }
-    else
-    {
-      System.out.println(message);
-      t.printStackTrace();
-    }
-  }
-
-  public static void debug(String message)
-  {
-    if (initLogger())
-    {
-      log.debug(message, null);
-    }
-    else
-    {
-      System.out.println(message);
-    }
-
-  }
-
-  public static void debug(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.debug(message, t);
-    }
-    else
-    {
-      System.out.println(message);
-      t.printStackTrace();
-    }
-
-  }
-
-  public static void info(String message)
-  {
-    if (initLogger())
-    {
-      log.info(message, null);
-    }
-    else
-    {
-      System.out.println(message);
-    }
-
-  }
-
-  public static void info(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.info(message, t);
-    }
-    else
-    {
-      System.out.println(message);
-      t.printStackTrace();
-    }
-
-  }
-
-  public static void warn(String message)
-  {
-    if (initLogger())
-    {
-      log.warn(message, null);
-    }
-    else
-    {
-      System.out.println(message);
-    }
-
-  }
-
-  public static void warn(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.warn(message, t);
-    }
-    else
-    {
-      System.out.println(message);
-      t.printStackTrace();
-    }
-
-  }
-
-  public static void error(String message)
-  {
-    if (initLogger())
-    {
-      log.error(message, null);
-    }
-    else
-    {
-      System.err.println(message);
-    }
-
-  }
-
-  public static void error(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.error(message, t);
-    }
-    else
-    {
-      System.err.println(message);
-      t.printStackTrace(System.err);
-    }
-
-  }
-
-  public static void fatal(String message)
-  {
-    if (initLogger())
-    {
-      log.fatal(message, null);
-    }
-    else
-    {
-      System.err.println(message);
-    }
-
-  }
-
-  public static void fatal(String message, Throwable t)
-  {
-    if (initLogger())
-    {
-      log.fatal(message, t);
-    }
-    else
-    {
-      System.err.println(message);
-      t.printStackTrace(System.err);
-    }
-
-  }
-
-  public static boolean isDebugEnabled()
-  {
-    return log == null ? false : log.isDebugEnabled();
-  }
-
-  public static boolean isTraceEnabled()
-  {
-    return log == null ? false : log.isTraceEnabled();
-  }
-
   /**
    * Getdown appbase methods
    */