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.datamodel.PDBEntry;
56 import jalview.gui.Preferences;
57 import jalview.gui.UserDefinedColours;
58 import jalview.log.JLoggerLog4j;
59 import jalview.schemes.ColourSchemeLoader;
60 import jalview.schemes.ColourSchemes;
61 import jalview.schemes.UserColourScheme;
62 import jalview.structure.StructureImportSettings;
63 import jalview.urls.IdOrgSettings;
64 import jalview.util.ChannelProperties;
65 import jalview.util.ColorUtils;
66 import jalview.util.MessageManager;
67 import jalview.util.Platform;
68 import jalview.ws.sifts.SiftsSettings;
71 * Stores and retrieves Jalview Application Properties Lists and fields within
72 * list entries are separated by '|' symbols unless otherwise stated (|) clauses
73 * are alternative values for a tag. <br>
75 * Current properties include:
78 * logs.Axis.Level - one of the stringified Levels for log4j controlling the
79 * logging level for axis (used for web services) <br>
81 * <li>logs.Castor.Level - one of the stringified Levels for log4j controlling
82 * the logging level for castor (used for serialization) <br>
84 * <li>logs.Jalview.Level - Cache.log stringified level. <br>
86 * <li>SCREEN_WIDTH</li>
87 * <li>SCREEN_HEIGHT</li>
88 * <li>SCREEN_Y=285</li>
89 * <li>SCREEN_X=371</li>
90 * <li>SHOW_FULLSCREEN boolean</li>
91 * <li>FONT_NAME java font name for alignment text display</li>
92 * <li>FONT_SIZE size of displayed alignment text</li>
93 * <li>FONT_STYLE style of font displayed (sequence labels are always
95 * <li>GAP_SYMBOL character to treat as gap symbol (usually -,.,' ')</li>
96 * <li>LAST_DIRECTORY last directory for browsing alignment</li>
97 * <li>USER_DEFINED_COLOURS list of user defined colour scheme files</li>
98 * <li>SHOW_FULL_ID show id with '/start-end' numbers appended</li>
99 * <li>SHOW_IDENTITY show percentage identity annotation</li>
100 * <li>SHOW_QUALITY show alignment quality annotation</li>
101 * <li>SHOW_ANNOTATIONS show alignment annotation rows</li>
102 * <li>SHOW_CONSERVATION show alignment conservation annotation</li>
103 * <li>SORT_ANNOTATIONS currently either SEQUENCE_AND_LABEL or
104 * LABEL_AND_SEQUENCE</li>
105 * <li>SHOW_AUTOCALC_ABOVE true to show autocalculated annotations above
106 * sequence annotations</li>
107 * <li>CENTRE_COLUMN_LABELS centre the labels at each column in a displayed
108 * annotation row</li>
109 * <li>DEFAULT_COLOUR default colour scheme to apply for a new alignment</li>
110 * <li>DEFAULT_FILE_FORMAT file format used to save</li>
111 * <li>STARTUP_FILE file loaded on startup (may be a fully qualified url)</li>
112 * <li>SHOW_STARTUP_FILE flag to control loading of startup file</li>
113 * <li>VERSION the version of the jalview build</li>
114 * <li>BUILD_DATE date of this build</li>
115 * <li>LATEST_VERSION the latest jalview version advertised on the
116 * www.jalview.org</li>
117 * <li>PIR_MODELLER boolean indicating if PIR files are written with MODELLER
119 * <li>(FASTA,MSF,PILEUP,CLUSTAL,BLC,PIR,PFAM)_JVSUFFIX boolean for adding jv
120 * suffix to file</li>
121 * <li>RECENT_URL list of recently retrieved URLs</li>
122 * <li>RECENT_FILE list of recently opened files</li>
123 * <li>USE_PROXY flag for whether a http proxy is to be used</li>
124 * <li>PROXY_SERVER the proxy</li>
125 * <li>PROXY_PORT</li>
126 * <li>NOQUESTIONNAIRES true to prevent jalview from checking the questionnaire
128 * <li>QUESTIONNAIRE last questionnaire:responder id string from questionnaire
130 * <li>USAGESTATS (false - user prompted) Enable google analytics tracker for
131 * collecting usage statistics</li>
132 * <li>SHOW_OVERVIEW boolean for overview window display</li>
133 * <li>ANTI_ALIAS boolean for smooth fonts</li>
134 * <li>RIGHT_ALIGN_IDS boolean</li>
135 * <li>AUTO_CALC_CONSENSUS boolean for automatic recalculation of consensus</li>
136 * <li>PAD_GAPS boolean</li>
137 * <li>ID_ITALICS boolean</li>
138 * <li>SHOW_JV_SUFFIX</li>
139 * <li>WRAP_ALIGNMENT</li>
140 * <li>EPS_RENDERING (Prompt each time|Lineart|Text) default for EPS rendering
142 * <li>SORT_ALIGNMENT (No sort|Id|Pairwise Identity)</li>
143 * <li>SEQUENCE_LINKS list of name|URL pairs for opening a url with
145 * <li>STORED_LINKS list of name|url pairs which user has entered but are not
147 * <li>DEFAULT_LINK name of single url to be used when user double clicks a
148 * sequence id (must be in SEQUENCE_LINKS or STORED_LINKS)
149 * <li>GROUP_LINKS list of name|URL[|<separator>] tuples - see
150 * jalview.utils.GroupURLLink for more info</li>
151 * <li>DEFAULT_BROWSER for unix</li>
152 * <li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop
154 * <li>VERSION_CHECK (true) check for the latest release version from
155 * www.jalview.org (or the alias given by the www.jalview.org property)</li>
156 * <li>SHOW_NPFEATS_TOOLTIP (true) show non-positional features in the Sequence
158 * <li>SHOW_DBREFS_TOOLTIP (true) show Database Cross References in the Sequence
160 * <li>SHOW_UNCONSERVED (false) only render unconserved residues - conserved
161 * displayed as '.'</li>
162 * <li>SORT_BY_TREE (false) sort the current alignment view according to the
163 * order of a newly displayed tree</li>
164 * <li>DBFETCH_USEPICR (false) use PICR to recover valid DB references from
165 * sequence ID strings before attempting retrieval from any datasource</li>
166 * <li>SHOW_GROUP_CONSENSUS (false) Show consensus annotation for groups in the
168 * <li>SHOW_GROUP_CONSERVATION (false) Show conservation annotation for groups
169 * in the alignment.</li>
170 * <li>SHOW_CONSENSUS_HISTOGRAM (false) Show consensus annotation row's
172 * <li>SHOW_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
174 * <li>NORMALISE_CONSENSUS_LOGO (false) Show consensus annotation row's sequence
175 * logo normalised to row height rather than histogram height.</li>
176 * <li>FOLLOW_SELECTIONS (true) Controls whether a new alignment view should
177 * respond to selections made in other alignments containing the same sequences.
179 * <li>SHOW_JWS2_SERVICES (true) when set to false, jalview will not
180 * auto-discover JABAWS services</li>
181 * <li>JWS2HOSTURLS comma-separated list of URLs to try for JABAWS services</li>
182 * <li>SHOW_WSDISCOVERY_ERRORS (true) Controls if the web service URL discovery
183 * warning dialog box is displayed.</li>
184 * <li>ANNOTATIONCOLOUR_MIN (orange) Shade used for minimum value of annotation
185 * when shading by annotation</li>
186 * <li>ANNOTATIONCOLOUR_MAX (red) Shade used for maximum value of annotation
187 * when shading by annotation</li>
188 * <li>www.jalview.org (https://www.jalview.org) a property enabling all HTTP
189 * requests to be redirected to a mirror of https://www.jalview.org</li>
190 * <li>FIGURE_AUTOIDWIDTH (false) Expand the left hand column of an exported
191 * alignment figure to accommodate even the longest sequence ID or annotation
193 * <li>FIGURE_FIXEDIDWIDTH Specifies the width to use for the left-hand column
194 * when exporting an alignment as a figure (setting FIGURE_AUTOIDWIDTH to true
195 * will override this).</li>
196 * <li>STRUCT_FROM_PDB (false) derive secondary structure annotation from PDB
198 * <li>USE_RNAVIEW (false) use RNAViewer to derive secondary structure</li>
199 * <li>ADD_SS_ANN (false) add secondary structure annotation to alignment
201 * <li>ADD_TEMPFACT_ANN (false) add Temperature Factor annotation to alignment
203 * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
205 * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
206 * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
208 * <li>NONEWS - when set disables Jalview News from automatically appearing</li>
209 * <li>NOHTMLTEMPLATES - when set, the
210 * https://github.com/jalview/exporter-templates/tree/master/biojs repository is
211 * not downloaded automatically</li>
212 * <li>NOIDENTIFIERSSERVICE - when set, jalview won't automatically download
213 * available URL linkouts via www.jalview.org/services/identifiers</li>
216 * Deprecated settings:
219 * <li>DISCOVERY_START - Boolean - controls if discovery services are queried on
220 * startup (JWS1 services only)</li>
221 * <li>DISCOVERY_URLS - comma separated list of Discovery Service endpoints.
222 * (JWS1 services only)</li>
223 * <li>SHOW_JWS1_SERVICES (true) enable or disable the original Jalview 2
224 * services in the desktop GUI</li>
225 * <li>ENABLE_RSBS_EDITOR (false for 2.7 release) enable or disable RSBS editing
226 * panel in web service preferences</li>
230 * @version $Revision$
235 * property giving log4j level for CASTOR loggers
237 public static final String CASTORLOGLEVEL = "logs.Castor.level";
240 * property giving log4j level for AXIS loggers
242 public static final String AXISLOGLEVEL = "logs.Axis.level";
245 * property giving log4j level for Jalview Log
247 public static final String JALVIEWLOGLEVEL = "logs.Jalview.level";
250 public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST";
255 public static final String DEFAULT_SIFTS_DOWNLOAD_DIR = System
256 .getProperty("user.home") + File.separatorChar
257 + ".sifts_downloads" + File.separatorChar;
259 private final static String DEFAULT_CACHE_THRESHOLD_IN_DAYS = "2";
261 private final static String DEFAULT_FAIL_SAFE_PID_THRESHOLD = "30";
264 * Identifiers.org download settings
266 private static final String ID_ORG_FILE = System.getProperty("user.home")
267 + File.separatorChar + ".identifiers.org.ids.json";
270 * Allowed values are PDB or mmCIF
272 private final static String PDB_DOWNLOAD_FORMAT = PDBEntry.Type.MMCIF
275 private final static String DEFAULT_PDB_FILE_PARSER = StructureImportSettings.StructureParser.JMOL_PARSER
279 * a date formatter using a fixed (rather than the user's) locale;
280 * this ensures that date properties can be written and re-read successfully
281 * even if the user changes their locale setting
283 private static final DateFormat date_format = SimpleDateFormat
284 .getDateTimeInstance(SimpleDateFormat.MEDIUM,
285 SimpleDateFormat.MEDIUM, Locale.UK);
288 * Initialises the Jalview Application Log
291 public final static String JALVIEW_LOGGER_NAME = "JalviewLogger";
293 // save the proxy properties set at startup
294 public final static String[] startupProxyProperties = {
295 System.getProperty("http.proxyHost"),
296 System.getProperty("http.proxyPort"),
297 System.getProperty("https.proxyHost"),
298 System.getProperty("https.proxyPort"),
299 System.getProperty("http.proxyUser"),
300 System.getProperty("http.proxyPassword"),
301 System.getProperty("https.proxyUser"),
302 System.getProperty("https.proxyPassword"),
303 System.getProperty("http.nonProxyHosts") };
305 public final static String PROXYTYPE_NONE = "none";
307 // "false" and "true" for backward compatibility
308 public final static String PROXYTYPE_SYSTEM = "false";
310 public final static String PROXYTYPE_CUSTOM = "true";
312 // in-memory only storage of proxy password, safer to use char array
313 public static char[] proxyAuthPassword = null;
316 * Session properties, set by command line, try not to affect stored
319 private static Map<String, String> sessionProperties = new HashMap<>();
321 private static boolean bypassSessionProperties = false;
323 public static void enableSessionProperties()
325 bypassSessionProperties = false;
328 public static void disableSessionProperties()
330 bypassSessionProperties = true;
333 /** Jalview Properties */
334 public static Properties applicationProperties = new Properties()
336 // override results in properties output in alphabetical order
338 public synchronized Enumeration<Object> keys()
340 return Collections.enumeration(new TreeSet<>(super.keySet()));
344 /* build Properties (not all saved to .jalview_properties) */
345 public static Properties buildProperties = new Properties();
347 /** Default file is ~/.jalview_properties */
348 static String propertiesFile;
350 private static final String fallbackPropertiesFile = ".jalview_properties";
352 private static boolean propsAreReadOnly = Platform.isJS();
354 public static boolean isPropsAreReadOnly()
356 return propsAreReadOnly;
359 public static void setPropsAreReadOnly(boolean propsAreReadOnly)
361 Cache.propsAreReadOnly = propsAreReadOnly;
364 private final static String JS_PROPERTY_PREFIX = "jalview_";
367 * Loads properties from the given properties file. Any existing properties
370 public static void loadProperties(String propsFile)
372 propertiesFile = propsFile;
373 String releasePropertiesFile = null;
374 boolean defaultProperties = false;
375 if (propsFile == null && !propsAreReadOnly)
377 String channelPrefsFilename = ChannelProperties
378 .getProperty("preferences.filename");
379 String releasePrefsFilename = fallbackPropertiesFile;
380 propertiesFile = System.getProperty("user.home") + File.separatorChar
381 + channelPrefsFilename;
382 releasePropertiesFile = System.getProperty("user.home")
383 + File.separatorChar + releasePrefsFilename;
384 defaultProperties = true;
388 // don't corrupt the file we've been given.
389 propsAreReadOnly = true;
392 if (propertiesFile == null)
394 Platform.readInfoProperties(JS_PROPERTY_PREFIX,
395 applicationProperties);
404 // props file provided as URL
405 fis = new URL(propertiesFile).openStream();
406 if (!Jalview.quiet())
409 "Loading jalview properties from : " + propertiesFile);
411 "Disabling Jalview writing to user's local properties file.");
413 propsAreReadOnly = true;
414 } catch (Exception ex)
420 String readPropertiesFile = propertiesFile;
421 // if we're using the usual properties file and the channel properties
422 // file doesn't exist, read .jalview_properties
423 // (but we'll still save to the channel properties file).
424 if (defaultProperties && (!new File(propertiesFile).exists())
425 && (new File(releasePropertiesFile).exists()))
427 readPropertiesFile = releasePropertiesFile;
429 fis = new FileInputStream(readPropertiesFile);
431 applicationProperties.clear();
432 applicationProperties.load(fis);
434 // remove any old build properties
436 deleteBuildProperties();
438 } catch (Exception ex)
440 if (!Jalview.quiet())
441 System.out.println("Error reading properties file: " + ex);
445 /* TO BE REPLACED WITH PROXY_TYPE SETTINGS
446 if (getDefault("USE_PROXY", false))
448 String proxyServer = getDefault("PROXY_SERVER", ""),
449 proxyPort = getDefault("PROXY_PORT", "8080");
453 // PROXY TYPE settings (now three options "none", "false", "true", but using
454 // backward compatible strings)
455 String proxyType = getDefault("USE_PROXY", PROXYTYPE_SYSTEM);
456 // default to upgrading old settings
460 clearProxyProperties();
462 case PROXYTYPE_SYSTEM: // use system settings
463 resetProxyProperties();
465 case PROXYTYPE_CUSTOM: // use specified proxy settings
466 String httpHost = getDefault("PROXY_SERVER", "");
467 String httpPort = getDefault("PROXY_PORT", "8080");
468 String httpsHost = getDefault("PROXY_SERVER_HTTPS", httpHost);
469 String httpsPort = getDefault("PROXY_PORT_HTTPS", httpPort);
470 String httpUser = getDefault("PROXY_AUTH_USER", null);
471 // https.proxyUser and https.proxyPassword are not able to be
472 // independently set in Preferences yet (or http.nonProxyHosts)
473 String httpsUser = getDefault("PROXY_AUTH_USER_HTTPS", httpUser);
474 setProxyProperties(httpHost, httpPort, httpsHost, httpsPort, httpUser,
475 proxyAuthPassword, httpsUser, proxyAuthPassword, "localhost");
478 String message = "Incorrect PROXY_TYPE - should be 'none' (clear proxy properties), 'false' (system settings), 'true' (custom settings): "
480 Console.warn(message);
483 // LOAD THE AUTHORS FROM THE authors.props file
484 String authorDetails = resolveResourceURLFor("/authors.props");
488 if (authorDetails != null)
490 URL localJarFileURL = new URL(authorDetails);
491 InputStream in = localJarFileURL.openStream();
492 applicationProperties.load(in);
495 } catch (Exception ex)
497 if (!Jalview.quiet())
498 System.out.println("Error reading author details: " + ex);
499 authorDetails = null;
501 if (authorDetails == null)
503 applicationProperties.remove("AUTHORS");
504 applicationProperties.remove("AUTHORFNAMES");
505 applicationProperties.remove("YEAR");
508 loadBuildProperties(false);
511 .setMapWithSifts(Cache.getDefault("MAP_WITH_SIFTS", false));
513 SiftsSettings.setSiftDownloadDirectory(Cache
514 .getDefault("sifts_download_dir", DEFAULT_SIFTS_DOWNLOAD_DIR));
516 SiftsSettings.setFailSafePIDThreshold(
517 Cache.getDefault("sifts_fail_safe_pid_threshold",
518 DEFAULT_FAIL_SAFE_PID_THRESHOLD));
520 SiftsSettings.setCacheThresholdInDays(
521 Cache.getDefault("sifts_cache_threshold_in_days",
522 DEFAULT_CACHE_THRESHOLD_IN_DAYS));
524 IdOrgSettings.setUrl(getDefault("ID_ORG_HOSTURL",
525 "https://www.jalview.org/services/identifiers"));
526 IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
528 StructureImportSettings.setDefaultStructureFileFormat(
529 Cache.getDefault("PDB_DOWNLOAD_FORMAT", PDB_DOWNLOAD_FORMAT));
530 StructureImportSettings
531 .setDefaultPDBFileParser(DEFAULT_PDB_FILE_PARSER);
532 // StructureImportSettings
533 // .setDefaultPDBFileParser(Cache.getDefault(
534 // "DEFAULT_PDB_FILE_PARSER", DEFAULT_PDB_FILE_PARSER));
536 String jnlpVersion = System.getProperty("jalview.version");
538 // jnlpVersion will be null if a latest version check for the channel needs
540 // Dont do this check if running in headless mode
542 if (jnlpVersion == null && getDefault("VERSION_CHECK", true)
543 && (System.getProperty("java.awt.headless") == null || System
544 .getProperty("java.awt.headless").equals("false")))
547 class VersionChecker extends Thread
553 String remoteBuildPropertiesUrl = Cache
554 .getAppbaseBuildProperties();
556 String orgtimeout = System
557 .getProperty("sun.net.client.defaultConnectTimeout");
558 if (orgtimeout == null)
561 Console.debug("Setting default net timeout to " + orgtimeout
564 String remoteVersion = null;
565 if (remoteBuildPropertiesUrl.startsWith("http"))
569 System.setProperty("sun.net.client.defaultConnectTimeout",
572 URL url = new URL(remoteBuildPropertiesUrl);
574 BufferedReader in = new BufferedReader(
575 new InputStreamReader(url.openStream()));
577 Properties remoteBuildProperties = new Properties();
578 remoteBuildProperties.load(in);
579 remoteVersion = remoteBuildProperties.getProperty("VERSION");
580 } catch (Exception ex)
582 if (!Jalview.quiet())
585 "Non-fatal exception when checking version at "
586 + remoteBuildPropertiesUrl + ":");
587 System.out.println(ex);
589 remoteVersion = getProperty("VERSION");
592 System.setProperty("sun.net.client.defaultConnectTimeout",
595 setProperty("LATEST_VERSION", remoteVersion);
599 VersionChecker vc = new VersionChecker();
604 if (jnlpVersion != null)
606 setProperty("LATEST_VERSION", jnlpVersion);
610 applicationProperties.remove("LATEST_VERSION");
614 // LOAD USERDEFINED COLOURS
615 Cache.initUserColourSchemes(getProperty("USER_DEFINED_COLOURS"));
616 jalview.io.PIRFile.useModellerOutput = Cache.getDefault("PIR_MODELLER",
621 * construct a resource URL for the given absolute resource pathname
623 * @param resourcePath
626 private static String resolveResourceURLFor(String resourcePath)
629 if (Platform.isJS() || !Cache.class.getProtectionDomain()
630 .getCodeSource().getLocation().toString().endsWith(".jar"))
634 url = Cache.class.getResource(resourcePath).toString();
635 } catch (Exception ex)
637 System.err.println("Failed to resolve resource " + resourcePath
638 + ": " + ex.getMessage());
643 url = "jar:".concat(Cache.class.getProtectionDomain().getCodeSource()
644 .getLocation().toString().concat("!" + resourcePath));
649 public static void loadBuildProperties(boolean reportVersion)
651 String codeInstallation = getProperty("INSTALLATION");
652 boolean printVersion = codeInstallation == null;
655 * read build properties - from the Jalview jar for a Java distribution,
656 * or from codebase file in test or JalviewJS context
660 String buildDetails = resolveResourceURLFor("/.build_properties");
661 URL localJarFileURL = new URL(buildDetails);
662 InputStream in = localJarFileURL.openStream();
663 buildProperties.load(in);
665 if (buildProperties.getProperty("BUILD_DATE", null) != null)
667 applicationProperties.put("BUILD_DATE",
668 buildProperties.getProperty("BUILD_DATE"));
670 if (buildProperties.getProperty("INSTALLATION", null) != null)
672 applicationProperties.put("INSTALLATION",
673 buildProperties.getProperty("INSTALLATION"));
675 if (buildProperties.getProperty("VERSION", null) != null)
677 applicationProperties.put("VERSION",
678 buildProperties.getProperty("VERSION"));
680 if (buildProperties.getProperty("JAVA_COMPILE_VERSION", null) != null)
682 applicationProperties.put("JAVA_COMPILE_VERSION",
683 buildProperties.getProperty("JAVA_COMPILE_VERSION"));
685 } catch (Exception ex)
687 if (!Jalview.quiet())
688 System.out.println("Error reading build details: " + ex);
689 applicationProperties.remove("VERSION");
691 String codeVersion = getProperty("VERSION");
692 codeInstallation = getProperty("INSTALLATION");
694 if (codeVersion == null)
696 // THIS SHOULD ONLY BE THE CASE WHEN TESTING!!
697 codeVersion = "Test";
698 codeInstallation = "";
702 codeInstallation = " (" + codeInstallation + ")";
704 setProperty("VERSION", codeVersion);
705 new BuildDetails(codeVersion, null, codeInstallation);
706 if (printVersion && reportVersion)
708 System.out.println(ChannelProperties.getProperty("app_name")
709 + " version: " + codeVersion + codeInstallation);
713 private static void deleteBuildProperties()
715 applicationProperties.remove("LATEST_VERSION");
716 applicationProperties.remove("VERSION");
717 applicationProperties.remove("AUTHORS");
718 applicationProperties.remove("AUTHORFNAMES");
719 applicationProperties.remove("YEAR");
720 applicationProperties.remove("BUILD_DATE");
721 applicationProperties.remove("INSTALLATION");
725 * Gets Jalview application property of given key. Returns null if key not
731 * @return Property value
733 public static String getProperty(String key)
735 return getProperty(key, false);
738 public static String getProperty(String key,
739 boolean skipSessionProperties)
742 if (!(skipSessionProperties || bypassSessionProperties))
744 prop = getSessionProperty(key);
748 prop = applicationProperties.getProperty(key);
750 if (prop == null && Platform.isJS())
752 prop = applicationProperties.getProperty(Platform.getUniqueAppletID()
753 + "_" + JS_PROPERTY_PREFIX + key);
759 * These methods are used when checking if the saved preference is different
760 * to the default setting
763 public static boolean getDefault(String property, boolean def)
765 String string = getProperty(property);
768 def = Boolean.valueOf(string).booleanValue();
774 public static int getDefault(String property, int def)
776 String string = getProperty(property);
781 def = Integer.parseInt(string);
782 } catch (NumberFormatException e)
784 if (!Jalview.quiet())
785 System.out.println("Error parsing int property '" + property
786 + "' with value '" + string + "'");
794 * Answers the value of the given property, or the supplied default value if
795 * the property is not set
797 public static String getDefault(String property, String def)
799 String value = getProperty(property);
800 return value == null ? def : value;
804 * Stores property in the file "HOME_DIR/.jalview_properties"
809 * String value of property
811 * @return previous value of property (or null)
813 public static Object setProperty(String key, String obj)
815 Object oldValue = null;
818 oldValue = applicationProperties.setProperty(key, obj);
819 if (propertiesFile != null && !propsAreReadOnly
820 // don't rewrite if new value is same as old value
821 && !((obj == null && oldValue == null)
822 || (obj != null && obj.equals(oldValue))))
824 // reset the session property too
825 if (sessionProperties.containsKey(key))
827 sessionProperties.remove(key);
829 FileOutputStream out = new FileOutputStream(propertiesFile);
830 applicationProperties.store(out, "---JalviewX Properties File---");
833 } catch (Exception ex)
835 if (!Jalview.quiet())
837 "Error setting property: " + key + " " + obj + "\n" + ex);
843 * remove the specified property from the jalview properties file
847 public static void removeProperty(String string)
849 applicationProperties.remove(string);
854 * save the properties to the jalview properties path
856 public static void saveProperties()
858 if (!propsAreReadOnly)
862 FileOutputStream out = new FileOutputStream(propertiesFile);
863 applicationProperties.store(out, "---JalviewX Properties File---");
865 } catch (Exception ex)
867 if (!Jalview.quiet())
868 System.out.println("Error saving properties: " + ex);
874 * internal vamsas class discovery state
876 private static int vamsasJarsArePresent = -1;
879 * Searches for vamsas client classes on class path.
881 * @return true if vamsas client is present on classpath
883 public static boolean vamsasJarsPresent()
885 if (vamsasJarsArePresent == -1)
889 if (jalview.jbgui.GDesktop.class.getClassLoader()
890 .loadClass("uk.ac.vamsas.client.VorbaId") != null)
893 "Found Vamsas Classes (uk.ac..vamsas.client.VorbaId can be loaded)");
894 vamsasJarsArePresent = 1;
895 JLoggerLog4j lvclient = JLoggerLog4j.getLogger("uk.ac.vamsas",
896 Console.getCachedLogLevel("logs.Vamsas.Level"));
897 JLoggerLog4j.addAppender(lvclient, Console.log,
898 JALVIEW_LOGGER_NAME);
899 // Tell the user that debug is enabled
900 lvclient.debug(ChannelProperties.getProperty("app_name")
901 + " Vamsas Client Debugging Output Follows.");
903 } catch (Exception e)
905 vamsasJarsArePresent = 0;
906 Console.debug("Vamsas Classes are not present");
909 return (vamsasJarsArePresent > 0);
913 * internal vamsas class discovery state
915 private static int groovyJarsArePresent = -1;
918 * Searches for vamsas client classes on class path.
920 * @return true if vamsas client is present on classpath
922 public static boolean groovyJarsPresent()
924 if (groovyJarsArePresent == -1)
928 if (Cache.class.getClassLoader()
929 .loadClass("groovy.lang.GroovyObject") != null)
932 "Found Groovy (groovy.lang.GroovyObject can be loaded)");
933 groovyJarsArePresent = 1;
934 JLoggerLog4j lgclient = JLoggerLog4j.getLogger("groovy",
935 Console.getCachedLogLevel("logs.Groovy.Level"));
936 JLoggerLog4j.addAppender(lgclient, Console.log,
937 JALVIEW_LOGGER_NAME);
938 // Tell the user that debug is enabled
939 lgclient.debug(ChannelProperties.getProperty("app_name")
940 + " Groovy Client Debugging Output Follows.");
944 groovyJarsArePresent = 0;
945 Console.debug("Groovy Classes are not present", e);
946 } catch (Exception e)
948 groovyJarsArePresent = 0;
949 Console.debug("Groovy Classes are not present");
952 return (groovyJarsArePresent > 0);
956 * GA tracker object - actually JGoogleAnalyticsTracker null if tracking not
959 protected static Object tracker = null;
961 protected static Class trackerfocus = null;
963 protected static Class jgoogleanalyticstracker = null;
966 * Initialise the google tracker if it is not done already.
968 public static void initGoogleTracker()
972 if (jgoogleanalyticstracker == null)
974 // try to get the tracker class
977 jgoogleanalyticstracker = Cache.class.getClassLoader().loadClass(
978 "com.boxysystems.jgoogleanalytics.JGoogleAnalyticsTracker");
979 trackerfocus = Cache.class.getClassLoader()
980 .loadClass("com.boxysystems.jgoogleanalytics.FocusPoint");
981 } catch (Exception e)
984 "com.boxysystems.jgoogleanalytics package is not present - tracking not enabled.");
986 jgoogleanalyticstracker = null;
991 // now initialise tracker
992 Exception re = null, ex = null;
994 String vrs = "No Version Accessible";
997 // Google analytics tracking code for Library Finder
998 tracker = jgoogleanalyticstracker
999 .getConstructor(new Class[]
1000 { String.class, String.class, String.class })
1001 .newInstance(new Object[]
1002 { ChannelProperties.getProperty("app_name") + " Desktop",
1003 (vrs = Cache.getProperty("VERSION") + "_"
1004 + Cache.getDefault("BUILD_DATE", "unknown")),
1006 jgoogleanalyticstracker
1007 .getMethod("trackAsynchronously", new Class[]
1009 .invoke(tracker, new Object[]
1010 { trackerfocus.getConstructor(new Class[] { String.class })
1011 .newInstance(new Object[]
1012 { "Application Started." }) });
1013 } catch (RuntimeException e)
1016 } catch (Exception e)
1023 if (re != null || ex != null || err != null)
1027 Console.debug("Caught runtime exception in googletracker init:",
1033 "Failed to initialise GoogleTracker for Jalview Desktop with version "
1040 "Whilst initing GoogleTracker for Jalview Desktop version "
1047 Console.debug("Successfully initialised tracker.");
1053 * get the user's default colour if available
1059 public static Color getDefaultColour(String property, Color defcolour)
1061 String colprop = getProperty(property);
1062 if (colprop == null)
1066 Color col = ColorUtils.parseColourString(colprop);
1069 Console.warn("Couldn't parse '" + colprop + "' as a colour for "
1072 return (col == null) ? defcolour : col;
1076 * store a colour as a Jalview user default property
1081 public static void setColourProperty(String property, Color colour)
1083 setProperty(property, jalview.util.Format.getHexString(colour));
1087 * Stores a formatted date in a jalview property, using a fixed locale.
1089 * @param propertyName
1091 * @return the formatted date string
1093 public static String setDateProperty(String propertyName, Date date)
1095 String formatted = date_format.format(date);
1096 setProperty(propertyName, formatted);
1101 * Reads a date stored in a Jalview property, parses it (using a fixed locale
1102 * format) and returns as a Date, or null if parsing fails
1104 * @param propertyName
1108 public static Date getDateProperty(String propertyName)
1110 String val = getProperty(propertyName);
1115 return date_format.parse(val);
1116 } catch (Exception ex)
1118 System.err.println("Invalid or corrupt date in property '"
1119 + propertyName + "' : value was '" + val + "'");
1126 * get and parse a property as an integer. send any parsing problems to
1130 * @return null or Integer
1132 public static Integer getIntegerProperty(String property)
1134 String val = getProperty(property);
1135 if (val != null && (val = val.trim()).length() > 0)
1139 return Integer.valueOf(val);
1140 } catch (NumberFormatException x)
1142 System.err.println("Invalid integer in property '" + property
1143 + "' (value was '" + val + "')");
1150 * Set the specified value, or remove it if null or empty. Does not save the
1156 public static void setOrRemove(String propName, String value)
1158 if (propName == null)
1162 if (value == null || value.trim().length() < 1)
1164 Cache.applicationProperties.remove(propName);
1168 Cache.applicationProperties.setProperty(propName, value);
1173 * Loads in user colour schemes from files.
1176 * a '|'-delimited list of file paths
1178 public static void initUserColourSchemes(String files)
1180 if (files == null || files.length() == 0)
1185 // In case colours can't be loaded, we'll remove them
1186 // from the default list here.
1187 StringBuffer coloursFound = new StringBuffer();
1188 StringTokenizer st = new StringTokenizer(files, "|");
1189 while (st.hasMoreElements())
1191 String file = st.nextToken();
1194 UserColourScheme ucs = ColourSchemeLoader.loadColourScheme(file);
1197 if (coloursFound.length() > 0)
1199 coloursFound.append("|");
1201 coloursFound.append(file);
1202 ColourSchemes.getInstance().registerColourScheme(ucs);
1204 } catch (Exception ex)
1206 if (!Jalview.quiet())
1207 System.out.println("Error loading User ColourFile\n" + ex);
1210 if (!files.equals(coloursFound.toString()))
1212 if (coloursFound.toString().length() > 1)
1214 setProperty(UserDefinedColours.USER_DEFINED_COLOURS,
1215 coloursFound.toString());
1219 applicationProperties
1220 .remove(UserDefinedColours.USER_DEFINED_COLOURS);
1226 * Initial logging information helper for various versions output
1230 * @param defaultValue
1232 private static void appendIfNotNull(StringBuilder sb, String prefix,
1233 String value, String suffix, String defaultValue)
1235 if (value == null && defaultValue == null)
1241 sb.append(value == null ? defaultValue : value);
1248 * @return Jalview version, build details and JVM platform version for console
1250 public static String getVersionDetailsForConsole()
1252 StringBuilder sb = new StringBuilder();
1253 sb.append(ChannelProperties.getProperty("app_name"))
1254 .append(" Version: ");
1255 sb.append(Cache.getDefault("VERSION", "TEST"));
1257 sb.append(ChannelProperties.getProperty("app_name"))
1258 .append(" Installation: ");
1259 sb.append(Cache.getDefault("INSTALLATION", "unknown"));
1261 sb.append("Build Date: ");
1262 sb.append(Cache.getDefault("BUILD_DATE", "unknown"));
1264 sb.append("Java version: ");
1265 sb.append(System.getProperty("java.version"));
1267 sb.append("Java platform: ");
1268 sb.append(System.getProperty("os.arch"));
1270 sb.append(System.getProperty("os.name"));
1272 sb.append(System.getProperty("os.version"));
1274 appendIfNotNull(sb, "Install4j version: ",
1275 System.getProperty("sys.install4jVersion"), "\n", null);
1276 appendIfNotNull(sb, "Install4j template version: ",
1277 System.getProperty("installer_template_version"), "\n", null);
1278 appendIfNotNull(sb, "Launcher version: ",
1279 System.getProperty("launcher_version"), "\n", null);
1280 LookAndFeel laf = UIManager.getLookAndFeel();
1281 String lafName = laf == null ? "Not obtained" : laf.getName();
1282 String lafClass = laf == null ? "unknown" : laf.getClass().getName();
1283 sb.append("LookAndFeel: ");
1286 sb.append(lafClass);
1288 appendIfNotNull(sb, "Channel: ",
1289 ChannelProperties.getProperty("channel"), "\n", null);
1290 if (Console.isDebugEnabled()
1291 || !"release".equals(ChannelProperties.getProperty("channel")))
1293 appendIfNotNull(sb, "Getdown appdir: ",
1294 System.getProperty("getdowninstanceappdir"), "\n", null);
1295 appendIfNotNull(sb, "Getdown appbase: ",
1296 System.getProperty("getdowninstanceappbase"), "\n", null);
1297 appendIfNotNull(sb, "Java home: ", System.getProperty("java.home"),
1299 appendIfNotNull(sb, "Preferences file: ", propertiesFile, "\n",
1302 return sb.toString();
1307 * @return build details as reported in splashscreen
1309 public static String getBuildDetailsForSplash()
1311 // consider returning more human friendly info
1312 // eg 'built from Source' or update channel
1313 return Cache.getDefault("INSTALLATION", "unknown");
1316 public static String getStackTraceString(Throwable t)
1318 StringWriter sw = new StringWriter();
1319 PrintWriter pw = new PrintWriter(sw);
1320 t.printStackTrace(pw);
1321 return sw.toString();
1324 // proxy properties methods
1325 public static void clearProxyProperties()
1327 setProxyProperties(null, null, null, null, null, null, null, null,
1331 public static void resetProxyProperties()
1333 setProxyProperties(startupProxyProperties[0], startupProxyProperties[1],
1334 startupProxyProperties[2], startupProxyProperties[3],
1335 startupProxyProperties[4],
1336 startupProxyProperties[5] == null ? null
1337 : startupProxyProperties[5].toCharArray(),
1338 startupProxyProperties[6],
1339 startupProxyProperties[7] == null ? null
1340 : startupProxyProperties[7].toCharArray(),
1341 startupProxyProperties[8]);
1342 StringBuilder sb = new StringBuilder();
1343 sb.append("Setting proxy properties to: http.proxyHost=")
1344 .append(startupProxyProperties[0]).append(", http.proxyPort=")
1345 .append(startupProxyProperties[1])
1346 .append(startupProxyProperties[4] != null
1347 && !startupProxyProperties[4].isEmpty()
1348 ? " [" + startupProxyProperties[4] + "]"
1350 .append(", https.proxyHost=").append(startupProxyProperties[2])
1351 .append(", https.proxyPort=").append(startupProxyProperties[3])
1352 .append(startupProxyProperties[6] != null
1353 && !startupProxyProperties[6].isEmpty()
1354 ? " [" + startupProxyProperties[6] + "]"
1357 Console.debug(sb.toString());
1360 public static void setProxyPropertiesFromPreferences()
1362 setProxyPropertiesFromPreferences(Cache.PROXYTYPE_SYSTEM);
1365 public static void setProxyPropertiesFromPreferences(
1366 String previousProxyType)
1368 String proxyType = Cache.getDefault("USE_PROXY",
1369 Cache.PROXYTYPE_SYSTEM);
1370 if (previousProxyType != null
1371 && !proxyType.equals(Cache.PROXYTYPE_CUSTOM) // always apply
1373 && proxyType.equals(previousProxyType))
1380 case Cache.PROXYTYPE_NONE:
1381 if (!previousProxyType.equals(proxyType))
1383 Console.info("Setting no proxy settings");
1384 Cache.setProxyProperties(null, null, null, null, null, null, null,
1388 case Cache.PROXYTYPE_CUSTOM:
1389 // always re-set a custom proxy -- it might have changed, particularly
1391 Console.info("Setting custom proxy settings");
1392 boolean proxyAuthSet = Cache.getDefault("PROXY_AUTH", false);
1393 Cache.setProxyProperties(Cache.getDefault("PROXY_SERVER", null),
1394 Cache.getDefault("PROXY_PORT", null),
1395 Cache.getDefault("PROXY_SERVER_HTTPS", null),
1396 Cache.getDefault("PROXY_PORT_HTTPS", null),
1397 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1399 proxyAuthSet ? Cache.proxyAuthPassword : null,
1400 proxyAuthSet ? Cache.getDefault("PROXY_AUTH_USERNAME", "")
1402 proxyAuthSet ? Cache.proxyAuthPassword : null, "localhost");
1404 default: // system proxy settings by default
1405 Console.info("Setting system proxy settings");
1406 Cache.resetProxyProperties();
1410 public static void setProxyProperties(String httpHost, String httpPort,
1411 String httpsHost, String httpsPort, String httpUser,
1412 char[] httpPassword, String httpsUser, char[] httpsPassword,
1413 String nonProxyHosts)
1415 setOrClearSystemProperty("http.proxyHost", httpHost);
1416 setOrClearSystemProperty("http.proxyPort", httpPort);
1417 setOrClearSystemProperty("https.proxyHost", httpsHost);
1418 setOrClearSystemProperty("https.proxyPort", httpsPort);
1419 setOrClearSystemProperty("http.proxyUser", httpUser);
1420 setOrClearSystemProperty("https.proxyUser", httpsUser);
1421 // note: passwords for http.proxyPassword and https.proxyPassword are sent
1422 // via the Authenticator, properties do not need to be set
1424 // are we using a custom proxy (password prompt might be required)?
1425 boolean customProxySet = getDefault("USE_PROXY", PROXYTYPE_SYSTEM)
1426 .equals(PROXYTYPE_CUSTOM);
1429 * A bug in Java means the AuthCache does not get reset, so once it has working credentials,
1430 * it never asks for more, so changing the Authenticator has no effect (as getPasswordAuthentication()
1431 * is not re-called).
1432 * This could lead to password leak to a hostile proxy server, so I'm putting in a hack to clear
1434 * see https://www.generacodice.com/en/articolo/154918/Reset-the-Authenticator-credentials
1436 * Turns out this is only accessible in Java 8, and not in Java 9 onwards, so commenting out
1441 sun.net.www.protocol.http.AuthCacheValue
1442 .setAuthCache(new sun.net.www.protocol.http.AuthCacheImpl());
1443 } catch (Throwable t)
1445 Cache.error(t.getMessage());
1446 Cache.debug(getStackTraceString(t));
1450 if (httpUser != null || httpsUser != null)
1454 char[] displayHttpPw = new char[httpPassword == null ? 0
1455 : httpPassword.length];
1456 Arrays.fill(displayHttpPw, '*');
1458 "CACHE Proxy: setting new Authenticator with httpUser='"
1459 + httpUser + "' httpPassword='" + displayHttpPw
1461 if (!Platform.isJS())
1463 * java.net.Authenticator not implemented in SwingJS yet
1469 Authenticator.setDefault(new Authenticator()
1472 protected PasswordAuthentication getPasswordAuthentication()
1474 if (getRequestorType() == RequestorType.PROXY)
1476 String protocol = getRequestingProtocol();
1477 boolean needProxyPasswordSet = false;
1478 if (customProxySet &&
1479 // we have a username but no password for the scheme being
1481 (protocol.equalsIgnoreCase("http")
1482 && (httpUser != null && httpUser.length() > 0
1483 && (httpPassword == null
1484 || httpPassword.length == 0)))
1485 || (protocol.equalsIgnoreCase("https")
1486 && (httpsUser != null
1487 && httpsUser.length() > 0
1488 && (httpsPassword == null
1489 || httpsPassword.length == 0))))
1491 // open Preferences -> Connections
1492 String message = MessageManager
1493 .getString("label.proxy_password_required");
1494 Preferences.openPreferences(
1495 Preferences.TabRef.CONNECTIONS_TAB, message);
1496 Preferences.getInstance()
1497 .proxyAuthPasswordCheckHighlight(true, true);
1503 if (protocol.equalsIgnoreCase("http")
1504 && getRequestingHost()
1505 .equalsIgnoreCase(httpHost)
1506 && getRequestingPort() == Integer
1510 "AUTHENTICATOR returning PasswordAuthentication(\""
1511 + httpUser + "\", '"
1512 + new String(displayHttpPw) + "')");
1513 return new PasswordAuthentication(httpUser,
1516 if (protocol.equalsIgnoreCase("https")
1517 && getRequestingHost()
1518 .equalsIgnoreCase(httpsHost)
1519 && getRequestingPort() == Integer
1520 .valueOf(httpsPort))
1522 char[] displayHttpsPw = new char[httpPassword.length];
1523 Arrays.fill(displayHttpsPw, '*');
1525 "AUTHENTICATOR returning PasswordAuthentication(\""
1526 + httpsUser + "\", '" + displayHttpsPw
1528 return new PasswordAuthentication(httpsUser,
1531 } catch (NumberFormatException e)
1533 Console.error("Problem with proxy port values [http:"
1534 + httpPort + ", https:" + httpsPort + "]");
1537 "AUTHENTICATOR after trying to get PasswordAuthentication");
1540 // non proxy request
1541 Console.debug("AUTHENTICATOR returning null");
1545 } // end of j2sIgnore for java.net.Authenticator
1547 // required to re-enable basic authentication (should be okay for a
1550 "AUTHENTICATOR setting property 'jdk.http.auth.tunneling.disabledSchemes' to \"\"");
1551 System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
1552 } catch (SecurityException e)
1554 Console.error("Could not set default Authenticator");
1555 Console.debug(getStackTraceString(e));
1560 // reset the Authenticator to protect http.proxyUser and
1561 // http.proxyPassword Just In Case
1562 /* as noted above, due to bug in java this doesn't work if the sun.net.www.protocol.http.AuthCache
1563 * has working credentials. No workaround for Java 11.
1565 if (!Platform.isJS())
1567 * java.net.Authenticator not implemented in SwingJS yet
1574 "AUTHENTICATOR setting default Authenticator to null");
1575 Authenticator.setDefault(null);
1579 // nonProxyHosts not currently configurable in Preferences
1581 "AUTHENTICATOR setting property 'http.nonProxyHosts' to \""
1582 + nonProxyHosts + "\"");
1583 setOrClearSystemProperty("http.nonProxyHosts", nonProxyHosts);
1586 public static void setOrClearSystemProperty(String key, char[] value)
1588 setOrClearSystemProperty(key,
1589 (value == null) ? null : new String(value));
1592 public static void setOrClearSystemProperty(String key, String value)
1600 System.clearProperty(key);
1604 System.setProperty(key, value);
1609 * Getdown appbase methods
1612 private static final String releaseAppbase;
1614 private static String getdownAppbase;
1616 private static String getdownDistDir;
1620 if (!Platform.isJS())
1622 Float specversion = Float
1623 .parseFloat(System.getProperty("java.specification.version"));
1624 releaseAppbase = (specversion < 9)
1625 ? "https://www.jalview.org/getdown/release/1.8"
1626 : "https://www.jalview.org/getdown/release/11";
1630 // this value currenly made up, can be changed to URL that will be
1631 // "https://www.jalview.org/jalview-js/swingjs/j2s/build_properties"
1632 releaseAppbase = "https://www.jalview.org/jalview-js";
1633 getdownAppbase = releaseAppbase;
1634 getdownDistDir = "/swingjs/j2s";
1638 // look for properties (passed in by getdown) otherwise default to release
1639 private static void setGetdownAppbase()
1641 if (getdownAppbase != null)
1645 String appbase = System.getProperty("getdownappbase");
1646 String distDir = System.getProperty("getdowndistdir");
1647 if (appbase == null)
1649 appbase = buildProperties.getProperty("GETDOWNAPPBASE");
1650 distDir = buildProperties.getProperty("GETDOWNAPPDISTDIR");
1652 if (appbase == null)
1654 appbase = releaseAppbase;
1655 distDir = "release";
1657 if (appbase.endsWith("/"))
1659 appbase = appbase.substring(0, appbase.length() - 1);
1661 if (distDir == null)
1663 distDir = appbase.equals(releaseAppbase) ? "release" : "alt";
1665 getdownAppbase = appbase;
1666 getdownDistDir = distDir;
1669 public static String getGetdownAppbase()
1671 setGetdownAppbase();
1672 return getdownAppbase;
1675 public static String getAppbaseBuildProperties()
1677 String appbase = getGetdownAppbase();
1678 return appbase + "/" + getdownDistDir + "/build_properties";
1681 private static final Collection<String> bootstrapProperties = new ArrayList<>(
1682 Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST));
1684 public static Properties bootstrapProperties(String filename)
1686 Properties bootstrapProps = new Properties();
1688 if (filename != null)
1690 file = new File(filename);
1692 if (file == null || !file.exists())
1694 String channelPrefsFilename = ChannelProperties
1695 .getProperty("preferences.filename");
1696 String propertiesFilename = System.getProperty("user.home")
1697 + File.separatorChar + channelPrefsFilename;
1698 file = new File(propertiesFilename);
1700 if (file == null || !file.exists())
1702 String releasePrefsFilename = fallbackPropertiesFile;
1703 String releasePropertiesFilename = System.getProperty("user.home")
1704 + File.separatorChar + releasePrefsFilename;
1705 file = new File(releasePropertiesFilename);
1708 if (filename == null)
1712 System.err.println("Could not load bootstrap preferences file '"
1719 FileInputStream in = new FileInputStream(file.getAbsoluteFile());
1720 Properties props = new Properties();
1722 for (String prop : bootstrapProperties)
1724 if (props.containsKey(prop))
1725 bootstrapProps.put(prop, props.getProperty(prop));
1727 } catch (FileNotFoundException e)
1729 System.err.println("Could not find bootstrap preferences file '"
1730 + file.getAbsolutePath() + "'");
1731 } catch (IOException e)
1734 "IOException when loading bootstrap preferences file '"
1735 + file.getAbsolutePath() + "'");
1737 return bootstrapProps;
1740 public static void setSessionProperty(String key, String val)
1744 sessionProperties.put(key, val);
1748 public static String getSessionProperty(String key)
1750 return key == null ? null : sessionProperties.get(key);