Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8237967: No proper error message when --runtime-image points to non-e…
…xistent path

Reviewed-by: kizune, asemenyuk, almatvee
  • Loading branch information
Andy Herrick committed Mar 3, 2020
1 parent e44dcf0 commit aa547959657672e85b0a9b3b9328390a0689ccc3
@@ -262,6 +262,30 @@ public void validate() throws PackagerException {
}
}

// Validate resource dir
String resources = (String)bundlerArguments.get(
Arguments.CLIOptions.RESOURCE_DIR.getId());
if (resources != null) {
if (!(new File(resources)).exists()) {
throw new PackagerException(
"message.resource-dir-does-not-exist",
Arguments.CLIOptions.RESOURCE_DIR.getId(), resources);
}
}

// Validate predefined runtime dir
String runtime = (String)bundlerArguments.get(
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId());
if (runtime != null) {
if (!(new File(runtime)).exists()) {
throw new PackagerException(
"message.runtime-image-dir-does-not-exist",
Arguments.CLIOptions.PREDEFINED_RUNTIME_IMAGE.getId(),
runtime);
}
}


// Validate license file if set
String license = (String)bundlerArguments.get(
Arguments.CLIOptions.LICENSE_FILE.getId());
@@ -33,10 +33,11 @@ message.no-default-resource=no default package resource {0} {1} (add {2} to the
message.using-custom-resource-from-file=Using custom package resource {0} (loaded from file {1}).
message.using-custom-resource=Using custom package resource {0} (loaded from {1}).
message.creating-app-bundle=Creating app package: {0} in {1}
message.app-image-dir-does-not-exist=Specified application image directory {0}: {1} does not exists
message.app-image-dir-does-not-exist=Specified application image directory {0}: {1} does not exist
message.app-image-dir-does-not-exist.advice=Confirm that the value for {0} exists
message.runtime-image-dir-does-not-exist=Specified runtime image directory {0}: {1} does not exists
message.runtime-image-dir-does-not-exist=Specified runtime image directory {0}: {1} does not exist
message.runtime-image-dir-does-not-exist.advice=Confirm that the value for {0} exists
message.resource-dir-does-not-exist=Specified resource directory {0}: {1} does not exist
message.debug-working-directory=Kept working directory for debug: {0}
message.bundle-created=Succeeded in building {0} package
message.module-version=Using version "{0}" from module "{1}" as application version
@@ -37,6 +37,7 @@ message.app-image-dir-does-not-exist=\u6307\u5B9A\u3055\u308C\u305F\u30A2\u30D7\
message.app-image-dir-does-not-exist.advice={0}\u306E\u5024\u304C\u5B58\u5728\u3059\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044
message.runtime-image-dir-does-not-exist=\u6307\u5B9A\u3055\u308C\u305F\u30E9\u30F3\u30BF\u30A4\u30E0\u30FB\u30A4\u30E1\u30FC\u30B8\u30FB\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA {0}: {1}\u306F\u5B58\u5728\u3057\u307E\u305B\u3093
message.runtime-image-dir-does-not-exist.advice={0}\u306E\u5024\u304C\u5B58\u5728\u3059\u308B\u3053\u3068\u3092\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044
message.resource-dir-does-not-exist=Specified resource directory {0}: {1} does not exist
message.debug-working-directory=\u30C7\u30D0\u30C3\u30B0\u306E\u4F5C\u696D\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u304C\u4FDD\u6301\u3055\u308C\u307E\u3057\u305F: {0}
message.bundle-created={0}\u30D1\u30C3\u30B1\u30FC\u30B8\u306E\u4F5C\u6210\u306B\u6210\u529F\u3057\u307E\u3057\u305F
message.module-version=\u30E2\u30B8\u30E5\u30FC\u30EB"{1}"\u306E\u30D0\u30FC\u30B8\u30E7\u30F3"{0}"\u3092\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u30FB\u30D0\u30FC\u30B8\u30E7\u30F3\u3068\u3057\u3066\u4F7F\u7528
@@ -37,6 +37,7 @@ message.app-image-dir-does-not-exist=\u6307\u5B9A\u7684\u5E94\u7528\u7A0B\u5E8F\
message.app-image-dir-does-not-exist.advice=\u786E\u8BA4 {0} \u7684\u503C\u662F\u5426\u5B58\u5728
message.runtime-image-dir-does-not-exist=\u6307\u5B9A\u7684\u8FD0\u884C\u65F6\u6620\u50CF\u76EE\u5F55 {0}: {1} \u4E0D\u5B58\u5728
message.runtime-image-dir-does-not-exist.advice=\u786E\u8BA4 {0} \u7684\u503C\u662F\u5426\u5B58\u5728
message.resource-dir-does-not-exist=Specified resource directory {0}: {1} does not exist
message.debug-working-directory=\u7528\u4E8E\u8C03\u8BD5\u7684\u5DF2\u4FDD\u7559\u5DE5\u4F5C\u76EE\u5F55: {0}
message.bundle-created=\u5DF2\u6210\u529F\u5730\u6784\u5EFA {0} \u7A0B\u5E8F\u5305
message.module-version=\u6B63\u5728\u5C06\u6A21\u5757 "{1}" \u4E2D\u7684\u7248\u672C "{0}" \u7528\u4F5C\u5E94\u7528\u7A0B\u5E8F\u7248\u672C
@@ -21,22 +21,30 @@
* questions.
*/

import jdk.incubator.jpackage.internal.Bundlers;
import jdk.incubator.jpackage.internal.Bundler;

/*
* @test
* @summary jpackage invalid argument test
* @library ../helpers
* @build JPackageHelper
* @build JPackagePath
* @modules jdk.incubator.jpackage
* @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
* @run main/othervm -Xmx512m InvalidArgTest
*/
public class InvalidArgTest {

private static final String ARG1 = "--no-such-argument";
private static final String ARG2 = "--dest";
private static final String ARG3 = "--runtime-image";
private static final String ARG4 = "--resource-dir";

private static final String RESULT1 =
"Invalid Option: [--no-such-argument]";
private static final String RESULT2 = "--main-jar or --module";
private static final String RESULT3 = "does not exist";
private static final String RESULT4 = "does not exist";

private static void validate(String arg, String output) throws Exception {
String[] result = JPackageHelper.splitAndFilter(output);
@@ -58,7 +66,29 @@ private static void validate(String arg, String output) throws Exception {
System.err.println("Actual: " + result[0]);
throw new AssertionError("Unexpected output: " + result[0]);
}
} else if (arg.equals(ARG3)) {
if (!result[0].trim().contains(RESULT3)) {
System.err.println("Expected error msg to contain: " + RESULT3);
System.err.println("Actual: " + result[0]);
throw new AssertionError("Unexpected output: " + result[0]);
}
} else if (arg.equals(ARG4)) {
if (!result[0].trim().contains(RESULT4)) {
System.err.println("Expected error msg to contain: " + RESULT4);
System.err.println("Actual: " + result[0]);
throw new AssertionError("Unexpected output: " + result[0]);
}
}
}

private static boolean defaultSupported() {
for (Bundler bundler :
Bundlers.createBundlersInstance().getBundlers("INSTALLER")) {
if (bundler.isDefault() && bundler.supported(true)) {
return true;
}
}
return false;
}

private static void testInvalidArg() throws Exception {
@@ -69,6 +99,15 @@ private static void testInvalidArg() throws Exception {
output = JPackageHelper.executeCLI(false,
"--type", "app-image", ARG2);
validate(ARG2, output);

output = JPackageHelper.executeCLI(false,
ARG3, "JDK-non-existant");
validate(ARG3, output);

output = JPackageHelper.executeCLI(false,
ARG3, System.getProperty("java.home"),
ARG4, "non-existant-resource-dir");
validate(ARG4, output);
}

private static void testInvalidArgToolProvider() throws Exception {
@@ -79,6 +118,15 @@ private static void testInvalidArgToolProvider() throws Exception {
output = JPackageHelper.executeToolProvider(false,
"--type", "app-image", ARG2);
validate(ARG2, output);

output = JPackageHelper.executeToolProvider(false,
ARG3, "JDK-non-existant");
validate(ARG3, output);

output = JPackageHelper.executeCLI(false,
ARG3, System.getProperty("java.home"),
ARG4, "non-existant-resource-dir");
validate(ARG4, output);
}

public static void main(String[] args) throws Exception {

0 comments on commit aa54795

Please sign in to comment.