2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import java.awt.Color;
24 import java.io.BufferedReader;
26 import java.io.FileInputStream;
27 import java.io.FileNotFoundException;
28 import java.io.FileOutputStream;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.io.InputStreamReader;
32 import java.io.PrintWriter;
33 import java.io.StringWriter;
34 import java.net.Authenticator;
35 import java.net.PasswordAuthentication;
37 import java.text.DateFormat;
38 import java.text.SimpleDateFormat;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.Collection;
42 import java.util.Collections;
43 import java.util.Date;
44 import java.util.Enumeration;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Locale;
49 import java.util.Properties;
50 import java.util.StringTokenizer;
51 import java.util.TreeSet;
53 import javax.swing.LookAndFeel;
54 import javax.swing.UIManager;
56 import jalview.analytics.Plausible;
57 import jalview.bin.argparser.Arg;
58 import jalview.bin.argparser.ArgParser;
59 import jalview.datamodel.PDBEntry;
60 import jalview.gui.Preferences;
61 import jalview.gui.UserDefinedColours;
62 import jalview.log.JLoggerLog4j;
63 import jalview.schemes.ColourSchemeLoader;
64 import jalview.schemes.ColourSchemes;
65 import jalview.schemes.UserColourScheme;
66 import jalview.structure.StructureImportSettings;
67 import jalview.urls.IdOrgSettings;
68 import jalview.util.ChannelProperties;
69 import jalview.util.ColorUtils;
70 import jalview.util.HttpUtils;
71 import jalview.util.MessageManager;
72 import jalview.util.Platform;
73 import jalview.ws.sifts.SiftsSettings;
76 * Stores and retrieves Jalview Application Properties Lists and fields within
77 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
78 * are alternative values for a tag. <br>
80 * Current properties include:
83 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
84 * logging level for axis (used for web services) <br>
86 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
87 * the logging level for castor (used for serialization) <br>
89 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
91 * <li>SCREEN_WIDTH</li>
92 * <li>SCREEN_HEIGHT</li>
93 * <li>SCREEN_Y=285</li>
94 * <li>SCREEN_X=371</li>
95 * <li>SHOW_FULLSCREEN boolean</li>
96 * <li>FONT_NAME java font name for alignment text display</li>
97 * <li>FONT_SIZE size of displayed alignment text</li>
98 * <li>FONT_STYLE style of font displayed (sequence labels are always
100 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
101 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
102 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
103 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
104 * <li>SHOW_IDENTITY show percentage identity annotation</li>
105 * <li>SHOW_QUALITY show alignment quality annotation</li>
106 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
107 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
108 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
109 * LABEL_AND_SEQUENCE</li>
110 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
111 * sequence annotations</li>
112 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
113 * annotation row</li>
114 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
115 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
116 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
117 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
118 * <li>VERSION the version of the jalview build</li>
119 * <li>BUILD_DATE date of this build</li>
120 * <li>LATEST_VERSION the latest jalview version advertised on the
121 * www.jalview.org</li>
122 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
124 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
125 * suffix to file</li>
126 * <li>RECENT_URL list of recently retrieved URLs</li>
127 * <li>RECENT_FILE list of recently opened files</li>
128 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
129 * <li>PROXY_SERVER the proxy</li>
130 * <li>PROXY_PORT</li>
131 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
133 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
135 * <li>USAGESTATS (false - user prompted) Enable analytics tracker for
136 * collecting usage statistics</li>
137 * <li>SHOW_OVERVIEW boolean for overview window display</li>
138 * <li>ANTI_ALIAS boolean for smooth fonts</li>
139 * <li>RIGHT_ALIGN_IDS boolean</li>
140 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
141 * <li>PAD_GAPS boolean</li>
142 * <li>ID_ITALICS boolean</li>
143 * <li>SHOW_JV_SUFFIX</li>
144 * <li>WRAP_ALIGNMENT</li>
145 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
147 * <li>BITMAP_SCALE - scale factor for PNG export - default 0.0 - native
149 * <li>BITMAP_HEIGHT - height bound for PNG export or 0 for unbound</li>
150 * <li>BITMAP_WIDTH - width bound for PNG export or 0 for unbound</li>
151 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
152 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
154 * <li>STORED_LINKS list of name|url pairs which user has entered but are not
156 * <li>DEFAULT_LINK name of single url to be used when user double clicks a
157 * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
158 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
159 * jalview.utils.GroupURLLink for more info</li>
160 * <li>DEFAULT_BROWSER for unix</li>
161 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
163 * <li>VERSION_CHECK (true) check for the latest release version from
164 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
165 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
167 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
169 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
170 * displayed as '.'</li>
171 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
172 * order of a newly displayed tree</li>
173 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
174 * sequence ID strings before attempting retrieval from any datasource</li>
175 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
177 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
178 * in the alignment.</li>
179 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
181 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
183 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
184 * logo normalised to row height rather than histogram height.</li>
185 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
186 * respond to selections made in other alignments containing the same sequences.
188 * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
189 * auto-discover JABAWS services</li>
190 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
191 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
192 * warning dialog box is displayed.</li>
193 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
194 * when shading by annotation</li>
195 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
196 * when shading by annotation</li>
197 * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
198 * requests to be redirected to a mirror of https://www.jalview.org</li>
199 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
200 * alignment figure to accommodate even the longest sequence ID or annotation
202 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
203 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
204 * will override this).</li>
205 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
207 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
208 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
210 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
212 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
214 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
215 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
217 * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
218 * <li>NOHTMLTEMPLATES - when set, the
219 * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
220 * not downloaded automatically</li>
221 * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
222 * available URL linkouts via www.jalview.org/services/identifiers</li>
225 * Deprecated settings:
228 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
229 * startup (JWS1 services only)</li>
230 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
231 * (JWS1 services only)</li>
232 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
233 * services in the desktop GUI</li>
234 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
235 * panel in web service preferences</li>
239 * @version $Revision$
244 * property giving log4j level for CASTOR loggers
246 public static final String CASTORLOGLEVEL = "logs.Castor.level";
249 * property giving log4j level for AXIS loggers
251 public static final String AXISLOGLEVEL = "logs.Axis.level";
254 * property giving log4j level for Jalview Log
256 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
259 public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST";
264 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
265 .getProperty("user.home") + File.separatorChar
266 + ".sifts_downloads" + File.separatorChar;
268 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
270 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
273 * Identifiers.org download settings
275 private static final String ID_ORG_FILE = System.getProperty("user.home")
276 + File.separatorChar + ".identifiers.org.ids.json";
279 * Allowed values are PDB or mmCIF
281 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
284 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
288 * a date formatter using a fixed (rather than the user's) locale;
289 * this ensures that date properties can be written and re-read successfully
290 * even if the user changes their locale setting
292 private static final DateFormat date_format = SimpleDateFormat
293 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
294 SimpleDateFormat.MEDIUM, Locale.UK);
297 * Initialises the Jalview Application Log
300 public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
302 // save the proxy properties set at startup
303 public final static String[] startupProxyProperties = {
304 System.getProperty("http.proxyHost"),
305 System.getProperty("http.proxyPort"),
306 System.getProperty("https.proxyHost"),
307 System.getProperty("https.proxyPort"),
308 System.getProperty("http.proxyUser"),
309 System.getProperty("http.proxyPassword"),
310 System.getProperty("https.proxyUser"),
311 System.getProperty("https.proxyPassword"),
312 System.getProperty("http.nonProxyHosts") };
314 public final static String PROXYTYPE_NONE = "none";
316 // "false" and "true" for backward compatibility
317 public final static String PROXYTYPE_SYSTEM = "false";
319 public final static String PROXYTYPE_CUSTOM = "true";
321 // in-memory only storage of proxy password, safer to use char array
322 public static char[] proxyAuthPassword = null;
325 * Session properties, set by command line, try not to affect stored
328 private static Map<String, String> sessionProperties = new HashMap<>();
330 private static boolean bypassSessionProperties = false;
332 public static void enableSessionProperties()
334 bypassSessionProperties = false;
337 public static void disableSessionProperties()
339 bypassSessionProperties = true;
342 /** Jalview Properties */
343 public static Properties applicationProperties = new Properties()
345 // override results in properties output in alphabetical order
347 public synchronized Enumeration<Object> keys()
349 return Collections.enumeration(new TreeSet<>(super.keySet()));
353 /* build Properties (not all saved to .jalview_properties) */
354 public static Properties buildProperties = new Properties();
356 /** Default file is ~/.jalview_properties */
357 static String propertiesFile;
359 private static final String fallbackPropertiesFile = ".jalview_properties";
361 private static boolean propsAreReadOnly = Platform.isJS();
363 public static boolean isPropsAreReadOnly()
365 return propsAreReadOnly;
368 public static void setPropsAreReadOnly(boolean propsAreReadOnly)
370 Cache.propsAreReadOnly = propsAreReadOnly;
373 private final static String JS_PROPERTY_PREFIX = "jalview_";
376 * Loads properties from the given properties file. Any existing properties
379 public static void loadProperties(String propsFile)
381 propertiesFile = propsFile;
382 String releasePropertiesFile = null;
383 boolean defaultProperties = false;
384 if (propsFile == null && !propsAreReadOnly)
386 String channelPrefsFilename = ChannelProperties
387 .getProperty("preferences.filename");
388 String releasePrefsFilename = fallbackPropertiesFile;
389 propertiesFile = System.getProperty("user.home") + File.separatorChar
390 + channelPrefsFilename;
391 releasePropertiesFile = System.getProperty("user.home")
392 + File.separatorChar + releasePrefsFilename;
393 defaultProperties = true;
397 // don't corrupt the file we've been given.
398 propsAreReadOnly = true;
401 if (propertiesFile == null)
403 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
404 applicationProperties);
413 // props file provided as URL
414 fis = HttpUtils.openStream(new URL(propertiesFile));
415 if (!Jalview.quiet())
417 jalview.bin.Console.outPrintln(
418 "Loading jalview properties from : " + propertiesFile);
419 jalview.bin.Console.outPrintln(
420 "Disabling Jalview writing to user's local properties file.");
422 propsAreReadOnly = true;
423 } catch (Exception ex)
429 String readPropertiesFile = propertiesFile;
430 // if we're using the usual properties file and the channel properties
431 // file doesn't exist, read .jalview_properties
432 // (but we'll still save to the channel properties file).
433 if (defaultProperties && (!new File(propertiesFile).exists())
434 && (new File(releasePropertiesFile).exists()))
436 readPropertiesFile = releasePropertiesFile;
438 fis = new FileInputStream(readPropertiesFile);
440 applicationProperties.clear();
441 applicationProperties.load(fis);
443 // remove any old build properties
445 deleteBuildProperties();
447 } catch (Exception ex)
449 if (!Jalview.quiet())
451 .outPrintln("Error reading properties file: " + ex);
455 /* TO BE REPLACED WITH PROXY_TYPE SETTINGS
456 if (getDefault("USE_PROXY", false))
458 String proxyServer = getDefault("PROXY_SERVER", ""),
459 proxyPort = getDefault("PROXY_PORT", "8080");
463 // PROXY TYPE settings (now three options "none", "false", "true", but using
464 // backward compatible strings)
465 String proxyType = getDefault("USE_PROXY", PROXYTYPE_SYSTEM);
466 // default to upgrading old settings
470 clearProxyProperties();
472 case PROXYTYPE_SYSTEM: // use system settings
473 resetProxyProperties();
475 case PROXYTYPE_CUSTOM: // use specified proxy settings
476 String httpHost = getDefault("PROXY_SERVER", "");
477 String httpPort = getDefault("PROXY_PORT", "8080");
478 String httpsHost = getDefault("PROXY_SERVER_HTTPS", httpHost);
479 String httpsPort = getDefault("PROXY_PORT_HTTPS", httpPort);
480 String httpUser = getDefault("PROXY_AUTH_USER", null);
481 // https.proxyUser and https.proxyPassword are not able to be
482 // independently set in Preferences yet (or http.nonProxyHosts)
483 String httpsUser = getDefault("PROXY_AUTH_USER_HTTPS", httpUser);
484 setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
485 proxyAuthPassword, httpsUser, proxyAuthPassword, "localhost");
488 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
490 Console.warn(message);
493 // LOAD THE AUTHORS FROM THE authors.props file
494 String authorDetails = resolveResourceURLFor("/authors.props");
498 if (authorDetails != null)
500 URL localJarFileURL = new URL(authorDetails);
501 InputStream in = localJarFileURL.openStream();
502 applicationProperties.load(in);
505 } catch (Exception ex)
507 if (!Jalview.quiet())
509 .outPrintln("Error reading author details: " + ex);
510 authorDetails = null;
512 if (authorDetails == null)
514 applicationProperties.remove("AUTHORS");
515 applicationProperties.remove("AUTHORFNAMES");
516 applicationProperties.remove("YEAR");
519 loadBuildProperties(false);
522 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
524 SiftsSettings.setSiftDownloadDirectory(Cache
525 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
527 SiftsSettings.setFailSafePIDThreshold(
528 Cache.getDefault("sifts_fail_safe_pid_threshold",
529 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
531 SiftsSettings.setCacheThresholdInDays(
532 Cache.getDefault("sifts_cache_threshold_in_days",
533 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
535 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
536 "https://www.jalview.org/services/identifiers"));
537 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
539 StructureImportSettings.setDefaultStructureFileFormat(
540 Cache.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
541 StructureImportSettings
542 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
543 // StructureImportSettings
544 // .setDefaultPDBFileParser(Cache.getDefault(
545 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
547 String jnlpVersion = System.getProperty("jalview.version");
549 // jnlpVersion will be null if a latest version check for the channel needs
551 // Dont do this check if running in headless mode
553 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
554 && (System.getProperty("java.awt.headless") == null || System
555 .getProperty("java.awt.headless").equals("false")))
558 class VersionChecker extends Thread
564 String remoteBuildPropertiesUrl = Cache
565 .getAppbaseBuildProperties();
567 String orgtimeout = System
568 .getProperty("sun.net.client.defaultConnectTimeout");
569 if (orgtimeout == null)
572 Console.debug("Setting default net timeout to " + orgtimeout
575 String remoteVersion = null;
576 if (remoteBuildPropertiesUrl.startsWith("http"))
580 System.setProperty("sun.net.client.defaultConnectTimeout",
583 URL url = new URL(remoteBuildPropertiesUrl);
585 BufferedReader in = new BufferedReader(
586 new InputStreamReader(HttpUtils.openStream(url)));
588 Properties remoteBuildProperties = new Properties();
589 remoteBuildProperties.load(in);
590 remoteVersion = remoteBuildProperties.getProperty("VERSION");
591 } catch (Exception ex)
593 if (!Jalview.quiet())
595 jalview.bin.Console.errPrintln(
596 "Non-fatal exception when checking version at "
597 + remoteBuildPropertiesUrl + ":");
598 jalview.bin.Console.printStackTrace(ex);
600 remoteVersion = getProperty("VERSION");
603 System.setProperty("sun.net.client.defaultConnectTimeout",
606 setProperty("LATEST_VERSION", remoteVersion);
610 VersionChecker vc = new VersionChecker();
615 if (jnlpVersion != null)
617 setProperty("LATEST_VERSION", jnlpVersion);
621 applicationProperties.remove("LATEST_VERSION");
625 // LOAD USERDEFINED COLOURS
626 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
627 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
632 * construct a resource URL for the given absolute resource pathname
634 * @param resourcePath
637 private static String resolveResourceURLFor(String resourcePath)
640 if (Platform.isJS() || !Cache.class.getProtectionDomain()
641 .getCodeSource().getLocation().toString().endsWith(".jar"))
645 url = Cache.class.getResource(resourcePath).toString();
646 } catch (Exception ex)
648 jalview.bin.Console.errPrintln("Failed to resolve resource "
649 + resourcePath + ": " + ex.getMessage());
654 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
655 .getLocation().toString().concat("!" + resourcePath));
660 public static void loadBuildProperties(boolean reportVersion)
662 String codeInstallation = getProperty("INSTALLATION");
663 boolean printVersion = codeInstallation == null;
666 * read build properties - from the Jalview jar for a Java distribution,
667 * or from codebase file in test or JalviewJS context
671 String buildDetails = resolveResourceURLFor("/.build_properties");
672 URL localJarFileURL = new URL(buildDetails);
673 InputStream in = localJarFileURL.openStream();
674 buildProperties.load(in);
676 if (buildProperties.getProperty("BUILD_DATE", null) != null)
678 applicationProperties.put("BUILD_DATE",
679 buildProperties.getProperty("BUILD_DATE"));
681 if (buildProperties.getProperty("INSTALLATION", null) != null)
683 applicationProperties.put("INSTALLATION",
684 buildProperties.getProperty("INSTALLATION"));
686 if (buildProperties.getProperty("VERSION", null) != null)
688 applicationProperties.put("VERSION",
689 buildProperties.getProperty("VERSION"));
691 if (buildProperties.getProperty("JAVA_COMPILE_VERSION", null) != null)
693 applicationProperties.put("JAVA_COMPILE_VERSION",
694 buildProperties.getProperty("JAVA_COMPILE_VERSION"));
696 } catch (Exception ex)
698 if (!Jalview.quiet())
700 .outPrintln("Error reading build details: " + ex);
701 applicationProperties.remove("VERSION");
703 String codeVersion = getProperty("VERSION");
704 codeInstallation = getProperty("INSTALLATION");
706 if (codeVersion == null)
708 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
709 codeVersion = "Test";
710 codeInstallation = "";
714 codeInstallation = " (" + codeInstallation + ")";
716 setProperty("VERSION", codeVersion);
717 new BuildDetails(codeVersion, null, codeInstallation);
718 if (printVersion && reportVersion)
721 .outPrintln(ChannelProperties.getProperty("app_name")
722 + " version: " + codeVersion + codeInstallation);
726 private static void deleteBuildProperties()
728 applicationProperties.remove("LATEST_VERSION");
729 applicationProperties.remove("VERSION");
730 applicationProperties.remove("AUTHORS");
731 applicationProperties.remove("AUTHORFNAMES");
732 applicationProperties.remove("YEAR");
733 applicationProperties.remove("BUILD_DATE");
734 applicationProperties.remove("INSTALLATION");
738 * Gets Jalview application property of given key. Returns null if key not
744 * @return Property value
746 public static String getProperty(String key)
748 return getProperty(key, false);
751 public static String getProperty(String key,
752 boolean skipSessionProperties)
755 if (!(skipSessionProperties || bypassSessionProperties))
757 prop = getSessionProperty(key);
761 prop = applicationProperties.getProperty(key);
763 if (prop == null && Platform.isJS())
765 prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
766 + "_" + JS_PROPERTY_PREFIX + key);
772 * These methods are used when checking if the saved preference is different
773 * to the default setting
776 public static boolean getDefault(String property, boolean def)
778 String string = getProperty(property);
781 def = Boolean.valueOf(string).booleanValue();
787 public static int getDefault(String property, int def)
789 String string = getProperty(property);
794 def = Integer.parseInt(string);
795 } catch (NumberFormatException e)
797 if (!Jalview.quiet())
798 jalview.bin.Console.errPrintln("Error parsing int property '"
799 + property + "' with value '" + string + "'");
806 public static float getDefault(String property, float def)
808 String string = getProperty(property);
813 def = Float.parseFloat(string);
814 } catch (NumberFormatException e)
816 if (!Jalview.quiet())
817 jalview.bin.Console.errPrintln("Error parsing float property '"
818 + property + "' with value '" + string + "'");
826 * Answers the value of the given property, or the supplied default value if
827 * the property is not set
829 public static String getDefault(String property, String def)
831 String value = getProperty(property);
832 return value == null ? def : value;
836 * Stores property in the file "HOME_DIR/.jalview_properties"
841 * String value of property
843 * @return previous value of property (or null)
845 public static Object setProperty(String key, String obj)
847 Object oldValue = null;
850 oldValue = applicationProperties.setProperty(key, obj);
851 if (propertiesFile != null && !propsAreReadOnly
852 // don't rewrite if new value is same as old value
853 && !((obj == null && oldValue == null)
854 || (obj != null && obj.equals(oldValue))))
856 // reset the session property too
857 if (sessionProperties.containsKey(key))
859 sessionProperties.remove(key);
861 FileOutputStream out = new FileOutputStream(propertiesFile);
862 applicationProperties.store(out, "---JalviewX Properties File---");
865 } catch (Exception ex)
867 if (!Jalview.quiet())
868 jalview.bin.Console.errPrintln(
869 "Error setting property: " + key + " " + obj + "\n" + ex);
875 * remove the specified property from the jalview properties file
879 public static void removeProperty(String string)
881 applicationProperties.remove(string);
886 * save the properties to the jalview properties path
888 public static void saveProperties()
890 if (!propsAreReadOnly)
894 FileOutputStream out = new FileOutputStream(propertiesFile);
895 applicationProperties.store(out, "---JalviewX Properties File---");
897 } catch (Exception ex)
899 if (!Jalview.quiet())
900 jalview.bin.Console.errPrintln("Error saving properties: " + ex);
906 * internal vamsas class discovery state
908 private static int vamsasJarsArePresent = -1;
911 * Searches for vamsas client classes on class path.
913 * @return true if vamsas client is present on classpath
915 public static boolean vamsasJarsPresent()
917 if (vamsasJarsArePresent == -1)
921 if (jalview.jbgui.GDesktop.class.getClassLoader()
922 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
925 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
926 vamsasJarsArePresent = 1;
927 JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
928 Console.getCachedLogLevel("logs.Vamsas.Level"));
929 JLoggerLog4j.addAppender(lvclient, Console.log,
930 JALVIEW_LOGGER_NAME);
931 // Tell the user that debug is enabled
932 lvclient.debug(ChannelProperties.getProperty("app_name")
933 + " Vamsas Client Debugging Output Follows.");
935 } catch (Exception e)
937 vamsasJarsArePresent = 0;
938 Console.debug("Vamsas Classes are not present");
941 return (vamsasJarsArePresent > 0);
945 * internal vamsas class discovery state
947 private static int groovyJarsArePresent = -1;
950 * Searches for vamsas client classes on class path.
952 * @return true if vamsas client is present on classpath
954 public static boolean groovyJarsPresent()
956 if (groovyJarsArePresent == -1)
960 if (Cache.class.getClassLoader()
961 .loadClass("groovy.lang.GroovyObject") != null)
964 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
965 groovyJarsArePresent = 1;
966 JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
967 Console.getCachedLogLevel("logs.Groovy.Level"));
968 JLoggerLog4j.addAppender(lgclient, Console.log,
969 JALVIEW_LOGGER_NAME);
970 // Tell the user that debug is enabled
971 lgclient.debug(ChannelProperties.getProperty("app_name")
972 + " Groovy Client Debugging Output Follows.");
976 groovyJarsArePresent = 0;
977 Console.debug("Groovy Classes are not present", e);
978 } catch (Exception e)
980 groovyJarsArePresent = 0;
981 Console.debug("Groovy Classes are not present");
984 return (groovyJarsArePresent > 0);
988 * Initialise the tracker if it is not done already.
990 public static void initAnalytics()
992 Plausible.setEnabled(true);
994 String appName = ChannelProperties.getProperty("app_name") + " Desktop";
995 String version = Cache.getProperty("VERSION") + "_"
996 + Cache.getDefault("BUILD_DATE", "unknown");
998 /* we don't want to encode ':' as "%3A" for backward compatibility with the UA setup
1001 path = "/" + String.join("/", URLEncoder.encode(appName, "UTF-8"),
1002 URLEncoder.encode(version, "UTF-8"),
1003 URLEncoder.encode(APPLICATION_STARTED, "UTF-8"));
1004 } catch (UnsupportedEncodingException e)
1007 List<String> pathParts = new ArrayList<>();
1008 pathParts.add(appName);
1009 pathParts.add(version);
1010 pathParts.add(APPLICATION_STARTED);
1011 path = ("/" + String.join("/", pathParts)).replace(' ', '+');
1015 Plausible plausible = Plausible.getInstance();
1017 // This will send a new "application_launch" event with parameters
1018 // including the old-style "path", the channel name and version
1019 plausible.sendEvent("application_launch", path, true);
1022 private static final String APPLICATION_STARTED = "Application Started";
1025 * get the user's default colour if available
1031 public static Color getDefaultColour(String property, Color defcolour)
1033 String colprop = getProperty(property);
1034 if (colprop == null)
1038 Color col = ColorUtils.parseColourString(colprop);
1041 Console.warn("Couldn't parse '" + colprop + "' as a colour for "
1044 return (col == null) ? defcolour : col;
1048 * store a colour as a Jalview user default property
1053 public static void setColourProperty(String property, Color colour)
1055 setProperty(property, jalview.util.Format.getHexString(colour));
1059 * Stores a formatted date in a jalview property, using a fixed locale.
1061 * @param propertyName
1063 * @return the formatted date string
1065 public static String setDateProperty(String propertyName, Date date)
1067 String formatted = date_format.format(date);
1068 setProperty(propertyName, formatted);
1073 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1074 * format) and returns as a Date, or null if parsing fails
1076 * @param propertyName
1080 public static Date getDateProperty(String propertyName)
1082 String val = getProperty(propertyName);
1087 return date_format.parse(val);
1088 } catch (Exception ex)
1091 .errPrintln("Invalid or corrupt date in property '"
1092 + propertyName + "' : value was '" + val + "'");
1099 * get and parse a property as an integer. send any parsing problems to
1103 * @return null or Integer
1105 public static Integer getIntegerProperty(String property)
1107 String val = getProperty(property);
1108 if (val != null && (val = val.trim()).length() > 0)
1112 return Integer.valueOf(val);
1113 } catch (NumberFormatException x)
1115 jalview.bin.Console.errPrintln("Invalid integer in property '"
1116 + property + "' (value was '" + val + "')");
1123 * Set the specified value, or remove it if null or empty. Does not save the
1129 public static void setOrRemove(String propName, String value)
1131 if (propName == null)
1135 if (value == null || value.trim().length() < 1)
1137 Cache.applicationProperties.remove(propName);
1141 Cache.applicationProperties.setProperty(propName, value);
1146 * Loads in user colour schemes from files.
1149 * a '|'-delimited list of file paths
1151 public static void initUserColourSchemes(String files)
1153 if (files == null || files.length() == 0)
1158 // In case colours can't be loaded, we'll remove them
1159 // from the default list here.
1160 StringBuffer coloursFound = new StringBuffer();
1161 StringTokenizer st = new StringTokenizer(files, "|");
1162 while (st.hasMoreElements())
1164 String file = st.nextToken();
1167 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1170 if (coloursFound.length() > 0)
1172 coloursFound.append("|");
1174 coloursFound.append(file);
1175 ColourSchemes.getInstance().registerColourScheme(ucs);
1177 } catch (Exception ex)
1179 if (!Jalview.quiet())
1181 .outPrintln("Error loading User ColourFile\n" + ex);
1184 if (!files.equals(coloursFound.toString()))
1186 if (coloursFound.toString().length() > 1)
1188 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1189 coloursFound.toString());
1193 applicationProperties
1194 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1200 * Initial logging information helper for various versions output
1204 * @param defaultValue
1206 private static void appendIfNotNull(StringBuilder sb, String prefix,
1207 String value, String suffix, String defaultValue)
1209 if (value == null && defaultValue == null)
1215 sb.append(value == null ? defaultValue : value);
1222 * @return Jalview version, build details and JVM platform version for console
1224 public static String getVersionDetailsForConsole()
1226 StringBuilder sb = new StringBuilder();
1227 sb.append(ChannelProperties.getProperty("app_name"))
1228 .append(" Version: ");
1229 sb.append(Cache.getDefault("VERSION", "TEST"));
1231 sb.append(ChannelProperties.getProperty("app_name"))
1232 .append(" Installation: ");
1233 sb.append(Cache.getDefault("INSTALLATION", "unknown"));
1235 sb.append("Build Date: ");
1236 sb.append(Cache.getDefault("BUILD_DATE", "unknown"));
1238 sb.append("Java version: ");
1239 sb.append(System.getProperty("java.version"));
1241 sb.append("Java platform: ");
1242 sb.append(System.getProperty("os.arch"));
1244 sb.append(System.getProperty("os.name"));
1246 sb.append(System.getProperty("os.version"));
1248 appendIfNotNull(sb, "Install4j version: ",
1249 System.getProperty("sys.install4jVersion"), "\n", null);
1250 appendIfNotNull(sb, "Install4j template version: ",
1251 System.getProperty("installer_template_version"), "\n", null);
1252 appendIfNotNull(sb, "Launcher version: ",
1253 System.getProperty("launcher_version"), "\n", null);
1254 LookAndFeel laf = UIManager.getLookAndFeel();
1255 String lafName = laf == null ? "Not obtained" : laf.getName();
1256 String lafClass = laf == null ? "unknown" : laf.getClass().getName();
1257 sb.append("LookAndFeel: ");
1260 sb.append(lafClass);
1262 appendIfNotNull(sb, "Channel: ",
1263 ChannelProperties.getProperty("channel"), "\n", null);
1264 if (Console.isDebugEnabled()
1265 || !"release".equals(ChannelProperties.getProperty("channel")))
1267 appendIfNotNull(sb, "Getdown appdir: ",
1268 System.getProperty("getdowninstanceappdir"), "\n", null);
1269 appendIfNotNull(sb, "Getdown appbase: ",
1270 System.getProperty("getdowninstanceappbase"), "\n", null);
1271 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1273 appendIfNotNull(sb, "Preferences file: ", propertiesFile, "\n",
1276 return sb.toString();
1281 * @return build details as reported in splashscreen
1283 public static String getBuildDetailsForSplash()
1285 // consider returning more human friendly info
1286 // eg 'built from Source' or update channel
1287 return Cache.getDefault("INSTALLATION", "unknown");
1290 public static String getStackTraceString(Throwable t)
1292 StringWriter sw = new StringWriter();
1293 PrintWriter pw = new PrintWriter(sw);
1294 t.printStackTrace(pw);
1295 return sw.toString();
1298 // proxy properties methods
1299 public static void clearProxyProperties()
1301 setProxyProperties(null, null, null, null, null, null, null, null,
1305 public static void resetProxyProperties()
1307 setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
1308 startupProxyProperties[2], startupProxyProperties[3],
1309 startupProxyProperties[4],
1310 startupProxyProperties[5] == null ? null
1311 : startupProxyProperties[5].toCharArray(),
1312 startupProxyProperties[6],
1313 startupProxyProperties[7] == null ? null
1314 : startupProxyProperties[7].toCharArray(),
1315 startupProxyProperties[8]);
1316 StringBuilder sb = new StringBuilder();
1317 sb.append("Setting proxy properties to: http.proxyHost=")
1318 .append(startupProxyProperties[0]).append(", http.proxyPort=")
1319 .append(startupProxyProperties[1])
1320 .append(startupProxyProperties[4] != null
1321 && !startupProxyProperties[4].isEmpty()
1322 ? " [" + startupProxyProperties[4] + "]"
1324 .append(", https.proxyHost=").append(startupProxyProperties[2])
1325 .append(", https.proxyPort=").append(startupProxyProperties[3])
1326 .append(startupProxyProperties[6] != null
1327 && !startupProxyProperties[6].isEmpty()
1328 ? " [" + startupProxyProperties[6] + "]"
1331 Console.debug(sb.toString());
1334 public static void setProxyPropertiesFromPreferences()
1336 setProxyPropertiesFromPreferences(Cache.PROXYTYPE_SYSTEM);
1339 public static void setProxyPropertiesFromPreferences(
1340 String previousProxyType)
1342 String proxyType = Cache.getDefault("USE_PROXY",
1343 Cache.PROXYTYPE_SYSTEM);
1344 if (previousProxyType != null
1345 && !proxyType.equals(Cache.PROXYTYPE_CUSTOM) // always apply
1347 && proxyType.equals(previousProxyType))
1354 case Cache.PROXYTYPE_NONE:
1355 if (!previousProxyType.equals(proxyType))
1357 Console.info("Setting no proxy settings");
1358 Cache.setProxyProperties(null, null, null, null, null, null, null,
1362 case Cache.PROXYTYPE_CUSTOM:
1363 // always re-set a custom proxy -- it might have changed, particularly
1365 Console.info("Setting custom proxy settings");
1366 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
1367 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
1368 Cache.getDefault("PROXY_PORT", null),
1369 Cache.getDefault("PROXY_SERVER_HTTPS", null),
1370 Cache.getDefault("PROXY_PORT_HTTPS", null),
1371 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1373 proxyAuthSet ? Cache.proxyAuthPassword : null,
1374 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1376 proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
1378 default: // system proxy settings by default
1379 Console.info("Setting system proxy settings");
1380 Cache.resetProxyProperties();
1384 public static void setProxyProperties(String httpHost, String httpPort,
1385 String httpsHost, String httpsPort, String httpUser,
1386 char[] httpPassword, String httpsUser, char[] httpsPassword,
1387 String nonProxyHosts)
1389 setOrClearSystemProperty("http.proxyHost", httpHost);
1390 setOrClearSystemProperty("http.proxyPort", httpPort);
1391 setOrClearSystemProperty("https.proxyHost", httpsHost);
1392 setOrClearSystemProperty("https.proxyPort", httpsPort);
1393 setOrClearSystemProperty("http.proxyUser", httpUser);
1394 setOrClearSystemProperty("https.proxyUser", httpsUser);
1395 // note: passwords for http.proxyPassword and https.proxyPassword are sent
1396 // via the Authenticator, properties do not need to be set
1398 // are we using a custom proxy (password prompt might be required)?
1399 boolean customProxySet = getDefault("USE_PROXY", PROXYTYPE_SYSTEM)
1400 .equals(PROXYTYPE_CUSTOM);
1403 * A bug in Java means the AuthCache does not get reset, so once it has working credentials,
1404 * it never asks for more, so changing the Authenticator has no effect (as getPasswordAuthentication()
1405 * is not re-called).
1406 * This could lead to password leak to a hostile proxy server, so I'm putting in a hack to clear
1408 * see https://www.generacodice.com/en/articolo/154918/Reset-the-Authenticator-credentials
1410 * Turns out this is only accessible in Java 8, and not in Java 9 onwards, so commenting out
1415 sun.net.www.protocol.http.AuthCacheValue
1416 .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl());
1417 } catch (Throwable t)
1419 Cache.error(t.getMessage());
1420 Cache.debug(getStackTraceString(t));
1424 if (httpUser != null || httpsUser != null)
1428 char[] displayHttpPw = new char[httpPassword == null ? 0
1429 : httpPassword.length];
1430 Arrays.fill(displayHttpPw, '*');
1432 "CACHE Proxy: setting new Authenticator with httpUser='"
1433 + httpUser + "' httpPassword='" + displayHttpPw
1435 if (!Platform.isJS())
1437 * java.net.Authenticator not implemented in SwingJS yet
1443 Authenticator.setDefault(new Authenticator()
1446 protected PasswordAuthentication getPasswordAuthentication()
1448 if (getRequestorType() == RequestorType.PROXY)
1450 String protocol = getRequestingProtocol();
1451 boolean needProxyPasswordSet = false;
1452 if (customProxySet &&
1453 // we have a username but no password for the scheme being
1455 (protocol.equalsIgnoreCase("http")
1456 && (httpUser != null
1457 && httpUser.length() > 0
1458 && (httpPassword == null
1459 || httpPassword.length == 0)))
1460 || (protocol.equalsIgnoreCase("https")
1461 && (httpsUser != null
1462 && httpsUser.length() > 0
1463 && (httpsPassword == null
1464 || httpsPassword.length == 0))))
1466 // open Preferences -> Connections
1467 String message = MessageManager
1468 .getString("label.proxy_password_required");
1469 Preferences.openPreferences(
1470 Preferences.TabRef.CONNECTIONS_TAB, message);
1471 Preferences.getInstance()
1472 .proxyAuthPasswordCheckHighlight(true, true);
1478 if (protocol.equalsIgnoreCase("http")
1479 && getRequestingHost()
1480 .equalsIgnoreCase(httpHost)
1481 && getRequestingPort() == Integer
1485 "AUTHENTICATOR returning PasswordAuthentication(\""
1486 + httpUser + "\", '"
1487 + new String(displayHttpPw) + "')");
1488 return new PasswordAuthentication(httpUser,
1491 if (protocol.equalsIgnoreCase("https")
1492 && getRequestingHost()
1493 .equalsIgnoreCase(httpsHost)
1494 && getRequestingPort() == Integer
1495 .valueOf(httpsPort))
1497 char[] displayHttpsPw = new char[httpPassword.length];
1498 Arrays.fill(displayHttpsPw, '*');
1500 "AUTHENTICATOR returning PasswordAuthentication(\""
1501 + httpsUser + "\", '" + displayHttpsPw
1503 return new PasswordAuthentication(httpsUser,
1506 } catch (NumberFormatException e)
1508 Console.error("Problem with proxy port values [http:"
1509 + httpPort + ", https:" + httpsPort + "]");
1512 "AUTHENTICATOR after trying to get PasswordAuthentication");
1515 // non proxy request
1516 Console.debug("AUTHENTICATOR returning null");
1520 } // end of j2sIgnore for java.net.Authenticator
1522 // required to re-enable basic authentication (should be okay for a
1525 "AUTHENTICATOR setting property 'jdk.http.auth.tunneling.disabledSchemes' to \"\"");
1526 System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
1527 } catch (SecurityException e)
1529 Console.error("Could not set default Authenticator");
1530 Console.debug(getStackTraceString(e));
1535 // reset the Authenticator to protect http.proxyUser and
1536 // http.proxyPassword Just In Case
1537 /* as noted above, due to bug in java this doesn't work if the sun.net.www.protocol.http.AuthCache
1538 * has working credentials. No workaround for Java 11.
1540 if (!Platform.isJS())
1542 * java.net.Authenticator not implemented in SwingJS yet
1549 "AUTHENTICATOR setting default Authenticator to null");
1550 Authenticator.setDefault(null);
1554 // nonProxyHosts not currently configurable in Preferences
1556 "AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
1557 + nonProxyHosts + "\"");
1558 setOrClearSystemProperty("http.nonProxyHosts", nonProxyHosts);
1561 public static void setOrClearSystemProperty(String key, char[] value)
1563 setOrClearSystemProperty(key,
1564 (value == null) ? null : new String(value));
1567 public static void setOrClearSystemProperty(String key, String value)
1575 System.clearProperty(key);
1579 System.setProperty(key, value);
1584 * Getdown appbase methods
1587 private static final String releaseAppbase;
1589 private static String getdownAppbase;
1591 private static String getdownDistDir;
1595 if (!Platform.isJS())
1597 Float specversion = Float
1598 .parseFloat(System.getProperty("java.specification.version"));
1599 releaseAppbase = (specversion < 9)
1600 ? "https://www.jalview.org/getdown/release/1.8"
1601 : "https://www.jalview.org/getdown/release/11";
1605 // this value currenly made up, can be changed to URL that will be
1606 // "https://www.jalview.org/jalview-js/swingjs/j2s/build_properties"
1607 releaseAppbase = "https://www.jalview.org/jalview-js";
1608 getdownAppbase = releaseAppbase;
1609 getdownDistDir = "/swingjs/j2s";
1613 // look for properties (passed in by getdown) otherwise default to release
1614 private static void setGetdownAppbase()
1616 if (getdownAppbase != null)
1620 String appbase = System.getProperty("getdownappbase");
1621 String distDir = System.getProperty("getdowndistdir");
1622 if (appbase == null)
1624 appbase = buildProperties.getProperty("GETDOWNAPPBASE");
1625 distDir = buildProperties.getProperty("GETDOWNAPPDISTDIR");
1627 if (appbase == null)
1629 appbase = releaseAppbase;
1630 distDir = "release";
1632 if (appbase.endsWith("/"))
1634 appbase = appbase.substring(0, appbase.length() - 1);
1636 if (distDir == null)
1638 distDir = appbase.equals(releaseAppbase) ? "release" : "alt";
1640 getdownAppbase = appbase;
1641 getdownDistDir = distDir;
1644 public static String getGetdownAppbase()
1646 setGetdownAppbase();
1647 return getdownAppbase;
1650 public static String getAppbaseBuildProperties()
1652 String appbase = getGetdownAppbase();
1653 return appbase + "/" + getdownDistDir + "/build_properties";
1656 private static final Collection<String> bootstrapProperties = new ArrayList<>(
1657 Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST));
1659 public static Properties bootstrapProperties(String filename)
1661 Properties bootstrapProps = new Properties();
1663 if (filename != null)
1665 file = new File(filename);
1667 if (file == null || !file.exists())
1672 .errPrintln("Could not load bootstrap preferences file '"
1673 + file.getPath() + "'");
1675 String channelPrefsFilename = ChannelProperties
1676 .getProperty("preferences.filename");
1677 String propertiesFilename = System.getProperty("user.home")
1678 + File.separatorChar + channelPrefsFilename;
1679 jalview.bin.Console.errPrintln(
1680 "Using default properties file '" + propertiesFilename + "'");
1681 file = new File(propertiesFilename);
1683 if (file == null || !file.exists())
1686 String releasePrefsFilename = fallbackPropertiesFile;
1687 String releasePropertiesFilename = System.getProperty("user.home")
1688 + File.separatorChar + releasePrefsFilename;
1689 jalview.bin.Console.errPrintln("Falling back to properties file '"
1690 + releasePropertiesFilename + "'");
1691 file = new File(releasePropertiesFilename);
1697 .errPrintln("Could not load bootstrap preferences file '"
1698 + file.getPath() + "'");
1704 FileInputStream in = new FileInputStream(file.getAbsoluteFile());
1705 Properties props = new Properties();
1707 for (String prop : bootstrapProperties)
1709 if (props.containsKey(prop))
1710 bootstrapProps.put(prop, props.getProperty(prop));
1712 } catch (FileNotFoundException e)
1715 .errPrintln("Could not find bootstrap preferences file '"
1716 + file.getAbsolutePath() + "'");
1717 } catch (IOException e)
1719 jalview.bin.Console.errPrintln(
1720 "IOException when loading bootstrap preferences file '"
1721 + file.getAbsolutePath() + "'");
1723 return bootstrapProps;
1726 public static void setSessionProperty(String key, String val)
1730 sessionProperties.put(key, val);
1734 public static String getSessionProperty(String key)
1736 return key == null ? null : sessionProperties.get(key);
1739 public static boolean getArgCacheDefault(Arg a, String pref, boolean def)
1741 ArgParser ap = Jalview.getInstance().getArgParser();
1742 return ap.isSet(a) ? ap.getBoolean(a) : getDefault(pref, def);