From: Ben Soares Date: Thu, 25 May 2023 16:34:49 +0000 (+0100) Subject: JAL-3820 JAL-3830 improvements to script launching. Icon on macOS. Fixed CLASSPATH. X-Git-Tag: Release_2_11_4_0~296 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f6e495e7dace3de7fd890cb9f817a99ec5fcbbcc;p=jalview.git JAL-3820 JAL-3830 improvements to script launching. Icon on macOS. Fixed CLASSPATH. --- diff --git a/getdown/lib/getdown-core.jar b/getdown/lib/getdown-core.jar index 41540fd..7c99c93 100644 Binary files a/getdown/lib/getdown-core.jar and b/getdown/lib/getdown-core.jar differ diff --git a/getdown/lib/getdown-launcher-local.jar b/getdown/lib/getdown-launcher-local.jar index c1237da..c6901ae 100644 Binary files a/getdown/lib/getdown-launcher-local.jar and b/getdown/lib/getdown-launcher-local.jar differ diff --git a/getdown/lib/getdown-launcher.jar b/getdown/lib/getdown-launcher.jar index 46e7327..24e3eb2 100644 Binary files a/getdown/lib/getdown-launcher.jar and b/getdown/lib/getdown-launcher.jar differ diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java index 75106cc..2bce673 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/HiDPISetting.java @@ -1,8 +1,28 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.bin; -import java.awt.HeadlessException; import java.util.Locale; +import java.awt.HeadlessException; public class HiDPISetting { @@ -36,6 +56,8 @@ public class HiDPISetting public static int scale = 0; + public final static int MAX_SCALE = 8; + private static boolean doneInit = false; private static boolean allowScalePropertyArg = false; @@ -68,8 +90,17 @@ public class HiDPISetting // get and use command line property values first String setHiDPIProperty = System.getProperty(setHiDPIPropertyName); - setHiDPI = setHiDPIProperty != null - && setHiDPIProperty.equalsIgnoreCase("true"); + boolean setHiDPIPropertyBool = Boolean.parseBoolean(setHiDPIProperty); + + // allow -DsetHiDPI=false to turn off HiDPI scaling + if (setHiDPIProperty != null && !setHiDPIPropertyBool) + { + clear(); + doneInit = true; + return; + } + + setHiDPI = setHiDPIProperty != null && setHiDPIPropertyBool; String setHiDPIScaleProperty = System .getProperty(setHiDPIScalePropertyName); @@ -78,6 +109,12 @@ public class HiDPISetting try { setHiDPIScale = Integer.parseInt(setHiDPIScaleProperty); + // if setHiDPIScale property is validly set and setHiDPI property wasn't + // attempted to be set we assume setHiDPIScale to be true + if (setHiDPIProperty == null) + { + setHiDPI = true; + } } catch (NumberFormatException e) { System.err.println(setHiDPIScalePropertyName + " property give (" @@ -151,6 +188,16 @@ public class HiDPISetting int dimensionScale = 1 + (mindimension / bigScreenThreshold); + // reject outrageous values -- dpiScale in particular could be mistaken + if (dpiScale > MAX_SCALE) + { + dpiScale = 1; + } + if (dimensionScale > MAX_SCALE) + { + dimensionScale = 1; + } + // choose larger of dimensionScale or dpiScale (most likely dimensionScale // as dpiScale often misreported) int autoScale = Math.max(dpiScale, dimensionScale); diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java index f5f0196..bb545cb 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/MemorySetting.java @@ -22,6 +22,8 @@ */ package jalview.bin; +import java.util.Locale; + /** * Methods to decide on appropriate memory setting for Jalview based on two * optionally provided values: jvmmempc - the maximum percentage of total @@ -33,8 +35,6 @@ package jalview.bin; * @author bsoares * */ -import java.util.Locale; - public class MemorySetting { public static final String MAX_HEAPSIZE_PERCENT_PROPERTY_NAME = "jvmmempc"; @@ -363,7 +363,7 @@ public class MemorySetting public static String memoryLongToString(long mem) { - return memoryLongToString(mem, "%.1f"); + return memoryLongToString(mem, "%.3f"); } public static String memoryLongToString(long mem, String format) @@ -409,4 +409,4 @@ public class MemorySetting return ADJUSTMENT_MESSAGE; } -} \ No newline at end of file +} diff --git a/getdown/src/getdown/core/src/main/java/jalview/bin/ScreenInfo.java b/getdown/src/getdown/core/src/main/java/jalview/bin/ScreenInfo.java index 899bf94..18ef79e 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/bin/ScreenInfo.java +++ b/getdown/src/getdown/core/src/main/java/jalview/bin/ScreenInfo.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.bin; import java.awt.Toolkit; diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/ChannelProperties.java b/getdown/src/getdown/core/src/main/java/jalview/util/ChannelProperties.java index 40f6110..4832588 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/util/ChannelProperties.java +++ b/getdown/src/getdown/core/src/main/java/jalview/util/ChannelProperties.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.util; import java.awt.Image; @@ -57,6 +77,7 @@ public class ChannelProperties defaultProps.put("default_appbase", "https://www.jalview.org/getdown/release/1.8"); defaultProps.put("preferences.filename", ".jalview_properties"); + defaultProps.put("channel", "none"); // load channel_properties Properties tryChannelProps = new Properties(); diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java b/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java index 3302dba..ee3b2c6 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java +++ b/getdown/src/getdown/core/src/main/java/jalview/util/LaunchUtils.java @@ -1,9 +1,32 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.util; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Properties; public class LaunchUtils @@ -53,4 +76,102 @@ public class LaunchUtils { return Boolean.parseBoolean(getUserPreference(key)); } + + public static int JAVA_COMPILE_VERSION = 0; + + public static int getJavaCompileVersion() + { + if (JAVA_COMPILE_VERSION > 0) + { + return JAVA_COMPILE_VERSION; + } + String buildDetails = "jar:".concat(LaunchUtils.class + .getProtectionDomain().getCodeSource().getLocation().toString() + .concat("!" + "/.build_properties")); + try + { + URL localFileURL = new URL(buildDetails); + InputStream in = localFileURL.openStream(); + Properties buildProperties = new Properties(); + buildProperties.load(in); + in.close(); + String JCV = buildProperties.getProperty("JAVA_COMPILE_VERSION", + null); + if (JCV == null) + { + System.out.println( + "Could not obtain JAVA_COMPILE_VERSION for comparison"); + return -2; + } + JAVA_COMPILE_VERSION = Integer.parseInt(JCV); + } catch (MalformedURLException e) + { + System.err.println("Could not find " + buildDetails); + return -3; + } catch (IOException e) + { + System.err.println("Could not load " + buildDetails); + return -4; + } catch (NumberFormatException e) + { + System.err.println("Could not parse JAVA_COMPILE_VERSION"); + return -5; + } + + return JAVA_COMPILE_VERSION; + } + + public static int JAVA_VERSION = 0; + + public static int getJavaVersion() + { + if (JAVA_VERSION > 0) + { + return JAVA_VERSION; + } + try + { + String JV = System.getProperty("java.version"); + if (JV == null) + { + System.out.println("Could not obtain java.version for comparison"); + return -2; + } + if (JV.startsWith("1.")) + { + JV = JV.substring(2); + } + JAVA_VERSION = JV.indexOf(".") == -1 ? Integer.parseInt(JV) + : Integer.parseInt(JV.substring(0, JV.indexOf("."))); + } catch (NumberFormatException e) + { + System.err.println("Could not parse java.version"); + return -3; + } + return JAVA_VERSION; + } + + public static boolean checkJavaVersion() + { + String buildDetails = "jar:".concat(LaunchUtils.class + .getProtectionDomain().getCodeSource().getLocation().toString() + .concat("!" + "/.build_properties")); + + int java_compile_version = getJavaCompileVersion(); + int java_version = getJavaVersion(); + + if (java_compile_version <= 0 || java_version <= 0) + { + System.out.println("Could not make Java version check"); + return true; + } + // Warn if these java.version and JAVA_COMPILE_VERSION conditions exist + // Usually this means a Java 11 compiled JAR being run by a Java 11 JVM + if (java_version >= 11 && java_compile_version < 11) + { + return false; + } + + return true; + } } diff --git a/getdown/src/getdown/core/src/main/java/jalview/util/StringUtils.java b/getdown/src/getdown/core/src/main/java/jalview/util/StringUtils.java index afb9c89..1c67c92 100644 --- a/getdown/src/getdown/core/src/main/java/jalview/util/StringUtils.java +++ b/getdown/src/getdown/core/src/main/java/jalview/util/StringUtils.java @@ -25,6 +25,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.regex.Matcher; import java.util.regex.Pattern; public class StringUtils @@ -412,7 +413,8 @@ public class StringUtils { return s.toUpperCase(Locale.ROOT); } - return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1).toLowerCase(Locale.ROOT); + return s.substring(0, 1).toUpperCase(Locale.ROOT) + + s.substring(1).toLowerCase(Locale.ROOT); } /** @@ -583,4 +585,54 @@ public class StringUtils } return min < text.length() + 1 ? min : -1; } + + public static int indexOfFirstWhitespace(String text) + { + int index = -1; + Pattern pat = Pattern.compile("\\s"); + Matcher m = pat.matcher(text); + if (m.find()) + { + index = m.start(); + } + return index; + } + + /* + * implementation of String.replaceLast. + * Replaces only the last occurrence of toReplace in string with replacement. + */ + public static String replaceLast(String string, String toReplace, + String replacement) + { + int pos = string.lastIndexOf(toReplace); + if (pos > -1) + { + return new StringBuilder().append(string.substring(0, pos)) + .append(replacement) + .append(string.substring(pos + toReplace.length())) + .toString(); + } + else + { + return string; + } + + } + + /* + * return the maximum length of a List of Strings + */ + public static int maxLength(List l) + { + int max = 0; + for (String s : l) + { + if (s == null) + continue; + if (s.length() > max) + max = s.length(); + } + return max; + } } diff --git a/j11lib/getdown-core.jar b/j11lib/getdown-core.jar index 41540fd..7c99c93 100644 Binary files a/j11lib/getdown-core.jar and b/j11lib/getdown-core.jar differ diff --git a/j8lib/getdown-core.jar b/j8lib/getdown-core.jar index 41540fd..7c99c93 100644 Binary files a/j8lib/getdown-core.jar and b/j8lib/getdown-core.jar differ diff --git a/src/jalview/bin/Launcher.java b/src/jalview/bin/Launcher.java index 246f0a2..a87d322 100644 --- a/src/jalview/bin/Launcher.java +++ b/src/jalview/bin/Launcher.java @@ -50,9 +50,6 @@ public class Launcher { private final static String startClass = "jalview.bin.Jalview"; - private final static String dockIconPath = ChannelProperties - .getProperty("logo.512"); - private static boolean checkJVMSymlink(String testBin) { File testBinFile = new File(testBin); @@ -262,6 +259,8 @@ public class Launcher { if (!dockIcon) { + String dockIconPath = System.getProperty("getdownappdir", ".") + + File.separator + "resource/jalview_logo.png"; command.add("-Xdock:icon=" + dockIconPath); } if (!dockName) diff --git a/utils/getdown/bin/jalview.ps1 b/utils/getdown/bin/jalview.ps1 index 65998bc..1098010 100755 --- a/utils/getdown/bin/jalview.ps1 +++ b/utils/getdown/bin/jalview.ps1 @@ -80,9 +80,9 @@ $CONSOLEWIDTH = $Host.UI.RawUI.WindowSize.Width # quote the args and the command (in case of spaces) with escape chars (`) and precede with & to indicate command not string if ( $myArgs.count -eq 0 ) { - Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher" + Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher" } else { $myArgsString = '"' + $($myArgs -join '" "') + '"' - Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${myArgsString}" + Invoke-Expression -Command "& `"${JAVA}`" `"-DCONSOLEWIDTH=${CONSOLEWIDTH}`" `"-Dgetdownappdir=${APPDIR}`" -cp `"${CLASSPATH}`" jalview.bin.Launcher ${myArgsString}" } diff --git a/utils/getdown/bin/jalview.sh b/utils/getdown/bin/jalview.sh index 62da28c..9e3a8c7 100755 --- a/utils/getdown/bin/jalview.sh +++ b/utils/getdown/bin/jalview.sh @@ -65,7 +65,8 @@ CLASSPATH="" declare -a JARPATHS=() if [ -e "${GETDOWNTXT}" ]; then # always check grep and sed regexes on macos -- they're not the same - for JAR in $(grep -e '^code\s*=\s*' "${GETDOWNTXT}" | sed -e 's/^code\s*=\s*//;'); do +for JAR in $(grep -e '^code[[:space:]]*=[[:space:]]*' "${GETDOWNTXT}" | while read -r line; do echo $line | sed -E -e 's/code[[:space:]]*=[[:space:]]*//;'; done); + do [ -n "${CLASSPATH}" ] && CLASSPATH="${CLASSPATH}:" CLASSPATH="${CLASSPATH}${APPDIR}/${JAR}" JARPATHS=( "${JARPATHS[@]}" "${APPDIR}/${JAR}" ) @@ -122,6 +123,7 @@ elif command -v resize 2>&1 >/dev/null; then COLUMNS=$(resize -u | grep COLUMNS= | sed -e 's/.*=//;s/;//') 2>/dev/null fi JVMARGS=( "${JVMARGS[@]}" "-DCONSOLEWIDTH=${COLUMNS}" ) +JVMARGS=( "${JVMARGS[@]}" "-Dgetdownappdir=${APPDIR}" ) # Is there a bundled Java? If not just try one in the PATH (do need .exe in WSL) if [ \! -e "${JAVA}" ]; then diff --git a/utils/install4j/install4j10_template.install4j b/utils/install4j/install4j10_template.install4j index f1eee56..6127d8b 100644 --- a/utils/install4j/install4j10_template.install4j +++ b/utils/install4j/install4j10_template.install4j @@ -1454,6 +1454,8 @@ ${compiler:JALVIEW_APPLICATION_NAME} will now launch. + + @@ -1469,6 +1471,8 @@ ${compiler:JALVIEW_APPLICATION_NAME} will now launch. + +