Merge branch 'improvement/JAL-3280_Migrate_the_VersionChecker_service_to_build_proper...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 3 Sep 2020 11:20:22 +0000 (12:20 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 3 Sep 2020 11:20:22 +0000 (12:20 +0100)
build.gradle
src/jalview/bin/Cache.java
test/jalview/bin/CacheTest.java
test/jalview/bin/testProps.jvprops [new file with mode: 0644]

index 5281bb1..68d0c04 100644 (file)
@@ -1377,6 +1377,10 @@ task getdownWebsite() {
     //getdownTextString += "class = " + file(getdownLauncher).getName() + "\n"
     getdownTextString += "resource = ${getdown_launcher_new}\n"
     getdownTextString += "class = ${main_class}\n"
+    /* NOT setting these properties so that getdownappbase and getdowndistdir will default to release version
+     * getdownTextString += "jvmarg = -Dgetdowndistdir=${getdownAppDistDir}\n"
+     * getdownTextString += "jvmarg = -Dgetdownappbase=${getdownAppBase}\n"
+     */
 
     def getdown_txt = file("${getdownWebsiteDir}/getdown.txt")
     getdown_txt.write(getdownTextString)
@@ -1403,7 +1407,7 @@ task getdownWebsite() {
       copy {
         from getdown_txt
         from getdownLauncher
-        from "${getdownWebsiteDir}/${getdown_build_properties}"
+        from "${getdownAppDir}/${getdown_build_properties}"
         if (file(getdownLauncher).getName() != getdown_launcher) {
           rename(file(getdownLauncher).getName(), getdown_launcher)
         }
index ba28717..2ea7196 100755 (executable)
@@ -316,7 +316,8 @@ public class Cache
       // 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); 
+      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())));
@@ -455,9 +456,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)
@@ -471,28 +475,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");
           }
@@ -1147,6 +1142,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");
     }
@@ -1171,4 +1168,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";
+  }
 }
index e762dd5..9edfd3b 100644 (file)
  */
 package jalview.bin;
 
+import static org.testng.Assert.assertNotEquals;
+import static org.testng.Assert.assertTrue;
 import static org.testng.AssertJUnit.assertEquals;
-
-import jalview.gui.JvOptionPane;
+import static org.testng.AssertJUnit.assertNotNull;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -32,6 +33,8 @@ import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import jalview.gui.JvOptionPane;
+
 public class CacheTest
 {
 
@@ -70,9 +73,28 @@ public class CacheTest
     assertEquals(formattedDate, formattedDate2);
 
     // currently using Locale.UK to format dates:
-    assertEquals(
-            formattedDate2,
-            SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.MEDIUM,
-                    SimpleDateFormat.MEDIUM, Locale.UK).format(now));
+    assertEquals(formattedDate2,
+            SimpleDateFormat
+                    .getDateTimeInstance(SimpleDateFormat.MEDIUM,
+                            SimpleDateFormat.MEDIUM, Locale.UK)
+                    .format(now));
+  }
+
+  @Test(groups = "Functional")
+  public void testVersionChecker()
+  {
+    Cache.loadProperties("test/jalview/bin/testProps.jvprops");
+    try
+    {
+      // 10s sleep to allow VersionChecker thread to run
+      Thread.sleep(10000);
+    } catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+    String latestVersion = Cache.getProperty("LATEST_VERSION");
+    assertNotNull(latestVersion);
+    assertNotEquals(latestVersion, "test");
+    assertTrue(latestVersion.startsWith("2."));
   }
 }
diff --git a/test/jalview/bin/testProps.jvprops b/test/jalview/bin/testProps.jvprops
new file mode 100644 (file)
index 0000000..a1ab82a
--- /dev/null
@@ -0,0 +1,2 @@
+VERSION_CHECK=true
+LATEST_VERSION=test