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.MessageManager;
71 import jalview.util.Platform;
72 import jalview.ws.sifts.SiftsSettings;
75 * Stores and retrieves Jalview Application Properties Lists and fields within
76 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
77 * are alternative values for a tag. <br>
79 * Current properties include:
82 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
83 * logging level for axis (used for web services) <br>
85 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
86 * the logging level for castor (used for serialization) <br>
88 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
90 * <li>SCREEN_WIDTH</li>
91 * <li>SCREEN_HEIGHT</li>
92 * <li>SCREEN_Y=285</li>
93 * <li>SCREEN_X=371</li>
94 * <li>SHOW_FULLSCREEN boolean</li>
95 * <li>FONT_NAME java font name for alignment text display</li>
96 * <li>FONT_SIZE size of displayed alignment text</li>
97 * <li>FONT_STYLE style of font displayed (sequence labels are always
99 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
100 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
101 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
102 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
103 * <li>SHOW_IDENTITY show percentage identity annotation</li>
104 * <li>SHOW_QUALITY show alignment quality annotation</li>
105 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
106 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
107 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
108 * LABEL_AND_SEQUENCE</li>
109 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
110 * sequence annotations</li>
111 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
112 * annotation row</li>
113 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
114 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
115 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
116 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
117 * <li>VERSION the version of the jalview build</li>
118 * <li>BUILD_DATE date of this build</li>
119 * <li>LATEST_VERSION the latest jalview version advertised on the
120 * www.jalview.org</li>
121 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
123 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
124 * suffix to file</li>
125 * <li>RECENT_URL list of recently retrieved URLs</li>
126 * <li>RECENT_FILE list of recently opened files</li>
127 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
128 * <li>PROXY_SERVER the proxy</li>
129 * <li>PROXY_PORT</li>
130 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
132 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
134 * <li>USAGESTATS (false - user prompted) Enable analytics tracker for
135 * collecting usage statistics</li>
136 * <li>SHOW_OVERVIEW boolean for overview window display</li>
137 * <li>ANTI_ALIAS boolean for smooth fonts</li>
138 * <li>RIGHT_ALIGN_IDS boolean</li>
139 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
140 * <li>PAD_GAPS boolean</li>
141 * <li>ID_ITALICS boolean</li>
142 * <li>SHOW_JV_SUFFIX</li>
143 * <li>WRAP_ALIGNMENT</li>
144 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
146 * <li>BITMAP_SCALE - scale factor for PNG export - default 0.0 - native
148 * <li>BITMAP_HEIGHT - height bound for PNG export or 0 for unbound</li>
149 * <li>BITMAP_WIDTH - width bound for PNG export or 0 for unbound</li>
150 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
151 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
153 * <li>STORED_LINKS list of name|url pairs which user has entered but are not
155 * <li>DEFAULT_LINK name of single url to be used when user double clicks a
156 * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
157 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
158 * jalview.utils.GroupURLLink for more info</li>
159 * <li>DEFAULT_BROWSER for unix</li>
160 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
162 * <li>VERSION_CHECK (true) check for the latest release version from
163 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
164 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
166 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
168 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
169 * displayed as '.'</li>
170 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
171 * order of a newly displayed tree</li>
172 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
173 * sequence ID strings before attempting retrieval from any datasource</li>
174 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
176 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
177 * in the alignment.</li>
178 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
180 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
182 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
183 * logo normalised to row height rather than histogram height.</li>
184 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
185 * respond to selections made in other alignments containing the same sequences.
187 * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
188 * auto-discover JABAWS services</li>
189 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
190 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
191 * warning dialog box is displayed.</li>
192 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
193 * when shading by annotation</li>
194 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
195 * when shading by annotation</li>
196 * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
197 * requests to be redirected to a mirror of https://www.jalview.org</li>
198 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
199 * alignment figure to accommodate even the longest sequence ID or annotation
201 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
202 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
203 * will override this).</li>
204 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
206 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
207 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
209 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
211 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
213 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
214 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
216 * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
217 * <li>NOHTMLTEMPLATES - when set, the
218 * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
219 * not downloaded automatically</li>
220 * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
221 * available URL linkouts via www.jalview.org/services/identifiers</li>
224 * Deprecated settings:
227 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
228 * startup (JWS1 services only)</li>
229 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
230 * (JWS1 services only)</li>
231 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
232 * services in the desktop GUI</li>
233 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
234 * panel in web service preferences</li>
238 * @version $Revision$
243 * property giving log4j level for CASTOR loggers
245 public static final String CASTORLOGLEVEL = "logs.Castor.level";
248 * property giving log4j level for AXIS loggers
250 public static final String AXISLOGLEVEL = "logs.Axis.level";
253 * property giving log4j level for Jalview Log
255 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
258 public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST";
263 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
264 .getProperty("user.home") + File.separatorChar
265 + ".sifts_downloads" + File.separatorChar;
267 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
269 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
272 * Identifiers.org download settings
274 private static final String ID_ORG_FILE = System.getProperty("user.home")
275 + File.separatorChar + ".identifiers.org.ids.json";
278 * Allowed values are PDB or mmCIF
280 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
283 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
287 * a date formatter using a fixed (rather than the user's) locale;
288 * this ensures that date properties can be written and re-read successfully
289 * even if the user changes their locale setting
291 private static final DateFormat date_format = SimpleDateFormat
292 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
293 SimpleDateFormat.MEDIUM, Locale.UK);
296 * Initialises the Jalview Application Log
299 public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
301 // save the proxy properties set at startup
302 public final static String[] startupProxyProperties = {
303 System.getProperty("http.proxyHost"),
304 System.getProperty("http.proxyPort"),
305 System.getProperty("https.proxyHost"),
306 System.getProperty("https.proxyPort"),
307 System.getProperty("http.proxyUser"),
308 System.getProperty("http.proxyPassword"),
309 System.getProperty("https.proxyUser"),
310 System.getProperty("https.proxyPassword"),
311 System.getProperty("http.nonProxyHosts") };
313 public final static String PROXYTYPE_NONE = "none";
315 // "false" and "true" for backward compatibility
316 public final static String PROXYTYPE_SYSTEM = "false";
318 public final static String PROXYTYPE_CUSTOM = "true";
320 // in-memory only storage of proxy password, safer to use char array
321 public static char[] proxyAuthPassword = null;
324 * Session properties, set by command line, try not to affect stored
327 private static Map<String, String> sessionProperties = new HashMap<>();
329 private static boolean bypassSessionProperties = false;
331 public static void enableSessionProperties()
333 bypassSessionProperties = false;
336 public static void disableSessionProperties()
338 bypassSessionProperties = true;
341 /** Jalview Properties */
342 public static Properties applicationProperties = new Properties()
344 // override results in properties output in alphabetical order
346 public synchronized Enumeration<Object> keys()
348 return Collections.enumeration(new TreeSet<>(super.keySet()));
352 /* build Properties (not all saved to .jalview_properties) */
353 public static Properties buildProperties = new Properties();
355 /** Default file is ~/.jalview_properties */
356 static String propertiesFile;
358 private static final String fallbackPropertiesFile = ".jalview_properties";
360 private static boolean propsAreReadOnly = Platform.isJS();
362 public static boolean isPropsAreReadOnly()
364 return propsAreReadOnly;
367 public static void setPropsAreReadOnly(boolean propsAreReadOnly)
369 Cache.propsAreReadOnly = propsAreReadOnly;
372 private final static String JS_PROPERTY_PREFIX = "jalview_";
375 * Loads properties from the given properties file. Any existing properties
378 public static void loadProperties(String propsFile)
380 propertiesFile = propsFile;
381 String releasePropertiesFile = null;
382 boolean defaultProperties = false;
383 if (propsFile == null && !propsAreReadOnly)
385 String channelPrefsFilename = ChannelProperties
386 .getProperty("preferences.filename");
387 String releasePrefsFilename = fallbackPropertiesFile;
388 propertiesFile = System.getProperty("user.home") + File.separatorChar
389 + channelPrefsFilename;
390 releasePropertiesFile = System.getProperty("user.home")
391 + File.separatorChar + releasePrefsFilename;
392 defaultProperties = true;
396 // don't corrupt the file we've been given.
397 propsAreReadOnly = true;
400 if (propertiesFile == null)
402 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
403 applicationProperties);
412 // props file provided as URL
413 fis = new URL(propertiesFile).openStream();
414 if (!Jalview.quiet())
416 jalview.bin.Console.outPrintln(
417 "Loading jalview properties from : " + propertiesFile);
418 jalview.bin.Console.outPrintln(
419 "Disabling Jalview writing to user's local properties file.");
421 propsAreReadOnly = true;
422 } catch (Exception ex)
428 String readPropertiesFile = propertiesFile;
429 // if we're using the usual properties file and the channel properties
430 // file doesn't exist, read .jalview_properties
431 // (but we'll still save to the channel properties file).
432 if (defaultProperties && (!new File(propertiesFile).exists())
433 && (new File(releasePropertiesFile).exists()))
435 readPropertiesFile = releasePropertiesFile;
437 fis = new FileInputStream(readPropertiesFile);
439 applicationProperties.clear();
440 applicationProperties.load(fis);
442 // remove any old build properties
444 deleteBuildProperties();
446 } catch (Exception ex)
448 if (!Jalview.quiet())
450 .outPrintln("Error reading properties file: " + ex);
454 /* TO BE REPLACED WITH PROXY_TYPE SETTINGS
455 if (getDefault("USE_PROXY", false))
457 String proxyServer = getDefault("PROXY_SERVER", ""),
458 proxyPort = getDefault("PROXY_PORT", "8080");
462 // PROXY TYPE settings (now three options "none", "false", "true", but using
463 // backward compatible strings)
464 String proxyType = getDefault("USE_PROXY", PROXYTYPE_SYSTEM);
465 // default to upgrading old settings
469 clearProxyProperties();
471 case PROXYTYPE_SYSTEM: // use system settings
472 resetProxyProperties();
474 case PROXYTYPE_CUSTOM: // use specified proxy settings
475 String httpHost = getDefault("PROXY_SERVER", "");
476 String httpPort = getDefault("PROXY_PORT", "8080");
477 String httpsHost = getDefault("PROXY_SERVER_HTTPS", httpHost);
478 String httpsPort = getDefault("PROXY_PORT_HTTPS", httpPort);
479 String httpUser = getDefault("PROXY_AUTH_USER", null);
480 // https.proxyUser and https.proxyPassword are not able to be
481 // independently set in Preferences yet (or http.nonProxyHosts)
482 String httpsUser = getDefault("PROXY_AUTH_USER_HTTPS", httpUser);
483 setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
484 proxyAuthPassword, httpsUser, proxyAuthPassword, "localhost");
487 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
489 Console.warn(message);
492 // LOAD THE AUTHORS FROM THE authors.props file
493 String authorDetails = resolveResourceURLFor("/authors.props");
497 if (authorDetails != null)
499 URL localJarFileURL = new URL(authorDetails);
500 InputStream in = localJarFileURL.openStream();
501 applicationProperties.load(in);
504 } catch (Exception ex)
506 if (!Jalview.quiet())
508 .outPrintln("Error reading author details: " + ex);
509 authorDetails = null;
511 if (authorDetails == null)
513 applicationProperties.remove("AUTHORS");
514 applicationProperties.remove("AUTHORFNAMES");
515 applicationProperties.remove("YEAR");
518 loadBuildProperties(false);
521 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
523 SiftsSettings.setSiftDownloadDirectory(Cache
524 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
526 SiftsSettings.setFailSafePIDThreshold(
527 Cache.getDefault("sifts_fail_safe_pid_threshold",
528 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
530 SiftsSettings.setCacheThresholdInDays(
531 Cache.getDefault("sifts_cache_threshold_in_days",
532 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
534 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
535 "https://www.jalview.org/services/identifiers"));
536 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
538 StructureImportSettings.setDefaultStructureFileFormat(
539 Cache.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
540 StructureImportSettings
541 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
542 // StructureImportSettings
543 // .setDefaultPDBFileParser(Cache.getDefault(
544 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
546 String jnlpVersion = System.getProperty("jalview.version");
548 // jnlpVersion will be null if a latest version check for the channel needs
550 // Dont do this check if running in headless mode
552 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
553 && (System.getProperty("java.awt.headless") == null || System
554 .getProperty("java.awt.headless").equals("false")))
557 class VersionChecker extends Thread
563 String remoteBuildPropertiesUrl = Cache
564 .getAppbaseBuildProperties();
566 String orgtimeout = System
567 .getProperty("sun.net.client.defaultConnectTimeout");
568 if (orgtimeout == null)
571 Console.debug("Setting default net timeout to " + orgtimeout
574 String remoteVersion = null;
575 if (remoteBuildPropertiesUrl.startsWith("http"))
579 System.setProperty("sun.net.client.defaultConnectTimeout",
582 URL url = new URL(remoteBuildPropertiesUrl);
584 BufferedReader in = new BufferedReader(
585 new InputStreamReader(url.openStream()));
587 Properties remoteBuildProperties = new Properties();
588 remoteBuildProperties.load(in);
589 remoteVersion = remoteBuildProperties.getProperty("VERSION");
590 } catch (Exception ex)
592 if (!Jalview.quiet())
594 jalview.bin.Console.errPrintln(
595 "Non-fatal exception when checking version at "
596 + remoteBuildPropertiesUrl + ":");
597 jalview.bin.Console.printStackTrace(ex);
599 remoteVersion = getProperty("VERSION");
602 System.setProperty("sun.net.client.defaultConnectTimeout",
605 setProperty("LATEST_VERSION", remoteVersion);
609 VersionChecker vc = new VersionChecker();
614 if (jnlpVersion != null)
616 setProperty("LATEST_VERSION", jnlpVersion);
620 applicationProperties.remove("LATEST_VERSION");
624 // LOAD USERDEFINED COLOURS
625 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
626 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
631 * construct a resource URL for the given absolute resource pathname
633 * @param resourcePath
636 private static String resolveResourceURLFor(String resourcePath)
639 if (Platform.isJS() || !Cache.class.getProtectionDomain()
640 .getCodeSource().getLocation().toString().endsWith(".jar"))
644 url = Cache.class.getResource(resourcePath).toString();
645 } catch (Exception ex)
647 jalview.bin.Console.errPrintln("Failed to resolve resource "
648 + resourcePath + ": " + ex.getMessage());
653 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
654 .getLocation().toString().concat("!" + resourcePath));
659 public static void loadBuildProperties(boolean reportVersion)
661 String codeInstallation = getProperty("INSTALLATION");
662 boolean printVersion = codeInstallation == null;
665 * read build properties - from the Jalview jar for a Java distribution,
666 * or from codebase file in test or JalviewJS context
670 String buildDetails = resolveResourceURLFor("/.build_properties");
671 URL localJarFileURL = new URL(buildDetails);
672 InputStream in = localJarFileURL.openStream();
673 buildProperties.load(in);
675 if (buildProperties.getProperty("BUILD_DATE", null) != null)
677 applicationProperties.put("BUILD_DATE",
678 buildProperties.getProperty("BUILD_DATE"));
680 if (buildProperties.getProperty("INSTALLATION", null) != null)
682 applicationProperties.put("INSTALLATION",
683 buildProperties.getProperty("INSTALLATION"));
685 if (buildProperties.getProperty("VERSION", null) != null)
687 applicationProperties.put("VERSION",
688 buildProperties.getProperty("VERSION"));
690 if (buildProperties.getProperty("JAVA_COMPILE_VERSION", null) != null)
692 applicationProperties.put("JAVA_COMPILE_VERSION",
693 buildProperties.getProperty("JAVA_COMPILE_VERSION"));
695 } catch (Exception ex)
697 if (!Jalview.quiet())
699 .outPrintln("Error reading build details: " + ex);
700 applicationProperties.remove("VERSION");
702 String codeVersion = getProperty("VERSION");
703 codeInstallation = getProperty("INSTALLATION");
705 if (codeVersion == null)
707 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
708 codeVersion = "Test";
709 codeInstallation = "";
713 codeInstallation = " (" + codeInstallation + ")";
715 setProperty("VERSION", codeVersion);
716 new BuildDetails(codeVersion, null, codeInstallation);
717 if (printVersion && reportVersion)
720 .outPrintln(ChannelProperties.getProperty("app_name")
721 + " version: " + codeVersion + codeInstallation);
725 private static void deleteBuildProperties()
727 applicationProperties.remove("LATEST_VERSION");
728 applicationProperties.remove("VERSION");
729 applicationProperties.remove("AUTHORS");
730 applicationProperties.remove("AUTHORFNAMES");
731 applicationProperties.remove("YEAR");
732 applicationProperties.remove("BUILD_DATE");
733 applicationProperties.remove("INSTALLATION");
737 * Gets Jalview application property of given key. Returns null if key not
743 * @return Property value
745 public static String getProperty(String key)
747 return getProperty(key, false);
750 public static String getProperty(String key,
751 boolean skipSessionProperties)
754 if (!(skipSessionProperties || bypassSessionProperties))
756 prop = getSessionProperty(key);
760 prop = applicationProperties.getProperty(key);
762 if (prop == null && Platform.isJS())
764 prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
765 + "_" + JS_PROPERTY_PREFIX + key);
771 * These methods are used when checking if the saved preference is different
772 * to the default setting
775 public static boolean getDefault(String property, boolean def)
777 String string = getProperty(property);
780 def = Boolean.valueOf(string).booleanValue();
786 public static int getDefault(String property, int def)
788 String string = getProperty(property);
793 def = Integer.parseInt(string);
794 } catch (NumberFormatException e)
796 if (!Jalview.quiet())
797 jalview.bin.Console.errPrintln("Error parsing int property '"
798 + property + "' with value '" + string + "'");
805 public static float getDefault(String property, float def)
807 String string = getProperty(property);
812 def = Float.parseFloat(string);
813 } catch (NumberFormatException e)
815 if (!Jalview.quiet())
816 jalview.bin.Console.errPrintln("Error parsing float property '"
817 + property + "' with value '" + string + "'");
825 * Answers the value of the given property, or the supplied default value if
826 * the property is not set
828 public static String getDefault(String property, String def)
830 String value = getProperty(property);
831 return value == null ? def : value;
835 * Stores property in the file "HOME_DIR/.jalview_properties"
840 * String value of property
842 * @return previous value of property (or null)
844 public static Object setProperty(String key, String obj)
846 Object oldValue = null;
849 oldValue = applicationProperties.setProperty(key, obj);
850 if (propertiesFile != null && !propsAreReadOnly
851 // don't rewrite if new value is same as old value
852 && !((obj == null && oldValue == null)
853 || (obj != null && obj.equals(oldValue))))
855 // reset the session property too
856 if (sessionProperties.containsKey(key))
858 sessionProperties.remove(key);
860 FileOutputStream out = new FileOutputStream(propertiesFile);
861 applicationProperties.store(out, "---JalviewX Properties File---");
864 } catch (Exception ex)
866 if (!Jalview.quiet())
867 jalview.bin.Console.errPrintln(
868 "Error setting property: " + key + " " + obj + "\n" + ex);
874 * remove the specified property from the jalview properties file
878 public static void removeProperty(String string)
880 applicationProperties.remove(string);
885 * save the properties to the jalview properties path
887 public static void saveProperties()
889 if (!propsAreReadOnly)
893 FileOutputStream out = new FileOutputStream(propertiesFile);
894 applicationProperties.store(out, "---JalviewX Properties File---");
896 } catch (Exception ex)
898 if (!Jalview.quiet())
899 jalview.bin.Console.errPrintln("Error saving properties: " + ex);
905 * internal vamsas class discovery state
907 private static int vamsasJarsArePresent = -1;
910 * Searches for vamsas client classes on class path.
912 * @return true if vamsas client is present on classpath
914 public static boolean vamsasJarsPresent()
916 if (vamsasJarsArePresent == -1)
920 if (jalview.jbgui.GDesktop.class.getClassLoader()
921 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
924 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
925 vamsasJarsArePresent = 1;
926 JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
927 Console.getCachedLogLevel("logs.Vamsas.Level"));
928 JLoggerLog4j.addAppender(lvclient, Console.log,
929 JALVIEW_LOGGER_NAME);
930 // Tell the user that debug is enabled
931 lvclient.debug(ChannelProperties.getProperty("app_name")
932 + " Vamsas Client Debugging Output Follows.");
934 } catch (Exception e)
936 vamsasJarsArePresent = 0;
937 Console.debug("Vamsas Classes are not present");
940 return (vamsasJarsArePresent > 0);
944 * internal vamsas class discovery state
946 private static int groovyJarsArePresent = -1;
949 * Searches for vamsas client classes on class path.
951 * @return true if vamsas client is present on classpath
953 public static boolean groovyJarsPresent()
955 if (groovyJarsArePresent == -1)
959 if (Cache.class.getClassLoader()
960 .loadClass("groovy.lang.GroovyObject") != null)
963 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
964 groovyJarsArePresent = 1;
965 JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
966 Console.getCachedLogLevel("logs.Groovy.Level"));
967 JLoggerLog4j.addAppender(lgclient, Console.log,
968 JALVIEW_LOGGER_NAME);
969 // Tell the user that debug is enabled
970 lgclient.debug(ChannelProperties.getProperty("app_name")
971 + " Groovy Client Debugging Output Follows.");
975 groovyJarsArePresent = 0;
976 Console.debug("Groovy Classes are not present", e);
977 } catch (Exception e)
979 groovyJarsArePresent = 0;
980 Console.debug("Groovy Classes are not present");
983 return (groovyJarsArePresent > 0);
987 * Initialise the tracker if it is not done already.
989 public static void initAnalytics()
991 Plausible.setEnabled(true);
993 String appName = ChannelProperties.getProperty("app_name") + " Desktop";
994 String version = Cache.getProperty("VERSION") + "_"
995 + Cache.getDefault("BUILD_DATE", "unknown");
997 /* we don't want to encode ':' as "%3A" for backward compatibility with the UA setup
1000 path = "/" + String.join("/", URLEncoder.encode(appName, "UTF-8"),
1001 URLEncoder.encode(version, "UTF-8"),
1002 URLEncoder.encode(APPLICATION_STARTED, "UTF-8"));
1003 } catch (UnsupportedEncodingException e)
1006 List<String> pathParts = new ArrayList<>();
1007 pathParts.add(appName);
1008 pathParts.add(version);
1009 pathParts.add(APPLICATION_STARTED);
1010 path = ("/" + String.join("/", pathParts)).replace(' ', '+');
1014 Plausible plausible = Plausible.getInstance();
1016 // This will send a new "application_launch" event with parameters
1017 // including the old-style "path", the channel name and version
1018 plausible.sendEvent("application_launch", path, true);
1021 private static final String APPLICATION_STARTED = "Application Started";
1024 * get the user's default colour if available
1030 public static Color getDefaultColour(String property, Color defcolour)
1032 String colprop = getProperty(property);
1033 if (colprop == null)
1037 Color col = ColorUtils.parseColourString(colprop);
1040 Console.warn("Couldn't parse '" + colprop + "' as a colour for "
1043 return (col == null) ? defcolour : col;
1047 * store a colour as a Jalview user default property
1052 public static void setColourProperty(String property, Color colour)
1054 setProperty(property, jalview.util.Format.getHexString(colour));
1058 * Stores a formatted date in a jalview property, using a fixed locale.
1060 * @param propertyName
1062 * @return the formatted date string
1064 public static String setDateProperty(String propertyName, Date date)
1066 String formatted = date_format.format(date);
1067 setProperty(propertyName, formatted);
1072 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1073 * format) and returns as a Date, or null if parsing fails
1075 * @param propertyName
1079 public static Date getDateProperty(String propertyName)
1081 String val = getProperty(propertyName);
1086 return date_format.parse(val);
1087 } catch (Exception ex)
1090 .errPrintln("Invalid or corrupt date in property '"
1091 + propertyName + "' : value was '" + val + "'");
1098 * get and parse a property as an integer. send any parsing problems to
1102 * @return null or Integer
1104 public static Integer getIntegerProperty(String property)
1106 String val = getProperty(property);
1107 if (val != null && (val = val.trim()).length() > 0)
1111 return Integer.valueOf(val);
1112 } catch (NumberFormatException x)
1114 jalview.bin.Console.errPrintln("Invalid integer in property '"
1115 + property + "' (value was '" + val + "')");
1122 * Set the specified value, or remove it if null or empty. Does not save the
1128 public static void setOrRemove(String propName, String value)
1130 if (propName == null)
1134 if (value == null || value.trim().length() < 1)
1136 Cache.applicationProperties.remove(propName);
1140 Cache.applicationProperties.setProperty(propName, value);
1145 * Loads in user colour schemes from files.
1148 * a '|'-delimited list of file paths
1150 public static void initUserColourSchemes(String files)
1152 if (files == null || files.length() == 0)
1157 // In case colours can't be loaded, we'll remove them
1158 // from the default list here.
1159 StringBuffer coloursFound = new StringBuffer();
1160 StringTokenizer st = new StringTokenizer(files, "|");
1161 while (st.hasMoreElements())
1163 String file = st.nextToken();
1166 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1169 if (coloursFound.length() > 0)
1171 coloursFound.append("|");
1173 coloursFound.append(file);
1174 ColourSchemes.getInstance().registerColourScheme(ucs);
1176 } catch (Exception ex)
1178 if (!Jalview.quiet())
1180 .outPrintln("Error loading User ColourFile\n" + ex);
1183 if (!files.equals(coloursFound.toString()))
1185 if (coloursFound.toString().length() > 1)
1187 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1188 coloursFound.toString());
1192 applicationProperties
1193 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1199 * Initial logging information helper for various versions output
1203 * @param defaultValue
1205 private static void appendIfNotNull(StringBuilder sb, String prefix,
1206 String value, String suffix, String defaultValue)
1208 if (value == null && defaultValue == null)
1214 sb.append(value == null ? defaultValue : value);
1221 * @return Jalview version, build details and JVM platform version for console
1223 public static String getVersionDetailsForConsole()
1225 StringBuilder sb = new StringBuilder();
1226 sb.append(ChannelProperties.getProperty("app_name"))
1227 .append(" Version: ");
1228 sb.append(Cache.getDefault("VERSION", "TEST"));
1230 sb.append(ChannelProperties.getProperty("app_name"))
1231 .append(" Installation: ");
1232 sb.append(Cache.getDefault("INSTALLATION", "unknown"));
1234 sb.append("Build Date: ");
1235 sb.append(Cache.getDefault("BUILD_DATE", "unknown"));
1237 sb.append("Java version: ");
1238 sb.append(System.getProperty("java.version"));
1240 sb.append("Java platform: ");
1241 sb.append(System.getProperty("os.arch"));
1243 sb.append(System.getProperty("os.name"));
1245 sb.append(System.getProperty("os.version"));
1247 appendIfNotNull(sb, "Install4j version: ",
1248 System.getProperty("sys.install4jVersion"), "\n", null);
1249 appendIfNotNull(sb, "Install4j template version: ",
1250 System.getProperty("installer_template_version"), "\n", null);
1251 appendIfNotNull(sb, "Launcher version: ",
1252 System.getProperty("launcher_version"), "\n", null);
1253 LookAndFeel laf = UIManager.getLookAndFeel();
1254 String lafName = laf == null ? "Not obtained" : laf.getName();
1255 String lafClass = laf == null ? "unknown" : laf.getClass().getName();
1256 sb.append("LookAndFeel: ");
1259 sb.append(lafClass);
1261 appendIfNotNull(sb, "Channel: ",
1262 ChannelProperties.getProperty("channel"), "\n", null);
1263 if (Console.isDebugEnabled()
1264 || !"release".equals(ChannelProperties.getProperty("channel")))
1266 appendIfNotNull(sb, "Getdown appdir: ",
1267 System.getProperty("getdowninstanceappdir"), "\n", null);
1268 appendIfNotNull(sb, "Getdown appbase: ",
1269 System.getProperty("getdowninstanceappbase"), "\n", null);
1270 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1272 appendIfNotNull(sb, "Preferences file: ", propertiesFile, "\n",
1275 return sb.toString();
1280 * @return build details as reported in splashscreen
1282 public static String getBuildDetailsForSplash()
1284 // consider returning more human friendly info
1285 // eg 'built from Source' or update channel
1286 return Cache.getDefault("INSTALLATION", "unknown");
1289 public static String getStackTraceString(Throwable t)
1291 StringWriter sw = new StringWriter();
1292 PrintWriter pw = new PrintWriter(sw);
1293 t.printStackTrace(pw);
1294 return sw.toString();
1297 // proxy properties methods
1298 public static void clearProxyProperties()
1300 setProxyProperties(null, null, null, null, null, null, null, null,
1304 public static void resetProxyProperties()
1306 setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
1307 startupProxyProperties[2], startupProxyProperties[3],
1308 startupProxyProperties[4],
1309 startupProxyProperties[5] == null ? null
1310 : startupProxyProperties[5].toCharArray(),
1311 startupProxyProperties[6],
1312 startupProxyProperties[7] == null ? null
1313 : startupProxyProperties[7].toCharArray(),
1314 startupProxyProperties[8]);
1315 StringBuilder sb = new StringBuilder();
1316 sb.append("Setting proxy properties to: http.proxyHost=")
1317 .append(startupProxyProperties[0]).append(", http.proxyPort=")
1318 .append(startupProxyProperties[1])
1319 .append(startupProxyProperties[4] != null
1320 && !startupProxyProperties[4].isEmpty()
1321 ? " [" + startupProxyProperties[4] + "]"
1323 .append(", https.proxyHost=").append(startupProxyProperties[2])
1324 .append(", https.proxyPort=").append(startupProxyProperties[3])
1325 .append(startupProxyProperties[6] != null
1326 && !startupProxyProperties[6].isEmpty()
1327 ? " [" + startupProxyProperties[6] + "]"
1330 Console.debug(sb.toString());
1333 public static void setProxyPropertiesFromPreferences()
1335 setProxyPropertiesFromPreferences(Cache.PROXYTYPE_SYSTEM);
1338 public static void setProxyPropertiesFromPreferences(
1339 String previousProxyType)
1341 String proxyType = Cache.getDefault("USE_PROXY",
1342 Cache.PROXYTYPE_SYSTEM);
1343 if (previousProxyType != null
1344 && !proxyType.equals(Cache.PROXYTYPE_CUSTOM) // always apply
1346 && proxyType.equals(previousProxyType))
1353 case Cache.PROXYTYPE_NONE:
1354 if (!previousProxyType.equals(proxyType))
1356 Console.info("Setting no proxy settings");
1357 Cache.setProxyProperties(null, null, null, null, null, null, null,
1361 case Cache.PROXYTYPE_CUSTOM:
1362 // always re-set a custom proxy -- it might have changed, particularly
1364 Console.info("Setting custom proxy settings");
1365 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
1366 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
1367 Cache.getDefault("PROXY_PORT", null),
1368 Cache.getDefault("PROXY_SERVER_HTTPS", null),
1369 Cache.getDefault("PROXY_PORT_HTTPS", null),
1370 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1372 proxyAuthSet ? Cache.proxyAuthPassword : null,
1373 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1375 proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
1377 default: // system proxy settings by default
1378 Console.info("Setting system proxy settings");
1379 Cache.resetProxyProperties();
1383 public static void setProxyProperties(String httpHost, String httpPort,
1384 String httpsHost, String httpsPort, String httpUser,
1385 char[] httpPassword, String httpsUser, char[] httpsPassword,
1386 String nonProxyHosts)
1388 setOrClearSystemProperty("http.proxyHost", httpHost);
1389 setOrClearSystemProperty("http.proxyPort", httpPort);
1390 setOrClearSystemProperty("https.proxyHost", httpsHost);
1391 setOrClearSystemProperty("https.proxyPort", httpsPort);
1392 setOrClearSystemProperty("http.proxyUser", httpUser);
1393 setOrClearSystemProperty("https.proxyUser", httpsUser);
1394 // note: passwords for http.proxyPassword and https.proxyPassword are sent
1395 // via the Authenticator, properties do not need to be set
1397 // are we using a custom proxy (password prompt might be required)?
1398 boolean customProxySet = getDefault("USE_PROXY", PROXYTYPE_SYSTEM)
1399 .equals(PROXYTYPE_CUSTOM);
1402 * A bug in Java means the AuthCache does not get reset, so once it has working credentials,
1403 * it never asks for more, so changing the Authenticator has no effect (as getPasswordAuthentication()
1404 * is not re-called).
1405 * This could lead to password leak to a hostile proxy server, so I'm putting in a hack to clear
1407 * see https://www.generacodice.com/en/articolo/154918/Reset-the-Authenticator-credentials
1409 * Turns out this is only accessible in Java 8, and not in Java 9 onwards, so commenting out
1414 sun.net.www.protocol.http.AuthCacheValue
1415 .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl());
1416 } catch (Throwable t)
1418 Cache.error(t.getMessage());
1419 Cache.debug(getStackTraceString(t));
1423 if (httpUser != null || httpsUser != null)
1427 char[] displayHttpPw = new char[httpPassword == null ? 0
1428 : httpPassword.length];
1429 Arrays.fill(displayHttpPw, '*');
1431 "CACHE Proxy: setting new Authenticator with httpUser='"
1432 + httpUser + "' httpPassword='" + displayHttpPw
1434 if (!Platform.isJS())
1436 * java.net.Authenticator not implemented in SwingJS yet
1442 Authenticator.setDefault(new Authenticator()
1445 protected PasswordAuthentication getPasswordAuthentication()
1447 if (getRequestorType() == RequestorType.PROXY)
1449 String protocol = getRequestingProtocol();
1450 boolean needProxyPasswordSet = false;
1451 if (customProxySet &&
1452 // we have a username but no password for the scheme being
1454 (protocol.equalsIgnoreCase("http")
1455 && (httpUser != null && httpUser.length() > 0
1456 && (httpPassword == null
1457 || httpPassword.length == 0)))
1458 || (protocol.equalsIgnoreCase("https")
1459 && (httpsUser != null
1460 && httpsUser.length() > 0
1461 && (httpsPassword == null
1462 || httpsPassword.length == 0))))
1464 // open Preferences -> Connections
1465 String message = MessageManager
1466 .getString("label.proxy_password_required");
1467 Preferences.openPreferences(
1468 Preferences.TabRef.CONNECTIONS_TAB, message);
1469 Preferences.getInstance()
1470 .proxyAuthPasswordCheckHighlight(true, true);
1476 if (protocol.equalsIgnoreCase("http")
1477 && getRequestingHost()
1478 .equalsIgnoreCase(httpHost)
1479 && getRequestingPort() == Integer
1483 "AUTHENTICATOR returning PasswordAuthentication(\""
1484 + httpUser + "\", '"
1485 + new String(displayHttpPw) + "')");
1486 return new PasswordAuthentication(httpUser,
1489 if (protocol.equalsIgnoreCase("https")
1490 && getRequestingHost()
1491 .equalsIgnoreCase(httpsHost)
1492 && getRequestingPort() == Integer
1493 .valueOf(httpsPort))
1495 char[] displayHttpsPw = new char[httpPassword.length];
1496 Arrays.fill(displayHttpsPw, '*');
1498 "AUTHENTICATOR returning PasswordAuthentication(\""
1499 + httpsUser + "\", '" + displayHttpsPw
1501 return new PasswordAuthentication(httpsUser,
1504 } catch (NumberFormatException e)
1506 Console.error("Problem with proxy port values [http:"
1507 + httpPort + ", https:" + httpsPort + "]");
1510 "AUTHENTICATOR after trying to get PasswordAuthentication");
1513 // non proxy request
1514 Console.debug("AUTHENTICATOR returning null");
1518 } // end of j2sIgnore for java.net.Authenticator
1520 // required to re-enable basic authentication (should be okay for a
1523 "AUTHENTICATOR setting property 'jdk.http.auth.tunneling.disabledSchemes' to \"\"");
1524 System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
1525 } catch (SecurityException e)
1527 Console.error("Could not set default Authenticator");
1528 Console.debug(getStackTraceString(e));
1533 // reset the Authenticator to protect http.proxyUser and
1534 // http.proxyPassword Just In Case
1535 /* as noted above, due to bug in java this doesn't work if the sun.net.www.protocol.http.AuthCache
1536 * has working credentials. No workaround for Java 11.
1538 if (!Platform.isJS())
1540 * java.net.Authenticator not implemented in SwingJS yet
1547 "AUTHENTICATOR setting default Authenticator to null");
1548 Authenticator.setDefault(null);
1552 // nonProxyHosts not currently configurable in Preferences
1554 "AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
1555 + nonProxyHosts + "\"");
1556 setOrClearSystemProperty("http.nonProxyHosts", nonProxyHosts);
1559 public static void setOrClearSystemProperty(String key, char[] value)
1561 setOrClearSystemProperty(key,
1562 (value == null) ? null : new String(value));
1565 public static void setOrClearSystemProperty(String key, String value)
1573 System.clearProperty(key);
1577 System.setProperty(key, value);
1582 * Getdown appbase methods
1585 private static final String releaseAppbase;
1587 private static String getdownAppbase;
1589 private static String getdownDistDir;
1593 if (!Platform.isJS())
1595 Float specversion = Float
1596 .parseFloat(System.getProperty("java.specification.version"));
1597 releaseAppbase = (specversion < 9)
1598 ? "https://www.jalview.org/getdown/release/1.8"
1599 : "https://www.jalview.org/getdown/release/11";
1603 // this value currenly made up, can be changed to URL that will be
1604 // "https://www.jalview.org/jalview-js/swingjs/j2s/build_properties"
1605 releaseAppbase = "https://www.jalview.org/jalview-js";
1606 getdownAppbase = releaseAppbase;
1607 getdownDistDir = "/swingjs/j2s";
1611 // look for properties (passed in by getdown) otherwise default to release
1612 private static void setGetdownAppbase()
1614 if (getdownAppbase != null)
1618 String appbase = System.getProperty("getdownappbase");
1619 String distDir = System.getProperty("getdowndistdir");
1620 if (appbase == null)
1622 appbase = buildProperties.getProperty("GETDOWNAPPBASE");
1623 distDir = buildProperties.getProperty("GETDOWNAPPDISTDIR");
1625 if (appbase == null)
1627 appbase = releaseAppbase;
1628 distDir = "release";
1630 if (appbase.endsWith("/"))
1632 appbase = appbase.substring(0, appbase.length() - 1);
1634 if (distDir == null)
1636 distDir = appbase.equals(releaseAppbase) ? "release" : "alt";
1638 getdownAppbase = appbase;
1639 getdownDistDir = distDir;
1642 public static String getGetdownAppbase()
1644 setGetdownAppbase();
1645 return getdownAppbase;
1648 public static String getAppbaseBuildProperties()
1650 String appbase = getGetdownAppbase();
1651 return appbase + "/" + getdownDistDir + "/build_properties";
1654 private static final Collection<String> bootstrapProperties = new ArrayList<>(
1655 Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST));
1657 public static Properties bootstrapProperties(String filename)
1659 Properties bootstrapProps = new Properties();
1661 if (filename != null)
1663 file = new File(filename);
1665 if (file == null || !file.exists())
1670 .errPrintln("Could not load bootstrap preferences file '"
1671 + file.getPath() + "'");
1673 String channelPrefsFilename = ChannelProperties
1674 .getProperty("preferences.filename");
1675 String propertiesFilename = System.getProperty("user.home")
1676 + File.separatorChar + channelPrefsFilename;
1677 jalview.bin.Console.errPrintln(
1678 "Using default properties file '" + propertiesFilename + "'");
1679 file = new File(propertiesFilename);
1681 if (file == null || !file.exists())
1684 String releasePrefsFilename = fallbackPropertiesFile;
1685 String releasePropertiesFilename = System.getProperty("user.home")
1686 + File.separatorChar + releasePrefsFilename;
1687 jalview.bin.Console.errPrintln("Falling back to properties file '"
1688 + releasePropertiesFilename + "'");
1689 file = new File(releasePropertiesFilename);
1695 .errPrintln("Could not load bootstrap preferences file '"
1696 + file.getPath() + "'");
1702 FileInputStream in = new FileInputStream(file.getAbsoluteFile());
1703 Properties props = new Properties();
1705 for (String prop : bootstrapProperties)
1707 if (props.containsKey(prop))
1708 bootstrapProps.put(prop, props.getProperty(prop));
1710 } catch (FileNotFoundException e)
1713 .errPrintln("Could not find bootstrap preferences file '"
1714 + file.getAbsolutePath() + "'");
1715 } catch (IOException e)
1717 jalview.bin.Console.errPrintln(
1718 "IOException when loading bootstrap preferences file '"
1719 + file.getAbsolutePath() + "'");
1721 return bootstrapProps;
1724 public static void setSessionProperty(String key, String val)
1728 sessionProperties.put(key, val);
1732 public static String getSessionProperty(String key)
1734 return key == null ? null : sessionProperties.get(key);
1737 public static boolean getArgCacheDefault(Arg a, String pref, boolean def)
1739 ArgParser ap = Jalview.getInstance().getArgParser();
1740 return ap.isSet(a) ? ap.getBoolean(a) : getDefault(pref, def);