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.
24 import java.io.FileInputStream;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.net.MalformedURLException;
30 import java.util.Properties;
32 import jalview.bin.Console;
34 public class LaunchUtils
37 public static void loadChannelProps(File dir)
39 ChannelProperties.loadProps(dir);
42 private static Properties userPreferences = null;
44 public static String getUserPreference(String key)
46 if (userPreferences == null)
48 String channelPrefsFilename = ChannelProperties
49 .getProperty("preferences.filename");
50 if (channelPrefsFilename == null)
54 File propertiesFile = new File(System.getProperty("user.home"),
55 channelPrefsFilename);
56 if (!propertiesFile.exists())
62 userPreferences = new Properties();
63 userPreferences.load(new FileInputStream(propertiesFile));
64 } catch (FileNotFoundException e)
66 // didn't find user preferences file
68 } catch (IOException e)
70 System.err.println(e.getMessage());
74 return userPreferences.getProperty(key);
77 public static boolean getBooleanUserPreference(String key)
79 return Boolean.parseBoolean(getUserPreference(key));
82 public static int JAVA_COMPILE_VERSION = 0;
84 public static int getJavaCompileVersion()
90 else if (JAVA_COMPILE_VERSION > 0)
92 return JAVA_COMPILE_VERSION;
94 String buildDetails = "jar:".concat(LaunchUtils.class
95 .getProtectionDomain().getCodeSource().getLocation().toString()
96 .concat("!" + "/.build_properties"));
99 URL localFileURL = new URL(buildDetails);
100 InputStream in = localFileURL.openStream();
101 Properties buildProperties = new Properties();
102 buildProperties.load(in);
104 String JCV = buildProperties.getProperty("JAVA_COMPILE_VERSION",
108 Console.outputMessage(
109 "Could not obtain JAVA_COMPILE_VERSION for comparison");
112 JAVA_COMPILE_VERSION = Integer.parseInt(JCV);
113 } catch (MalformedURLException e)
115 System.err.println("Could not find " + buildDetails);
117 } catch (IOException e)
119 System.err.println("Could not load " + buildDetails);
121 } catch (NumberFormatException e)
123 System.err.println("Could not parse JAVA_COMPILE_VERSION");
127 return JAVA_COMPILE_VERSION;
130 public static int JAVA_VERSION = 0;
132 public static int getJavaVersion()
138 else if (JAVA_VERSION > 0)
144 String JV = System.getProperty("java.version");
147 Console.outputMessage(
148 "Could not obtain java.version for comparison");
151 if (JV.startsWith("1."))
153 JV = JV.substring(2);
155 JAVA_VERSION = JV.indexOf(".") == -1 ? Integer.parseInt(JV)
156 : Integer.parseInt(JV.substring(0, JV.indexOf(".")));
157 } catch (NumberFormatException e)
159 System.err.println("Could not parse java.version");
165 public static boolean checkJavaVersion()
171 String buildDetails = "jar:".concat(LaunchUtils.class
172 .getProtectionDomain().getCodeSource().getLocation().toString()
173 .concat("!" + "/.build_properties"));
175 int java_compile_version = getJavaCompileVersion();
176 int java_version = getJavaVersion();
178 if (java_compile_version <= 0 || java_version <= 0)
180 Console.outputMessage("Could not make Java version check");
183 // Warn if these java.version and JAVA_COMPILE_VERSION conditions exist
184 // Usually this means a Java 11 compiled JAR being run by a Java 11 JVM
185 if (java_version >= 11 && java_compile_version < 11)