Skip to content

Commit f9d2fb8

Browse files
committed
8227529: With malformed --app-image the error messages are awful
Backport-of: 56d4c33f4096d98d08eba870070b5f21125f80be
1 parent ddddc1a commit f9d2fb8

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ public Path outputBundle() {
423423
return outputDir().resolve(bundleName);
424424
}
425425

426+
Optional<Path> nullableOutputBundle() {
427+
try {
428+
return Optional.ofNullable(outputBundle());
429+
} catch (Exception ex) {
430+
return Optional.empty();
431+
}
432+
}
433+
426434
/**
427435
* Returns application layout.
428436
*
@@ -749,11 +757,15 @@ public Executor.Result execute(int expectedExitCode) {
749757
if (hasArgument("--dest")) {
750758
if (isImagePackageType()) {
751759
TKit.deleteDirectoryContentsRecursive(outputDir());
752-
} else if (ThrowingSupplier.toSupplier(() -> TKit.deleteIfExists(
753-
outputBundle())).get()) {
754-
TKit.trace(
755-
String.format("Deleted [%s] file before running jpackage",
756-
outputBundle()));
760+
} else {
761+
nullableOutputBundle().ifPresent(path -> {
762+
if (ThrowingSupplier.toSupplier(() -> TKit.deleteIfExists(
763+
path)).get()) {
764+
TKit.trace(String.format(
765+
"Deleted [%s] file before running jpackage",
766+
path));
767+
}
768+
});
757769
}
758770
}
759771

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -582,7 +582,9 @@ public void accept(Action action, JPackageCommand cmd) {
582582
if (expectedJPackageExitCode == 0) {
583583
TKit.assertFileExists(cmd.outputBundle());
584584
} else {
585-
TKit.assertPathExists(cmd.outputBundle(), false);
585+
cmd.nullableOutputBundle().ifPresent(outputBundle -> {
586+
TKit.assertPathExists(outputBundle, false);
587+
});
586588
}
587589
verifyPackageBundle(cmd, result);
588590
break;

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

+50
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.nio.file.Files;
2626
import java.io.IOException;
2727
import java.util.List;
28+
import jdk.jpackage.internal.AppImageFile;
2829
import jdk.jpackage.test.Annotations.Parameter;
2930
import jdk.jpackage.test.TKit;
3031
import jdk.jpackage.test.JPackageCommand;
@@ -101,6 +102,55 @@ public static void testEmpty(boolean withIcon) throws IOException {
101102
// default: {CREATE, UNPACK, VERIFY}, but we can't verify foreign image
102103
}
103104

105+
@Test
106+
public static void testBadAppImage() throws IOException {
107+
Path appImageDir = TKit.createTempDirectory("appimage");
108+
Files.createFile(appImageDir.resolve("foo"));
109+
configureAppImageWithoutJPackageXMLFile(appImageDir).addInitializer(
110+
cmd -> {
111+
cmd.removeArgumentWithValue("--name");
112+
}).run(Action.CREATE);
113+
}
114+
115+
@Test
116+
public static void testBadAppImage2() throws IOException {
117+
Path appImageDir = TKit.createTempDirectory("appimage");
118+
Files.createFile(appImageDir.resolve("foo"));
119+
configureAppImageWithoutJPackageXMLFile(appImageDir).run(Action.CREATE);
120+
}
121+
122+
@Test
123+
public static void testBadAppImage3() throws IOException {
124+
Path appImageDir = TKit.createTempDirectory("appimage");
125+
126+
JPackageCommand appImageCmd = JPackageCommand.helloAppImage().
127+
setFakeRuntime().setArgumentValue("--dest", appImageDir);
128+
129+
configureAppImageWithoutJPackageXMLFile(appImageCmd.outputBundle()).
130+
addRunOnceInitializer(() -> {
131+
appImageCmd.execute();
132+
Files.delete(AppImageFile.getPathInAppImage(appImageCmd.
133+
outputBundle()));
134+
}).run(Action.CREATE);
135+
}
136+
137+
private static PackageTest configureAppImageWithoutJPackageXMLFile(
138+
Path appImageDir) {
139+
return new PackageTest()
140+
.addInitializer(cmd -> {
141+
cmd.saveConsoleOutput(true);
142+
cmd.addArguments("--app-image", appImageDir);
143+
cmd.removeArgumentWithValue("--input");
144+
cmd.ignoreDefaultVerbose(true); // no "--verbose" option
145+
})
146+
.addBundleVerifier((cmd, result) -> {
147+
TKit.assertTextStream(
148+
"Error: Missing .jpackage.xml file in app-image dir").apply(
149+
result.getOutput().stream());
150+
})
151+
.setExpectedExitCode(1);
152+
}
153+
104154
private static Path iconPath(String name) {
105155
return TKit.TEST_SRC_ROOT.resolve(Path.of("resources", name
106156
+ TKit.ICON_SUFFIX));

0 commit comments

Comments
 (0)