From b7d225fc8a17594a1ddacd775a819b9ffc70131b Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Thu, 4 Mar 2021 19:19:34 +0000 Subject: [PATCH] JAL-3594 Allow a channel to use a different preferences file than .jalview_properties, with initial read from .jalview_properties --- src/jalview/bin/Cache.java | 23 +++++++++++++++++--- src/jalview/util/ChannelProperties.java | 12 +++++----- utils/channels/default/resources/channel.props | 1 + utils/channels/develop/resources/channel.props | 1 + utils/channels/jalviewjs/resources/channel.props | 1 + utils/channels/release/resources/channel.props | 1 + .../channels/test-release/resources/channel.props | 1 + 7 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 4a83b35..353f449 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -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); diff --git a/src/jalview/util/ChannelProperties.java b/src/jalview/util/ChannelProperties.java index ede528f..109eaa5 100644 --- a/src/jalview/util/ChannelProperties.java +++ b/src/jalview/util/ChannelProperties.java @@ -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 diff --git a/utils/channels/default/resources/channel.props b/utils/channels/default/resources/channel.props index 4e6d27a..3e7e153 100644 --- a/utils/channels/default/resources/channel.props +++ b/utils/channels/default/resources/channel.props @@ -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 diff --git a/utils/channels/develop/resources/channel.props b/utils/channels/develop/resources/channel.props index fa848de..8af68fa 100644 --- a/utils/channels/develop/resources/channel.props +++ b/utils/channels/develop/resources/channel.props @@ -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 diff --git a/utils/channels/jalviewjs/resources/channel.props b/utils/channels/jalviewjs/resources/channel.props index 02e117d..8195dc8 100644 --- a/utils/channels/jalviewjs/resources/channel.props +++ b/utils/channels/jalviewjs/resources/channel.props @@ -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 diff --git a/utils/channels/release/resources/channel.props b/utils/channels/release/resources/channel.props index d19b281..abdfd3f 100644 --- a/utils/channels/release/resources/channel.props +++ b/utils/channels/release/resources/channel.props @@ -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 diff --git a/utils/channels/test-release/resources/channel.props b/utils/channels/test-release/resources/channel.props index 3ef86d3..0ab4f86 100644 --- a/utils/channels/test-release/resources/channel.props +++ b/utils/channels/test-release/resources/channel.props @@ -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 -- 1.7.10.2