Skip to content

Commit 1397ee5

Browse files
author
Alexey Semenyuk
committedMar 26, 2025
8334322: Misleading values of keys in jpackage resource bundle
Reviewed-by: almatvee
1 parent 441bd12 commit 1397ee5

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed
 

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxDebBundler.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, 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
@@ -83,11 +83,15 @@ public class LinuxDebBundler extends LinuxPackageBundler {
8383
},
8484
(s, p) -> {
8585
if (!DEB_PACKAGE_NAME_PATTERN.matcher(s).matches()) {
86-
throw new IllegalArgumentException(new ConfigException(
86+
try {
87+
throw new ConfigException(
8788
MessageFormat.format(I18N.getString(
88-
"error.invalid-value-for-package-name"), s),
89+
"error.deb-invalid-value-for-package-name"), s),
8990
I18N.getString(
90-
"error.invalid-value-for-package-name.advice")));
91+
"error.deb-invalid-value-for-package-name.advice"));
92+
} catch (ConfigException ex) {
93+
throw new IllegalArgumentException(ex);
94+
}
9195
}
9296

9397
return s;

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/LinuxRpmBundler.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, 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
@@ -87,11 +87,15 @@ public class LinuxRpmBundler extends LinuxPackageBundler {
8787
},
8888
(s, p) -> {
8989
if (!RPM_PACKAGE_NAME_PATTERN.matcher(s).matches()) {
90-
String msgKey = "error.invalid-value-for-package-name";
91-
throw new IllegalArgumentException(
92-
new ConfigException(MessageFormat.format(
93-
I18N.getString(msgKey), s),
94-
I18N.getString(msgKey + ".advice")));
90+
try {
91+
throw new ConfigException(
92+
MessageFormat.format(I18N.getString(
93+
"error.rpm-invalid-value-for-package-name"), s),
94+
I18N.getString(
95+
"error.rpm-invalid-value-for-package-name.advice"));
96+
} catch (ConfigException ex) {
97+
throw new IllegalArgumentException(ex);
98+
}
9599
}
96100

97101
return s;

‎src/jdk.jpackage/linux/classes/jdk/jpackage/internal/resources/LinuxResources.properties

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2017, 2025, 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
@@ -46,8 +46,11 @@ error.tool-old-version.advice=Please install required packages
4646

4747
error.invalid-install-dir=Invalid installation directory "{0}"
4848

49-
error.invalid-value-for-package-name=Invalid value "{0}" for the bundle name.
50-
error.invalid-value-for-package-name.advice=Set the "linux-bundle-name" option to a valid Debian package name. Note that the package names must consist only of lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.). They must be at least two characters long and must start with an alphanumeric character.
49+
error.deb-invalid-value-for-package-name=Invalid value "{0}" for the package name.
50+
error.deb-invalid-value-for-package-name.advice=Set the "--linux-package-name" option to a valid Debian package name. Note that the package names must consist only of lower case letters (a-z), digits (0-9), plus (+) and minus (-) signs, and periods (.). They must be at least two characters long and must start with a letter character.
51+
52+
error.rpm-invalid-value-for-package-name=Invalid value "{0}" for the package name.
53+
error.rpm-invalid-value-for-package-name.advice=Set the "--linux-package-name" option to a valid RPM package name. Note that the package names must consist only of letters (a-z, A-Z), digits (0-9), plus (+) and minus (-) signs, periods (.) and underscores (_). They must be at least one character long and must start with a letter.
5154

5255
message.icon-not-png=The specified icon "{0}" is not a PNG file and will not be used. The default icon will be used in it's place.
5356
message.test-for-tool=Test for [{0}]. Result: {1}

‎src/jdk.jpackage/share/classes/jdk/jpackage/internal/Arguments.java

+19-3
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,7 @@ private void generateBundle(Map<String,? super Object> params)
700700

701701
Map<String, ? super Object> localParams = new HashMap<>(params);
702702
try {
703-
bundler.validate(localParams);
704-
Path result = bundler.execute(localParams,
705-
StandardBundlerParam.OUTPUT_DIR.fetchFrom(params));
703+
Path result = executeBundler(bundler, params, localParams);
706704
if (result == null) {
707705
throw new PackagerException("MSG_BundlerFailed",
708706
bundler.getID(), bundler.getName());
@@ -737,6 +735,24 @@ private void generateBundle(Map<String,? super Object> params)
737735
}
738736
}
739737

738+
private static Path executeBundler(Bundler bundler, Map<String, ? super Object> params,
739+
Map<String, ? super Object> localParams) throws ConfigException, PackagerException {
740+
try {
741+
bundler.validate(localParams);
742+
return bundler.execute(localParams, StandardBundlerParam.OUTPUT_DIR.fetchFrom(params));
743+
} catch (ConfigException|PackagerException ex) {
744+
throw ex;
745+
} catch (RuntimeException ex) {
746+
if (ex.getCause() instanceof ConfigException cfgEx) {
747+
throw cfgEx;
748+
} else if (ex.getCause() instanceof PackagerException pkgEx) {
749+
throw pkgEx;
750+
} else {
751+
throw ex;
752+
}
753+
}
754+
}
755+
740756
static CLIOptions toCLIOption(String arg) {
741757
CLIOptions option;
742758
if ((option = argIds.get(arg)) == null) {

‎test/jdk/tools/jpackage/share/ErrorTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ public static Collection<Object[]> invalidAppVersion() {
410410
@ParameterSupplier("basic")
411411
@ParameterSupplier(value="testWindows", ifOS = WINDOWS)
412412
@ParameterSupplier(value="testMac", ifOS = MACOS)
413+
@ParameterSupplier(value="testLinux", ifOS = LINUX)
413414
@ParameterSupplier(value="winOption", ifNotOS = WINDOWS)
414415
@ParameterSupplier(value="linuxOption", ifNotOS = LINUX)
415416
@ParameterSupplier(value="macOption", ifNotOS = MACOS)
@@ -585,6 +586,23 @@ public static void testAppContentWarning() {
585586
cmd.execute(1);
586587
}
587588

589+
public static Collection<Object[]> testLinux() {
590+
final List<TestSpec> testCases = new ArrayList<>();
591+
592+
testCases.addAll(Stream.of(
593+
testSpec().type(PackageType.LINUX_DEB).addArgs("--linux-package-name", "#")
594+
.error("error.deb-invalid-value-for-package-name", "#")
595+
.error("error.deb-invalid-value-for-package-name.advice"),
596+
testSpec().type(PackageType.LINUX_RPM).addArgs("--linux-package-name", "#")
597+
.error("error.rpm-invalid-value-for-package-name", "#")
598+
.error("error.rpm-invalid-value-for-package-name.advice")
599+
).map(TestSpec.Builder::create).filter(spec -> {
600+
return spec.type().orElseThrow().isSupported();
601+
}).toList());
602+
603+
return toTestArgs(testCases.stream());
604+
}
605+
588606
private static void duplicate(TestSpec.Builder builder, Consumer<TestSpec> accumulator, Consumer<TestSpec.Builder> mutator) {
589607
accumulator.accept(builder.create());
590608
mutator.accept(builder);

0 commit comments

Comments
 (0)
Please sign in to comment.