# HG changeset patch # User herrick # Date 1551315843 18000 # Node ID bfa094e6ce15510e61c9a1f02486709b70d44d17 # Parent 8018ecf829bc00e5e775f853c6a89e32bdad58fa 8191709 : javapackager detects WiX 3.10 as 3.1 and fails to use WiX 3.6+ compatible code Submitten-by: almatvee Reviewed-by: kbr, herrick diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/share/classes/jdk/jpackage/internal/VersionExtractor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/VersionExtractor.java Wed Feb 27 20:04:03 2019 -0500 @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code 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 + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.jpackage.internal; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.text.MessageFormat; +import java.util.ResourceBundle; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class VersionExtractor extends PrintStream { + + private static final ResourceBundle I18N = ResourceBundle.getBundle( + "jdk.jpackage.internal.resources.MainResources"); + + private final String pattern; + private String version = null; + + public VersionExtractor(String pattern) { + super(new ByteArrayOutputStream()); + + this.pattern = pattern; + } + + public String getVersion() { + if (version == null) { + String content + = new String(((ByteArrayOutputStream) out).toByteArray()); + Pattern p = Pattern.compile(pattern); + Matcher matcher = p.matcher(content); + if (matcher.find()) { + version = matcher.group(1); + } + } + return version; + } + + public static boolean isLessThan(String version, String compareTo) + throws RuntimeException { + if (version == null || version.isEmpty()) { + throw new RuntimeException(MessageFormat.format( + I18N.getString("ERR_VersionComparison"), + version, compareTo)); + } + + if (compareTo == null || compareTo.isEmpty()) { + throw new RuntimeException(MessageFormat.format( + I18N.getString("ERR_VersionComparison"), + version, compareTo)); + } + + String [] versionArray = version.trim().split(Pattern.quote(".")); + String [] compareToArray = compareTo.trim().split(Pattern.quote(".")); + + for (int i = 0; i < versionArray.length; i++) { + int v1 = Integer.parseInt(versionArray[i]); + int v2 = Integer.parseInt(compareToArray[i]); + if (v1 < v2) { + return true; + } else if (v1 > v2) { + return false; + } + } + + return false; + } +} diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties Wed Feb 27 19:45:26 2019 -0500 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties Wed Feb 27 20:04:03 2019 -0500 @@ -43,7 +43,7 @@ param.build-root.name=Build Root param.build-root.description=The directory in which to use and place temporary files. param.category.name=Category -param.category.description=The category oor group of the application. Generally speaking you will also want to specify application specific categories as well. +param.category.description=The category or group of the application. Generally speaking you will also want to specify application specific categories as well. param.category.default=Unknown param.copyright.name=Copyright param.copyright.description=The copyright for the application. @@ -176,3 +176,4 @@ ERR_LicenseFileNotExit=Error: Specified license file does not exist. ERR_BuildRootInvalid=Error: build-root ({0}) must be empty directory. ERR_InvalidOption=Error: Invalid Option: [{0}] +ERR_VersionComparison=Error: Failed to compare version {0} with {1}. diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties Wed Feb 27 19:45:26 2019 -0500 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties Wed Feb 27 20:04:03 2019 -0500 @@ -43,7 +43,7 @@ param.build-root.name=Build Root param.build-root.description=The directory in which to use and place temporary files. param.category.name=Category -param.category.description=The category oor group of the application. Generally speaking you will also want to specify application specific categories as well. +param.category.description=The category or group of the application. Generally speaking you will also want to specify application specific categories as well. param.category.default=Unknown param.copyright.name=Copyright param.copyright.description=The copyright for the application. @@ -176,3 +176,4 @@ ERR_LicenseFileNotExit=Error: Specified license file does not exist. ERR_BuildRootInvalid=Error: build-root ({0}) must be empty directory. ERR_InvalidOption=Error: Invalid Option: [{0}] +ERR_VersionComparison=Error: Failed to compare version {0} with {1}. diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties Wed Feb 27 19:45:26 2019 -0500 +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties Wed Feb 27 20:04:03 2019 -0500 @@ -43,7 +43,7 @@ param.build-root.name=Build Root param.build-root.description=The directory in which to use and place temporary files. param.category.name=Category -param.category.description=The category oor group of the application. Generally speaking you will also want to specify application specific categories as well. +param.category.description=The category or group of the application. Generally speaking you will also want to specify application specific categories as well. param.category.default=Unknown param.copyright.name=Copyright param.copyright.description=The copyright for the application. @@ -176,3 +176,4 @@ ERR_LicenseFileNotExit=Error: Specified license file does not exist. ERR_BuildRootInvalid=Error: build-root ({0}) must be empty directory. ERR_InvalidOption=Error: Invalid Option: [{0}] +ERR_VersionComparison=Error: Failed to compare version {0} with {1}. diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java Wed Feb 27 19:45:26 2019 -0500 +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinExeBundler.java Wed Feb 27 20:04:03 2019 -0500 @@ -200,39 +200,18 @@ return (Platform.getPlatform() == Platform.WINDOWS); } - static class VersionExtractor extends PrintStream { - double version = 0f; - - public VersionExtractor() { - super(new ByteArrayOutputStream()); - } - - double getVersion() { - if (version == 0f) { - String content = - new String(((ByteArrayOutputStream) out).toByteArray()); - Pattern pattern = Pattern.compile("Inno Setup (\\d+.?\\d*)"); - Matcher matcher = pattern.matcher(content); - if (matcher.find()) { - String v = matcher.group(1); - version = Double.parseDouble(v); - } - } - return version; - } - } - - private static double findToolVersion(String toolName) { + private static String findToolVersion(String toolName) { try { - if (toolName == null || "".equals(toolName)) return 0f; + if (toolName == null || "".equals(toolName)) return null; ProcessBuilder pb = new ProcessBuilder( toolName, "/?"); - VersionExtractor ve = new VersionExtractor(); + VersionExtractor ve = + new VersionExtractor("Inno Setup (\\d+.?\\d*)"); IOUtils.exec(pb, Log.isDebug(), true, ve); // not interested in the output - double version = ve.getVersion(); + String version = ve.getVersion(); Log.verbose(MessageFormat.format( getString("message.tool-version"), toolName, version)); return version; @@ -240,7 +219,7 @@ if (Log.isDebug()) { Log.verbose(e); } - return 0f; + return null; } } @@ -283,13 +262,13 @@ getString("error.copyright-is-too-long.advice")); } - double innoVersion = findToolVersion( + String innoVersion = findToolVersion( TOOL_INNO_SETUP_COMPILER_EXECUTABLE.fetchFrom(p)); //Inno Setup 5+ is required - double minVersion = 5.0f; + String minVersion = "5.0"; - if (innoVersion < minVersion) { + if (VersionExtractor.isLessThan(innoVersion, minVersion)) { Log.error(MessageFormat.format( getString("message.tool-wrong-version"), TOOL_INNO_SETUP_COMPILER, innoVersion, minVersion)); diff -r 8018ecf829bc -r bfa094e6ce15 src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java Wed Feb 27 19:45:26 2019 -0500 +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java Wed Feb 27 20:04:03 2019 -0500 @@ -243,39 +243,17 @@ return (Platform.getPlatform() == Platform.WINDOWS); } - static class VersionExtractor extends PrintStream { - double version = 0f; - - public VersionExtractor() { - super(new ByteArrayOutputStream()); - } - - double getVersion() { - if (version == 0f) { - String content = - new String(((ByteArrayOutputStream) out).toByteArray()); - Pattern pattern = Pattern.compile("version (\\d+.\\d+)"); - Matcher matcher = pattern.matcher(content); - if (matcher.find()) { - String v = matcher.group(1); - version = Double.parseDouble(v); - } - } - return version; - } - } - - private static double findToolVersion(String toolName) { + private static String findToolVersion(String toolName) { try { - if (toolName == null || "".equals(toolName)) return 0f; + if (toolName == null || "".equals(toolName)) return null; ProcessBuilder pb = new ProcessBuilder( toolName, "/?"); - VersionExtractor ve = new VersionExtractor(); + VersionExtractor ve = new VersionExtractor("version (\\d+.\\d+)"); // not interested in the output IOUtils.exec(pb, Log.isDebug(), true, ve); - double version = ve.getVersion(); + String version = ve.getVersion(); Log.verbose(MessageFormat.format( I18N.getString("message.tool-version"), toolName, version)); @@ -284,7 +262,7 @@ if (Log.isDebug()) { Log.verbose(e); } - return 0f; + return null; } } @@ -300,22 +278,22 @@ // we are not interested in return code, only possible exception APP_BUNDLER.fetchFrom(p).validate(p); - double candleVersion = + String candleVersion = findToolVersion(TOOL_CANDLE_EXECUTABLE.fetchFrom(p)); - double lightVersion = + String lightVersion = findToolVersion(TOOL_LIGHT_EXECUTABLE.fetchFrom(p)); // WiX 3.0+ is required - double minVersion = 3.0f; + String minVersion = "3.0"; boolean bad = false; - if (candleVersion < minVersion) { + if (VersionExtractor.isLessThan(candleVersion, minVersion)) { Log.verbose(MessageFormat.format( I18N.getString("message.wrong-tool-version"), TOOL_CANDLE, candleVersion, minVersion)); bad = true; } - if (lightVersion < minVersion) { + if (VersionExtractor.isLessThan(lightVersion, minVersion)) { Log.verbose(MessageFormat.format( I18N.getString("message.wrong-tool-version"), TOOL_LIGHT, lightVersion, minVersion)); @@ -328,7 +306,7 @@ I18N.getString("error.no-wix-tools.advice")); } - if (lightVersion >= 3.6f) { + if (!VersionExtractor.isLessThan(lightVersion, "3.6")) { Log.verbose(I18N.getString("message.use-wix36-features")); p.put(CAN_USE_WIX36.getID(), Boolean.TRUE); } @@ -743,7 +721,7 @@ out.println(prefix + " "); out.println(prefix + " "); out.println(prefix + "