Skip to content

Commit 70c4e2c

Browse files
author
Alexey Semenyuk
committedNov 22, 2024
8344587: Reduce number of "jdk.jpackage.internal" classes used from other packages
Reviewed-by: almatvee
1 parent 1114704 commit 70c4e2c

21 files changed

+320
-93
lines changed
 

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/AppImageFile.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
import static jdk.jpackage.internal.StandardBundlerParam.APP_STORE;
6262
import jdk.jpackage.internal.util.XmlUtils;
6363

64-
public final class AppImageFile {
64+
final class AppImageFile {
6565

6666
// These values will be loaded from AppImage xml file.
6767
private final String appVersion;

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/IOUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*
4141
* A collection of static utility methods.
4242
*/
43-
public class IOUtils {
43+
final class IOUtils {
4444

4545
public static void copyFile(Path sourceFile, Path destFile)
4646
throws IOException {

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/PackageFile.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.Objects;
3232
import java.util.Optional;
3333

34-
public final class PackageFile {
34+
final class PackageFile {
3535

3636
/**
3737
* Returns path to package file.

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/PathUtils.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,23 @@
2626

2727
import java.nio.file.Path;
2828
import java.util.Optional;
29-
import jdk.jpackage.internal.IOUtils;
3029

3130
public final class PathUtils {
3231

3332
public static String getSuffix(Path path) {
34-
String filename = replaceSuffix(IOUtils.getFileName(path), null).toString();
35-
return IOUtils.getFileName(path).toString().substring(filename.length());
33+
String filename = replaceSuffix(path.getFileName(), null).toString();
34+
return path.getFileName().toString().substring(filename.length());
3635
}
3736

3837
public static Path addSuffix(Path path, String suffix) {
3938
Path parent = path.getParent();
40-
String filename = IOUtils.getFileName(path).toString() + suffix;
39+
String filename = path.getFileName().toString() + suffix;
4140
return parent != null ? parent.resolve(filename) : Path.of(filename);
4241
}
4342

4443
public static Path replaceSuffix(Path path, String suffix) {
4544
Path parent = path.getParent();
46-
String filename = IOUtils.getFileName(path).toString().replaceAll("\\.[^.]*$",
45+
String filename = path.getFileName().toString().replaceAll("\\.[^.]*$",
4746
"") + Optional.ofNullable(suffix).orElse("");
4847
return parent != null ? parent.resolve(filename) : Path.of(filename);
4948
}

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/util/XmlUtils.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@
3939
import javax.xml.transform.TransformerException;
4040
import javax.xml.transform.TransformerFactory;
4141
import javax.xml.transform.stax.StAXResult;
42-
import jdk.jpackage.internal.IOUtils;
4342

4443

4544
public final class XmlUtils {
4645

4746
public static void createXml(Path dstFile, XmlConsumer xmlConsumer) throws
4847
IOException {
4948
XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance();
50-
Files.createDirectories(IOUtils.getParent(dstFile));
49+
Files.createDirectories(dstFile.getParent());
5150
try (Writer w = Files.newBufferedWriter(dstFile)) {
5251
// Wrap with pretty print proxy
5352
XMLStreamWriter xml = (XMLStreamWriter) Proxy.newProxyInstance(XMLStreamWriter.class.getClassLoader(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package jdk.jpackage.test;
24+
25+
import java.io.IOException;
26+
import java.nio.file.Files;
27+
import java.nio.file.Path;
28+
import java.util.Map;
29+
import java.util.Optional;
30+
import javax.xml.xpath.XPath;
31+
import javax.xml.xpath.XPathFactory;
32+
import jdk.internal.util.OperatingSystem;
33+
import jdk.jpackage.internal.util.XmlUtils;
34+
import static jdk.jpackage.internal.util.function.ThrowingSupplier.toSupplier;
35+
import org.w3c.dom.Document;
36+
37+
public record AppImageFile(String mainLauncherName, String mainLauncherClassName,
38+
String version, boolean macSigned, boolean macAppStore) {
39+
40+
public static Path getPathInAppImage(Path appImageDir) {
41+
return ApplicationLayout.platformAppImage()
42+
.resolveAt(appImageDir)
43+
.appDirectory()
44+
.resolve(FILENAME);
45+
}
46+
47+
public AppImageFile(String mainLauncherName, String mainLauncherClassName) {
48+
this(mainLauncherName, mainLauncherClassName, "1.0", false, false);
49+
}
50+
51+
public void save(Path appImageDir) throws IOException {
52+
XmlUtils.createXml(getPathInAppImage(appImageDir), xml -> {
53+
xml.writeStartElement("jpackage-state");
54+
xml.writeAttribute("version", getVersion());
55+
xml.writeAttribute("platform", getPlatform());
56+
57+
xml.writeStartElement("app-version");
58+
xml.writeCharacters(version);
59+
xml.writeEndElement();
60+
61+
xml.writeStartElement("main-launcher");
62+
xml.writeCharacters(mainLauncherName);
63+
xml.writeEndElement();
64+
65+
xml.writeStartElement("main-class");
66+
xml.writeCharacters(mainLauncherClassName);
67+
xml.writeEndElement();
68+
69+
xml.writeStartElement("signed");
70+
xml.writeCharacters(Boolean.toString(macSigned));
71+
xml.writeEndElement();
72+
73+
xml.writeStartElement("app-store");
74+
xml.writeCharacters(Boolean.toString(macAppStore));
75+
xml.writeEndElement();
76+
});
77+
}
78+
79+
public static AppImageFile load(Path appImageDir) {
80+
return toSupplier(() -> {
81+
Document doc = XmlUtils.initDocumentBuilder().parse(
82+
Files.newInputStream(getPathInAppImage(appImageDir)));
83+
84+
XPath xPath = XPathFactory.newInstance().newXPath();
85+
86+
var version = xPath.evaluate("/jpackage-state/app-version/text()", doc);
87+
88+
var mainLauncherName = xPath.evaluate(
89+
"/jpackage-state/main-launcher/text()", doc);
90+
91+
var mainLauncherClassName = xPath.evaluate(
92+
"/jpackage-state/main-class/text()", doc);
93+
94+
var macSigned = Optional.ofNullable(xPath.evaluate(
95+
"/jpackage-state/signed/text()", doc)).map(
96+
Boolean::parseBoolean).orElse(false);
97+
98+
var macAppStore = Optional.ofNullable(xPath.evaluate(
99+
"/jpackage-state/app-store/text()", doc)).map(
100+
Boolean::parseBoolean).orElse(false);
101+
102+
return new AppImageFile(mainLauncherName, mainLauncherClassName,
103+
version, macSigned, macAppStore);
104+
105+
}).get();
106+
}
107+
108+
private static String getVersion() {
109+
return System.getProperty("java.version");
110+
}
111+
112+
private static String getPlatform() {
113+
return PLATFORM_LABELS.get(OperatingSystem.current());
114+
}
115+
116+
private static final String FILENAME = ".jpackage.xml";
117+
118+
private static final Map<OperatingSystem, String> PLATFORM_LABELS = Map.of(
119+
OperatingSystem.LINUX, "linux",
120+
OperatingSystem.WINDOWS, "windows",
121+
OperatingSystem.MACOS, "macOS");
122+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package jdk.jpackage.test;
26+
27+
import java.nio.file.Path;
28+
import java.util.Optional;
29+
30+
public record ApplicationLayout(Path launchersDirectory, Path appDirectory,
31+
Path runtimeDirectory, Path runtimeHomeDirectory, Path appModsDirectory,
32+
Path destktopIntegrationDirectory, Path contentDirectory) {
33+
34+
public ApplicationLayout resolveAt(Path root) {
35+
return new ApplicationLayout(
36+
resolve(root, launchersDirectory),
37+
resolve(root, appDirectory),
38+
resolve(root, runtimeDirectory),
39+
resolve(root, runtimeHomeDirectory),
40+
resolve(root, appModsDirectory),
41+
resolve(root, destktopIntegrationDirectory),
42+
resolve(root, contentDirectory));
43+
}
44+
45+
public static ApplicationLayout linuxAppImage() {
46+
return new ApplicationLayout(
47+
Path.of("bin"),
48+
Path.of("lib/app"),
49+
Path.of("lib/runtime"),
50+
Path.of("lib/runtime"),
51+
Path.of("lib/app/mods"),
52+
Path.of("lib"),
53+
Path.of("lib")
54+
);
55+
}
56+
57+
public static ApplicationLayout windowsAppImage() {
58+
return new ApplicationLayout(
59+
Path.of(""),
60+
Path.of("app"),
61+
Path.of("runtime"),
62+
Path.of("runtime"),
63+
Path.of("app/mods"),
64+
Path.of(""),
65+
Path.of("")
66+
);
67+
}
68+
69+
public static ApplicationLayout macAppImage() {
70+
return new ApplicationLayout(
71+
Path.of("Contents/MacOS"),
72+
Path.of("Contents/app"),
73+
Path.of("Contents/runtime"),
74+
Path.of("Contents/runtime/Contents/Home"),
75+
Path.of("Contents/app/mods"),
76+
Path.of("Contents/Resources"),
77+
Path.of("Contents")
78+
);
79+
}
80+
81+
public static ApplicationLayout platformAppImage() {
82+
if (TKit.isWindows()) {
83+
return windowsAppImage();
84+
}
85+
86+
if (TKit.isLinux()) {
87+
return linuxAppImage();
88+
}
89+
90+
if (TKit.isOSX()) {
91+
return macAppImage();
92+
}
93+
94+
throw new IllegalArgumentException("Unknown platform");
95+
}
96+
97+
public static ApplicationLayout javaRuntime() {
98+
return new ApplicationLayout(
99+
null,
100+
null,
101+
Path.of(""),
102+
null,
103+
null,
104+
null,
105+
null
106+
);
107+
}
108+
109+
public static ApplicationLayout linuxUsrTreePackageImage(Path prefix,
110+
String packageName) {
111+
final Path lib = prefix.resolve(Path.of("lib", packageName));
112+
return new ApplicationLayout(
113+
prefix.resolve("bin"),
114+
lib.resolve("app"),
115+
lib.resolve("runtime"),
116+
lib.resolve("runtime"),
117+
lib.resolve("app/mods"),
118+
lib,
119+
lib
120+
);
121+
}
122+
123+
private static Path resolve(Path base, Path path) {
124+
return Optional.ofNullable(path).map(base::resolve).orElse(null);
125+
}
126+
}

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/Functional.java

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package jdk.jpackage.test;
2424

25-
import java.lang.reflect.InvocationTargetException;
2625
import java.util.function.BiConsumer;
2726
import java.util.function.Consumer;
2827
import java.util.function.Function;

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageCommand.java

+12-51
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
import java.util.regex.Pattern;
4646
import java.util.stream.Collectors;
4747
import java.util.stream.Stream;
48-
import jdk.jpackage.internal.AppImageFile;
49-
import jdk.jpackage.internal.ApplicationLayout;
50-
import jdk.jpackage.internal.PackageFile;
51-
import jdk.jpackage.internal.util.XmlUtils;
5248
import static jdk.jpackage.test.AdditionalLauncher.forEachAdditionalLauncher;
5349
import jdk.jpackage.internal.util.function.ThrowingConsumer;
5450
import jdk.jpackage.internal.util.function.ThrowingFunction;
@@ -157,8 +153,10 @@ public String getArgumentValue(String argName,
157153
public <T> T getArgumentValue(String argName,
158154
Supplier<T> defaultValueSupplier,
159155
Function<String, T> stringConverter) {
160-
return getArgumentValue(argName, (unused) -> defaultValueSupplier.get(),
161-
stringConverter);
156+
return getArgumentValue(argName,
157+
Optional.ofNullable(defaultValueSupplier).map(supplier -> {
158+
return (Function<JPackageCommand, T>)unused -> supplier.get();
159+
}).orElse(null), stringConverter);
162160
}
163161

164162
public String getArgumentValue(String argName,
@@ -217,9 +215,9 @@ public String version() {
217215
}
218216

219217
public String name() {
220-
String appImage = getArgumentValue("--app-image", () -> null);
218+
String appImage = getArgumentValue("--app-image");
221219
if (appImage != null) {
222-
String name = AppImageFile.extractAppName(Path.of(appImage));
220+
String name = AppImageFile.load(Path.of(appImage)).mainLauncherName();
223221
// can be null if using foreign app-image
224222
return ((name != null) ? name : getArgumentValue("--name"));
225223
}
@@ -233,7 +231,7 @@ public String installerName() {
233231
if (installerName == null) {
234232
String appImage = getArgumentValue("--app-image");
235233
if (appImage != null) {
236-
installerName = AppImageFile.extractAppName(Path.of(appImage));
234+
installerName = AppImageFile.load(Path.of(appImage)).mainLauncherName();
237235
}
238236
}
239237
return installerName;
@@ -306,42 +304,6 @@ public JPackageCommand setFakeRuntime() {
306304
return this;
307305
}
308306

309-
public void createJPackageXMLFile(String mainLauncher, String mainClass)
310-
throws IOException {
311-
Path jpackageXMLFile = AppImageFile.getPathInAppImage(
312-
Optional.ofNullable(getArgumentValue("--app-image")).map(
313-
Path::of).orElseThrow(() -> {
314-
return new RuntimeException(
315-
"Error: --app-image expected");
316-
}));
317-
318-
XmlUtils.createXml(jpackageXMLFile, xml -> {
319-
xml.writeStartElement("jpackage-state");
320-
xml.writeAttribute("version", AppImageFile.getVersion());
321-
xml.writeAttribute("platform", AppImageFile.getPlatform());
322-
323-
xml.writeStartElement("app-version");
324-
xml.writeCharacters("1.0");
325-
xml.writeEndElement();
326-
327-
xml.writeStartElement("main-launcher");
328-
xml.writeCharacters(mainLauncher);
329-
xml.writeEndElement();
330-
331-
xml.writeStartElement("main-class");
332-
xml.writeCharacters(mainClass);
333-
xml.writeEndElement();
334-
335-
xml.writeStartElement("signed");
336-
xml.writeCharacters("false");
337-
xml.writeEndElement();
338-
339-
xml.writeStartElement("app-store");
340-
xml.writeCharacters("false");
341-
xml.writeEndElement();
342-
});
343-
}
344-
345307
JPackageCommand addPrerequisiteAction(ThrowingConsumer<JPackageCommand> action) {
346308
verifyMutable();
347309
prerequisiteActions.add(action);
@@ -935,7 +897,7 @@ JPackageCommand assertAppLayout() {
935897
private void assertAppImageFile() {
936898
Path appImageDir = Path.of("");
937899
if (isImagePackageType() && hasArgument("--app-image")) {
938-
appImageDir = Path.of(getArgumentValue("--app-image", () -> null));
900+
appImageDir = Path.of(getArgumentValue("--app-image"));
939901
}
940902

941903
final Path lookupPath = AppImageFile.getPathInAppImage(appImageDir);
@@ -956,12 +918,12 @@ private void assertAppImageFile() {
956918
AppImageFile aif = AppImageFile.load(rootDir);
957919

958920
boolean expectedValue = hasArgument("--mac-sign");
959-
boolean actualValue = aif.isSigned();
921+
boolean actualValue = aif.macSigned();
960922
TKit.assertEquals(Boolean.toString(expectedValue), Boolean.toString(actualValue),
961923
"Check for unexptected value in app image file for <signed>");
962924

963925
expectedValue = hasArgument("--mac-app-store");
964-
actualValue = aif.isAppStore();
926+
actualValue = aif.macAppStore();
965927
TKit.assertEquals(Boolean.toString(expectedValue), Boolean.toString(actualValue),
966928
"Check for unexptected value in app image file for <app-store>");
967929
}
@@ -975,9 +937,8 @@ private void assertPackageFile() {
975937
assertFileInAppImage(lookupPath, null);
976938
} else {
977939
if (TKit.isOSX() && hasArgument("--app-image")) {
978-
String appImage = getArgumentValue("--app-image",
979-
() -> null);
980-
if (AppImageFile.load(Path.of(appImage)).isSigned()) {
940+
String appImage = getArgumentValue("--app-image");
941+
if (AppImageFile.load(Path.of(appImage)).macSigned()) {
981942
assertFileInAppImage(lookupPath, null);
982943
} else {
983944
assertFileInAppImage(lookupPath, lookupPath);

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import java.util.regex.Pattern;
4141
import java.util.stream.Collectors;
4242
import java.util.stream.Stream;
43-
import jdk.jpackage.internal.ApplicationLayout;
4443
import jdk.jpackage.internal.util.PathUtils;
4544
import jdk.jpackage.internal.util.function.ThrowingConsumer;
4645
import jdk.jpackage.test.PackageTest.PackageHandlers;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package jdk.jpackage.test;
24+
25+
import java.nio.file.Path;
26+
27+
public final class PackageFile {
28+
29+
public static Path getPathInAppImage(Path appImageDir) {
30+
return ApplicationLayout.platformAppImage()
31+
.resolveAt(appImageDir)
32+
.appDirectory()
33+
.resolve(FILENAME);
34+
}
35+
36+
private static final String FILENAME = ".package";
37+
}

‎test/jdk/tools/jpackage/helpers/jdk/jpackage/test/PackageTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.util.stream.Collectors;
4646
import java.util.stream.Stream;
4747
import java.util.stream.StreamSupport;
48-
import jdk.jpackage.internal.ApplicationLayout;
4948
import jdk.jpackage.internal.util.function.ThrowingBiConsumer;
5049
import static jdk.jpackage.internal.util.function.ThrowingBiConsumer.toBiConsumer;
5150
import jdk.jpackage.internal.util.function.ThrowingConsumer;

‎test/jdk/tools/jpackage/macosx/SigningPackageFromTwoStepAppImageTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import java.nio.file.Path;
25-
import jdk.jpackage.internal.ApplicationLayout;
25+
import jdk.jpackage.test.ApplicationLayout;
2626
import jdk.jpackage.test.JPackageCommand;
2727
import jdk.jpackage.test.TKit;
2828
import jdk.jpackage.test.PackageTest;

‎test/jdk/tools/jpackage/macosx/SigningPackageTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import java.nio.file.Path;
25-
import jdk.jpackage.internal.ApplicationLayout;
25+
import jdk.jpackage.test.ApplicationLayout;
2626
import jdk.jpackage.test.JPackageCommand;
2727
import jdk.jpackage.test.PackageTest;
2828
import jdk.jpackage.test.PackageType;

‎test/jdk/tools/jpackage/macosx/SigningPackageTwoStepTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*/
2323

2424
import java.nio.file.Path;
25-
import jdk.jpackage.internal.ApplicationLayout;
25+
import jdk.jpackage.test.ApplicationLayout;
2626
import jdk.jpackage.test.JPackageCommand;
2727
import jdk.jpackage.test.TKit;
2828
import jdk.jpackage.test.PackageTest;

‎test/jdk/tools/jpackage/share/AppImagePackageTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.nio.file.Files;
2626
import java.io.IOException;
2727
import java.util.List;
28-
import jdk.jpackage.internal.AppImageFile;
28+
import jdk.jpackage.test.AppImageFile;
2929
import jdk.jpackage.test.Annotations.Parameter;
3030
import jdk.jpackage.test.TKit;
3131
import jdk.jpackage.test.JPackageCommand;
@@ -87,7 +87,7 @@ public static void testEmpty(boolean withIcon) throws IOException {
8787
cmd.addArguments("--icon", iconPath("icon"));
8888
}
8989
cmd.removeArgumentWithValue("--input");
90-
cmd.createJPackageXMLFile("EmptyAppImagePackageTest", "Hello");
90+
new AppImageFile("EmptyAppImagePackageTest", "Hello").save(appImageDir);
9191

9292
// on mac, with --app-image and without --mac-package-identifier,
9393
// will try to infer it from the image, so foreign image needs it.

‎test/jdk/tools/jpackage/share/AppVersionTest.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@
2626
import java.util.Collection;
2727
import java.util.ArrayList;
2828
import java.util.List;
29-
import javax.xml.xpath.XPathConstants;
3029
import javax.xml.xpath.XPathExpressionException;
31-
import javax.xml.xpath.XPathFactory;
32-
import jdk.jpackage.internal.AppImageFile;
30+
import jdk.jpackage.test.AppImageFile;
3331
import jdk.jpackage.test.Annotations.Parameters;
3432
import jdk.jpackage.test.Annotations.Test;
3533
import jdk.jpackage.test.JPackageCommand;
3634
import jdk.jpackage.test.PackageTest;
3735
import jdk.jpackage.test.TKit;
38-
import jdk.jpackage.internal.AppImageFile;
39-
import org.w3c.dom.Document;
4036

4137
/*
4238
* @test
@@ -116,10 +112,7 @@ public void test() throws XPathExpressionException, IOException {
116112
}
117113
cmd.executeAndAssertHelloAppImageCreated();
118114

119-
Document xml = AppImageFile.readXml(cmd.outputBundle());
120-
String actualVersion = XPathFactory.newInstance().newXPath().evaluate(
121-
"/jpackage-state/app-version/text()", xml, XPathConstants.STRING).toString();
122-
115+
String actualVersion = AppImageFile.load(cmd.outputBundle()).version();
123116
TKit.assertEquals(expectedVersion, actualVersion,
124117
"Check application version");
125118
}

‎test/jdk/tools/jpackage/share/InOutPathTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import java.util.function.Predicate;
3232
import java.util.stream.Stream;
3333
import jdk.internal.util.OperatingSystem;
34-
import jdk.jpackage.internal.AppImageFile;
35-
import jdk.jpackage.internal.ApplicationLayout;
36-
import jdk.jpackage.internal.PackageFile;
34+
import jdk.jpackage.test.AppImageFile;
35+
import jdk.jpackage.test.ApplicationLayout;
36+
import jdk.jpackage.test.PackageFile;
3737
import jdk.jpackage.test.Annotations.Parameters;
3838
import jdk.jpackage.test.Annotations.Test;
3939
import jdk.jpackage.internal.util.function.ThrowingConsumer;

‎test/jdk/tools/jpackage/share/ModulePathTest3.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,16 @@
2929
import java.util.Collection;
3030
import java.util.List;
3131
import javax.xml.xpath.XPathExpressionException;
32-
import javax.xml.xpath.XPathConstants;
33-
import javax.xml.xpath.XPathFactory;
34-
import jdk.jpackage.internal.AppImageFile;
32+
import jdk.jpackage.test.AppImageFile;
3533
import jdk.jpackage.test.HelloApp;
3634
import jdk.jpackage.test.JavaAppDesc;
3735
import jdk.jpackage.test.Annotations.Test;
38-
import jdk.jpackage.test.Annotations.Parameter;
3936
import jdk.jpackage.test.Annotations.Parameters;
4037
import jdk.jpackage.test.Executor;
4138
import jdk.jpackage.test.JPackageCommand;
4239
import jdk.jpackage.test.JavaTool;
4340
import jdk.jpackage.test.PackageType;
4441
import jdk.jpackage.test.TKit;
45-
import org.w3c.dom.Document;
4642

4743

4844
/*
@@ -105,11 +101,7 @@ private void testIt(String mainAppDesc) throws XPathExpressionException,
105101
cmd.executeAndAssertHelloAppImageCreated();
106102

107103
if (appDesc.moduleVersion() != null) {
108-
Document xml = AppImageFile.readXml(cmd.outputBundle());
109-
String actualVersion = XPathFactory.newInstance().newXPath().evaluate(
110-
"/jpackage-state/app-version/text()", xml,
111-
XPathConstants.STRING).toString();
112-
104+
String actualVersion = AppImageFile.load(cmd.outputBundle()).version();
113105
TKit.assertEquals(appDesc.moduleVersion(), actualVersion,
114106
"Check application version");
115107
}

‎test/jdk/tools/jpackage/share/PredefinedAppImageErrorTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Collection;
2929
import java.util.List;
3030

31+
import jdk.jpackage.test.AppImageFile;
3132
import jdk.jpackage.test.Annotations.Parameters;
3233
import jdk.jpackage.test.Annotations.Test;
3334
import jdk.jpackage.test.JPackageCommand;
@@ -111,7 +112,7 @@ private void getDummyAppImage(JPackageCommand cmd) throws IOException {
111112
Files.createFile(dummyAppFile);
112113

113114
cmd.addArguments("--app-image", dummyAppFolder.toString());
114-
cmd.createJPackageXMLFile("PredefinedAppImageErrorTest", "Hello");
115+
new AppImageFile("PredefinedAppImageErrorTest", "Hello").save(dummyAppFolder);
115116
}
116117

117118
}

‎test/jdk/tools/jpackage/share/RuntimeImageSymbolicLinksTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import java.nio.file.Files;
2525
import java.nio.file.Path;
26-
import jdk.jpackage.internal.ApplicationLayout;
26+
import jdk.jpackage.test.ApplicationLayout;
2727
import jdk.jpackage.test.TKit;
2828
import jdk.jpackage.test.Annotations.Test;
2929
import jdk.jpackage.test.JPackageCommand;

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Nov 22, 2024

@openjdk-notifier[bot]
Please sign in to comment.