Merge branch 'develop' into improvement/JAL-4193_cl_arg_prevent_startup_file
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 1 Jun 2023 17:16:56 +0000 (18:16 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Thu, 1 Jun 2023 17:16:56 +0000 (18:16 +0100)
1  2 
src/jalview/bin/Cache.java

@@@ -42,9 -42,7 +42,9 @@@ import java.util.Collection
  import java.util.Collections;
  import java.util.Date;
  import java.util.Enumeration;
 +import java.util.HashMap;
  import java.util.Locale;
 +import java.util.Map;
  import java.util.Properties;
  import java.util.StringTokenizer;
  import java.util.TreeSet;
@@@ -312,24 -310,6 +312,24 @@@ public class Cach
    // in-memory only storage of proxy password, safer to use char array
    public static char[] proxyAuthPassword = null;
  
 +  /**
 +   * Session properties, set by command line, try not to affect stored
 +   * properties!
 +   */
 +  private static Map<String, String> sessionProperties = new HashMap<>();
 +
 +  private static boolean bypassSessionProperties = false;
 +
 +  public static void enableSessionProperties()
 +  {
 +    bypassSessionProperties = false;
 +  }
 +
 +  public static void disableSessionProperties()
 +  {
 +    bypassSessionProperties = true;
 +  }
 +
    /** Jalview Properties */
    public static Properties applicationProperties = new Properties()
    {
     */
    public static String getProperty(String key)
    {
 -    String prop = applicationProperties.getProperty(key);
 +    return getProperty(key, false);
 +  }
 +
 +  public static String getProperty(String key,
 +          boolean skipSessionProperties)
 +  {
 +    String prop = null;
 +    if (!(skipSessionProperties || bypassSessionProperties))
 +    {
 +      prop = getSessionProperty(key);
 +    }
 +    if (prop == null)
 +    {
 +      prop = applicationProperties.getProperty(key);
 +    }
      if (prop == null && Platform.isJS())
      {
        prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
      try
      {
        oldValue = applicationProperties.setProperty(key, obj);
 -      if (propertiesFile != null && !propsAreReadOnly)
 +      if (propertiesFile != null && !propsAreReadOnly
 +      // don't rewrite if new value is same as old value
 +              && !((obj == null && oldValue == null)
 +                      || (obj != null && obj.equals(oldValue))))
        {
 +        // reset the session property too
 +        if (sessionProperties.containsKey(key))
 +        {
 +          sessionProperties.remove(key);
 +        }
          FileOutputStream out = new FileOutputStream(propertiesFile);
          applicationProperties.store(out, "---JalviewX Properties File---");
          out.close();
                  if (customProxySet &&
                  // we have a username but no password for the scheme being
                  // requested
-                         (protocol.equalsIgnoreCase("http")
-                                 && (httpUser != null
-                                         && httpUser.length() > 0
-                                         && (httpPassword == null
-                                                 || httpPassword.length == 0)))
+                 (protocol.equalsIgnoreCase("http")
+                         && (httpUser != null && httpUser.length() > 0
+                                 && (httpPassword == null
+                                         || httpPassword.length == 0)))
                          || (protocol.equalsIgnoreCase("https")
                                  && (httpsUser != null
                                          && httpsUser.length() > 0
      }
      return bootstrapProps;
    }
 +
 +  public static void setSessionProperty(String key, String val)
 +  {
 +    if (key != null)
 +    {
 +      sessionProperties.put(key, val);
 +    }
 +  }
 +
 +  public static String getSessionProperty(String key)
 +  {
 +    return key == null ? null : sessionProperties.get(key);
 +  }
  }