-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8344587: Reduce number of "jdk.jpackage.internal" classes used from o…
…ther packages Reviewed-by: almatvee
- Loading branch information
Alexey Semenyuk
committed
Nov 22, 2024
1 parent
1114704
commit 70c4e2c
Showing
21 changed files
with
320 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/AppImageFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright (c) 2024, 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. | ||
* | ||
* 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.test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import javax.xml.xpath.XPath; | ||
import javax.xml.xpath.XPathFactory; | ||
import jdk.internal.util.OperatingSystem; | ||
import jdk.jpackage.internal.util.XmlUtils; | ||
import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier; | ||
import org.w3c.dom.Document; | ||
|
||
public record AppImageFile(String mainLauncherName, String mainLauncherClassName, | ||
String version, boolean macSigned, boolean macAppStore) { | ||
|
||
public static Path getPathInAppImage(Path appImageDir) { | ||
return ApplicationLayout.platformAppImage() | ||
.resolveAt(appImageDir) | ||
.appDirectory() | ||
.resolve(FILENAME); | ||
} | ||
|
||
public AppImageFile(String mainLauncherName, String mainLauncherClassName) { | ||
this(mainLauncherName, mainLauncherClassName, "1.0", false, false); | ||
} | ||
|
||
public void save(Path appImageDir) throws IOException { | ||
XmlUtils.createXml(getPathInAppImage(appImageDir), xml -> { | ||
xml.writeStartElement("jpackage-state"); | ||
xml.writeAttribute("version", getVersion()); | ||
xml.writeAttribute("platform", getPlatform()); | ||
|
||
xml.writeStartElement("app-version"); | ||
xml.writeCharacters(version); | ||
xml.writeEndElement(); | ||
|
||
xml.writeStartElement("main-launcher"); | ||
xml.writeCharacters(mainLauncherName); | ||
xml.writeEndElement(); | ||
|
||
xml.writeStartElement("main-class"); | ||
xml.writeCharacters(mainLauncherClassName); | ||
xml.writeEndElement(); | ||
|
||
xml.writeStartElement("signed"); | ||
xml.writeCharacters(Boolean.toString(macSigned)); | ||
xml.writeEndElement(); | ||
|
||
xml.writeStartElement("app-store"); | ||
xml.writeCharacters(Boolean.toString(macAppStore)); | ||
xml.writeEndElement(); | ||
}); | ||
} | ||
|
||
public static AppImageFile load(Path appImageDir) { | ||
return toSupplier(() -> { | ||
Document doc = XmlUtils.initDocumentBuilder().parse( | ||
Files.newInputStream(getPathInAppImage(appImageDir))); | ||
|
||
XPath xPath = XPathFactory.newInstance().newXPath(); | ||
|
||
var version = xPath.evaluate("/jpackage-state/app-version/text()", doc); | ||
|
||
var mainLauncherName = xPath.evaluate( | ||
"/jpackage-state/main-launcher/text()", doc); | ||
|
||
var mainLauncherClassName = xPath.evaluate( | ||
"/jpackage-state/main-class/text()", doc); | ||
|
||
var macSigned = Optional.ofNullable(xPath.evaluate( | ||
"/jpackage-state/signed/text()", doc)).map( | ||
Boolean::parseBoolean).orElse(false); | ||
|
||
var macAppStore = Optional.ofNullable(xPath.evaluate( | ||
"/jpackage-state/app-store/text()", doc)).map( | ||
Boolean::parseBoolean).orElse(false); | ||
|
||
return new AppImageFile(mainLauncherName, mainLauncherClassName, | ||
version, macSigned, macAppStore); | ||
|
||
}).get(); | ||
} | ||
|
||
private static String getVersion() { | ||
return System.getProperty("java.version"); | ||
} | ||
|
||
private static String getPlatform() { | ||
return PLATFORM_LABELS.get(OperatingSystem.current()); | ||
} | ||
|
||
private static final String FILENAME = ".jpackage.xml"; | ||
|
||
private static final Map<OperatingSystem, String> PLATFORM_LABELS = Map.of( | ||
OperatingSystem.LINUX, "linux", | ||
OperatingSystem.WINDOWS, "windows", | ||
OperatingSystem.MACOS, "macOS"); | ||
} |
126 changes: 126 additions & 0 deletions
126
test/jdk/tools/jpackage/helpers/jdk/jpackage/test/ApplicationLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright (c) 2024, 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.test; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Optional; | ||
|
||
public record ApplicationLayout(Path launchersDirectory, Path appDirectory, | ||
Path runtimeDirectory, Path runtimeHomeDirectory, Path appModsDirectory, | ||
Path destktopIntegrationDirectory, Path contentDirectory) { | ||
|
||
public ApplicationLayout resolveAt(Path root) { | ||
return new ApplicationLayout( | ||
resolve(root, launchersDirectory), | ||
resolve(root, appDirectory), | ||
resolve(root, runtimeDirectory), | ||
resolve(root, runtimeHomeDirectory), | ||
resolve(root, appModsDirectory), | ||
resolve(root, destktopIntegrationDirectory), | ||
resolve(root, contentDirectory)); | ||
} | ||
|
||
public static ApplicationLayout linuxAppImage() { | ||
return new ApplicationLayout( | ||
Path.of("bin"), | ||
Path.of("lib/app"), | ||
Path.of("lib/runtime"), | ||
Path.of("lib/runtime"), | ||
Path.of("lib/app/mods"), | ||
Path.of("lib"), | ||
Path.of("lib") | ||
); | ||
} | ||
|
||
public static ApplicationLayout windowsAppImage() { | ||
return new ApplicationLayout( | ||
Path.of(""), | ||
Path.of("app"), | ||
Path.of("runtime"), | ||
Path.of("runtime"), | ||
Path.of("app/mods"), | ||
Path.of(""), | ||
Path.of("") | ||
); | ||
} | ||
|
||
public static ApplicationLayout macAppImage() { | ||
return new ApplicationLayout( | ||
Path.of("Contents/MacOS"), | ||
Path.of("Contents/app"), | ||
Path.of("Contents/runtime"), | ||
Path.of("Contents/runtime/Contents/Home"), | ||
Path.of("Contents/app/mods"), | ||
Path.of("Contents/Resources"), | ||
Path.of("Contents") | ||
); | ||
} | ||
|
||
public static ApplicationLayout platformAppImage() { | ||
if (TKit.isWindows()) { | ||
return windowsAppImage(); | ||
} | ||
|
||
if (TKit.isLinux()) { | ||
return linuxAppImage(); | ||
} | ||
|
||
if (TKit.isOSX()) { | ||
return macAppImage(); | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown platform"); | ||
} | ||
|
||
public static ApplicationLayout javaRuntime() { | ||
return new ApplicationLayout( | ||
null, | ||
null, | ||
Path.of(""), | ||
null, | ||
null, | ||
null, | ||
null | ||
); | ||
} | ||
|
||
public static ApplicationLayout linuxUsrTreePackageImage(Path prefix, | ||
String packageName) { | ||
final Path lib = prefix.resolve(Path.of("lib", packageName)); | ||
return new ApplicationLayout( | ||
prefix.resolve("bin"), | ||
lib.resolve("app"), | ||
lib.resolve("runtime"), | ||
lib.resolve("runtime"), | ||
lib.resolve("app/mods"), | ||
lib, | ||
lib | ||
); | ||
} | ||
|
||
private static Path resolve(Path base, Path path) { | ||
return Optional.ofNullable(path).map(base::resolve).orElse(null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.