JAL-3814 NONEWS property
[jalview.git] / src / jalview / bin / Cache.java
index 6e44b0c..2904fc3 100755 (executable)
@@ -174,8 +174,8 @@ import jalview.ws.sifts.SiftsSettings;
  * when shading by annotation</li>
  * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
  * when shading by annotation</li>
- * <li>www.jalview.org (http://www.jalview.org) a property enabling all HTTP
- * requests to be redirected to a mirror of http://www.jalview.org</li>
+ * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
+ * requests to be redirected to a mirror of https://www.jalview.org</li>
  * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
  * alignment figure to accommodate even the longest sequence ID or annotation
  * label.</li>
@@ -195,6 +195,7 @@ import jalview.ws.sifts.SiftsSettings;
  * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
  * </li>
  * 
+ * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
  * </ul>
  * Deprecated settings:
  * <ul>
@@ -315,6 +316,10 @@ public class Cache
       // lcastor = Logger.getLogger("org.exolab.castor.xml.Marshaller");
       // lcastor.setLevel(Level.toLevel(Cache.getDefault("logs.Castor.Level",
       // Level.INFO.toString())));
+      // we shouldn't need to do this
+      org.apache.log4j.Logger.getRootLogger()
+              .setLevel(org.apache.log4j.Level.INFO);
+
       jalview.bin.Cache.log.setLevel(Level.toLevel(Cache
               .getDefault("logs.Jalview.level", Level.INFO.toString())));
       // laxis.addAppender(ap);
@@ -428,7 +433,7 @@ public class Cache
                     DEFAULT_CACHE_THRESHOLD_IN_DAYS));
 
     IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
-            "http://www.jalview.org/services/identifiers"));
+            "https://www.jalview.org/services/identifiers"));
     IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
 
     StructureImportSettings.setDefaultStructureFileFormat(jalview.bin.Cache
@@ -452,9 +457,12 @@ public class Cache
 
       class VersionChecker extends Thread
       {
+
         @Override
         public void run()
         {
+          String buildPropertiesUrl = Cache.getAppbaseBuildProperties();
+
           String orgtimeout = System
                   .getProperty("sun.net.client.defaultConnectTimeout");
           if (orgtimeout == null)
@@ -468,28 +476,19 @@ public class Cache
           {
             System.setProperty("sun.net.client.defaultConnectTimeout",
                     "5000");
-            java.net.URL url = new java.net.URL(Cache
-                    .getDefault("www.jalview.org", "http://www.jalview.org")
-                    + "/webstart/jalview.jnlp");
+            java.net.URL url = new java.net.URL(buildPropertiesUrl);
+
             BufferedReader in = new BufferedReader(
                     new InputStreamReader(url.openStream()));
-            String line = null;
-            while ((line = in.readLine()) != null)
-            {
-              if (line.indexOf("jalview.version") == -1)
-              {
-                continue;
-              }
-
-              line = line.substring(line.indexOf("value=") + 7);
-              line = line.substring(0, line.lastIndexOf("\""));
-              remoteVersion = line;
-              break;
-            }
+
+            Properties remoteBuildProperties = new Properties();
+            remoteBuildProperties.load(in);
+            remoteVersion = remoteBuildProperties.getProperty("VERSION");
           } catch (Exception ex)
           {
-            System.out.println(
-                    "Non-fatal exception when checking version at www.jalview.org :");
+            System.out
+                    .println("Non-fatal exception when checking version at "
+                            + buildPropertiesUrl + ":");
             System.out.println(ex);
             remoteVersion = getProperty("VERSION");
           }
@@ -1144,6 +1143,8 @@ public class Cache
     {
       appendIfNotNull(sb, "Getdown appdir: ",
               System.getProperty("getdownappdir"), "\n", null);
+      appendIfNotNull(sb, "Getdown appbase: ",
+              System.getProperty("getdownappbase"), "\n", null);
       appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
               "\n", "unknown");
     }
@@ -1168,4 +1169,61 @@ public class Cache
     t.printStackTrace(pw);
     return sw.toString();
   }
+
+  /**
+   * Getdown appbase methods
+   */
+
+  private static final String releaseAppbase;
+
+  private static String getdownAppbase;
+
+  private static String getdownDistDir;
+
+  static
+  {
+    Float specversion = Float
+            .parseFloat(System.getProperty("java.specification.version"));
+    releaseAppbase = (specversion < 9)
+            ? "https://www.jalview.org/getdown/release/1.8"
+            : "https://www.jalview.org/getdown/release/11";
+  }
+
+  // look for properties (passed in by getdown) otherwise default to release
+  private static void setGetdownAppbase()
+  {
+    if (getdownAppbase != null)
+    {
+      return;
+    }
+    String appbase = System.getProperty("getdownappbase");
+    String distDir = System.getProperty("getdowndistdir");
+    if (appbase == null)
+    {
+      appbase = releaseAppbase;
+      distDir = "release";
+    }
+    if (appbase.endsWith("/"))
+    {
+      appbase = appbase.substring(0, appbase.length() - 1);
+    }
+    if (distDir == null)
+    {
+      distDir = appbase.equals(releaseAppbase) ? "release" : "alt";
+    }
+    getdownAppbase = appbase;
+    getdownDistDir = distDir;
+  }
+
+  public static String getGetdownAppbase()
+  {
+    setGetdownAppbase();
+    return getdownAppbase;
+  }
+
+  public static String getAppbaseBuildProperties()
+  {
+    String appbase = getGetdownAppbase();
+    return appbase + "/" + getdownDistDir + "/build_properties";
+  }
 }