diff --git a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties index 6f05b6230641c..3aabe1f4ba510 100644 --- a/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties +++ b/src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties @@ -54,7 +54,6 @@ message.output-to-location=Package (.deb) saved to: {0}. message.debs-like-licenses=Debian packages should specify a license. The absence of a license will cause some linux distributions to complain about the quality of the application. message.outputting-bundle-location=Generating RPM for installer to: {0}. message.output-bundle-location=Package (.rpm) saved to: {0}. -message.creating-association-with-null-extension=Creating association with null extension. message.ldd-not-available=ldd command not found. Package dependencies will not be generated. message.deb-ldd-not-available.advice=Install "libc-bin" DEB package to get ldd. diff --git a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties index 7ce20925439d2..d01297aa814dd 100644 --- a/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties +++ b/src/jdk.jpackage/macosx/classes/jdk/jpackage/internal/resources/MacResources.properties @@ -26,17 +26,14 @@ error.invalid-cfbundle-version.advice=Set a compatible 'app-version' value. Valid versions are one to three integers separated by dots. error.explicit-sign-no-cert=Signature explicitly requested but no signing certificate found error.explicit-sign-no-cert.advice=Specify a valid mac-signing-key-user-name and mac-signing-keychain -error.must-sign-app-store=Mac App Store apps must be signed, and signing has been disabled by bundler configuration -error.must-sign-app-store.advice=Use --mac-sign option with appropriate user-name and keychain -error.certificate.expired=Error: Certificate expired {0} +error.certificate.expired=Certificate expired {0} error.cert.not.found=No certificate found matching [{0}] using keychain [{1}] error.multiple.certs.found=Multiple certificates matching name [{0}] found in keychain [{1}] -error.app-image.mac-sign.required=Error: --mac-sign option is required with predefined application image and with type [app-image] -error.tool.failed.with.output=Error: "{0}" failed with following output: +error.app-image.mac-sign.required=--mac-sign option is required with predefined application image and with type [app-image] +error.tool.failed.with.output="{0}" failed with following output: error.invalid-runtime-image-missing-file=Runtime image "{0}" is missing "{1}" file error.invalid-runtime-image-bin-dir=Runtime image "{0}" should not contain "bin" folder error.invalid-runtime-image-bin-dir.advice=Use --strip-native-commands jlink option when generating runtime image used with {0} option -resource.bundle-config-file=Bundle config file resource.app-info-plist=Application Info.plist resource.app-runtime-info-plist=Embedded Java Runtime Info.plist resource.runtime-info-plist=Java Runtime Info.plist @@ -59,14 +56,10 @@ message.preparing-info-plist=Preparing Info.plist: {0}. message.icon-not-icns= The specified icon "{0}" is not an ICNS file and will not be used. The default icon will be used in it's place. message.version-string-too-many-components='app-version' may have between 1 and 3 numbers: 1, 1.2, 1.2.3. message.version-string-first-number-not-zero=The first number in an app-version cannot be zero or negative. -message.creating-association-with-null-extension=Creating association with null extension. -message.ignoring.symlink=Warning: codesign is skipping the symlink {0}. -message.already.signed=File already signed: {0}. -message.keychain.error=Error: unable to get keychain list. -message.invalid-identifier=invalid mac bundle identifier [{0}]. +message.keychain.error=Unable to get keychain list. +message.invalid-identifier=Invalid mac bundle identifier [{0}]. message.invalid-identifier.advice=specify identifier with "--mac-package-identifier". message.building-dmg=Building DMG package for {0}. -message.running-script=Running shell script on application image [{0}]. message.preparing-dmg-setup=Preparing dmg setup: {0}. message.creating-dmg-file=Creating DMG file: {0}. message.dmg-cannot-be-overwritten=Dmg file exists [{0}] and can not be removed. diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/BuildEnvBuilder.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/BuildEnvBuilder.java index a33df97507204..17b805b8259b9 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/BuildEnvBuilder.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/BuildEnvBuilder.java @@ -24,8 +24,8 @@ */ package jdk.jpackage.internal; -import java.io.IOException; -import java.nio.file.Files; +import static jdk.jpackage.internal.cli.StandardValidator.IS_DIRECTORY_EMPTY_OR_NON_EXISTENT_PREDICATE; + import java.nio.file.Path; import java.util.Objects; import java.util.Optional; @@ -41,19 +41,11 @@ final class BuildEnvBuilder { } BuildEnv create() { - var exceptionBuilder = I18N.buildConfigException("ERR_BuildRootInvalid", root); - if (Files.isDirectory(root)) { - try (var rootDirContents = Files.list(root)) { - if (rootDirContents.findAny().isPresent()) { - // The root directory is not empty. - throw exceptionBuilder.create(); - } - } catch (IOException ioe) { - throw exceptionBuilder.cause(ioe).create(); - } - } else if (Files.exists(root)) { - // The root is not a directory. - throw exceptionBuilder.create(); + // The directory should be validated earlier with a proper error message. + // Here is only a sanity check. + if (!IS_DIRECTORY_EMPTY_OR_NON_EXISTENT_PREDICATE.test(root)) { + throw new UnsupportedOperationException( + String.format("Root work directory [%s] should be empty or non existent", root)); } return BuildEnv.create(root, Optional.ofNullable(resourceDir), verbose, diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/OptionsAnalyzer.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/OptionsAnalyzer.java index adba2f7abb42d..67e87d55d8b8f 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/OptionsAnalyzer.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/OptionsAnalyzer.java @@ -418,13 +418,10 @@ Optional validate(Options cmdline) { asOptionList(PREDEFINED_RUNTIME_IMAGE, ADD_MODULES), asOptionList(PREDEFINED_RUNTIME_IMAGE, JLINK_OPTIONS), asOptionList(MAC_SIGNING_KEY_NAME, MAC_APP_IMAGE_SIGN_IDENTITY), - asOptionList(MAC_SIGNING_KEY_NAME, MAC_INSTALLER_SIGN_IDENTITY) + asOptionList(MAC_SIGNING_KEY_NAME, MAC_INSTALLER_SIGN_IDENTITY), + asOptionList(MODULE, MAIN_JAR) ).map(MutualExclusiveOptions::new).forEach(config::add); - config.add(new MutualExclusiveOptions(asOptionList(MODULE, MAIN_JAR), _ -> { - return error("ERR_BothMainJarAndModule"); - })); - MUTUAL_EXCLUSIVE_OPTIONS = List.copyOf(config); } } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOption.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOption.java index bd9bd0f60407f..6de3b7e5c5c05 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOption.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOption.java @@ -32,7 +32,6 @@ import static jdk.jpackage.internal.cli.StandardBundlingOperation.SIGN_MAC_APP_IMAGE; import static jdk.jpackage.internal.cli.StandardBundlingOperation.fromOptionName; import static jdk.jpackage.internal.cli.StandardOptionContext.createOptionSpecBuilderMutator; -import static jdk.jpackage.internal.cli.StandardOptionValueExceptionFactory.ERROR_WITHOUT_CONTEXT; import static jdk.jpackage.internal.cli.StandardOptionValueExceptionFactory.ERROR_WITH_VALUE; import static jdk.jpackage.internal.cli.StandardOptionValueExceptionFactory.ERROR_WITH_VALUE_AND_OPTION_NAME; import static jdk.jpackage.internal.cli.StandardOptionValueExceptionFactory.forMessageWithOptionValueAndName; @@ -177,10 +176,7 @@ public boolean test(Path path) { public static final OptionValue COPYRIGHT = stringOption("copyright").valuePattern("copyright string").create(); - public static final OptionValue LICENSE_FILE = fileOption("license-file") - .validatorExceptionFormatString("ERR_LicenseFileNotExit") - .validatorExceptionFactory(ERROR_WITHOUT_CONTEXT) - .create(); + public static final OptionValue LICENSE_FILE = fileOption("license-file").create(); public static final OptionValue APP_VERSION = stringOption("app-version").create(); @@ -216,12 +212,10 @@ public boolean test(Path path) { .validatorExceptionFactory((optionName, optionValue, formatString, cause) -> { if (cause.orElseThrow() instanceof StandardValidator.DirectoryListingIOException) { formatString = "error.path-parameter-ioexception"; - return ERROR_WITH_VALUE_AND_OPTION_NAME.create(optionName, optionValue, formatString, cause); - } else { - return ERROR_WITH_VALUE.create(optionName, optionValue, formatString, cause); } + return ERROR_WITH_VALUE_AND_OPTION_NAME.create(optionName, optionValue, formatString, cause); }) - .validatorExceptionFormatString("ERR_BuildRootInvalid") + .validatorExceptionFormatString("error.parameter-not-empty-directory") .validator(StandardValidator.IS_DIRECTORY_EMPTY_OR_NON_EXISTENT) .create(); @@ -236,8 +230,6 @@ public boolean test(Path path) { public static final OptionValue PREDEFINED_APP_IMAGE = directoryOption("app-image") .scope(CREATE_NATIVE).inScope(SIGN_MAC_APP_IMAGE).inScope(BundlingOperationModifier.BUNDLE_PREDEFINED_APP_IMAGE) - .validatorExceptionFactory(ERROR_WITH_VALUE) - .validatorExceptionFormatString("ERR_AppImageNotExist") .mutate(createOptionSpecBuilderMutator((b, context) -> { if (context.os() == OperatingSystem.MACOS) { b.description("help.option.app-image" + resourceKeySuffix(context.os())); @@ -538,7 +530,7 @@ static Consumer> launcherShortcutOptionMutat }); })) .converterExceptionFactory(ERROR_WITH_VALUE_AND_OPTION_NAME) - .converterExceptionFormatString("error.invalid-option-value") + .converterExceptionFormatString("error.parameter-not-launcher-shortcut-dir") .converter(mainLauncherShortcutConv()) .defaultOptionalValue(new LauncherShortcut(LauncherShortcutStartupDirectory.DEFAULT)) .valuePattern("shortcut startup directory"); @@ -637,8 +629,8 @@ private static OptionValue createAddLauncherOption(String .converterExceptionFactory((optionName, optionValue, formatString, cause) -> { final var theCause = cause.orElseThrow(); if (theCause instanceof AddLauncherSyntaxException) { - return ERROR_WITHOUT_CONTEXT.create(optionName, - optionValue, "ERR_NoAddLauncherName", cause); + return ERROR_WITH_VALUE_AND_OPTION_NAME.create(optionName, + optionValue, "error.parameter-add-launcher-malformed", cause); } else { return (RuntimeException)theCause; } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOptionValueExceptionFactory.java b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOptionValueExceptionFactory.java index e79d283b38619..d125c402142bc 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOptionValueExceptionFactory.java +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/cli/StandardOptionValueExceptionFactory.java @@ -32,18 +32,10 @@ final class StandardOptionValueExceptionFactory { - static OptionValueExceptionFactory forMessageWithOptionValue(Path propertyFile) { - return forMessageWithOptionValue(appendPath(propertyFile)).printOptionPrefix(false).create(); - } - static OptionValueExceptionFactory forMessageWithOptionValueAndName(Path propertyFile) { return forMessageWithOptionValueAndName(appendPath(propertyFile)).printOptionPrefix(false).create(); } - static OptionValueExceptionFactory forFixedMessage(Path propertyFile) { - return forFixedMessage(appendPath(propertyFile)).printOptionPrefix(false).create(); - } - private StandardOptionValueExceptionFactory() { } @@ -63,17 +55,9 @@ private static OptionValueExceptionFactory.Builder forMessage .formatArgumentsTransformer(mapper.apply(StandardArgumentsMapper.VALUE_AND_NAME)); } - private static OptionValueExceptionFactory.Builder forFixedMessage(UnaryOperator mapper) { - return OptionValueExceptionFactory.build(JPackageException::new) - .formatArgumentsTransformer(mapper.apply(StandardArgumentsMapper.NONE)); - } - static final OptionValueExceptionFactory ERROR_WITH_VALUE = forMessageWithOptionValue(UnaryOperator.identity()).create(); - static final OptionValueExceptionFactory ERROR_WITHOUT_CONTEXT = - forFixedMessage(UnaryOperator.identity()).create(); - static final OptionValueExceptionFactory ERROR_WITH_VALUE_AND_OPTION_NAME = forMessageWithOptionValueAndName(UnaryOperator.identity()).create(); } diff --git a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties index 9e7dfc25de6d4..c61e60fe4ec17 100644 --- a/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties +++ b/src/jdk.jpackage/share/classes/jdk/jpackage/internal/resources/MainResources.properties @@ -47,7 +47,6 @@ message.creating-app-bundle=Creating app package: {0} in {1} 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 -message.module-class=Using class "{0}" from module "{1}" as application main class message.error-header={0} message.advice-header=Advice to fix: {0} @@ -58,7 +57,7 @@ error.version-string-invalid-component=Version [{0}] contains invalid component error.cannot-create-output-dir=Destination directory {0} cannot be created error.cannot-write-to-output-dir=Destination directory {0} is not writable -error.root-exists=Error: Application destination directory {0} already exists +error.root-exists=Application destination directory {0} already exists 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.main-jar-does-not-exist=The configured main jar does not exist {0} in the input directory @@ -73,6 +72,7 @@ error.parameter-not-uuid=The value "{0}" provided for parameter {1} is not a val error.parameter-not-path=The value "{0}" provided for parameter {1} is not a valid path error.parameter-not-file=The value "{0}" provided for parameter {1} is not a file error.parameter-not-directory=The value "{0}" provided for parameter {1} is not a directory +error.parameter-not-empty-directory=The value "{0}" provided for parameter {1} is not an empty directory or non existent path error.parameter-not-url=The value "{0}" provided for parameter {1} is not a valid URL error.parameter-not-launcher-shortcut-dir=The value "{0}" provided for parameter {1} is not a valid shortcut startup directory error.path-parameter-ioexception=I/O error accessing path value "{0}" of parameter {1} @@ -101,33 +101,25 @@ error.blocked.option=jlink option [{0}] is not permitted in --jlink-options error.no.name=Name not specified with --name and cannot infer one from app-image error.no.name.advice=Specify name with --name -error.missing-app-image-file=Error: "{0}" file is missing in the predefined app image "{1}" -error.invalid-app-image-file=Error: "{0}" file in the predefined app image "{1}" is corrupted or was created by another version of jpackage -error.malformed-app-image-file=Error: "{0}" file in the predefined app image "{1}" contains malformed XML data -error.reading-app-image-file=Error: Failed to read "{0}" file in the predefined app image "{1}" +error.missing-app-image-file="{0}" file is missing in the predefined app image "{1}" +error.invalid-app-image-file="{0}" file in the predefined app image "{1}" is corrupted or was created by another version of jpackage +error.malformed-app-image-file="{0}" file in the predefined app image "{1}" contains malformed XML data +error.reading-app-image-file=Failed to read "{0}" file in the predefined app image "{1}" error.invalid-install-dir=Invalid installation directory "{0}" -error.invalid-option-value=Invalid value "{0}" of option {1} - -ERR_NoMainClass=Error: Main application class is missing -ERR_UnsupportedOption=Error: Option [{0}] is not valid on this platform -ERR_InvalidTypeOption=Error: Option [{0}] is not valid with type [{1}] -ERR_NoInstallerEntryPoint=Error: Option [{0}] is not valid without --module or --main-jar entry point option -ERR_MutuallyExclusiveOptions=Error: Mutually exclusive options [{0}] and [{1}] -ERR_InvalidOptionWithAppImageSigning=Error: Option [{0}] is not valid when signing application image - -ERR_MissingArgument=Error: Missing argument: {0} -ERR_MissingArgument2=Error: Missing argument: {0} or {1} -ERR_AppImageNotExist=Error: App image directory "{0}" does not exist -ERR_NoAddLauncherName=Error: --add-launcher option requires a name and a file path (--add-launcher =) -ERR_InvalidAppName=Error: Invalid Application name: {0} -ERR_InvalidSLName=Error: Invalid Add Launcher name: {0} -ERR_LicenseFileNotExit=Error: Specified license file does not exist -ERR_BuildRootInvalid=Error: temp ({0}) must be non-existent or empty directory -ERR_InvalidOption=Error: Invalid Option: [{0}] -ERR_InvalidInstallerType=Error: Invalid or unsupported type: [{0}] -ERR_BothMainJarAndModule=Error: Cannot have both --main-jar and --module Options -ERR_NoEntryPoint=Error: creating application image requires --main-jar or --module Option -ERR_CannotParseOptions=Error: Processing @filename option: {0} -ERR_MissingJLinkOptMacAppStore=Error: --mac-app-store argument requires a {0} option for --jlink-options argument +ERR_NoMainClass=Main application class is missing +ERR_UnsupportedOption=Option [{0}] is not valid on this platform +ERR_InvalidTypeOption=Option [{0}] is not valid with type [{1}] +ERR_NoInstallerEntryPoint=Option [{0}] is not valid without --module or --main-jar entry point option +ERR_MutuallyExclusiveOptions=Mutually exclusive options [{0}] and [{1}] +ERR_InvalidOptionWithAppImageSigning=Option [{0}] is not valid when signing application image + +ERR_MissingArgument2=Missing argument: {0} or {1} +ERR_InvalidAppName=Invalid Application name: {0} +ERR_InvalidSLName=Invalid Add Launcher name: {0} +ERR_InvalidOption=Invalid Option: [{0}] +ERR_InvalidInstallerType=Invalid or unsupported type: [{0}] +ERR_NoEntryPoint=creating application image requires --main-jar or --module Option +ERR_CannotParseOptions=Processing @filename option: {0} +ERR_MissingJLinkOptMacAppStore=--mac-app-store argument requires a {0} option for --jlink-options argument diff --git a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties index 50be1a0a1e5bc..1f485e6c6c8ef 100644 --- a/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties +++ b/src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties @@ -26,7 +26,6 @@ param.menu-group.default=Unknown resource.executable-properties-template=Template for creating executable properties file -resource.setup-icon=setup dialog icon resource.post-msi-script=script to run after msi file for exe installer is created resource.wxl-file=WiX localization file resource.main-wix-file=Main WiX project file @@ -60,12 +59,10 @@ message.potential.windows.defender.issue=Warning: Windows Defender may prevent j message.outputting-to-location=Generating EXE for installer to: {0}. message.output-location=Installer (.exe) saved to: {0} message.tool-version=Detected [{0}] version [{1}]. -message.creating-association-with-null-extension=Creating association with null extension. message.wrong-tool-version=Detected [{0}] version {1} but version {2} is required. message.use-wix36-features=WiX {0} detected. Enabling advanced cleanup action. message.product-code=MSI ProductCode: {0}. message.upgrade-code=MSI UpgradeCode: {0}. message.preparing-msi-config=Preparing MSI config: {0}. message.generating-msi=Generating MSI: {0}. -message.invalid.install.dir=Warning: Invalid install directory {0}. Install directory should be a relative sub-path under the default installation location such as "Program Files". Defaulting to application name "{1}". diff --git a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsProcessorTest.java b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsProcessorTest.java index 4712adf15c10e..53b726d8f1a52 100644 --- a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsProcessorTest.java +++ b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsProcessorTest.java @@ -264,7 +264,7 @@ public void testBundlingOperationConfigurationErrors(@TempDir Path workDir) { @Test public void testMultipleCommandLineStructureAnalyzerErrors() { build().createAppImageByDefault().expectValidationErrors( - new JPackageException(I18N.format("ERR_BothMainJarAndModule")), + new JPackageException(I18N.format("ERR_MutuallyExclusiveOptions", "-m", "--main-jar")), new JPackageException(I18N.format("ERR_MissingArgument2", "--runtime-image", "--module-path")), new JPackageException(I18N.format("error.no-input-parameter")) ).validationErrorsOrdered(false).create("-m", "com.foo", "--main-jar", "main.jar").validate(); diff --git a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsValidationFailTest.excludes b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsValidationFailTest.excludes index 4f1dda06f6885..0e7545bd83da1 100644 --- a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsValidationFailTest.excludes +++ b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/OptionsValidationFailTest.excludes @@ -1,42 +1,42 @@ -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 0.2]; errors=[message.version-string-first-number-not-zero, error.invalid-cfbundle-version.advice]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.2.3.4]; errors=[message.version-string-too-many-components, error.invalid-cfbundle-version.advice]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.]; errors=[error.version-string-zero-length-component+[1.]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.b.3]; errors=[error.version-string-invalid-component+[1.b.3, b.3]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, ]; errors=[error.version-string-empty]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --add-modules]; errors=[error.blocked.option+[--add-modules]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --foo]; errors=[error.jlink.failed+[Error: unknown option: --foo]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --module-path]; errors=[error.blocked.option+[--module-path]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --output]; errors=[error.blocked.option+[--output]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--main-jar, non-existent.jar]; errors=[error.main-jar-does-not-exist+[non-existent.jar]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[error.invalid-runtime-image-missing-file+[@@EMPTY_DIR@@, lib/**/libjli.dylib]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) -ErrorTest.test(IMAGE; app-desc=Hello; args-del=[--main-class]; errors=[error.no-main-class-with-main-jar+[hello.jar], error.no-main-class-with-main-jar.advice+[hello.jar]]) -ErrorTest.test(IMAGE; args-add=[--module, com.foo.bar, --runtime-image, @@JAVA_HOME@@]; errors=[error.no-module-in-path+[com.foo.bar]]) -ErrorTest.test(IMAGE; args-add=[--module, java.base, --runtime-image, @@JAVA_HOME@@]; errors=[ERR_NoMainClass]) -ErrorTest.test(LINUX_DEB; app-desc=Hello; args-add=[--linux-package-name, #]; errors=[error.deb-invalid-value-for-package-name+[#], error.deb-invalid-value-for-package-name.advice]) -ErrorTest.test(LINUX_RPM; app-desc=Hello; args-add=[--linux-package-name, #]; errors=[error.rpm-invalid-value-for-package-name+[#], error.rpm-invalid-value-for-package-name.advice]) -ErrorTest.test(MAC_PKG; app-desc=Hello; args-add=[--mac-package-identifier, #1]; errors=[message.invalid-identifier+[#1]]) -ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--mac-app-store, --runtime-image, @@JAVA_HOME@@]; errors=[error.invalid-runtime-image-bin-dir+[@@JAVA_HOME@@], error.invalid-runtime-image-bin-dir.advice+[--mac-app-store]]) -ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[error.invalid-runtime-image-missing-file+[@@EMPTY_DIR@@, lib/**/libjli.dylib]]) -ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) -ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) -ErrorTest.test(NATIVE; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[error.invalid-runtime-image-missing-file+[@@EMPTY_DIR@@, lib/**/libjli.dylib]]) -ErrorTest.test(NATIVE; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) -ErrorTest.test(NATIVE; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[error.invalid-runtime-image-missing-file+[@@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.2.3.4.5]; errors=[error.msi-product-version-components+[1.2.3.4.5], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.2.65536]; errors=[error.msi-product-version-build-out-of-range+[1.2.65536], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.256]; errors=[error.msi-product-version-minor-out-of-range+[1.256], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1234]; errors=[error.msi-product-version-components+[1234], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 256.1]; errors=[error.msi-product-version-major-out-of-range+[256.1], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--launcher-as-service]; errors=[error.missing-service-installer, error.missing-service-installer.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.2.3.4.5]; errors=[error.msi-product-version-components+[1.2.3.4.5], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.2.65536]; errors=[error.msi-product-version-build-out-of-range+[1.2.65536], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.256]; errors=[error.msi-product-version-minor-out-of-range+[1.256], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1234]; errors=[error.msi-product-version-components+[1234], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 256.1]; errors=[error.msi-product-version-major-out-of-range+[256.1], error.version-string-wrong-format.advice]) -ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--launcher-as-service]; errors=[error.missing-service-installer, error.missing-service-installer.advice]) -ErrorTest.test(args-add=[@foo]; errors=[ERR_CannotParseOptions+[foo]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 0.2]; errors=[message.error-header+[message.version-string-first-number-not-zero], message.advice-header+[error.invalid-cfbundle-version.advice]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.2.3.4]; errors=[message.error-header+[message.version-string-too-many-components], message.advice-header+[error.invalid-cfbundle-version.advice]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.]; errors=[message.error-header+[error.version-string-zero-length-component, 1.]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, 1.b.3]; errors=[message.error-header+[error.version-string-invalid-component, 1.b.3, b.3]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--app-version, ]; errors=[message.error-header+[error.version-string-empty]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --add-modules]; errors=[message.error-header+[error.blocked.option, --add-modules]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --foo]; errors=[message.error-header+[error.jlink.failed, Error: unknown option: --foo]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --module-path]; errors=[message.error-header+[error.blocked.option, --module-path]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--jlink-options, --output]; errors=[message.error-header+[error.blocked.option, --output]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--main-jar, non-existent.jar]; errors=[message.error-header+[error.main-jar-does-not-exist, non-existent.jar]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@EMPTY_DIR@@, lib/**/libjli.dylib]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) +ErrorTest.test(IMAGE; app-desc=Hello; args-del=[--main-class]; errors=[message.error-header+[error.no-main-class-with-main-jar, hello.jar], message.advice-header+[error.no-main-class-with-main-jar.advice, hello.jar]]) +ErrorTest.test(IMAGE; args-add=[--module, com.foo.bar, --runtime-image, @@JAVA_HOME@@]; errors=[message.error-header+[error.no-module-in-path, com.foo.bar]]) +ErrorTest.test(IMAGE; args-add=[--module, java.base, --runtime-image, @@JAVA_HOME@@]; errors=[message.error-header+[ERR_NoMainClass]]) +ErrorTest.test(LINUX_DEB; app-desc=Hello; args-add=[--linux-package-name, #]; errors=[message.error-header+[error.deb-invalid-value-for-package-name, #], message.advice-header+[error.deb-invalid-value-for-package-name.advice]]) +ErrorTest.test(LINUX_RPM; app-desc=Hello; args-add=[--linux-package-name, #]; errors=[message.error-header+[error.rpm-invalid-value-for-package-name, #], message.advice-header+[error.rpm-invalid-value-for-package-name.advice]]) +ErrorTest.test(MAC_PKG; app-desc=Hello; args-add=[--mac-package-identifier, #1]; errors=[message.error-header+[message.invalid-identifier, #1]]) +ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--mac-app-store, --runtime-image, @@JAVA_HOME@@]; errors=[message.error-header+[error.invalid-runtime-image-bin-dir, @@JAVA_HOME@@], message.advice-header+[error.invalid-runtime-image-bin-dir.advice, --mac-app-store]]) +ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@EMPTY_DIR@@, lib/**/libjli.dylib]]) +ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) +ErrorTest.test(NATIVE; app-desc=Hello; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) +ErrorTest.test(NATIVE; args-add=[--runtime-image, @@EMPTY_DIR@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@EMPTY_DIR@@, lib/**/libjli.dylib]]) +ErrorTest.test(NATIVE; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_BUNDLE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_BUNDLE@@, Contents/Home/lib/**/libjli.dylib]]) +ErrorTest.test(NATIVE; args-add=[--runtime-image, @@INVALID_MAC_RUNTIME_IMAGE@@]; errors=[message.error-header+[error.invalid-runtime-image-missing-file, @@INVALID_MAC_RUNTIME_IMAGE@@, lib/**/libjli.dylib]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.2.3.4.5]; errors=[message.error-header+[error.msi-product-version-components, 1.2.3.4.5], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.2.65536]; errors=[message.error-header+[error.msi-product-version-build-out-of-range, 1.2.65536], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1.256]; errors=[message.error-header+[error.msi-product-version-minor-out-of-range, 1.256], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 1234]; errors=[message.error-header+[error.msi-product-version-components, 1234], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--app-version, 256.1]; errors=[message.error-header+[error.msi-product-version-major-out-of-range, 256.1], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_EXE; app-desc=Hello; args-add=[--launcher-as-service]; errors=[message.error-header+[error.missing-service-installer], message.advice-header+[error.missing-service-installer.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.2.3.4.5]; errors=[message.error-header+[error.msi-product-version-components, 1.2.3.4.5], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.2.65536]; errors=[message.error-header+[error.msi-product-version-build-out-of-range, 1.2.65536], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1.256]; errors=[message.error-header+[error.msi-product-version-minor-out-of-range, 1.256], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 1234]; errors=[message.error-header+[error.msi-product-version-components, 1234], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--app-version, 256.1]; errors=[message.error-header+[error.msi-product-version-major-out-of-range, 256.1], message.advice-header+[error.version-string-wrong-format.advice]]) +ErrorTest.test(WIN_MSI; app-desc=Hello; args-add=[--launcher-as-service]; errors=[message.error-header+[error.missing-service-installer], message.advice-header+[error.missing-service-installer.advice]]) +ErrorTest.test(args-add=[@foo]; errors=[message.error-header+[ERR_CannotParseOptions, foo]]) ErrorTest.testMacSigningIdentityValidation(IMAGE, --mac-app-image-sign-identity, true) ErrorTest.testMacSigningIdentityValidation(IMAGE, --mac-signing-key-user-name, false) ErrorTest.testMacSigningIdentityValidation(MAC_DMG, --mac-app-image-sign-identity, true) diff --git a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/StandardOptionTest.java b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/StandardOptionTest.java index 20807952b721b..b786f484cb49b 100644 --- a/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/StandardOptionTest.java +++ b/test/jdk/tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/StandardOptionTest.java @@ -164,14 +164,14 @@ public void test_TEMP_ROOT_invalid(@TempDir Path workDir) throws IOException { var ex = assertThrowsExactly(JPackageException.class, spec.converter().orElseThrow().convert(spec.name(), StringToken.of(tempRoot.toString()))::orElseThrow); - assertEquals(I18N.format("ERR_BuildRootInvalid", tempRoot), ex.getMessage()); + assertEquals(I18N.format("error.parameter-not-empty-directory", tempRoot, "--temp"), ex.getMessage()); assertEquals(NotDirectoryException.class, ex.getCause().getClass()); tempRoot = workDir; ex = assertThrowsExactly(JPackageException.class, spec.converter().orElseThrow().convert(spec.name(), StringToken.of(tempRoot.toString()))::orElseThrow); - assertEquals(I18N.format("ERR_BuildRootInvalid", tempRoot), ex.getMessage()); + assertEquals(I18N.format("error.parameter-not-empty-directory", tempRoot, "--temp"), ex.getMessage()); assertEquals(DirectoryNotEmptyException.class, ex.getCause().getClass()); } @@ -417,8 +417,8 @@ private static Collection testAddLauncherOption() { buildAddLauncherTest().expect("foo", "some.properties"), buildAddLauncherTest().expect("foo", "a/b/some.properties").expect("bar", "="), buildAddLauncherTest().expect("a", "a.properties").expect("a", "b.properties"), - buildAddLauncherTest().optionValue("some").expectErrors(I18N.format("ERR_NoAddLauncherName")), - buildAddLauncherTest().optionValue("").expectErrors(I18N.format("ERR_NoAddLauncherName")), + buildAddLauncherTest().optionValue("some").expectErrors(I18N.format("error.parameter-add-launcher-malformed", "some", "--add-launcher")), + buildAddLauncherTest().optionValue("").expectErrors(I18N.format("error.parameter-add-launcher-malformed", "", "--add-launcher")), buildAddLauncherTest().optionValue("=").expectErrors(I18N.format("ERR_InvalidSLName", "")), buildAddLauncherTest().optionValue("a=").expectErrors(I18N.format("error.parameter-add-launcher-not-file", "", "a")), buildAddLauncherTest().optionValue("=a").expectErrors(I18N.format("ERR_InvalidSLName", "")), @@ -481,7 +481,8 @@ LauncherShortcutTestSpec create() { return List.of(I18N.format("error.properties-parameter-not-launcher-shortcut-dir", optionValue, option.getSpec().name().name(), DUMMY_PROPERTY_FILE)); } else { - return List.of(I18N.format("error.invalid-option-value", optionValue, option.getSpec().name().formatForCommandLine())); + return List.of(I18N.format("error.parameter-not-launcher-shortcut-dir", + optionValue, option.getSpec().name().formatForCommandLine())); } }), propertyFile, Optional.ofNullable(optionValue)); } diff --git a/test/jdk/tools/jpackage/share/BasicTest.java b/test/jdk/tools/jpackage/share/BasicTest.java index 7dcd9f73d2d53..958fe15071169 100644 --- a/test/jdk/tools/jpackage/share/BasicTest.java +++ b/test/jdk/tools/jpackage/share/BasicTest.java @@ -410,7 +410,7 @@ public void testTemp(TestTempType type) throws IOException { if (TestTempType.TEMPDIR_NOT_EMPTY.equals(type)) { pkgTest.setExpectedExitCode(1).addInitializer(cmd -> { cmd.validateOutput(JPackageStringBundle.MAIN.cannedFormattedString( - "ERR_BuildRootInvalid", cmd.getArgumentValue("--temp"))); + "error.parameter-not-empty-directory", cmd.getArgumentValue("--temp"), "--temp")); }).addBundleVerifier(cmd -> { // Check jpackage didn't use the supplied directory. Path tempDir = Path.of(cmd.getArgumentValue("--temp")); diff --git a/test/jdk/tools/jpackage/share/ErrorTest.java b/test/jdk/tools/jpackage/share/ErrorTest.java index 4395db77212dc..955c17e604389 100644 --- a/test/jdk/tools/jpackage/share/ErrorTest.java +++ b/test/jdk/tools/jpackage/share/ErrorTest.java @@ -27,6 +27,8 @@ import static jdk.internal.util.OperatingSystem.MACOS; import static jdk.internal.util.OperatingSystem.WINDOWS; import static jdk.jpackage.internal.util.function.ThrowingFunction.toFunction; +import static jdk.jpackage.test.JPackageCommand.makeAdvice; +import static jdk.jpackage.test.JPackageCommand.makeError; import java.nio.file.Files; import java.nio.file.Path; @@ -39,6 +41,7 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; +import java.util.function.UnaryOperator; import java.util.regex.Pattern; import java.util.stream.Stream; import jdk.jpackage.internal.util.TokenReplace; @@ -200,7 +203,7 @@ private static Optional defaultNativeType() { } public record TestSpec(Optional type, Optional appDesc, List addArgs, - List removeArgs, List expectedErrors) { + List removeArgs, List expectedMessages) { static final class Builder { @@ -265,26 +268,30 @@ Builder removeArgs(String... v) { return removeArgs(List.of(v)); } - Builder setErrors(List v) { - expectedErrors = v; + Builder setMessages(List v) { + expectedMessages = v; return this; } - Builder setErrors(CannedFormattedString... v) { - return setErrors(List.of(v)); + Builder setMessages(CannedFormattedString... v) { + return setMessages(List.of(v)); } - Builder errors(List v) { - expectedErrors.addAll(v); + Builder messages(List v) { + expectedMessages.addAll(v); return this; } - Builder errors(CannedFormattedString... v) { - return errors(List.of(v)); + Builder messages(CannedFormattedString... v) { + return messages(List.of(v)); } Builder error(String key, Object ... args) { - return errors(JPackageStringBundle.MAIN.cannedFormattedString(key, args)); + return messages(makeError(JPackageStringBundle.MAIN.cannedFormattedString(key, args))); + } + + Builder advice(String key, Object ... args) { + return messages(makeAdvice(JPackageStringBundle.MAIN.cannedFormattedString(key, args))); } Builder invalidTypeArg(String arg, String... otherArgs) { @@ -298,14 +305,14 @@ Builder unsupportedPlatformOption(String arg, String ... otherArgs) { TestSpec create() { return new TestSpec(Optional.ofNullable(type), Optional.ofNullable(appDesc), - List.copyOf(addArgs), List.copyOf(removeArgs), List.copyOf(expectedErrors)); + List.copyOf(addArgs), List.copyOf(removeArgs), List.copyOf(expectedMessages)); } private PackageTypeSpec type = new PackageTypeSpec(PackageType.IMAGE); private String appDesc = DEFAULT_APP_DESC; private List addArgs = new ArrayList<>(); private List removeArgs = new ArrayList<>(); - private List expectedErrors = new ArrayList<>(); + private List expectedMessages = new ArrayList<>(); } public TestSpec { @@ -315,7 +322,7 @@ TestSpec create() { addArgs.forEach(Objects::requireNonNull); Objects.requireNonNull(removeArgs); removeArgs.forEach(Objects::requireNonNull); - if (expectedErrors.isEmpty()) { + if (expectedMessages.isEmpty()) { throw new IllegalArgumentException("The list of expected errors must be non-empty"); } } @@ -353,10 +360,14 @@ void test(Map> tokenValueSuppliers) { cmd.clearArguments().addArguments(newArgs); } - defaultInit(cmd, expectedErrors); + defaultInit(cmd, expectedMessages); cmd.execute(1); } + TestSpec mapExpectedMessages(UnaryOperator mapper) { + return new TestSpec(type, appDesc, addArgs, removeArgs, expectedMessages.stream().map(mapper).toList()); + } + @Override public final String toString() { final var sb = new StringBuilder(); @@ -372,7 +383,7 @@ public final String toString() { if (!removeArgs.isEmpty()) { sb.append("args-del=").append(removeArgs).append("; "); } - sb.append("errors=").append(expectedErrors); + sb.append("errors=").append(expectedMessages); return sb.toString(); } @@ -395,7 +406,7 @@ public static Collection basic() { // no main-class testSpec().removeArgs("--main-class") .error("error.no-main-class-with-main-jar", "hello.jar") - .error("error.no-main-class-with-main-jar.advice", "hello.jar"), + .advice("error.no-main-class-with-main-jar.advice", "hello.jar"), // non-existent main jar testSpec().addArgs("--main-jar", "non-existent.jar") .error("error.main-jar-does-not-exist", "non-existent.jar"), @@ -404,7 +415,7 @@ public static Collection basic() { .error("error.parameter-not-directory", "non-existent.runtime", "--runtime-image"), // non-existent app image testSpec().noAppDesc().nativeType().addArgs("--name", "foo", "--app-image", "non-existent.appimage") - .error("ERR_AppImageNotExist", "non-existent.appimage"), + .error("error.parameter-not-directory", "non-existent.appimage", "--app-image"), // non-existent resource-dir testSpec().addArgs("--resource-dir", "non-existent.dir") .error("error.parameter-not-directory", "non-existent.dir", "--resource-dir"), @@ -413,7 +424,7 @@ public static Collection basic() { .error("error.parameter-not-file", "non-existent.icon", "--icon"), // non-existent license file testSpec().nativeType().addArgs("--license-file", "non-existent.license") - .error("ERR_LicenseFileNotExit"), + .error("error.parameter-not-file", "non-existent.license", "--license-file"), // invalid type testSpec().addArgs("--type", "invalid-type") .error("ERR_InvalidInstallerType", "invalid-type"), @@ -421,16 +432,13 @@ public static Collection basic() { testSpec().removeArgs("--input").error("error.no-input-parameter"), // no --module-path testSpec().appDesc("com.other/com.other.Hello").removeArgs("--module-path") - .error("ERR_MissingArgument", "--runtime-image or --module-path"), + .error("ERR_MissingArgument2", "--runtime-image", "--module-path"), // no main class in module path testSpec().noAppDesc().addArgs("--module", "java.base", "--runtime-image", Token.JAVA_HOME.token()) .error("ERR_NoMainClass"), // no module in module path testSpec().noAppDesc().addArgs("--module", "com.foo.bar", "--runtime-image", Token.JAVA_HOME.token()) .error("error.no-module-in-path", "com.foo.bar"), - // --main-jar and --module-name - testSpec().noAppDesc().addArgs("--main-jar", "foo.jar", "--module", "foo.bar") - .error("ERR_BothMainJarAndModule"), // non-existing argument file testSpec().noAppDesc().notype().addArgs("@foo") .error("ERR_CannotParseOptions", "foo"), @@ -439,6 +447,12 @@ public static Collection basic() { .error("error.jlink.failed", "Error: unknown option: --foo") ).map(TestSpec.Builder::create).toList()); + // --main-jar and --module-name + createMutuallyExclusive( + new ArgumentGroup("--module", "foo.bar"), + new ArgumentGroup("--main-jar", "foo.jar") + ).map(TestSpec.Builder::noAppDesc).map(TestSpec.Builder::create).forEach(testCases::add); + // forbidden jlink options testCases.addAll(Stream.of("--output", "--add-modules", "--module-path").map(opt -> { return testSpec().addArgs("--jlink-options", opt).error("error.blocked.option", opt); @@ -533,13 +547,21 @@ public static Collection testRuntimeInstallerInvalidOptions() { public static void testAdditionLaunchers(TestSpec spec) { final Path propsFile = TKit.createTempFile("add-launcher.properties"); TKit.createPropertiesFile(propsFile, Map.of()); - spec.test(Map.of(Token.ADD_LAUNCHER_PROPERTY_FILE, cmd -> propsFile)); + spec.mapExpectedMessages(cannedStr -> { + return cannedStr.mapArgs(arg -> { + if (arg == Token.ADD_LAUNCHER_PROPERTY_FILE) { + return propsFile; + } else { + return arg; + } + }); + }).test(Map.of(Token.ADD_LAUNCHER_PROPERTY_FILE, cmd -> propsFile)); } public static Collection testAdditionLaunchers() { return fromTestSpecBuilders(Stream.of( testSpec().addArgs("--add-launcher", Token.ADD_LAUNCHER_PROPERTY_FILE.token()) - .error("ERR_NoAddLauncherName"), + .error("error.parameter-add-launcher-malformed", Token.ADD_LAUNCHER_PROPERTY_FILE, "--add-launcher"), testSpec().removeArgs("--name").addArgs("--name", "foo", "--add-launcher", "foo=" + Token.ADD_LAUNCHER_PROPERTY_FILE.token()) .error("error.launcher-duplicate-name", "foo") )); @@ -577,24 +599,24 @@ public static Collection testWindows() { return Stream.of( testSpec().type(type).addArgs("--launcher-as-service") .error("error.missing-service-installer") - .error("error.missing-service-installer.advice"), + .advice("error.missing-service-installer.advice"), // The below version strings are invalid for msi and exe packaging. // They are valid for app image packaging. testSpec().type(type).addArgs("--app-version", "1234") .error("error.msi-product-version-components", "1234") - .error("error.version-string-wrong-format.advice"), + .advice("error.version-string-wrong-format.advice"), testSpec().type(type).addArgs("--app-version", "1.2.3.4.5") .error("error.msi-product-version-components", "1.2.3.4.5") - .error("error.version-string-wrong-format.advice"), + .advice("error.version-string-wrong-format.advice"), testSpec().type(type).addArgs("--app-version", "256.1") .error("error.msi-product-version-major-out-of-range", "256.1") - .error("error.version-string-wrong-format.advice"), + .advice("error.version-string-wrong-format.advice"), testSpec().type(type).addArgs("--app-version", "1.256") .error("error.msi-product-version-minor-out-of-range", "1.256") - .error("error.version-string-wrong-format.advice"), + .advice("error.version-string-wrong-format.advice"), testSpec().type(type).addArgs("--app-version", "1.2.65536") .error("error.msi-product-version-build-out-of-range", "1.2.65536") - .error("error.version-string-wrong-format.advice") + .advice("error.version-string-wrong-format.advice") ); }).flatMap(x -> x).map(TestSpec.Builder::create).toList()); @@ -610,10 +632,10 @@ public static Collection testMac() { testCases.addAll(Stream.of( testSpec().addArgs("--app-version", "0.2") .error("message.version-string-first-number-not-zero") - .error("error.invalid-cfbundle-version.advice"), + .advice("error.invalid-cfbundle-version.advice"), testSpec().addArgs("--app-version", "1.2.3.4") .error("message.version-string-too-many-components") - .error("error.invalid-cfbundle-version.advice"), + .advice("error.invalid-cfbundle-version.advice"), testSpec().invalidTypeArg("--mac-installer-sign-identity", "foo"), testSpec().type(PackageType.MAC_DMG).invalidTypeArg("--mac-installer-sign-identity", "foo"), testSpec().invalidTypeArg("--mac-dmg-content", "foo"), @@ -659,10 +681,10 @@ public static Collection testLinux() { testCases.addAll(Stream.of( testSpec().type(PackageType.LINUX_DEB).addArgs("--linux-package-name", "#") .error("error.deb-invalid-value-for-package-name", "#") - .error("error.deb-invalid-value-for-package-name.advice"), + .advice("error.deb-invalid-value-for-package-name.advice"), testSpec().type(PackageType.LINUX_RPM).addArgs("--linux-package-name", "#") .error("error.rpm-invalid-value-for-package-name", "#") - .error("error.rpm-invalid-value-for-package-name.advice") + .advice("error.rpm-invalid-value-for-package-name.advice") ).map(TestSpec.Builder::create).toList()); invalidShortcut(testCases::add, "--linux-shortcut"); @@ -683,12 +705,14 @@ public static void testMacSigningIdentityValidation(PackageType type, String opt final var signingId = "foo"; final List errorMessages = new ArrayList<>(); - errorMessages.add(JPackageStringBundle.MAIN.cannedFormattedString( - "error.cert.not.found", "Developer ID Application: " + signingId, "")); + errorMessages.add(makeError(JPackageStringBundle.MAIN.cannedFormattedString( + "error.cert.not.found", "Developer ID Application: " + signingId, ""))); errorMessages.addAll(Stream.of( - "error.explicit-sign-no-cert", - "error.explicit-sign-no-cert.advice" - ).map(JPackageStringBundle.MAIN::cannedFormattedString).toList()); + Map.>entry("error.explicit-sign-no-cert", JPackageCommand::makeError), + Map.>entry("error.explicit-sign-no-cert.advice", JPackageCommand::makeAdvice) + ).map(e -> { + return e.getValue().apply(JPackageStringBundle.MAIN.cannedFormattedString(e.getKey())); + }).toList()); final var cmd = JPackageCommand.helloAppImage() .ignoreDefaultVerbose(true) @@ -725,21 +749,21 @@ private static void duplicateForMacSign(TestSpec.Builder builder, Consumer accumulator, String shortcutOption) { Objects.requireNonNull(shortcutOption); Stream.of("true", "false", "").map(value -> { - return testSpec().nativeType().addArgs(shortcutOption, value).error("error.invalid-option-value", value, shortcutOption).create(); + return testSpec().nativeType().addArgs(shortcutOption, value).error("error.parameter-not-launcher-shortcut-dir", value, shortcutOption).create(); }).forEach(accumulator); } private static void macInvalidRuntime(Consumer accumulator) { - var runtimeWithBinDirErr = JPackageStringBundle.MAIN.cannedFormattedString( + var runtimeWithBinDirErr = makeError(JPackageStringBundle.MAIN.cannedFormattedString( "error.invalid-runtime-image-bin-dir", JPackageCommand.cannedArgument(cmd -> { return Path.of(cmd.getArgumentValue("--runtime-image")); - }, Token.JAVA_HOME.token())); - var runtimeWithBinDirErrAdvice = JPackageStringBundle.MAIN.cannedFormattedString( - "error.invalid-runtime-image-bin-dir.advice", "--mac-app-store"); + }, Token.JAVA_HOME.token()))); + var runtimeWithBinDirErrAdvice = makeAdvice(JPackageStringBundle.MAIN.cannedFormattedString( + "error.invalid-runtime-image-bin-dir.advice", "--mac-app-store")); Stream.of( testSpec().nativeType().addArgs("--mac-app-store", "--runtime-image", Token.JAVA_HOME.token()) - .errors(runtimeWithBinDirErr, runtimeWithBinDirErrAdvice) + .messages(runtimeWithBinDirErr, runtimeWithBinDirErrAdvice) ).map(TestSpec.Builder::create).forEach(accumulator); Stream.of( @@ -771,14 +795,14 @@ static MissingRuntimeFileError missingLibjli(Token runtimeDir) { } TestSpec.Builder applyTo(TestSpec.Builder builder) { - return builder.addArgs("--runtime-image", runtimeDir.token()).errors(expectedErrorMsg()); + return builder.addArgs("--runtime-image", runtimeDir.token()).messages(expectedErrorMsg()); } private CannedFormattedString expectedErrorMsg() { - return JPackageStringBundle.MAIN.cannedFormattedString( + return makeError(JPackageStringBundle.MAIN.cannedFormattedString( "error.invalid-runtime-image-missing-file", JPackageCommand.cannedArgument(cmd -> { return Path.of(cmd.getArgumentValue("--runtime-image")); - }, runtimeDir.token()), missingFile); + }, runtimeDir.token()), missingFile)); } } @@ -849,7 +873,7 @@ public static Collection macOption() { ); } - private static void defaultInit(JPackageCommand cmd, List expectedErrors) { + private static void defaultInit(JPackageCommand cmd, List expectedMessages) { // Disable default logic adding `--verbose` option // to jpackage command line. @@ -860,7 +884,7 @@ private static void defaultInit(JPackageCommand cmd, List // with jpackage arguments in this test. cmd.ignoreDefaultRuntime(true); - cmd.validateOutput(expectedErrors.toArray(CannedFormattedString[]::new)); + cmd.validateOutput(expectedMessages.toArray(CannedFormattedString[]::new)); } private static Collection toTestArgs(Stream stream) { diff --git a/test/jdk/tools/jpackage/share/ModulePathTest.java b/test/jdk/tools/jpackage/share/ModulePathTest.java index 06b30ec89e72a..5e053fc0fae9e 100644 --- a/test/jdk/tools/jpackage/share/ModulePathTest.java +++ b/test/jdk/tools/jpackage/share/ModulePathTest.java @@ -126,7 +126,7 @@ public void test(String javaAppDesc) throws IOException { final CannedFormattedString expectedErrorMessage; if (modulePathArgs.isEmpty()) { expectedErrorMessage = JPackageStringBundle.MAIN.cannedFormattedString( - "ERR_MissingArgument", "--runtime-image or --module-path"); + "ERR_MissingArgument2", "--runtime-image", "--module-path"); } else { expectedErrorMessage = JPackageStringBundle.MAIN.cannedFormattedString( "error.no-module-in-path", appDesc.moduleName());