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 public class LaunchUtils
35 public static void loadChannelProps(File dir)
37 ChannelProperties.loadProps(dir);
40 private static Properties userPreferences = null;
42 public static String getUserPreference(String key)
44 if (userPreferences == null)
46 String channelPrefsFilename = ChannelProperties
47 .getProperty("preferences.filename");
48 if (channelPrefsFilename == null)
52 File propertiesFile = new File(System.getProperty("user.home"),
53 channelPrefsFilename);
54 if (!propertiesFile.exists())
60 userPreferences = new Properties();
61 userPreferences.load(new FileInputStream(propertiesFile));
62 } catch (FileNotFoundException e)
64 // didn't find user preferences file
66 } catch (IOException e)
68 System.err.println(e.getMessage());
72 return userPreferences.getProperty(key);
75 public static boolean getBooleanUserPreference(String key)
77 return Boolean.parseBoolean(getUserPreference(key));
80 public static int JAVA_COMPILE_VERSION = 0;
82 public static int getJavaCompileVersion()
88 else if (JAVA_COMPILE_VERSION > 0)
90 return JAVA_COMPILE_VERSION;
92 String buildDetails = "jar:".concat(LaunchUtils.class
93 .getProtectionDomain().getCodeSource().getLocation().toString()
94 .concat("!" + "/.build_properties"));
97 URL localFileURL = new URL(buildDetails);
98 InputStream in = localFileURL.openStream();
99 Properties buildProperties = new Properties();
100 buildProperties.load(in);
102 String JCV = buildProperties.getProperty("JAVA_COMPILE_VERSION",
107 "Could not obtain JAVA_COMPILE_VERSION for comparison");
110 JAVA_COMPILE_VERSION = Integer.parseInt(JCV);
111 } catch (MalformedURLException e)
113 System.err.println("Could not find " + buildDetails);
115 } catch (IOException e)
117 System.err.println("Could not load " + buildDetails);
119 } catch (NumberFormatException e)
121 System.err.println("Could not parse JAVA_COMPILE_VERSION");
125 return JAVA_COMPILE_VERSION;
128 public static int JAVA_VERSION = 0;
130 public static int getJavaVersion()
136 else if (JAVA_VERSION > 0)
142 String JV = System.getProperty("java.version");
145 System.out.println("Could not obtain java.version for comparison");
148 if (JV.startsWith("1."))
150 JV = JV.substring(2);
152 JAVA_VERSION = JV.indexOf(".") == -1 ? Integer.parseInt(JV)
153 : Integer.parseInt(JV.substring(0, JV.indexOf(".")));
154 } catch (NumberFormatException e)
156 System.err.println("Could not parse java.version");
162 public static boolean checkJavaVersion()
168 String buildDetails = "jar:".concat(LaunchUtils.class
169 .getProtectionDomain().getCodeSource().getLocation().toString()
170 .concat("!" + "/.build_properties"));
172 int java_compile_version = getJavaCompileVersion();
173 int java_version = getJavaVersion();
175 if (java_compile_version <= 0 || java_version <= 0)
177 System.out.println("Could not make Java version check");
180 // Warn if these java.version and JAVA_COMPILE_VERSION conditions exist
181 // Usually this means a Java 11 compiled JAR being run by a Java 11 JVM
182 if (java_version >= 11 && java_compile_version < 11)