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_SSCONSENSUS_HISTOGRAM (false) Show secondary structure consensus annotation row's
182 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
184 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
185 * logo normalised to row height rather than histogram height.</li>
186 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
187 * respond to selections made in other alignments containing the same sequences.
189 * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
190 * auto-discover JABAWS services</li>
191 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
192 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
193 * warning dialog box is displayed.</li>
194 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
195 * when shading by annotation</li>
196 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
197 * when shading by annotation</li>
198 * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
199 * requests to be redirected to a mirror of https://www.jalview.org</li>
200 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
201 * alignment figure to accommodate even the longest sequence ID or annotation
203 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
204 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
205 * will override this).</li>
206 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
208 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
209 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
211 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
213 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
215 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
216 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
218 * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
219 * <li>NOHTMLTEMPLATES - when set, the
220 * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
221 * not downloaded automatically</li>
222 * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
223 * available URL linkouts via www.jalview.org/services/identifiers</li>
226 * Deprecated settings:
229 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
230 * startup (JWS1 services only)</li>
231 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
232 * (JWS1 services only)</li>
233 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
234 * services in the desktop GUI</li>
235 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
236 * panel in web service preferences</li>
240 * @version $Revision$
245 * property giving log4j level for CASTOR loggers
247 public static final String CASTORLOGLEVEL = "logs.Castor.level";
250 * property giving log4j level for AXIS loggers
252 public static final String AXISLOGLEVEL = "logs.Axis.level";
255 * property giving log4j level for Jalview Log
257 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
260 public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST";
265 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
266 .getProperty("user.home") + File.separatorChar
267 + ".sifts_downloads" + File.separatorChar;
269 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
271 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
274 * Identifiers.org download settings
276 private static final String ID_ORG_FILE = System.getProperty("user.home")
277 + File.separatorChar + ".identifiers.org.ids.json";
280 * Allowed values are PDB or mmCIF
282 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
285 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
289 * a date formatter using a fixed (rather than the user's) locale;
290 * this ensures that date properties can be written and re-read successfully
291 * even if the user changes their locale setting
293 private static final DateFormat date_format = SimpleDateFormat
294 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
295 SimpleDateFormat.MEDIUM, Locale.UK);
298 * Initialises the Jalview Application Log
301 public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
303 // save the proxy properties set at startup
304 public final static String[] startupProxyProperties = {
305 System.getProperty("http.proxyHost"),
306 System.getProperty("http.proxyPort"),
307 System.getProperty("https.proxyHost"),
308 System.getProperty("https.proxyPort"),
309 System.getProperty("http.proxyUser"),
310 System.getProperty("http.proxyPassword"),
311 System.getProperty("https.proxyUser"),
312 System.getProperty("https.proxyPassword"),
313 System.getProperty("http.nonProxyHosts") };
315 public final static String PROXYTYPE_NONE = "none";
317 // "false" and "true" for backward compatibility
318 public final static String PROXYTYPE_SYSTEM = "false";
320 public final static String PROXYTYPE_CUSTOM = "true";
322 // in-memory only storage of proxy password, safer to use char array
323 public static char[] proxyAuthPassword = null;
326 * Session properties, set by command line, try not to affect stored
329 private static Map<String, String> sessionProperties = new HashMap<>();
331 private static boolean bypassSessionProperties = false;
333 public static void enableSessionProperties()
335 bypassSessionProperties = false;
338 public static void disableSessionProperties()
340 bypassSessionProperties = true;
343 /** Jalview Properties */
344 public static Properties applicationProperties = new Properties()
346 // override results in properties output in alphabetical order
348 public synchronized Enumeration<Object> keys()
350 return Collections.enumeration(new TreeSet<>(super.keySet()));
354 /* build Properties (not all saved to .jalview_properties) */
355 public static Properties buildProperties = new Properties();
357 /** Default file is ~/.jalview_properties */
358 static String propertiesFile;
360 private static final String fallbackPropertiesFile = ".jalview_properties";
362 private static boolean propsAreReadOnly = Platform.isJS();
364 public static boolean isPropsAreReadOnly()
366 return propsAreReadOnly;
369 public static void setPropsAreReadOnly(boolean propsAreReadOnly)
371 Cache.propsAreReadOnly = propsAreReadOnly;
374 private final static String JS_PROPERTY_PREFIX = "jalview_";
377 * Loads properties from the given properties file. Any existing properties
380 public static void loadProperties(String propsFile)
382 propertiesFile = propsFile;
383 String releasePropertiesFile = null;
384 boolean defaultProperties = false;
385 if (propsFile == null && !propsAreReadOnly)
387 String channelPrefsFilename = ChannelProperties
388 .getProperty("preferences.filename");
389 String releasePrefsFilename = fallbackPropertiesFile;
390 propertiesFile = System.getProperty("user.home") + File.separatorChar
391 + channelPrefsFilename;
392 releasePropertiesFile = System.getProperty("user.home")
393 + File.separatorChar + releasePrefsFilename;
394 defaultProperties = true;
398 // don't corrupt the file we've been given.
399 propsAreReadOnly = true;
402 if (propertiesFile == null)
404 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
405 applicationProperties);
414 // props file provided as URL
415 fis = new URL(propertiesFile).openStream();
416 if (!Jalview.quiet())
418 jalview.bin.Console.outPrintln(
419 "Loading jalview properties from : " + propertiesFile);
420 jalview.bin.Console.outPrintln(
421 "Disabling Jalview writing to user's local properties file.");
423 propsAreReadOnly = true;
424 } catch (Exception ex)
430 String readPropertiesFile = propertiesFile;
431 // if we're using the usual properties file and the channel properties
432 // file doesn't exist, read .jalview_properties
433 // (but we'll still save to the channel properties file).
434 if (defaultProperties && (!new File(propertiesFile).exists())
435 && (new File(releasePropertiesFile).exists()))
437 readPropertiesFile = releasePropertiesFile;
439 fis = new FileInputStream(readPropertiesFile);
441 applicationProperties.clear();
442 applicationProperties.load(fis);
444 // remove any old build properties
446 deleteBuildProperties();
448 } catch (Exception ex)
450 if (!Jalview.quiet())
452 .outPrintln("Error reading properties file: " + ex);
456 /* TO BE REPLACED WITH PROXY_TYPE SETTINGS
457 if (getDefault("USE_PROXY", false))
459 String proxyServer = getDefault("PROXY_SERVER", ""),
460 proxyPort = getDefault("PROXY_PORT", "8080");
464 // PROXY TYPE settings (now three options "none", "false", "true", but using
465 // backward compatible strings)
466 String proxyType = getDefault("USE_PROXY", PROXYTYPE_SYSTEM);
467 // default to upgrading old settings
471 clearProxyProperties();
473 case PROXYTYPE_SYSTEM: // use system settings
474 resetProxyProperties();
476 case PROXYTYPE_CUSTOM: // use specified proxy settings
477 String httpHost = getDefault("PROXY_SERVER", "");
478 String httpPort = getDefault("PROXY_PORT", "8080");
479 String httpsHost = getDefault("PROXY_SERVER_HTTPS", httpHost);
480 String httpsPort = getDefault("PROXY_PORT_HTTPS", httpPort);
481 String httpUser = getDefault("PROXY_AUTH_USER", null);
482 // https.proxyUser and https.proxyPassword are not able to be
483 // independently set in Preferences yet (or http.nonProxyHosts)
484 String httpsUser = getDefault("PROXY_AUTH_USER_HTTPS", httpUser);
485 setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
486 proxyAuthPassword, httpsUser, proxyAuthPassword, "localhost");
489 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
491 Console.warn(message);
494 // LOAD THE AUTHORS FROM THE authors.props file
495 String authorDetails = resolveResourceURLFor("/authors.props");
499 if (authorDetails != null)
501 URL localJarFileURL = new URL(authorDetails);
502 InputStream in = localJarFileURL.openStream();
503 applicationProperties.load(in);
506 } catch (Exception ex)
508 if (!Jalview.quiet())
510 .outPrintln("Error reading author details: " + ex);
511 authorDetails = null;
513 if (authorDetails == null)
515 applicationProperties.remove("AUTHORS");
516 applicationProperties.remove("AUTHORFNAMES");
517 applicationProperties.remove("YEAR");
520 loadBuildProperties(false);
523 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
525 SiftsSettings.setSiftDownloadDirectory(Cache
526 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
528 SiftsSettings.setFailSafePIDThreshold(
529 Cache.getDefault("sifts_fail_safe_pid_threshold",
530 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
532 SiftsSettings.setCacheThresholdInDays(
533 Cache.getDefault("sifts_cache_threshold_in_days",
534 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
536 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
537 "https://www.jalview.org/services/identifiers"));
538 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
540 StructureImportSettings.setDefaultStructureFileFormat(
541 Cache.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
542 StructureImportSettings
543 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
544 // StructureImportSettings
545 // .setDefaultPDBFileParser(Cache.getDefault(
546 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
548 String jnlpVersion = System.getProperty("jalview.version");
550 // jnlpVersion will be null if a latest version check for the channel needs
552 // Dont do this check if running in headless mode
554 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
555 && (System.getProperty("java.awt.headless") == null || System
556 .getProperty("java.awt.headless").equals("false")))
559 class VersionChecker extends Thread
565 String remoteBuildPropertiesUrl = Cache
566 .getAppbaseBuildProperties();
568 String orgtimeout = System
569 .getProperty("sun.net.client.defaultConnectTimeout");
570 if (orgtimeout == null)
573 Console.debug("Setting default net timeout to " + orgtimeout
576 String remoteVersion = null;
577 if (remoteBuildPropertiesUrl.startsWith("http"))
581 System.setProperty("sun.net.client.defaultConnectTimeout",
584 URL url = new URL(remoteBuildPropertiesUrl);
586 BufferedReader in = new BufferedReader(
587 new InputStreamReader(url.openStream()));
589 Properties remoteBuildProperties = new Properties();
590 remoteBuildProperties.load(in);
591 remoteVersion = remoteBuildProperties.getProperty("VERSION");
592 } catch (Exception ex)
594 if (!Jalview.quiet())
596 jalview.bin.Console.errPrintln(
597 "Non-fatal exception when checking version at "
598 + remoteBuildPropertiesUrl + ":");
599 jalview.bin.Console.printStackTrace(ex);
601 remoteVersion = getProperty("VERSION");
604 System.setProperty("sun.net.client.defaultConnectTimeout",
607 setProperty("LATEST_VERSION", remoteVersion);
611 VersionChecker vc = new VersionChecker();
616 if (jnlpVersion != null)
618 setProperty("LATEST_VERSION", jnlpVersion);
622 applicationProperties.remove("LATEST_VERSION");
626 // LOAD USERDEFINED COLOURS
627 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
628 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
633 * construct a resource URL for the given absolute resource pathname
635 * @param resourcePath
638 private static String resolveResourceURLFor(String resourcePath)
641 if (Platform.isJS() || !Cache.class.getProtectionDomain()
642 .getCodeSource().getLocation().toString().endsWith(".jar"))
646 url = Cache.class.getResource(resourcePath).toString();
647 } catch (Exception ex)
649 jalview.bin.Console.errPrintln("Failed to resolve resource "
650 + resourcePath + ": " + ex.getMessage());
655 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
656 .getLocation().toString().concat("!" + resourcePath));
661 public static void loadBuildProperties(boolean reportVersion)
663 String codeInstallation = getProperty("INSTALLATION");
664 boolean printVersion = codeInstallation == null;
667 * read build properties - from the Jalview jar for a Java distribution,
668 * or from codebase file in test or JalviewJS context
672 String buildDetails = resolveResourceURLFor("/.build_properties");
673 URL localJarFileURL = new URL(buildDetails);
674 InputStream in = localJarFileURL.openStream();
675 buildProperties.load(in);
677 if (buildProperties.getProperty("BUILD_DATE", null) != null)
679 applicationProperties.put("BUILD_DATE",
680 buildProperties.getProperty("BUILD_DATE"));
682 if (buildProperties.getProperty("INSTALLATION", null) != null)
684 applicationProperties.put("INSTALLATION",
685 buildProperties.getProperty("INSTALLATION"));
687 if (buildProperties.getProperty("VERSION", null) != null)
689 applicationProperties.put("VERSION",
690 buildProperties.getProperty("VERSION"));
692 if (buildProperties.getProperty("JAVA_COMPILE_VERSION", null) != null)
694 applicationProperties.put("JAVA_COMPILE_VERSION",
695 buildProperties.getProperty("JAVA_COMPILE_VERSION"));
697 } catch (Exception ex)
699 if (!Jalview.quiet())
701 .outPrintln("Error reading build details: " + ex);
702 applicationProperties.remove("VERSION");
704 String codeVersion = getProperty("VERSION");
705 codeInstallation = getProperty("INSTALLATION");
707 if (codeVersion == null)
709 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
710 codeVersion = "Test";
711 codeInstallation = "";
715 codeInstallation = " (" + codeInstallation + ")";
717 setProperty("VERSION", codeVersion);
718 new BuildDetails(codeVersion, null, codeInstallation);
719 if (printVersion && reportVersion)
722 .outPrintln(ChannelProperties.getProperty("app_name")
723 + " version: " + codeVersion + codeInstallation);
727 private static void deleteBuildProperties()
729 applicationProperties.remove("LATEST_VERSION");
730 applicationProperties.remove("VERSION");
731 applicationProperties.remove("AUTHORS");
732 applicationProperties.remove("AUTHORFNAMES");
733 applicationProperties.remove("YEAR");
734 applicationProperties.remove("BUILD_DATE");
735 applicationProperties.remove("INSTALLATION");
739 * Gets Jalview application property of given key. Returns null if key not
745 * @return Property value
747 public static String getProperty(String key)
749 return getProperty(key, false);
752 public static String getProperty(String key,
753 boolean skipSessionProperties)
756 if (!(skipSessionProperties || bypassSessionProperties))
758 prop = getSessionProperty(key);
762 prop = applicationProperties.getProperty(key);
764 if (prop == null && Platform.isJS())
766 prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
767 + "_" + JS_PROPERTY_PREFIX + key);
773 * These methods are used when checking if the saved preference is different
774 * to the default setting
777 public static boolean getDefault(String property, boolean def)
779 String string = getProperty(property);
782 def = Boolean.valueOf(string).booleanValue();
788 public static int getDefault(String property, int def)
790 String string = getProperty(property);
795 def = Integer.parseInt(string);
796 } catch (NumberFormatException e)
798 if (!Jalview.quiet())
799 jalview.bin.Console.errPrintln("Error parsing int property '"
800 + property + "' with value '" + string + "'");
807 public static float getDefault(String property, float def)
809 String string = getProperty(property);
814 def = Float.parseFloat(string);
815 } catch (NumberFormatException e)
817 if (!Jalview.quiet())
818 jalview.bin.Console.errPrintln("Error parsing float property '"
819 + property + "' with value '" + string + "'");
827 * Answers the value of the given property, or the supplied default value if
828 * the property is not set
830 public static String getDefault(String property, String def)
832 String value = getProperty(property);
833 return value == null ? def : value;
837 * Stores property in the file "HOME_DIR/.jalview_properties"
842 * String value of property
844 * @return previous value of property (or null)
846 public static Object setProperty(String key, String obj)
848 Object oldValue = null;
851 oldValue = applicationProperties.setProperty(key, obj);
852 if (propertiesFile != null && !propsAreReadOnly
853 // don't rewrite if new value is same as old value
854 && !((obj == null && oldValue == null)
855 || (obj != null && obj.equals(oldValue))))
857 // reset the session property too
858 if (sessionProperties.containsKey(key))
860 sessionProperties.remove(key);
862 FileOutputStream out = new FileOutputStream(propertiesFile);
863 applicationProperties.store(out, "---JalviewX Properties File---");
866 } catch (Exception ex)
868 if (!Jalview.quiet())
869 jalview.bin.Console.errPrintln(
870 "Error setting property: " + key + " " + obj + "\n" + ex);
876 * remove the specified property from the jalview properties file
880 public static void removeProperty(String string)
882 applicationProperties.remove(string);
887 * save the properties to the jalview properties path
889 public static void saveProperties()
891 if (!propsAreReadOnly)
895 FileOutputStream out = new FileOutputStream(propertiesFile);
896 applicationProperties.store(out, "---JalviewX Properties File---");
898 } catch (Exception ex)
900 if (!Jalview.quiet())
901 jalview.bin.Console.errPrintln("Error saving properties: " + ex);
907 * internal vamsas class discovery state
909 private static int vamsasJarsArePresent = -1;
912 * Searches for vamsas client classes on class path.
914 * @return true if vamsas client is present on classpath
916 public static boolean vamsasJarsPresent()
918 if (vamsasJarsArePresent == -1)
922 if (jalview.jbgui.GDesktop.class.getClassLoader()
923 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
926 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
927 vamsasJarsArePresent = 1;
928 JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
929 Console.getCachedLogLevel("logs.Vamsas.Level"));
930 JLoggerLog4j.addAppender(lvclient, Console.log,
931 JALVIEW_LOGGER_NAME);
932 // Tell the user that debug is enabled
933 lvclient.debug(ChannelProperties.getProperty("app_name")
934 + " Vamsas Client Debugging Output Follows.");
936 } catch (Exception e)
938 vamsasJarsArePresent = 0;
939 Console.debug("Vamsas Classes are not present");
942 return (vamsasJarsArePresent > 0);
946 * internal vamsas class discovery state
948 private static int groovyJarsArePresent = -1;
951 * Searches for vamsas client classes on class path.
953 * @return true if vamsas client is present on classpath
955 public static boolean groovyJarsPresent()
957 if (groovyJarsArePresent == -1)
961 if (Cache.class.getClassLoader()
962 .loadClass("groovy.lang.GroovyObject") != null)
965 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
966 groovyJarsArePresent = 1;
967 JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
968 Console.getCachedLogLevel("logs.Groovy.Level"));
969 JLoggerLog4j.addAppender(lgclient, Console.log,
970 JALVIEW_LOGGER_NAME);
971 // Tell the user that debug is enabled
972 lgclient.debug(ChannelProperties.getProperty("app_name")
973 + " Groovy Client Debugging Output Follows.");
977 groovyJarsArePresent = 0;
978 Console.debug("Groovy Classes are not present", e);
979 } catch (Exception e)
981 groovyJarsArePresent = 0;
982 Console.debug("Groovy Classes are not present");
985 return (groovyJarsArePresent > 0);
989 * Initialise the tracker if it is not done already.
991 public static void initAnalytics()
993 Plausible.setEnabled(true);
995 String appName = ChannelProperties.getProperty("app_name") + " Desktop";
996 String version = Cache.getProperty("VERSION") + "_"
997 + Cache.getDefault("BUILD_DATE", "unknown");
999 /* we don't want to encode ':' as "%3A" for backward compatibility with the UA setup
1002 path = "/" + String.join("/", URLEncoder.encode(appName, "UTF-8"),
1003 URLEncoder.encode(version, "UTF-8"),
1004 URLEncoder.encode(APPLICATION_STARTED, "UTF-8"));
1005 } catch (UnsupportedEncodingException e)
1008 List<String> pathParts = new ArrayList<>();
1009 pathParts.add(appName);
1010 pathParts.add(version);
1011 pathParts.add(APPLICATION_STARTED);
1012 path = ("/" + String.join("/", pathParts)).replace(' ', '+');
1016 Plausible plausible = Plausible.getInstance();
1018 // This will send a new "application_launch" event with parameters
1019 // including the old-style "path", the channel name and version
1020 plausible.sendEvent("application_launch", path, true);
1023 private static final String APPLICATION_STARTED = "Application Started";
1026 * get the user's default colour if available
1032 public static Color getDefaultColour(String property, Color defcolour)
1034 String colprop = getProperty(property);
1035 if (colprop == null)
1039 Color col = ColorUtils.parseColourString(colprop);
1042 Console.warn("Couldn't parse '" + colprop + "' as a colour for "
1045 return (col == null) ? defcolour : col;
1049 * store a colour as a Jalview user default property
1054 public static void setColourProperty(String property, Color colour)
1056 setProperty(property, jalview.util.Format.getHexString(colour));
1060 * Stores a formatted date in a jalview property, using a fixed locale.
1062 * @param propertyName
1064 * @return the formatted date string
1066 public static String setDateProperty(String propertyName, Date date)
1068 String formatted = date_format.format(date);
1069 setProperty(propertyName, formatted);
1074 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1075 * format) and returns as a Date, or null if parsing fails
1077 * @param propertyName
1081 public static Date getDateProperty(String propertyName)
1083 String val = getProperty(propertyName);
1088 return date_format.parse(val);
1089 } catch (Exception ex)
1092 .errPrintln("Invalid or corrupt date in property '"
1093 + propertyName + "' : value was '" + val + "'");
1100 * get and parse a property as an integer. send any parsing problems to
1104 * @return null or Integer
1106 public static Integer getIntegerProperty(String property)
1108 String val = getProperty(property);
1109 if (val != null && (val = val.trim()).length() > 0)
1113 return Integer.valueOf(val);
1114 } catch (NumberFormatException x)
1116 jalview.bin.Console.errPrintln("Invalid integer in property '"
1117 + property + "' (value was '" + val + "')");
1124 * Set the specified value, or remove it if null or empty. Does not save the
1130 public static void setOrRemove(String propName, String value)
1132 if (propName == null)
1136 if (value == null || value.trim().length() < 1)
1138 Cache.applicationProperties.remove(propName);
1142 Cache.applicationProperties.setProperty(propName, value);
1147 * Loads in user colour schemes from files.
1150 * a '|'-delimited list of file paths
1152 public static void initUserColourSchemes(String files)
1154 if (files == null || files.length() == 0)
1159 // In case colours can't be loaded, we'll remove them
1160 // from the default list here.
1161 StringBuffer coloursFound = new StringBuffer();
1162 StringTokenizer st = new StringTokenizer(files, "|");
1163 while (st.hasMoreElements())
1165 String file = st.nextToken();
1168 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1171 if (coloursFound.length() > 0)
1173 coloursFound.append("|");
1175 coloursFound.append(file);
1176 ColourSchemes.getInstance().registerColourScheme(ucs);
1178 } catch (Exception ex)
1180 if (!Jalview.quiet())
1182 .outPrintln("Error loading User ColourFile\n" + ex);
1185 if (!files.equals(coloursFound.toString()))
1187 if (coloursFound.toString().length() > 1)
1189 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1190 coloursFound.toString());
1194 applicationProperties
1195 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1201 * Initial logging information helper for various versions output
1205 * @param defaultValue
1207 private static void appendIfNotNull(StringBuilder sb, String prefix,
1208 String value, String suffix, String defaultValue)
1210 if (value == null && defaultValue == null)
1216 sb.append(value == null ? defaultValue : value);
1223 * @return Jalview version, build details and JVM platform version for console
1225 public static String getVersionDetailsForConsole()
1227 StringBuilder sb = new StringBuilder();
1228 sb.append(ChannelProperties.getProperty("app_name"))
1229 .append(" Version: ");
1230 sb.append(Cache.getDefault("VERSION", "TEST"));
1232 sb.append(ChannelProperties.getProperty("app_name"))
1233 .append(" Installation: ");
1234 sb.append(Cache.getDefault("INSTALLATION", "unknown"));
1236 sb.append("Build Date: ");
1237 sb.append(Cache.getDefault("BUILD_DATE", "unknown"));
1239 sb.append("Java version: ");
1240 sb.append(System.getProperty("java.version"));
1242 sb.append("Java platform: ");
1243 sb.append(System.getProperty("os.arch"));
1245 sb.append(System.getProperty("os.name"));
1247 sb.append(System.getProperty("os.version"));
1249 appendIfNotNull(sb, "Install4j version: ",
1250 System.getProperty("sys.install4jVersion"), "\n", null);
1251 appendIfNotNull(sb, "Install4j template version: ",
1252 System.getProperty("installer_template_version"), "\n", null);
1253 appendIfNotNull(sb, "Launcher version: ",
1254 System.getProperty("launcher_version"), "\n", null);
1255 LookAndFeel laf = UIManager.getLookAndFeel();
1256 String lafName = laf == null ? "Not obtained" : laf.getName();
1257 String lafClass = laf == null ? "unknown" : laf.getClass().getName();
1258 sb.append("LookAndFeel: ");
1261 sb.append(lafClass);
1263 appendIfNotNull(sb, "Channel: ",
1264 ChannelProperties.getProperty("channel"), "\n", null);
1265 if (Console.isDebugEnabled()
1266 || !"release".equals(ChannelProperties.getProperty("channel")))
1268 appendIfNotNull(sb, "Getdown appdir: ",
1269 System.getProperty("getdowninstanceappdir"), "\n", null);
1270 appendIfNotNull(sb, "Getdown appbase: ",
1271 System.getProperty("getdowninstanceappbase"), "\n", null);
1272 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1274 appendIfNotNull(sb, "Preferences file: ", propertiesFile, "\n",
1277 return sb.toString();
1282 * @return build details as reported in splashscreen
1284 public static String getBuildDetailsForSplash()
1286 // consider returning more human friendly info
1287 // eg 'built from Source' or update channel
1288 return Cache.getDefault("INSTALLATION", "unknown");
1291 public static String getStackTraceString(Throwable t)
1293 StringWriter sw = new StringWriter();
1294 PrintWriter pw = new PrintWriter(sw);
1295 t.printStackTrace(pw);
1296 return sw.toString();
1299 // proxy properties methods
1300 public static void clearProxyProperties()
1302 setProxyProperties(null, null, null, null, null, null, null, null,
1306 public static void resetProxyProperties()
1308 setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
1309 startupProxyProperties[2], startupProxyProperties[3],
1310 startupProxyProperties[4],
1311 startupProxyProperties[5] == null ? null
1312 : startupProxyProperties[5].toCharArray(),
1313 startupProxyProperties[6],
1314 startupProxyProperties[7] == null ? null
1315 : startupProxyProperties[7].toCharArray(),
1316 startupProxyProperties[8]);
1317 StringBuilder sb = new StringBuilder();
1318 sb.append("Setting proxy properties to: http.proxyHost=")
1319 .append(startupProxyProperties[0]).append(", http.proxyPort=")
1320 .append(startupProxyProperties[1])
1321 .append(startupProxyProperties[4] != null
1322 && !startupProxyProperties[4].isEmpty()
1323 ? " [" + startupProxyProperties[4] + "]"
1325 .append(", https.proxyHost=").append(startupProxyProperties[2])
1326 .append(", https.proxyPort=").append(startupProxyProperties[3])
1327 .append(startupProxyProperties[6] != null
1328 && !startupProxyProperties[6].isEmpty()
1329 ? " [" + startupProxyProperties[6] + "]"
1332 Console.debug(sb.toString());
1335 public static void setProxyPropertiesFromPreferences()
1337 setProxyPropertiesFromPreferences(Cache.PROXYTYPE_SYSTEM);
1340 public static void setProxyPropertiesFromPreferences(
1341 String previousProxyType)
1343 String proxyType = Cache.getDefault("USE_PROXY",
1344 Cache.PROXYTYPE_SYSTEM);
1345 if (previousProxyType != null
1346 && !proxyType.equals(Cache.PROXYTYPE_CUSTOM) // always apply
1348 && proxyType.equals(previousProxyType))
1355 case Cache.PROXYTYPE_NONE:
1356 if (!previousProxyType.equals(proxyType))
1358 Console.info("Setting no proxy settings");
1359 Cache.setProxyProperties(null, null, null, null, null, null, null,
1363 case Cache.PROXYTYPE_CUSTOM:
1364 // always re-set a custom proxy -- it might have changed, particularly
1366 Console.info("Setting custom proxy settings");
1367 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
1368 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
1369 Cache.getDefault("PROXY_PORT", null),
1370 Cache.getDefault("PROXY_SERVER_HTTPS", null),
1371 Cache.getDefault("PROXY_PORT_HTTPS", null),
1372 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1374 proxyAuthSet ? Cache.proxyAuthPassword : null,
1375 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1377 proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
1379 default: // system proxy settings by default
1380 Console.info("Setting system proxy settings");
1381 Cache.resetProxyProperties();
1385 public static void setProxyProperties(String httpHost, String httpPort,
1386 String httpsHost, String httpsPort, String httpUser,
1387 char[] httpPassword, String httpsUser, char[] httpsPassword,
1388 String nonProxyHosts)
1390 setOrClearSystemProperty("http.proxyHost", httpHost);
1391 setOrClearSystemProperty("http.proxyPort", httpPort);
1392 setOrClearSystemProperty("https.proxyHost", httpsHost);
1393 setOrClearSystemProperty("https.proxyPort", httpsPort);
1394 setOrClearSystemProperty("http.proxyUser", httpUser);
1395 setOrClearSystemProperty("https.proxyUser", httpsUser);
1396 // note: passwords for http.proxyPassword and https.proxyPassword are sent
1397 // via the Authenticator, properties do not need to be set
1399 // are we using a custom proxy (password prompt might be required)?
1400 boolean customProxySet = getDefault("USE_PROXY", PROXYTYPE_SYSTEM)
1401 .equals(PROXYTYPE_CUSTOM);
1404 * A bug in Java means the AuthCache does not get reset, so once it has working credentials,
1405 * it never asks for more, so changing the Authenticator has no effect (as getPasswordAuthentication()
1406 * is not re-called).
1407 * This could lead to password leak to a hostile proxy server, so I'm putting in a hack to clear
1409 * see https://www.generacodice.com/en/articolo/154918/Reset-the-Authenticator-credentials
1411 * Turns out this is only accessible in Java 8, and not in Java 9 onwards, so commenting out
1416 sun.net.www.protocol.http.AuthCacheValue
1417 .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl());
1418 } catch (Throwable t)
1420 Cache.error(t.getMessage());
1421 Cache.debug(getStackTraceString(t));
1425 if (httpUser != null || httpsUser != null)
1429 char[] displayHttpPw = new char[httpPassword == null ? 0
1430 : httpPassword.length];
1431 Arrays.fill(displayHttpPw, '*');
1433 "CACHE Proxy: setting new Authenticator with httpUser='"
1434 + httpUser + "' httpPassword='" + displayHttpPw
1436 if (!Platform.isJS())
1438 * java.net.Authenticator not implemented in SwingJS yet
1444 Authenticator.setDefault(new Authenticator()
1447 protected PasswordAuthentication getPasswordAuthentication()
1449 if (getRequestorType() == RequestorType.PROXY)
1451 String protocol = getRequestingProtocol();
1452 boolean needProxyPasswordSet = false;
1453 if (customProxySet &&
1454 // we have a username but no password for the scheme being
1456 (protocol.equalsIgnoreCase("http")
1457 && (httpUser != null && 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);