imported properties via -props should never be overwritten
[jalview.git] / src / jalview / bin / Cache.java
index cebb504..f77c2f1 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -124,6 +124,11 @@ import org.biojava.dasobert.dasregistry.Das1Source;
  * histogram.</li>
  * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
  * logo.</li>
+ * <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_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
+ * warning dialog box is displayed.</li>
  * 
  * <li></li>
  * 
@@ -168,8 +173,14 @@ public class Cache
   /** Default file is ~/.jalview_properties */
   static String propertiesFile;
 
+  private static boolean propsAreReadOnly=false;
+
   public static void initLogger()
   {
+    if (log != null)
+    {
+      return;
+    }
     try
     {
       // TODO: redirect stdout and stderr here in order to grab the output of
@@ -216,11 +227,31 @@ public class Cache
     {
       propertiesFile = System.getProperty("user.home") + File.separatorChar
               + ".jalview_properties";
+    } else {
+      // don't corrupt the file we've been given.
+      propsAreReadOnly = true;
     }
 
     try
     {
-      FileInputStream fis = new FileInputStream(propertiesFile);
+      InputStream fis;
+      try
+      {
+        fis = new java.net.URL(propertiesFile).openStream();
+        System.out.println("Loading jalview properties from : "
+                + propertiesFile);
+        System.out
+                .println("Disabling Jalview writing to user's local properties file.");
+        propsAreReadOnly = true;
+
+      } catch (Exception ex)
+      {
+        fis = null;
+      }
+      if (fis == null)
+      {
+        fis = new FileInputStream(propertiesFile);
+      }
       applicationProperties.load(fis);
       applicationProperties.remove("LATEST_VERSION");
       applicationProperties.remove("VERSION");
@@ -235,9 +266,7 @@ public class Cache
       System.out.println("Using proxyServer: "
               + getDefault("PROXY_SERVER", null) + " proxyPort: "
               + getDefault("PROXY_PORT", null));
-      System
-              .setProperty("http.proxyHost", getDefault("PROXY_SERVER",
-                      null));
+      System.setProperty("http.proxyHost", getDefault("PROXY_SERVER", null));
       System.setProperty("http.proxyPort", getDefault("PROXY_PORT", null));
     }
 
@@ -247,8 +276,8 @@ public class Cache
     try
     {
       String buildDetails = "jar:".concat(Cache.class.getProtectionDomain()
-              .getCodeSource().getLocation().toString().concat(
-                      "!/.build_properties"));
+              .getCodeSource().getLocation().toString()
+              .concat("!/.build_properties"));
 
       java.net.URL localJarFileURL = new java.net.URL(buildDetails);
 
@@ -410,12 +439,16 @@ public class Cache
    */
   public static String setProperty(String key, String obj)
   {
+
     try
     {
-      FileOutputStream out = new FileOutputStream(propertiesFile);
       applicationProperties.setProperty(key, obj);
-      applicationProperties.store(out, "---JalviewX Properties File---");
-      out.close();
+      if (!propsAreReadOnly)
+      {
+        FileOutputStream out = new FileOutputStream(propertiesFile);
+        applicationProperties.store(out, "---JalviewX Properties File---");
+        out.close();
+      }
     } catch (Exception ex)
     {
       System.out.println("Error setting property: " + key + " " + obj
@@ -440,14 +473,17 @@ public class Cache
    */
   public static void saveProperties()
   {
-    try
-    {
-      FileOutputStream out = new FileOutputStream(propertiesFile);
-      applicationProperties.store(out, "---JalviewX Properties File---");
-      out.close();
-    } catch (Exception ex)
+    if (!propsAreReadOnly)
     {
-      System.out.println("Error saving properties: " + ex);
+      try
+      {
+        FileOutputStream out = new FileOutputStream(propertiesFile);
+        applicationProperties.store(out, "---JalviewX Properties File---");
+        out.close();
+      } catch (Exception ex)
+      {
+        System.out.println("Error saving properties: " + ex);
+      }
     }
   }
 
@@ -603,8 +639,7 @@ public class Cache
                   "com.boxysystems.jgoogleanalytics.FocusPoint");
         } catch (Exception e)
         {
-          log
-                  .debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
+          log.debug("com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
           tracker = null;
           jgoogleanalyticstracker = null;
           trackerfocus = null;
@@ -648,10 +683,7 @@ public class Cache
         if (log != null)
         {
           if (re != null)
-            log
-                    .debug(
-                            "Caught runtime exception in googletracker init:",
-                            re);
+            log.debug("Caught runtime exception in googletracker init:", re);
           if (ex != null)
             log.warn(
                     "Failed to initialise GoogleTracker for Jalview Desktop with version "