Skip to content

Commit 56d4c33

Browse files
author
Alexey Semenyuk
committed
8227529: With malformed --app-image the error messages are awful
Reviewed-by: almatvee
1 parent 76fea80 commit 56d4c33

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;
@@ -102,6 +103,55 @@ public static void testEmpty(boolean withIcon) throws IOException {
102103
// default: {CREATE, UNPACK, VERIFY}, but we can't verify foreign image
103104
}
104105

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

0 commit comments

Comments
 (0)