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.Locale;
48 import java.util.Properties;
49 import java.util.StringTokenizer;
50 import java.util.TreeSet;
52 import javax.swing.LookAndFeel;
53 import javax.swing.UIManager;
55 import jalview.analytics.GoogleAnalytics4;
56 import jalview.datamodel.PDBEntry;
57 import jalview.gui.Preferences;
58 import jalview.gui.UserDefinedColours;
59 import jalview.log.JLoggerLog4j;
60 import jalview.schemes.ColourSchemeLoader;
61 import jalview.schemes.ColourSchemes;
62 import jalview.schemes.UserColourScheme;
63 import jalview.structure.StructureImportSettings;
64 import jalview.urls.IdOrgSettings;
65 import jalview.util.ChannelProperties;
66 import jalview.util.ColorUtils;
67 import jalview.util.MessageManager;
68 import jalview.util.Platform;
69 import jalview.ws.sifts.SiftsSettings;
72 * Stores and retrieves Jalview Application Properties Lists and fields within
73 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
74 * are alternative values for a tag. <br>
76 * Current properties include:
79 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
80 * logging level for axis (used for web services) <br>
82 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
83 * the logging level for castor (used for serialization) <br>
85 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
87 * <li>SCREEN_WIDTH</li>
88 * <li>SCREEN_HEIGHT</li>
89 * <li>SCREEN_Y=285</li>
90 * <li>SCREEN_X=371</li>
91 * <li>SHOW_FULLSCREEN boolean</li>
92 * <li>FONT_NAME java font name for alignment text display</li>
93 * <li>FONT_SIZE size of displayed alignment text</li>
94 * <li>FONT_STYLE style of font displayed (sequence labels are always
96 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
97 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
98 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
99 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
100 * <li>SHOW_IDENTITY show percentage identity annotation</li>
101 * <li>SHOW_QUALITY show alignment quality annotation</li>
102 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
103 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
104 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
105 * LABEL_AND_SEQUENCE</li>
106 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
107 * sequence annotations</li>
108 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
109 * annotation row</li>
110 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
111 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
112 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
113 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
114 * <li>VERSION the version of the jalview build</li>
115 * <li>BUILD_DATE date of this build</li>
116 * <li>LATEST_VERSION the latest jalview version advertised on the
117 * www.jalview.org</li>
118 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
120 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
121 * suffix to file</li>
122 * <li>RECENT_URL list of recently retrieved URLs</li>
123 * <li>RECENT_FILE list of recently opened files</li>
124 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
125 * <li>PROXY_SERVER the proxy</li>
126 * <li>PROXY_PORT</li>
127 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
129 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
131 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
132 * collecting usage statistics</li>
133 * <li>SHOW_OVERVIEW boolean for overview window display</li>
134 * <li>ANTI_ALIAS boolean for smooth fonts</li>
135 * <li>RIGHT_ALIGN_IDS boolean</li>
136 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
137 * <li>PAD_GAPS boolean</li>
138 * <li>ID_ITALICS boolean</li>
139 * <li>SHOW_JV_SUFFIX</li>
140 * <li>WRAP_ALIGNMENT</li>
141 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
143 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
144 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
146 * <li>STORED_LINKS list of name|url pairs which user has entered but are not
148 * <li>DEFAULT_LINK name of single url to be used when user double clicks a
149 * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
150 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
151 * jalview.utils.GroupURLLink for more info</li>
152 * <li>DEFAULT_BROWSER for unix</li>
153 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
155 * <li>VERSION_CHECK (true) check for the latest release version from
156 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
157 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
159 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
161 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
162 * displayed as '.'</li>
163 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
164 * order of a newly displayed tree</li>
165 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
166 * sequence ID strings before attempting retrieval from any datasource</li>
167 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
169 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
170 * in the alignment.</li>
171 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
173 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
175 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
176 * logo normalised to row height rather than histogram height.</li>
177 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
178 * respond to selections made in other alignments containing the same sequences.
180 * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
181 * auto-discover JABAWS services</li>
182 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
183 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
184 * warning dialog box is displayed.</li>
185 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
186 * when shading by annotation</li>
187 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
188 * when shading by annotation</li>
189 * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
190 * requests to be redirected to a mirror of https://www.jalview.org</li>
191 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
192 * alignment figure to accommodate even the longest sequence ID or annotation
194 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
195 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
196 * will override this).</li>
197 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
199 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
200 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
202 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
204 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
206 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
207 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
209 * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
210 * <li>NOHTMLTEMPLATES - when set, the
211 * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
212 * not downloaded automatically</li>
213 * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
214 * available URL linkouts via www.jalview.org/services/identifiers</li>
217 * Deprecated settings:
220 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
221 * startup (JWS1 services only)</li>
222 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
223 * (JWS1 services only)</li>
224 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
225 * services in the desktop GUI</li>
226 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
227 * panel in web service preferences</li>
231 * @version $Revision$
236 * property giving log4j level for CASTOR loggers
238 public static final String CASTORLOGLEVEL = "logs.Castor.level";
241 * property giving log4j level for AXIS loggers
243 public static final String AXISLOGLEVEL = "logs.Axis.level";
246 * property giving log4j level for Jalview Log
248 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
251 public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST";
256 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
257 .getProperty("user.home") + File.separatorChar
258 + ".sifts_downloads" + File.separatorChar;
260 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
262 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
265 * Identifiers.org download settings
267 private static final String ID_ORG_FILE = System.getProperty("user.home")
268 + File.separatorChar + ".identifiers.org.ids.json";
271 * Allowed values are PDB or mmCIF
273 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
276 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
280 * a date formatter using a fixed (rather than the user's) locale;
281 * this ensures that date properties can be written and re-read successfully
282 * even if the user changes their locale setting
284 private static final DateFormat date_format = SimpleDateFormat
285 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
286 SimpleDateFormat.MEDIUM, Locale.UK);
289 * Initialises the Jalview Application Log
292 public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
294 // save the proxy properties set at startup
295 public final static String[] startupProxyProperties = {
296 System.getProperty("http.proxyHost"),
297 System.getProperty("http.proxyPort"),
298 System.getProperty("https.proxyHost"),
299 System.getProperty("https.proxyPort"),
300 System.getProperty("http.proxyUser"),
301 System.getProperty("http.proxyPassword"),
302 System.getProperty("https.proxyUser"),
303 System.getProperty("https.proxyPassword"),
304 System.getProperty("http.nonProxyHosts") };
306 public final static String PROXYTYPE_NONE = "none";
308 // "false" and "true" for backward compatibility
309 public final static String PROXYTYPE_SYSTEM = "false";
311 public final static String PROXYTYPE_CUSTOM = "true";
313 // in-memory only storage of proxy password, safer to use char array
314 public static char[] proxyAuthPassword = null;
317 * Session properties, set by command line, try not to affect stored
320 private static Map<String, String> sessionProperties = new HashMap<>();
322 private static boolean bypassSessionProperties = false;
324 public static void enableSessionProperties()
326 bypassSessionProperties = false;
329 public static void disableSessionProperties()
331 bypassSessionProperties = true;
334 /** Jalview Properties */
335 public static Properties applicationProperties = new Properties()
337 // override results in properties output in alphabetical order
339 public synchronized Enumeration<Object> keys()
341 return Collections.enumeration(new TreeSet<>(super.keySet()));
345 /* build Properties (not all saved to .jalview_properties) */
346 public static Properties buildProperties = new Properties();
348 /** Default file is ~/.jalview_properties */
349 static String propertiesFile;
351 private static final String fallbackPropertiesFile = ".jalview_properties";
353 private static boolean propsAreReadOnly = Platform.isJS();
355 public static boolean isPropsAreReadOnly()
357 return propsAreReadOnly;
360 public static void setPropsAreReadOnly(boolean propsAreReadOnly)
362 Cache.propsAreReadOnly = propsAreReadOnly;
365 private final static String JS_PROPERTY_PREFIX = "jalview_";
368 * Loads properties from the given properties file. Any existing properties
371 public static void loadProperties(String propsFile)
373 propertiesFile = propsFile;
374 String releasePropertiesFile = null;
375 boolean defaultProperties = false;
376 if (propsFile == null && !propsAreReadOnly)
378 String channelPrefsFilename = ChannelProperties
379 .getProperty("preferences.filename");
380 String releasePrefsFilename = fallbackPropertiesFile;
381 propertiesFile = System.getProperty("user.home") + File.separatorChar
382 + channelPrefsFilename;
383 releasePropertiesFile = System.getProperty("user.home")
384 + File.separatorChar + releasePrefsFilename;
385 defaultProperties = true;
389 // don't corrupt the file we've been given.
390 propsAreReadOnly = true;
393 if (propertiesFile == null)
395 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
396 applicationProperties);
405 // props file provided as URL
406 fis = new URL(propertiesFile).openStream();
407 if (!Jalview.quiet())
410 "Loading jalview properties from : " + propertiesFile);
412 "Disabling Jalview writing to user's local properties file.");
414 propsAreReadOnly = true;
415 } catch (Exception ex)
421 String readPropertiesFile = propertiesFile;
422 // if we're using the usual properties file and the channel properties
423 // file doesn't exist, read .jalview_properties
424 // (but we'll still save to the channel properties file).
425 if (defaultProperties && (!new File(propertiesFile).exists())
426 && (new File(releasePropertiesFile).exists()))
428 readPropertiesFile = releasePropertiesFile;
430 fis = new FileInputStream(readPropertiesFile);
432 applicationProperties.clear();
433 applicationProperties.load(fis);
435 // remove any old build properties
437 deleteBuildProperties();
439 } catch (Exception ex)
441 if (!Jalview.quiet())
442 System.out.println("Error reading properties file: " + ex);
446 /* TO BE REPLACED WITH PROXY_TYPE SETTINGS
447 if (getDefault("USE_PROXY", false))
449 String proxyServer = getDefault("PROXY_SERVER", ""),
450 proxyPort = getDefault("PROXY_PORT", "8080");
454 // PROXY TYPE settings (now three options "none", "false", "true", but using
455 // backward compatible strings)
456 String proxyType = getDefault("USE_PROXY", PROXYTYPE_SYSTEM);
457 // default to upgrading old settings
461 clearProxyProperties();
463 case PROXYTYPE_SYSTEM: // use system settings
464 resetProxyProperties();
466 case PROXYTYPE_CUSTOM: // use specified proxy settings
467 String httpHost = getDefault("PROXY_SERVER", "");
468 String httpPort = getDefault("PROXY_PORT", "8080");
469 String httpsHost = getDefault("PROXY_SERVER_HTTPS", httpHost);
470 String httpsPort = getDefault("PROXY_PORT_HTTPS", httpPort);
471 String httpUser = getDefault("PROXY_AUTH_USER", null);
472 // https.proxyUser and https.proxyPassword are not able to be
473 // independently set in Preferences yet (or http.nonProxyHosts)
474 String httpsUser = getDefault("PROXY_AUTH_USER_HTTPS", httpUser);
475 setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
476 proxyAuthPassword, httpsUser, proxyAuthPassword, "localhost");
479 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
481 Console.warn(message);
484 // LOAD THE AUTHORS FROM THE authors.props file
485 String authorDetails = resolveResourceURLFor("/authors.props");
489 if (authorDetails != null)
491 URL localJarFileURL = new URL(authorDetails);
492 InputStream in = localJarFileURL.openStream();
493 applicationProperties.load(in);
496 } catch (Exception ex)
498 if (!Jalview.quiet())
499 System.out.println("Error reading author details: " + ex);
500 authorDetails = null;
502 if (authorDetails == null)
504 applicationProperties.remove("AUTHORS");
505 applicationProperties.remove("AUTHORFNAMES");
506 applicationProperties.remove("YEAR");
509 loadBuildProperties(false);
512 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
514 SiftsSettings.setSiftDownloadDirectory(Cache
515 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
517 SiftsSettings.setFailSafePIDThreshold(
518 Cache.getDefault("sifts_fail_safe_pid_threshold",
519 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
521 SiftsSettings.setCacheThresholdInDays(
522 Cache.getDefault("sifts_cache_threshold_in_days",
523 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
525 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
526 "https://www.jalview.org/services/identifiers"));
527 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
529 StructureImportSettings.setDefaultStructureFileFormat(
530 Cache.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
531 StructureImportSettings
532 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
533 // StructureImportSettings
534 // .setDefaultPDBFileParser(Cache.getDefault(
535 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
537 String jnlpVersion = System.getProperty("jalview.version");
539 // jnlpVersion will be null if a latest version check for the channel needs
541 // Dont do this check if running in headless mode
543 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
544 && (System.getProperty("java.awt.headless") == null || System
545 .getProperty("java.awt.headless").equals("false")))
548 class VersionChecker extends Thread
554 String remoteBuildPropertiesUrl = Cache
555 .getAppbaseBuildProperties();
557 String orgtimeout = System
558 .getProperty("sun.net.client.defaultConnectTimeout");
559 if (orgtimeout == null)
562 Console.debug("Setting default net timeout to " + orgtimeout
565 String remoteVersion = null;
566 if (remoteBuildPropertiesUrl.startsWith("http"))
570 System.setProperty("sun.net.client.defaultConnectTimeout",
573 URL url = new URL(remoteBuildPropertiesUrl);
575 BufferedReader in = new BufferedReader(
576 new InputStreamReader(url.openStream()));
578 Properties remoteBuildProperties = new Properties();
579 remoteBuildProperties.load(in);
580 remoteVersion = remoteBuildProperties.getProperty("VERSION");
581 } catch (Exception ex)
583 if (!Jalview.quiet())
586 "Non-fatal exception when checking version at "
587 + remoteBuildPropertiesUrl + ":");
588 System.out.println(ex);
590 remoteVersion = getProperty("VERSION");
593 System.setProperty("sun.net.client.defaultConnectTimeout",
596 setProperty("LATEST_VERSION", remoteVersion);
600 VersionChecker vc = new VersionChecker();
605 if (jnlpVersion != null)
607 setProperty("LATEST_VERSION", jnlpVersion);
611 applicationProperties.remove("LATEST_VERSION");
615 // LOAD USERDEFINED COLOURS
616 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
617 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
622 * construct a resource URL for the given absolute resource pathname
624 * @param resourcePath
627 private static String resolveResourceURLFor(String resourcePath)
630 if (Platform.isJS() || !Cache.class.getProtectionDomain()
631 .getCodeSource().getLocation().toString().endsWith(".jar"))
635 url = Cache.class.getResource(resourcePath).toString();
636 } catch (Exception ex)
638 System.err.println("Failed to resolve resource " + resourcePath
639 + ": " + ex.getMessage());
644 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
645 .getLocation().toString().concat("!" + resourcePath));
650 public static void loadBuildProperties(boolean reportVersion)
652 String codeInstallation = getProperty("INSTALLATION");
653 boolean printVersion = codeInstallation == null;
656 * read build properties - from the Jalview jar for a Java distribution,
657 * or from codebase file in test or JalviewJS context
661 String buildDetails = resolveResourceURLFor("/.build_properties");
662 URL localJarFileURL = new URL(buildDetails);
663 InputStream in = localJarFileURL.openStream();
664 buildProperties.load(in);
666 if (buildProperties.getProperty("BUILD_DATE", null) != null)
668 applicationProperties.put("BUILD_DATE",
669 buildProperties.getProperty("BUILD_DATE"));
671 if (buildProperties.getProperty("INSTALLATION", null) != null)
673 applicationProperties.put("INSTALLATION",
674 buildProperties.getProperty("INSTALLATION"));
676 if (buildProperties.getProperty("VERSION", null) != null)
678 applicationProperties.put("VERSION",
679 buildProperties.getProperty("VERSION"));
681 if (buildProperties.getProperty("JAVA_COMPILE_VERSION", null) != null)
683 applicationProperties.put("JAVA_COMPILE_VERSION",
684 buildProperties.getProperty("JAVA_COMPILE_VERSION"));
686 } catch (Exception ex)
688 if (!Jalview.quiet())
689 System.out.println("Error reading build details: " + ex);
690 applicationProperties.remove("VERSION");
692 String codeVersion = getProperty("VERSION");
693 codeInstallation = getProperty("INSTALLATION");
695 if (codeVersion == null)
697 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
698 codeVersion = "Test";
699 codeInstallation = "";
703 codeInstallation = " (" + codeInstallation + ")";
705 setProperty("VERSION", codeVersion);
706 new BuildDetails(codeVersion, null, codeInstallation);
707 if (printVersion && reportVersion)
709 System.out.println(ChannelProperties.getProperty("app_name")
710 + " version: " + codeVersion + codeInstallation);
714 private static void deleteBuildProperties()
716 applicationProperties.remove("LATEST_VERSION");
717 applicationProperties.remove("VERSION");
718 applicationProperties.remove("AUTHORS");
719 applicationProperties.remove("AUTHORFNAMES");
720 applicationProperties.remove("YEAR");
721 applicationProperties.remove("BUILD_DATE");
722 applicationProperties.remove("INSTALLATION");
726 * Gets Jalview application property of given key. Returns null if key not
732 * @return Property value
734 public static String getProperty(String key)
736 return getProperty(key, false);
739 public static String getProperty(String key,
740 boolean skipSessionProperties)
743 if (!(skipSessionProperties || bypassSessionProperties))
745 prop = getSessionProperty(key);
749 prop = applicationProperties.getProperty(key);
751 if (prop == null && Platform.isJS())
753 prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
754 + "_" + JS_PROPERTY_PREFIX + key);
760 * These methods are used when checking if the saved preference is different
761 * to the default setting
764 public static boolean getDefault(String property, boolean def)
766 String string = getProperty(property);
769 def = Boolean.valueOf(string).booleanValue();
775 public static int getDefault(String property, int def)
777 String string = getProperty(property);
782 def = Integer.parseInt(string);
783 } catch (NumberFormatException e)
785 if (!Jalview.quiet())
786 System.out.println("Error parsing int property '" + property
787 + "' with value '" + string + "'");
795 * Answers the value of the given property, or the supplied default value if
796 * the property is not set
798 public static String getDefault(String property, String def)
800 String value = getProperty(property);
801 return value == null ? def : value;
805 * Stores property in the file "HOME_DIR/.jalview_properties"
810 * String value of property
812 * @return previous value of property (or null)
814 public static Object setProperty(String key, String obj)
816 Object oldValue = null;
819 oldValue = applicationProperties.setProperty(key, obj);
820 if (propertiesFile != null && !propsAreReadOnly
821 // don't rewrite if new value is same as old value
822 && !((obj == null && oldValue == null)
823 || (obj != null && obj.equals(oldValue))))
825 // reset the session property too
826 if (sessionProperties.containsKey(key))
828 sessionProperties.remove(key);
830 FileOutputStream out = new FileOutputStream(propertiesFile);
831 applicationProperties.store(out, "---JalviewX Properties File---");
834 } catch (Exception ex)
836 if (!Jalview.quiet())
838 "Error setting property: " + key + " " + obj + "\n" + ex);
844 * remove the specified property from the jalview properties file
848 public static void removeProperty(String string)
850 applicationProperties.remove(string);
855 * save the properties to the jalview properties path
857 public static void saveProperties()
859 if (!propsAreReadOnly)
863 FileOutputStream out = new FileOutputStream(propertiesFile);
864 applicationProperties.store(out, "---JalviewX Properties File---");
866 } catch (Exception ex)
868 if (!Jalview.quiet())
869 System.out.println("Error saving properties: " + ex);
875 * internal vamsas class discovery state
877 private static int vamsasJarsArePresent = -1;
880 * Searches for vamsas client classes on class path.
882 * @return true if vamsas client is present on classpath
884 public static boolean vamsasJarsPresent()
886 if (vamsasJarsArePresent == -1)
890 if (jalview.jbgui.GDesktop.class.getClassLoader()
891 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
894 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
895 vamsasJarsArePresent = 1;
896 JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
897 Console.getCachedLogLevel("logs.Vamsas.Level"));
898 JLoggerLog4j.addAppender(lvclient, Console.log,
899 JALVIEW_LOGGER_NAME);
900 // Tell the user that debug is enabled
901 lvclient.debug(ChannelProperties.getProperty("app_name")
902 + " Vamsas Client Debugging Output Follows.");
904 } catch (Exception e)
906 vamsasJarsArePresent = 0;
907 Console.debug("Vamsas Classes are not present");
910 return (vamsasJarsArePresent > 0);
914 * internal vamsas class discovery state
916 private static int groovyJarsArePresent = -1;
919 * Searches for vamsas client classes on class path.
921 * @return true if vamsas client is present on classpath
923 public static boolean groovyJarsPresent()
925 if (groovyJarsArePresent == -1)
929 if (Cache.class.getClassLoader()
930 .loadClass("groovy.lang.GroovyObject") != null)
933 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
934 groovyJarsArePresent = 1;
935 JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
936 Console.getCachedLogLevel("logs.Groovy.Level"));
937 JLoggerLog4j.addAppender(lgclient, Console.log,
938 JALVIEW_LOGGER_NAME);
939 // Tell the user that debug is enabled
940 lgclient.debug(ChannelProperties.getProperty("app_name")
941 + " Groovy Client Debugging Output Follows.");
945 groovyJarsArePresent = 0;
946 Console.debug("Groovy Classes are not present", e);
947 } catch (Exception e)
949 groovyJarsArePresent = 0;
950 Console.debug("Groovy Classes are not present");
953 return (groovyJarsArePresent > 0);
957 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
960 protected static Object tracker = null;
962 protected static Class trackerfocus = null;
964 protected static Class jgoogleanalyticstracker = null;
966 private static boolean useGA4 = true;
969 * Initialise the google tracker if it is not done already.
971 public static void initGoogleTracker()
975 GoogleAnalytics4.setEnabled(true);
977 String appName = ChannelProperties.getProperty("app_name")
979 String version = Cache.getProperty("VERSION") + "_"
980 + Cache.getDefault("BUILD_DATE", "unknown");
982 + String.join("/", appName, version, APPLICATION_STARTED);
983 GoogleAnalytics4 ga4 = GoogleAnalytics4.getInstance();
985 // This will add a page_view similar to the old UA analytics.
986 // We probably want to get rid of this once the application_launch event
987 // is being processed properly.
988 ga4.sendAnalytics("page_view", "page_location", path, "page_title",
989 APPLICATION_STARTED);
991 // This will send a new "application_launch" event with parameters
992 // including the old-style "path", the channel name and version
993 ga4.sendAnalytics("application_launch", "page_location", path);
999 if (jgoogleanalyticstracker == null)
1001 // try to get the tracker class
1004 jgoogleanalyticstracker = Cache.class.getClassLoader()
1006 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
1007 trackerfocus = Cache.class.getClassLoader().loadClass(
1008 "com.boxysystems.jgoogleanalytics.FocusPoint");
1009 } catch (Exception e)
1012 "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
1014 jgoogleanalyticstracker = null;
1015 trackerfocus = null;
1019 // now initialise tracker
1020 Exception re = null, ex = null;
1022 String vrs = "No Version Accessible";
1025 // Google analytics tracking code for Library Finder
1026 tracker = jgoogleanalyticstracker
1027 .getConstructor(new Class[]
1028 { String.class, String.class, String.class })
1029 .newInstance(new Object[]
1030 { ChannelProperties.getProperty("app_name") + " Desktop",
1031 (vrs = Cache.getProperty("VERSION") + "_"
1032 + Cache.getDefault("BUILD_DATE", "unknown")),
1034 jgoogleanalyticstracker
1035 .getMethod("trackAsynchronously", new Class[]
1037 .invoke(tracker, new Object[]
1039 .getConstructor(new Class[]
1041 .newInstance(new Object[]
1042 { APPLICATION_STARTED }) });
1043 } catch (RuntimeException e)
1046 } catch (Exception e)
1053 if (re != null || ex != null || err != null)
1057 Console.debug("Caught runtime exception in googletracker init:",
1063 "Failed to initialise GoogleTracker for Jalview Desktop with version "
1070 "Whilst initing GoogleTracker for Jalview Desktop version "
1077 Console.debug("Successfully initialised tracker.");
1083 private static final String APPLICATION_STARTED = "Application Started.";
1086 * get the user's default colour if available
1092 public static Color getDefaultColour(String property, Color defcolour)
1094 String colprop = getProperty(property);
1095 if (colprop == null)
1099 Color col = ColorUtils.parseColourString(colprop);
1102 Console.warn("Couldn't parse '" + colprop + "' as a colour for "
1105 return (col == null) ? defcolour : col;
1109 * store a colour as a Jalview user default property
1114 public static void setColourProperty(String property, Color colour)
1116 setProperty(property, jalview.util.Format.getHexString(colour));
1120 * Stores a formatted date in a jalview property, using a fixed locale.
1122 * @param propertyName
1124 * @return the formatted date string
1126 public static String setDateProperty(String propertyName, Date date)
1128 String formatted = date_format.format(date);
1129 setProperty(propertyName, formatted);
1134 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1135 * format) and returns as a Date, or null if parsing fails
1137 * @param propertyName
1141 public static Date getDateProperty(String propertyName)
1143 String val = getProperty(propertyName);
1148 return date_format.parse(val);
1149 } catch (Exception ex)
1151 System.err.println("Invalid or corrupt date in property '"
1152 + propertyName + "' : value was '" + val + "'");
1159 * get and parse a property as an integer. send any parsing problems to
1163 * @return null or Integer
1165 public static Integer getIntegerProperty(String property)
1167 String val = getProperty(property);
1168 if (val != null && (val = val.trim()).length() > 0)
1172 return Integer.valueOf(val);
1173 } catch (NumberFormatException x)
1175 System.err.println("Invalid integer in property '" + property
1176 + "' (value was '" + val + "')");
1183 * Set the specified value, or remove it if null or empty. Does not save the
1189 public static void setOrRemove(String propName, String value)
1191 if (propName == null)
1195 if (value == null || value.trim().length() < 1)
1197 Cache.applicationProperties.remove(propName);
1201 Cache.applicationProperties.setProperty(propName, value);
1206 * Loads in user colour schemes from files.
1209 * a '|'-delimited list of file paths
1211 public static void initUserColourSchemes(String files)
1213 if (files == null || files.length() == 0)
1218 // In case colours can't be loaded, we'll remove them
1219 // from the default list here.
1220 StringBuffer coloursFound = new StringBuffer();
1221 StringTokenizer st = new StringTokenizer(files, "|");
1222 while (st.hasMoreElements())
1224 String file = st.nextToken();
1227 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1230 if (coloursFound.length() > 0)
1232 coloursFound.append("|");
1234 coloursFound.append(file);
1235 ColourSchemes.getInstance().registerColourScheme(ucs);
1237 } catch (Exception ex)
1239 if (!Jalview.quiet())
1240 System.out.println("Error loading User ColourFile\n" + ex);
1243 if (!files.equals(coloursFound.toString()))
1245 if (coloursFound.toString().length() > 1)
1247 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1248 coloursFound.toString());
1252 applicationProperties
1253 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1259 * Initial logging information helper for various versions output
1263 * @param defaultValue
1265 private static void appendIfNotNull(StringBuilder sb, String prefix,
1266 String value, String suffix, String defaultValue)
1268 if (value == null && defaultValue == null)
1274 sb.append(value == null ? defaultValue : value);
1281 * @return Jalview version, build details and JVM platform version for console
1283 public static String getVersionDetailsForConsole()
1285 StringBuilder sb = new StringBuilder();
1286 sb.append(ChannelProperties.getProperty("app_name"))
1287 .append(" Version: ");
1288 sb.append(Cache.getDefault("VERSION", "TEST"));
1290 sb.append(ChannelProperties.getProperty("app_name"))
1291 .append(" Installation: ");
1292 sb.append(Cache.getDefault("INSTALLATION", "unknown"));
1294 sb.append("Build Date: ");
1295 sb.append(Cache.getDefault("BUILD_DATE", "unknown"));
1297 sb.append("Java version: ");
1298 sb.append(System.getProperty("java.version"));
1300 sb.append("Java platform: ");
1301 sb.append(System.getProperty("os.arch"));
1303 sb.append(System.getProperty("os.name"));
1305 sb.append(System.getProperty("os.version"));
1307 appendIfNotNull(sb, "Install4j version: ",
1308 System.getProperty("sys.install4jVersion"), "\n", null);
1309 appendIfNotNull(sb, "Install4j template version: ",
1310 System.getProperty("installer_template_version"), "\n", null);
1311 appendIfNotNull(sb, "Launcher version: ",
1312 System.getProperty("launcher_version"), "\n", null);
1313 LookAndFeel laf = UIManager.getLookAndFeel();
1314 String lafName = laf == null ? "Not obtained" : laf.getName();
1315 String lafClass = laf == null ? "unknown" : laf.getClass().getName();
1316 sb.append("LookAndFeel: ");
1319 sb.append(lafClass);
1321 appendIfNotNull(sb, "Channel: ",
1322 ChannelProperties.getProperty("channel"), "\n", null);
1323 if (Console.isDebugEnabled()
1324 || !"release".equals(ChannelProperties.getProperty("channel")))
1326 appendIfNotNull(sb, "Getdown appdir: ",
1327 System.getProperty("getdowninstanceappdir"), "\n", null);
1328 appendIfNotNull(sb, "Getdown appbase: ",
1329 System.getProperty("getdowninstanceappbase"), "\n", null);
1330 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1332 appendIfNotNull(sb, "Preferences file: ", propertiesFile, "\n",
1335 return sb.toString();
1340 * @return build details as reported in splashscreen
1342 public static String getBuildDetailsForSplash()
1344 // consider returning more human friendly info
1345 // eg 'built from Source' or update channel
1346 return Cache.getDefault("INSTALLATION", "unknown");
1349 public static String getStackTraceString(Throwable t)
1351 StringWriter sw = new StringWriter();
1352 PrintWriter pw = new PrintWriter(sw);
1353 t.printStackTrace(pw);
1354 return sw.toString();
1357 // proxy properties methods
1358 public static void clearProxyProperties()
1360 setProxyProperties(null, null, null, null, null, null, null, null,
1364 public static void resetProxyProperties()
1366 setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
1367 startupProxyProperties[2], startupProxyProperties[3],
1368 startupProxyProperties[4],
1369 startupProxyProperties[5] == null ? null
1370 : startupProxyProperties[5].toCharArray(),
1371 startupProxyProperties[6],
1372 startupProxyProperties[7] == null ? null
1373 : startupProxyProperties[7].toCharArray(),
1374 startupProxyProperties[8]);
1375 StringBuilder sb = new StringBuilder();
1376 sb.append("Setting proxy properties to: http.proxyHost=")
1377 .append(startupProxyProperties[0]).append(", http.proxyPort=")
1378 .append(startupProxyProperties[1])
1379 .append(startupProxyProperties[4] != null
1380 && !startupProxyProperties[4].isEmpty()
1381 ? " [" + startupProxyProperties[4] + "]"
1383 .append(", https.proxyHost=").append(startupProxyProperties[2])
1384 .append(", https.proxyPort=").append(startupProxyProperties[3])
1385 .append(startupProxyProperties[6] != null
1386 && !startupProxyProperties[6].isEmpty()
1387 ? " [" + startupProxyProperties[6] + "]"
1390 Console.debug(sb.toString());
1393 public static void setProxyPropertiesFromPreferences()
1395 setProxyPropertiesFromPreferences(Cache.PROXYTYPE_SYSTEM);
1398 public static void setProxyPropertiesFromPreferences(
1399 String previousProxyType)
1401 String proxyType = Cache.getDefault("USE_PROXY",
1402 Cache.PROXYTYPE_SYSTEM);
1403 if (previousProxyType != null
1404 && !proxyType.equals(Cache.PROXYTYPE_CUSTOM) // always apply
1406 && proxyType.equals(previousProxyType))
1413 case Cache.PROXYTYPE_NONE:
1414 if (!previousProxyType.equals(proxyType))
1416 Console.info("Setting no proxy settings");
1417 Cache.setProxyProperties(null, null, null, null, null, null, null,
1421 case Cache.PROXYTYPE_CUSTOM:
1422 // always re-set a custom proxy -- it might have changed, particularly
1424 Console.info("Setting custom proxy settings");
1425 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
1426 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
1427 Cache.getDefault("PROXY_PORT", null),
1428 Cache.getDefault("PROXY_SERVER_HTTPS", null),
1429 Cache.getDefault("PROXY_PORT_HTTPS", null),
1430 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1432 proxyAuthSet ? Cache.proxyAuthPassword : null,
1433 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1435 proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
1437 default: // system proxy settings by default
1438 Console.info("Setting system proxy settings");
1439 Cache.resetProxyProperties();
1443 public static void setProxyProperties(String httpHost, String httpPort,
1444 String httpsHost, String httpsPort, String httpUser,
1445 char[] httpPassword, String httpsUser, char[] httpsPassword,
1446 String nonProxyHosts)
1448 setOrClearSystemProperty("http.proxyHost", httpHost);
1449 setOrClearSystemProperty("http.proxyPort", httpPort);
1450 setOrClearSystemProperty("https.proxyHost", httpsHost);
1451 setOrClearSystemProperty("https.proxyPort", httpsPort);
1452 setOrClearSystemProperty("http.proxyUser", httpUser);
1453 setOrClearSystemProperty("https.proxyUser", httpsUser);
1454 // note: passwords for http.proxyPassword and https.proxyPassword are sent
1455 // via the Authenticator, properties do not need to be set
1457 // are we using a custom proxy (password prompt might be required)?
1458 boolean customProxySet = getDefault("USE_PROXY", PROXYTYPE_SYSTEM)
1459 .equals(PROXYTYPE_CUSTOM);
1462 * A bug in Java means the AuthCache does not get reset, so once it has working credentials,
1463 * it never asks for more, so changing the Authenticator has no effect (as getPasswordAuthentication()
1464 * is not re-called).
1465 * This could lead to password leak to a hostile proxy server, so I'm putting in a hack to clear
1467 * see https://www.generacodice.com/en/articolo/154918/Reset-the-Authenticator-credentials
1469 * Turns out this is only accessible in Java 8, and not in Java 9 onwards, so commenting out
1474 sun.net.www.protocol.http.AuthCacheValue
1475 .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl());
1476 } catch (Throwable t)
1478 Cache.error(t.getMessage());
1479 Cache.debug(getStackTraceString(t));
1483 if (httpUser != null || httpsUser != null)
1487 char[] displayHttpPw = new char[httpPassword == null ? 0
1488 : httpPassword.length];
1489 Arrays.fill(displayHttpPw, '*');
1491 "CACHE Proxy: setting new Authenticator with httpUser='"
1492 + httpUser + "' httpPassword='" + displayHttpPw
1494 if (!Platform.isJS())
1496 * java.net.Authenticator not implemented in SwingJS yet
1502 Authenticator.setDefault(new Authenticator()
1505 protected PasswordAuthentication getPasswordAuthentication()
1507 if (getRequestorType() == RequestorType.PROXY)
1509 String protocol = getRequestingProtocol();
1510 boolean needProxyPasswordSet = false;
1511 if (customProxySet &&
1512 // we have a username but no password for the scheme being
1514 (protocol.equalsIgnoreCase("http")
1515 && (httpUser != null
1516 && httpUser.length() > 0
1517 && (httpPassword == null
1518 || httpPassword.length == 0)))
1519 || (protocol.equalsIgnoreCase("https")
1520 && (httpsUser != null
1521 && httpsUser.length() > 0
1522 && (httpsPassword == null
1523 || httpsPassword.length == 0))))
1525 // open Preferences -> Connections
1526 String message = MessageManager
1527 .getString("label.proxy_password_required");
1528 Preferences.openPreferences(
1529 Preferences.TabRef.CONNECTIONS_TAB, message);
1530 Preferences.getInstance()
1531 .proxyAuthPasswordCheckHighlight(true, true);
1537 if (protocol.equalsIgnoreCase("http")
1538 && getRequestingHost()
1539 .equalsIgnoreCase(httpHost)
1540 && getRequestingPort() == Integer
1544 "AUTHENTICATOR returning PasswordAuthentication(\""
1545 + httpUser + "\", '"
1546 + new String(displayHttpPw) + "')");
1547 return new PasswordAuthentication(httpUser,
1550 if (protocol.equalsIgnoreCase("https")
1551 && getRequestingHost()
1552 .equalsIgnoreCase(httpsHost)
1553 && getRequestingPort() == Integer
1554 .valueOf(httpsPort))
1556 char[] displayHttpsPw = new char[httpPassword.length];
1557 Arrays.fill(displayHttpsPw, '*');
1559 "AUTHENTICATOR returning PasswordAuthentication(\""
1560 + httpsUser + "\", '" + displayHttpsPw
1562 return new PasswordAuthentication(httpsUser,
1565 } catch (NumberFormatException e)
1567 Console.error("Problem with proxy port values [http:"
1568 + httpPort + ", https:" + httpsPort + "]");
1571 "AUTHENTICATOR after trying to get PasswordAuthentication");
1574 // non proxy request
1575 Console.debug("AUTHENTICATOR returning null");
1579 } // end of j2sIgnore for java.net.Authenticator
1581 // required to re-enable basic authentication (should be okay for a
1584 "AUTHENTICATOR setting property 'jdk.http.auth.tunneling.disabledSchemes' to \"\"");
1585 System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
1586 } catch (SecurityException e)
1588 Console.error("Could not set default Authenticator");
1589 Console.debug(getStackTraceString(e));
1594 // reset the Authenticator to protect http.proxyUser and
1595 // http.proxyPassword Just In Case
1596 /* as noted above, due to bug in java this doesn't work if the sun.net.www.protocol.http.AuthCache
1597 * has working credentials. No workaround for Java 11.
1599 if (!Platform.isJS())
1601 * java.net.Authenticator not implemented in SwingJS yet
1608 "AUTHENTICATOR setting default Authenticator to null");
1609 Authenticator.setDefault(null);
1613 // nonProxyHosts not currently configurable in Preferences
1615 "AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
1616 + nonProxyHosts + "\"");
1617 setOrClearSystemProperty("http.nonProxyHosts", nonProxyHosts);
1620 public static void setOrClearSystemProperty(String key, char[] value)
1622 setOrClearSystemProperty(key,
1623 (value == null) ? null : new String(value));
1626 public static void setOrClearSystemProperty(String key, String value)
1634 System.clearProperty(key);
1638 System.setProperty(key, value);
1643 * Getdown appbase methods
1646 private static final String releaseAppbase;
1648 private static String getdownAppbase;
1650 private static String getdownDistDir;
1654 if (!Platform.isJS())
1656 Float specversion = Float
1657 .parseFloat(System.getProperty("java.specification.version"));
1658 releaseAppbase = (specversion < 9)
1659 ? "https://www.jalview.org/getdown/release/1.8"
1660 : "https://www.jalview.org/getdown/release/11";
1664 // this value currenly made up, can be changed to URL that will be
1665 // "https://www.jalview.org/jalview-js/swingjs/j2s/build_properties"
1666 releaseAppbase = "https://www.jalview.org/jalview-js";
1667 getdownAppbase = releaseAppbase;
1668 getdownDistDir = "/swingjs/j2s";
1672 // look for properties (passed in by getdown) otherwise default to release
1673 private static void setGetdownAppbase()
1675 if (getdownAppbase != null)
1679 String appbase = System.getProperty("getdownappbase");
1680 String distDir = System.getProperty("getdowndistdir");
1681 if (appbase == null)
1683 appbase = buildProperties.getProperty("GETDOWNAPPBASE");
1684 distDir = buildProperties.getProperty("GETDOWNAPPDISTDIR");
1686 if (appbase == null)
1688 appbase = releaseAppbase;
1689 distDir = "release";
1691 if (appbase.endsWith("/"))
1693 appbase = appbase.substring(0, appbase.length() - 1);
1695 if (distDir == null)
1697 distDir = appbase.equals(releaseAppbase) ? "release" : "alt";
1699 getdownAppbase = appbase;
1700 getdownDistDir = distDir;
1703 public static String getGetdownAppbase()
1705 setGetdownAppbase();
1706 return getdownAppbase;
1709 public static String getAppbaseBuildProperties()
1711 String appbase = getGetdownAppbase();
1712 return appbase + "/" + getdownDistDir + "/build_properties";
1715 private static final Collection<String> bootstrapProperties = new ArrayList<>(
1716 Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST));
1718 public static Properties bootstrapProperties(String filename)
1720 Properties bootstrapProps = new Properties();
1722 if (filename != null)
1724 file = new File(filename);
1726 if (file == null || !file.exists())
1728 String channelPrefsFilename = ChannelProperties
1729 .getProperty("preferences.filename");
1730 String propertiesFilename = System.getProperty("user.home")
1731 + File.separatorChar + channelPrefsFilename;
1732 file = new File(propertiesFilename);
1734 if (file == null || !file.exists())
1736 String releasePrefsFilename = fallbackPropertiesFile;
1737 String releasePropertiesFilename = System.getProperty("user.home")
1738 + File.separatorChar + releasePrefsFilename;
1739 file = new File(releasePropertiesFilename);
1742 if (filename == null)
1746 System.err.println("Could not load bootstrap preferences file '"
1753 FileInputStream in = new FileInputStream(file.getAbsoluteFile());
1754 Properties props = new Properties();
1756 for (String prop : bootstrapProperties)
1758 if (props.containsKey(prop))
1759 bootstrapProps.put(prop, props.getProperty(prop));
1761 } catch (FileNotFoundException e)
1763 System.err.println("Could not find bootstrap preferences file '"
1764 + file.getAbsolutePath() + "'");
1765 } catch (IOException e)
1768 "IOException when loading bootstrap preferences file '"
1769 + file.getAbsolutePath() + "'");
1771 return bootstrapProps;
1774 public static void setSessionProperty(String key, String val)
1778 sessionProperties.put(key, val);
1782 public static String getSessionProperty(String key)
1784 return key == null ? null : sessionProperties.get(key);