JAL-3594 Allow a channel to use a different preferences file than .jalview_properties...
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 4 Mar 2021 19:19:34 +0000 (19:19 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 4 Mar 2021 19:19:34 +0000 (19:19 +0000)
src/jalview/bin/Cache.java
src/jalview/util/ChannelProperties.java
utils/channels/default/resources/channel.props
utils/channels/develop/resources/channel.props
utils/channels/jalviewjs/resources/channel.props
utils/channels/release/resources/channel.props
utils/channels/test-release/resources/channel.props

index 4a83b35..353f449 100755 (executable)
@@ -376,10 +376,18 @@ public class Cache
   public static void loadProperties(String propsFile)
   {
     propertiesFile = propsFile;
+    String releasePropertiesFile = null;
+    boolean defaultProperties = false;
     if (propsFile == null && !propsAreReadOnly)
     {
+      String channelPrefsFilename = ChannelProperties
+              .getProperty("preferences.filename");
+      String releasePrefsFilename = ".jalview_properties";
       propertiesFile = System.getProperty("user.home") + File.separatorChar
-              + ".jalview_properties";
+              + channelPrefsFilename;
+      releasePropertiesFile = System.getProperty("user.home")
+              + File.separatorChar + releasePrefsFilename;
+      defaultProperties = true;
     }
     else
     {
@@ -399,20 +407,29 @@ public class Cache
         InputStream fis;
         try
         {
+          // props file provided as URL
           fis = new 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);
+          String readPropertiesFile = propertiesFile;
+          // if we're using the usual properties file and the channel properties
+          // file doesn't exist, read .jalview_properties
+          // (but we'll still save to the channel properties file).
+          if (defaultProperties && (!new File(propertiesFile).exists())
+                  && (new File(releasePropertiesFile).exists()))
+          {
+            readPropertiesFile = releasePropertiesFile;
+          }
+          fis = new FileInputStream(readPropertiesFile);
         }
         applicationProperties.clear();
         applicationProperties.load(fis);
index ede528f..109eaa5 100644 (file)
@@ -55,6 +55,7 @@ public class ChannelProperties
     defaultProps.put("uod_banner.32", "/default_images/UoD_banner-32.png");
     defaultProps.put("default_appbase",
             "https://www.jalview.org/getdown/release/1.8");
+    defaultProps.put("preferences.filename", ".jalview_properties");
 
     // load channel_properties
     Properties tryChannelProps = new Properties();
@@ -63,12 +64,11 @@ public class ChannelProperties
     if (channelPropsURL == null)
     {
       // complete failure of channel_properties, set all properties to defaults
-      System.err
-              .println("Failed to find '" + CHANNEL_PROPERTIES_FILENAME
-                      + "' file at '"
-                      + (channelPropsURL == null ? "null"
-                              : channelPropsURL.toString())
-                      + "'. Using class defaultProps.");
+      System.err.println("Failed to find '" + CHANNEL_PROPERTIES_FILENAME
+              + "' file at '"
+              + (channelPropsURL == null ? "null"
+                      : channelPropsURL.toString())
+              + "'. Using class defaultProps.");
       tryChannelProps = defaultProps;
     }
     else
index 4e6d27a..3e7e153 100644 (file)
@@ -16,3 +16,4 @@ uod_banner.28=/images/UoD_banner-28.png
 uod_banner.30=/images/UoD_banner-30.png
 uod_banner.32=/images/UoD_banner-32.png
 default_appbase=https://www.jalview.org/getdown/release/1.8
+preferences.filename=.jalview_properties
index fa848de..8af68fa 100644 (file)
@@ -16,3 +16,4 @@ uod_banner.28=/images/UoD_banner-28.png
 uod_banner.30=/images/UoD_banner-30.png
 uod_banner.32=/images/UoD_banner-32.png
 default_appbase=https://www.jalview.org/getdown/develop/11
+preferences.filename=.jalview_develop_properties
index 02e117d..8195dc8 100644 (file)
@@ -16,3 +16,4 @@ uod_banner.28=/images/UoD_banner-28.png
 uod_banner.30=/images/UoD_banner-30.png
 uod_banner.32=/images/UoD_banner-32.png
 default_appbase=https://www.jalview.org/getdown/release/1.8
+preferences.filename=.jalview_properties
index d19b281..abdfd3f 100644 (file)
@@ -16,3 +16,4 @@ uod_banner.28=/images/UoD_banner-28.png
 uod_banner.30=/images/UoD_banner-30.png
 uod_banner.32=/images/UoD_banner-32.png
 default_appbase=https://www.jalview.org/getdown/release/1.8
+preferences.filename=.jalview_properties
index 3ef86d3..0ab4f86 100644 (file)
@@ -16,3 +16,4 @@ uod_banner.28=/images/UoD_banner-28.png
 uod_banner.30=/images/UoD_banner-30.png
 uod_banner.32=/images/UoD_banner-32.png
 default_appbase=https://www.jalview.org/getdown/release/1.8
+preferences.filename=.jalview_properties