mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8304914: Use OperatingSystem, Architecture, and Version in jpackage
Reviewed-by: asemenyuk
This commit is contained in:
parent
eae1f59da9
commit
c3cd481a9a
23 changed files with 104 additions and 195 deletions
|
@ -283,6 +283,7 @@ module java.base {
|
|||
java.smartcardio,
|
||||
jdk.charsets,
|
||||
jdk.jlink,
|
||||
jdk.jpackage,
|
||||
jdk.net;
|
||||
exports sun.net to
|
||||
java.net.http,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2023, 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
|
||||
|
@ -46,6 +46,7 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import static jdk.jpackage.internal.OverridableResource.createResource;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.ABOUT_URL;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
|
||||
|
@ -508,7 +509,7 @@ public class LinuxDebBundler extends LinuxPackageBundler {
|
|||
|
||||
@Override
|
||||
public boolean supported(boolean runtimeInstaller) {
|
||||
return Platform.isLinux() && (new ToolValidator(TOOL_DPKG_DEB).validate() == null);
|
||||
return OperatingSystem.isLinux() && (new ToolValidator(TOOL_DPKG_DEB).validate() == null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2023, 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
|
||||
|
@ -37,6 +37,7 @@ import java.util.Optional;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.INSTALLER_NAME;
|
||||
|
@ -331,7 +332,7 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
|
|||
|
||||
@Override
|
||||
public boolean supported(boolean runtimeInstaller) {
|
||||
return Platform.isLinux() && (createRpmbuildToolValidator().validate() == null);
|
||||
return OperatingSystem.isLinux() && (createRpmbuildToolValidator().validate() == null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2023, 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
|
||||
|
@ -49,6 +49,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
|
|||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import jdk.internal.util.OSVersion;
|
||||
import static jdk.jpackage.internal.MacAppBundler.BUNDLE_ID_SIGNING_PREFIX;
|
||||
import static jdk.jpackage.internal.MacAppBundler.DEVELOPER_ID_APP_SIGNING_KEY;
|
||||
import static jdk.jpackage.internal.MacBaseInstallerBundler.SIGNING_KEYCHAIN;
|
||||
|
@ -401,7 +403,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
|
|||
ENTITLEMENTS.fetchFrom(params));
|
||||
}
|
||||
restoreKeychainList(params);
|
||||
} else if (Platform.isMac()) {
|
||||
} else if (OperatingSystem.isMacOS()) {
|
||||
signAppBundle(params, root, "-", null, null);
|
||||
} else {
|
||||
// Calling signAppBundle() without signingIdentity will result in
|
||||
|
@ -608,9 +610,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
|
|||
|
||||
public static void addNewKeychain(Map<String, ? super Object> params)
|
||||
throws IOException, InterruptedException {
|
||||
if (Platform.getMajorVersion() < 10 ||
|
||||
(Platform.getMajorVersion() == 10 &&
|
||||
Platform.getMinorVersion() < 12)) {
|
||||
if (OSVersion.current().compareTo(new OSVersion(10, 12)) < 0) {
|
||||
// we need this for OS X 10.12+
|
||||
return;
|
||||
}
|
||||
|
@ -662,9 +662,7 @@ public class MacAppImageBuilder extends AbstractAppImageBuilder {
|
|||
|
||||
public static void restoreKeychainList(Map<String, ? super Object> params)
|
||||
throws IOException{
|
||||
if (Platform.getMajorVersion() < 10 ||
|
||||
(Platform.getMajorVersion() == 10 &&
|
||||
Platform.getMinorVersion() < 12)) {
|
||||
if (OSVersion.current().compareTo(new OSVersion(10, 12)) < 0) {
|
||||
// we need this for OS X 10.12+
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2023, 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
|
||||
|
@ -25,6 +25,9 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.Architecture;
|
||||
import jdk.internal.util.OSVersion;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.URI;
|
||||
|
@ -318,7 +321,7 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
|
|||
xml.writeAttribute("customize", "never");
|
||||
xml.writeAttribute("require-scripts", "false");
|
||||
xml.writeAttribute("hostArchitectures",
|
||||
Platform.isArmMac() ? "arm64" : "x86_64");
|
||||
Architecture.isAARCH64() ? "arm64" : "x86_64");
|
||||
xml.writeEndElement(); // </options>
|
||||
xml.writeStartElement("choices-outline");
|
||||
xml.writeStartElement("line");
|
||||
|
@ -597,9 +600,7 @@ public class MacPkgBundler extends MacBaseInstallerBundler {
|
|||
// maybe sign
|
||||
if (Optional.ofNullable(
|
||||
SIGN_BUNDLE.fetchFrom(params)).orElse(Boolean.TRUE)) {
|
||||
if (Platform.getMajorVersion() > 10 ||
|
||||
(Platform.getMajorVersion() == 10 &&
|
||||
Platform.getMinorVersion() >= 12)) {
|
||||
if (OSVersion.current().compareTo(new OSVersion(10, 12)) >= 0) {
|
||||
// we need this for OS X 10.12+
|
||||
Log.verbose(I18N.getString("message.signing.pkg"));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2023, 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
|
||||
|
@ -30,6 +30,9 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import jdk.jpackage.internal.Arguments.CLIOptions;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.LAUNCHER_DATA;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.APP_NAME;
|
||||
|
@ -128,7 +131,7 @@ class AddLauncherArguments {
|
|||
CLIOptions.LAUNCHER_AS_SERVICE.getId(), getOptionValue(
|
||||
CLIOptions.LAUNCHER_AS_SERVICE));
|
||||
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
Arguments.putUnlessNull(bundleParams,
|
||||
CLIOptions.WIN_CONSOLE_HINT.getId(),
|
||||
getOptionValue(CLIOptions.WIN_CONSOLE_HINT));
|
||||
|
@ -138,7 +141,7 @@ class AddLauncherArguments {
|
|||
getOptionValue(CLIOptions.WIN_MENU_HINT));
|
||||
}
|
||||
|
||||
if (Platform.isLinux()) {
|
||||
if (OperatingSystem.isLinux()) {
|
||||
Arguments.putUnlessNull(bundleParams, CLIOptions.LINUX_CATEGORY.getId(),
|
||||
getOptionValue(CLIOptions.LINUX_CATEGORY));
|
||||
Arguments.putUnlessNull(bundleParams, SHORTCUT_HINT.getID(),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -138,7 +140,7 @@ class AppImageBundler extends AbstractBundler {
|
|||
IOUtils.writableOutputDir(outputDirectory);
|
||||
|
||||
String imageName = APP_NAME.fetchFrom(params);
|
||||
if (Platform.isMac()) {
|
||||
if (OperatingSystem.isMacOS()) {
|
||||
imageName = imageName + ".app";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -42,6 +42,8 @@ import javax.xml.xpath.XPath;
|
|||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
@ -72,9 +74,10 @@ public final class AppImageFile {
|
|||
|
||||
private static final String FILENAME = ".jpackage.xml";
|
||||
|
||||
private static final Map<Platform, String> PLATFORM_LABELS = Map.of(
|
||||
Platform.LINUX, "linux", Platform.WINDOWS, "windows", Platform.MAC,
|
||||
"macOS");
|
||||
private static final Map<OperatingSystem, String> PLATFORM_LABELS = Map.of(
|
||||
OperatingSystem.LINUX, "linux",
|
||||
OperatingSystem.WINDOWS, "windows",
|
||||
OperatingSystem.MACOS, "macOS");
|
||||
|
||||
private AppImageFile(Path appImageDir, String appVersion, String launcherName,
|
||||
String mainClass, List<LauncherInfo> launcherInfos,
|
||||
|
@ -434,7 +437,7 @@ public final class AppImageFile {
|
|||
}
|
||||
|
||||
public static String getPlatform() {
|
||||
return PLATFORM_LABELS.get(Platform.getPlatform());
|
||||
return PLATFORM_LABELS.get(OperatingSystem.current());
|
||||
}
|
||||
|
||||
static class LauncherInfo {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -179,19 +181,19 @@ public final class ApplicationLayout implements PathGroup.Facade<ApplicationLayo
|
|||
}
|
||||
|
||||
public static ApplicationLayout platformAppImage() {
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
return windowsAppImage();
|
||||
}
|
||||
|
||||
if (Platform.isLinux()) {
|
||||
if (OperatingSystem.isLinux()) {
|
||||
return linuxAppImage();
|
||||
}
|
||||
|
||||
if (Platform.isMac()) {
|
||||
if (OperatingSystem.isMacOS()) {
|
||||
return macAppImage();
|
||||
}
|
||||
|
||||
throw Platform.throwUnknownPlatformError();
|
||||
throw new IllegalArgumentException("Unknown platform: " + OperatingSystem.current());
|
||||
}
|
||||
|
||||
public static ApplicationLayout javaRuntime() {
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
|
@ -578,7 +580,7 @@ public class Arguments {
|
|||
boolean hasRuntime = allOptions.contains(
|
||||
CLIOptions.PREDEFINED_RUNTIME_IMAGE);
|
||||
boolean installerOnly = !imageOnly && hasAppImage;
|
||||
boolean isMac = Platform.isMac();
|
||||
boolean isMac = OperatingSystem.isMacOS();
|
||||
runtimeInstaller = !imageOnly && hasRuntime && !hasAppImage &&
|
||||
!hasMainModule && !hasMainJar;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.io.File;
|
||||
import java.text.MessageFormat;
|
||||
|
@ -46,8 +48,7 @@ public class CLIHelp {
|
|||
if (noArgs) {
|
||||
Log.info(I18N.getString("MSG_Help_no_args"));
|
||||
} else {
|
||||
Platform platform = (Log.isVerbose()) ?
|
||||
Platform.UNKNOWN : Platform.getPlatform();
|
||||
OperatingSystem platform = OperatingSystem.current();
|
||||
String types;
|
||||
String pLaunchOptions;
|
||||
String pInstallOptions;
|
||||
|
@ -55,7 +56,7 @@ public class CLIHelp {
|
|||
String pAppImageDescription;
|
||||
String pSignSampleUsage;
|
||||
switch (platform) {
|
||||
case MAC:
|
||||
case MACOS:
|
||||
types = "{\"app-image\", \"dmg\", \"pkg\"}";
|
||||
pLaunchOptions = I18N.getString("MSG_Help_mac_launcher");
|
||||
pInstallOptions = I18N.getString("MSG_Help_mac_install");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
class I18N {
|
||||
|
@ -41,13 +43,13 @@ class I18N {
|
|||
private static final ResourceBundle PLATFORM;
|
||||
|
||||
static {
|
||||
if (Platform.isLinux()) {
|
||||
if (OperatingSystem.isLinux()) {
|
||||
PLATFORM = ResourceBundle.getBundle(
|
||||
"jdk.jpackage.internal.resources.LinuxResources");
|
||||
} else if (Platform.isWindows()) {
|
||||
} else if (OperatingSystem.isWindows()) {
|
||||
PLATFORM = ResourceBundle.getBundle(
|
||||
"jdk.jpackage.internal.resources.WinResources");
|
||||
} else if (Platform.isMac()) {
|
||||
} else if (OperatingSystem.isMacOS()) {
|
||||
PLATFORM = ResourceBundle.getBundle(
|
||||
"jdk.jpackage.internal.resources.MacResources");
|
||||
} else {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
|
@ -77,7 +79,7 @@ public class IOUtils {
|
|||
@Override
|
||||
public FileVisitResult visitFile(Path file,
|
||||
BasicFileAttributes attr) throws IOException {
|
||||
if (Platform.getPlatform() == Platform.WINDOWS) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
Files.setAttribute(file, "dos:readonly", false);
|
||||
}
|
||||
try {
|
||||
|
@ -91,7 +93,7 @@ public class IOUtils {
|
|||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir,
|
||||
BasicFileAttributes attr) throws IOException {
|
||||
if (Platform.getPlatform() == Platform.WINDOWS) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
Files.setAttribute(dir, "dos:readonly", false);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
@ -358,7 +360,7 @@ final class LauncherData {
|
|||
// of `release` file.
|
||||
|
||||
final Path releaseFile;
|
||||
if (!Platform.isMac()) {
|
||||
if (!OperatingSystem.isMacOS()) {
|
||||
releaseFile = cookedRuntime.resolve("release");
|
||||
} else {
|
||||
// On Mac `cookedRuntime` can be runtime root or runtime home.
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2022, 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.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Platform
|
||||
*
|
||||
* Use <code>Platform</code> to detect the operating system
|
||||
* that is currently running.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* Platform platform = Platform.getPlatform();
|
||||
*
|
||||
* switch(platform) {
|
||||
* case Platform.MAC: {
|
||||
* // Do something
|
||||
* break;
|
||||
* }
|
||||
* case Platform.WINDOWS:
|
||||
* case Platform.LINUX: {
|
||||
* // Do something else
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
enum Platform {UNKNOWN, WINDOWS, LINUX, MAC;
|
||||
private static final Platform platform;
|
||||
private static final int majorVersion;
|
||||
private static final int minorVersion;
|
||||
|
||||
static {
|
||||
String os = System.getProperty("os.name").toLowerCase();
|
||||
|
||||
if (os.indexOf("win") >= 0) {
|
||||
platform = Platform.WINDOWS;
|
||||
}
|
||||
else if (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0) {
|
||||
platform = Platform.LINUX;
|
||||
}
|
||||
else if (os.indexOf("mac") >= 0) {
|
||||
platform = Platform.MAC;
|
||||
}
|
||||
else {
|
||||
platform = Platform.UNKNOWN;
|
||||
}
|
||||
|
||||
String version = System.getProperty("os.version");
|
||||
String[] parts = version.split(Pattern.quote("."));
|
||||
|
||||
if (parts.length > 0) {
|
||||
majorVersion = Integer.parseInt(parts[0]);
|
||||
|
||||
if (parts.length > 1) {
|
||||
minorVersion = Integer.parseInt(parts[1]);
|
||||
}
|
||||
else {
|
||||
minorVersion = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
majorVersion = -1;
|
||||
minorVersion = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private Platform() {}
|
||||
|
||||
static Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
static int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
static int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
static boolean isWindows() {
|
||||
return getPlatform() == WINDOWS;
|
||||
}
|
||||
|
||||
static boolean isMac() {
|
||||
return getPlatform() == MAC;
|
||||
}
|
||||
|
||||
static boolean isArmMac() {
|
||||
return (isMac() && "aarch64".equals(System.getProperty("os.arch")));
|
||||
}
|
||||
|
||||
static boolean isLinux() {
|
||||
return getPlatform() == LINUX;
|
||||
}
|
||||
|
||||
static RuntimeException throwUnknownPlatformError() {
|
||||
throw new IllegalArgumentException("Unknown platform");
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -99,14 +101,14 @@ class ScriptRunner {
|
|||
}
|
||||
|
||||
private static String shell() {
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
return "cscript";
|
||||
}
|
||||
return Optional.ofNullable(System.getenv("SHELL")).orElseGet(() -> "sh");
|
||||
}
|
||||
|
||||
private static String scriptSuffix() {
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
return ".wsf";
|
||||
}
|
||||
return ".sh";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2014, 2023, 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -582,7 +584,7 @@ class StandardBundlerParam<T> extends BundlerParamInfo<T> {
|
|||
PREDEFINED_RUNTIME_IMAGE.getID()));
|
||||
}
|
||||
|
||||
if (Platform.isMac()) {
|
||||
if (OperatingSystem.isMacOS()) {
|
||||
// On Mac topImage can be runtime root or runtime home.
|
||||
Path runtimeHome = topImage.resolve("Contents/Home");
|
||||
if (Files.isDirectory(runtimeHome)) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -24,6 +24,8 @@
|
|||
*/
|
||||
package jdk.jpackage.internal;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.text.MessageFormat;
|
||||
|
@ -45,7 +47,7 @@ public final class ToolValidator {
|
|||
this.toolPath = toolPath;
|
||||
args = new ArrayList<>();
|
||||
|
||||
if (Platform.getPlatform() == Platform.LINUX) {
|
||||
if (OperatingSystem.isLinux()) {
|
||||
setCommandLine("--version");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2023, 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
|
||||
|
@ -27,6 +27,7 @@ package jdk.jpackage.internal;
|
|||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import jdk.jpackage.internal.Arguments.CLIOptions;
|
||||
|
||||
/**
|
||||
|
@ -94,7 +95,7 @@ class ValidOptions {
|
|||
put(CLIOptions.LICENSE_FILE.getId(), USE.INSTALL);
|
||||
put(CLIOptions.INSTALL_DIR.getId(), USE.INSTALL);
|
||||
put(CLIOptions.PREDEFINED_APP_IMAGE.getId(),
|
||||
(Platform.getPlatform() == Platform.MAC) ?
|
||||
(OperatingSystem.isMacOS()) ?
|
||||
EnumSet.of(USE.INSTALL, USE.SIGN) :
|
||||
EnumSet.of(USE.INSTALL));
|
||||
put(CLIOptions.LAUNCHER_AS_SERVICE.getId(), USE.INSTALL);
|
||||
|
@ -102,9 +103,9 @@ class ValidOptions {
|
|||
put(CLIOptions.ABOUT_URL.getId(), USE.INSTALL);
|
||||
|
||||
put(CLIOptions.FILE_ASSOCIATIONS.getId(),
|
||||
(Platform.getPlatform() == Platform.MAC) ? USE.ALL : USE.INSTALL);
|
||||
(OperatingSystem.isMacOS()) ? USE.ALL : USE.INSTALL);
|
||||
|
||||
if (Platform.getPlatform() == Platform.WINDOWS) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
put(CLIOptions.WIN_CONSOLE_HINT.getId(), USE.LAUNCHER);
|
||||
|
||||
put(CLIOptions.WIN_HELP_URL.getId(), USE.INSTALL);
|
||||
|
@ -120,7 +121,7 @@ class ValidOptions {
|
|||
USE.INSTALL);
|
||||
}
|
||||
|
||||
if (Platform.getPlatform() == Platform.MAC) {
|
||||
if (OperatingSystem.isMacOS()) {
|
||||
put(CLIOptions.MAC_SIGN.getId(),
|
||||
EnumSet.of(USE.ALL, USE.SIGN));
|
||||
put(CLIOptions.MAC_BUNDLE_NAME.getId(), USE.ALL);
|
||||
|
@ -138,7 +139,7 @@ class ValidOptions {
|
|||
put(CLIOptions.DMG_CONTENT.getId(), USE.INSTALL);
|
||||
}
|
||||
|
||||
if (Platform.getPlatform() == Platform.LINUX) {
|
||||
if (OperatingSystem.isLinux()) {
|
||||
put(CLIOptions.LINUX_BUNDLE_NAME.getId(), USE.INSTALL);
|
||||
put(CLIOptions.LINUX_DEB_MAINTAINER.getId(), USE.INSTALL);
|
||||
put(CLIOptions.LINUX_CATEGORY.getId(), USE.INSTALL);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2023, 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
|
||||
|
@ -26,6 +26,8 @@
|
|||
package jdk.jpackage.internal;
|
||||
|
||||
import java.util.List;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import jdk.internal.util.OSVersion;
|
||||
|
||||
final class WindowsDefender {
|
||||
|
||||
|
@ -34,8 +36,8 @@ final class WindowsDefender {
|
|||
static final boolean isThereAPotentialWindowsDefenderIssue(String dir) {
|
||||
boolean result = false;
|
||||
|
||||
if (Platform.getPlatform() == Platform.WINDOWS &&
|
||||
Platform.getMajorVersion() == 10) {
|
||||
if (OperatingSystem.isWindows() &&
|
||||
OSVersion.current().major() == 10) {
|
||||
|
||||
// If DisableRealtimeMonitoring is not enabled then there
|
||||
// may be a problem.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2021, 2023, 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
|
||||
|
@ -42,6 +42,7 @@ import jdk.jpackage.internal.IOUtils.XmlConsumer;
|
|||
import jdk.jpackage.internal.OverridableResource.Source;
|
||||
import static jdk.jpackage.internal.OverridableResource.createResource;
|
||||
import static jdk.jpackage.internal.StandardBundlerParam.CONFIG_ROOT;
|
||||
import jdk.internal.util.Architecture;
|
||||
|
||||
/**
|
||||
* Creates WiX fragment.
|
||||
|
@ -102,7 +103,7 @@ abstract class WixFragmentBuilder {
|
|||
}
|
||||
|
||||
static boolean is64Bit() {
|
||||
return !("x86".equals(System.getProperty("os.arch")));
|
||||
return Architecture.is64bit();
|
||||
}
|
||||
|
||||
protected Path getConfigRoot() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -32,6 +32,8 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import jdk.jpackage.internal.resources.ResourceLocator;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
|
@ -198,17 +200,17 @@ public class OverridableResourceTest {
|
|||
private final static String DEFAULT_NAME;
|
||||
private final static Map<String, String> SUBSTITUTION_DATA;
|
||||
static {
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
DEFAULT_NAME = "WinLauncher.template";
|
||||
SUBSTITUTION_DATA = Map.of("COMPANY_NAME", "Foo9090345");
|
||||
} else if (Platform.isLinux()) {
|
||||
} else if (OperatingSystem.isLinux()) {
|
||||
DEFAULT_NAME = "template.control";
|
||||
SUBSTITUTION_DATA = Map.of("APPLICATION_PACKAGE", "Package1967");
|
||||
} else if (Platform.isMac()) {
|
||||
} else if (OperatingSystem.isMacOS()) {
|
||||
DEFAULT_NAME = "Info-lite.plist.template";
|
||||
SUBSTITUTION_DATA = Map.of("DEPLOY_BUNDLE_IDENTIFIER", "12345");
|
||||
} else {
|
||||
throw Platform.throwUnknownPlatformError();
|
||||
throw new IllegalArgumentException("Unknown platform: " + OperatingSystem.current());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2023, 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
|
||||
|
@ -24,6 +24,7 @@
|
|||
package jdk.jpackage.internal;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -93,7 +94,7 @@ public class ToolValidatorTest {
|
|||
|
||||
static {
|
||||
String fname = "java";
|
||||
if (Platform.isWindows()) {
|
||||
if (OperatingSystem.isWindows()) {
|
||||
fname = fname + ".exe";
|
||||
}
|
||||
TOOL_JAVA = Path.of(System.getProperty("java.home"), "bin", fname).toString();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue