8222901: different behavior when --name option not used
Reviewed-by: asemenyuk, almatvee
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractImageBundler.java Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/AbstractImageBundler.java Thu Jun 06 19:07:18 2019 -0400
@@ -128,6 +128,11 @@
name, outputDirectory.getAbsolutePath()));
}
+ // NAME will default to CLASS, so the real problem is no MAIN_CLASS
+ if (name == null) {
+ throw new PackagerException("ERR_NoMainClass");
+ }
+
// Create directory structure
File rootDirectory = new File(outputDirectory, name);
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/JLinkBundlerHelper.java Thu Jun 06 19:07:18 2019 -0400
@@ -182,6 +182,12 @@
static void execute(Map<String, ? super Object> params,
AbstractAppImageBuilder imageBuilder)
throws IOException, Exception {
+
+ // we might be able to build it (with no main class) but it won't run
+ if (StandardBundlerParam.MAIN_CLASS.fetchFrom(params) == null) {
+ throw new PackagerException("ERR_NoMainClass");
+ }
+
List<Path> modulePath =
StandardBundlerParam.MODULE_PATH.fetchFrom(params);
Set<String> addModules =
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/StandardBundlerParam.java Thu Jun 06 19:07:18 2019 -0400
@@ -161,6 +161,9 @@
BundleParams.PARAM_APPLICATION_CLASS);
if (s == null) {
s = JLinkBundlerHelper.getMainClass(params);
+ if (s.length() == 0) {
+ s = null;
+ }
}
return s;
},
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties Thu Jun 06 19:07:18 2019 -0400
@@ -47,8 +47,6 @@
error.cannot-create-output-dir=Output directory {0} cannot be created.
error.cannot-write-to-output-dir=Output directory {0} is not writable.
error.root-exists=Error: Application output directory {0} already exists.
-error.no-application-class=Main application class is missing.
-error.no-application-class.advice=Please specify main application class.
error.no-main-class-with-main-jar=A main class was not specified nor was one found in the jar {0}.
error.no-main-class-with-main-jar.advice=Specify a main class or ensure that the jar {0} specifies one in the manifest.
error.no-main-class=A main class was not specified nor was one found in the supplied application resources.
@@ -69,8 +67,7 @@
MSG_Version=jpackage version
MSG_BundlerFailed=Error: Bundler "{1}" ({0}) failed to produce a bundle.
-
-
+ERR_NoMainClass=Error: Main application class is missing.
ERR_UnsupportedOption=Error: Option [{0}] is not valid on this platform.
ERR_NotImageOption=Error: Option [{0}] is not valid in create-app-image mode.
ERR_NotInstallerOption=Error: Option [{0}] is not valid with --app-image option.
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_ja.properties Thu Jun 06 19:07:18 2019 -0400
@@ -47,8 +47,6 @@
error.cannot-create-output-dir=Output directory {0} cannot be created.
error.cannot-write-to-output-dir=Output directory {0} is not writable.
error.root-exists=Error: Application output directory {0} already exists.
-error.no-application-class=Main application class is missing.
-error.no-application-class.advice=Please specify main application class.
error.no-main-class-with-main-jar=A main class was not specified nor was one found in the jar {0}.
error.no-main-class-with-main-jar.advice=Specify a main class or ensure that the jar {0} specifies one in the manifest.
error.no-main-class=A main class was not specified nor was one found in the supplied application resources.
@@ -69,8 +67,7 @@
MSG_Version=jpackage version
MSG_BundlerFailed=Error: Bundler "{1}" ({0}) failed to produce a bundle.
-
-
+ERR_NoMainClass=Error: Main application class is missing.
ERR_UnsupportedOption=Error: Option [{0}] is not valid on this platform.
ERR_NotImageOption=Error: Option [{0}] is not valid in create-app-image mode.
ERR_NotInstallerOption=Error: Option [{0}] is not valid with --app-image option.
--- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties Fri May 31 08:26:31 2019 -0400
+++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources_zh_CN.properties Thu Jun 06 19:07:18 2019 -0400
@@ -47,8 +47,6 @@
error.cannot-create-output-dir=Output directory {0} cannot be created.
error.cannot-write-to-output-dir=Output directory {0} is not writable.
error.root-exists=Error: Application output directory {0} already exists.
-error.no-application-class=Main application class is missing.
-error.no-application-class.advice=Please specify main application class.
error.no-main-class-with-main-jar=A main class was not specified nor was one found in the jar {0}.
error.no-main-class-with-main-jar.advice=Specify a main class or ensure that the jar {0} specifies one in the manifest.
error.no-main-class=A main class was not specified nor was one found in the supplied application resources.
@@ -69,8 +67,7 @@
MSG_Version=jpackage version
MSG_BundlerFailed=Error: Bundler "{1}" ({0}) failed to produce a bundle.
-
-
+ERR_NoMainClass=Error: Main application class is missing.
ERR_UnsupportedOption=Error: Option [{0}] is not valid on this platform.
ERR_NotImageOption=Error: Option [{0}] is not valid in create-app-image mode.
ERR_NotInstallerOption=Error: Option [{0}] is not valid with --app-image option.
--- a/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleMainClassErrorTest.java Fri May 31 08:26:31 2019 -0400
+++ b/test/jdk/tools/jpackage/createappimage/JPackageCreateAppImageModuleMainClassErrorTest.java Thu Jun 06 19:07:18 2019 -0400
@@ -39,20 +39,27 @@
private static final String appOutput = JPackagePath.getAppOutputFile();
private static final String appWorkingDir = JPackagePath.getAppWorkingDir();
- private static final String [] CMD = {
+ private static final String [] CMD1 = {
"create-app-image",
"--output", OUTPUT,
"--name", "test",
"--module", "com.hello",
"--module-path", "input"};
+ private static final String [] CMD2 = {
+ "create-app-image",
+ "--output", OUTPUT,
+ "--name", "test",
+ "--module", "com.hello/com.hello.Hello",
+ "--module-path", "input"};
+
private static void validate(String buildOutput) throws Exception {
File outfile = new File(appWorkingDir + File.separator + appOutput);
int retVal = JPackageHelper.execute(outfile, app);
- if (retVal == 0) {
+ if (retVal != 0) {
throw new AssertionError(
- "Test application exited without error: ");
+ "Test application exited with error: ");
}
if (!outfile.exists()) {
@@ -61,15 +68,12 @@
String output = Files.readString(outfile.toPath());
String[] result = output.split("\n");
- if (result.length != 1) {
- System.out.println("outfile (" + outfile + ") content: " + output);
- throw new AssertionError(
- "Unexpected number of lines: " + result.length);
+ if (!result[0].trim().equals("jpackage test application")) {
+ throw new AssertionError("Unexpected result[0]: " + result[0]);
}
- if (!result[0].trim().contains(
- "does not have a ModuleMainClass attribute")) {
- throw new AssertionError("Unexpected result[0]: " + result[0]);
+ if (!result[1].trim().equals("args.length: 0")) {
+ throw new AssertionError("Unexpected result[1]: " + result[1]);
}
}
@@ -77,10 +81,16 @@
JPackageHelper.createHelloModule();
JPackageHelper.deleteOutputFolder(OUTPUT);
- validate(JPackageHelper.executeCLI(true, CMD));
+ JPackageHelper.executeCLI(false, CMD1);
JPackageHelper.deleteOutputFolder(OUTPUT);
- validate(JPackageHelper.executeToolProvider(true, CMD));
+ JPackageHelper.executeToolProvider(false, CMD1);
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ validate(JPackageHelper.executeCLI(true, CMD2));
+
+ JPackageHelper.deleteOutputFolder(OUTPUT);
+ validate(JPackageHelper.executeToolProvider(true, CMD2));
}
}