Skip to content

Commit ba158ed

Browse files
author
Alexey Semenyuk
committed
8334319: Missing keys in jpackage resource bundle
Reviewed-by: naoto, almatvee
1 parent 8a3c100 commit ba158ed

File tree

4 files changed

+65
-30
lines changed

4 files changed

+65
-30
lines changed

src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,14 +333,7 @@ public boolean validate(Map<String, ? super Object> params)
333333

334334
FileAssociation.verify(FileAssociation.fetchFrom(params));
335335

336-
var serviceInstallerResource = initServiceInstallerResource(params);
337-
if (serviceInstallerResource != null) {
338-
if (!Files.exists(serviceInstallerResource.getExternalPath())) {
339-
throw new ConfigException(I18N.getString(
340-
"error.missing-service-installer"), I18N.getString(
341-
"error.missing-service-installer.advice"));
342-
}
343-
}
336+
initServiceInstallerResource(params);
344337

345338
return true;
346339
} catch (RuntimeException re) {
@@ -407,11 +400,15 @@ private void prepareProto(Map<String, ? super Object> params)
407400
ensureByMutationFileIsRTF(destFile);
408401
}
409402

410-
var serviceInstallerResource = initServiceInstallerResource(params);
411-
if (serviceInstallerResource != null) {
412-
var serviceInstallerPath = serviceInstallerResource.getExternalPath();
413-
params.put(SERVICE_INSTALLER.getID(), new InstallableFile(
414-
serviceInstallerPath, serviceInstallerPath.getFileName()));
403+
try {
404+
var serviceInstallerResource = initServiceInstallerResource(params);
405+
if (serviceInstallerResource != null) {
406+
var serviceInstallerPath = serviceInstallerResource.getExternalPath();
407+
params.put(SERVICE_INSTALLER.getID(), new InstallableFile(
408+
serviceInstallerPath, serviceInstallerPath.getFileName()));
409+
}
410+
} catch (ConfigException ex) {
411+
throw new PackagerException(ex);
415412
}
416413
}
417414

@@ -763,7 +760,7 @@ private static void ensureByMutationFileIsRTF(Path f) {
763760
}
764761

765762
private static OverridableResource initServiceInstallerResource(
766-
Map<String, ? super Object> params) {
763+
Map<String, ? super Object> params) throws ConfigException {
767764
if (StandardBundlerParam.isRuntimeInstaller(params)) {
768765
// Runtime installer doesn't install launchers,
769766
// service installer not needed
@@ -781,12 +778,16 @@ private static OverridableResource initServiceInstallerResource(
781778
var result = createResource(null, params)
782779
.setPublicName("service-installer.exe")
783780
.setSourceOrder(OverridableResource.Source.External);
784-
if (result.getResourceDir() == null) {
785-
return null;
781+
if (result.getResourceDir() != null) {
782+
result.setExternal(result.getResourceDir().resolve(result.getPublicName()));
783+
784+
if (Files.exists(result.getExternalPath())) {
785+
return result;
786+
}
786787
}
787788

788-
return result.setExternal(result.getResourceDir().resolve(
789-
result.getPublicName()));
789+
throw new ConfigException(I18N.getString("error.missing-service-installer"),
790+
I18N.getString("error.missing-service-installer.advice"));
790791
}
791792

792793
private Path installerIcon;

src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ error.unlock-resource=Failed to unlock: {0}
5757
error.read-wix-l10n-file=Failed to parse {0} file
5858
error.extract-culture-from-wix-l10n-file=Failed to read value of culture from {0} file
5959
error.short-path-conv-fail=Failed to get short version of "{0}" path
60+
error.missing-service-installer='service-installer.exe' service installer not found in the resource directory
61+
error.missing-service-installer.advice=Add 'service-installer.exe' service installer to the resource directory
6062

6163
message.icon-not-ico=The specified icon "{0}" is not an ICO file and will not be used. The default icon will be used in it's place.
6264
message.potential.windows.defender.issue=Warning: Windows Defender may prevent jpackage from functioning. If there is an issue, it can be addressed by either disabling realtime monitoring, or adding an exclusion for the directory "{0}".

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/JPackageStringBundle.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ private String getString(String key) {
5656
}
5757

5858
private String getFormattedString(String key, Object[] args) {
59-
return MessageFormat.format(getString(key), args);
59+
var str = getString(key);
60+
if (args.length != 0) {
61+
return MessageFormat.format(str, args);
62+
} else {
63+
return str;
64+
}
6065
}
6166

6267
public CannedFormattedString cannedFormattedString(String key, String ... args) {

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

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
import jdk.jpackage.test.CannedFormattedString;
3232
import jdk.jpackage.test.JPackageCommand;
3333
import jdk.jpackage.test.JPackageStringBundle;
34+
import jdk.jpackage.test.PackageTest;
35+
import jdk.jpackage.test.RunnablePackageTest;
3436
import jdk.jpackage.test.TKit;
37+
import static jdk.internal.util.OperatingSystem.WINDOWS;
3538

3639
/*
3740
* @test
@@ -113,14 +116,9 @@ public static Collection input() {
113116
public static void test(String javaAppDesc, String[] jpackageArgs,
114117
String[] removeArgs, CannedFormattedString... expectedErrors) {
115118
// Init default jpackage test command line.
116-
var cmd = JPackageCommand.helloAppImage(javaAppDesc)
117-
// Disable default logic adding `--verbose` option
118-
// to jpackage command line.
119-
// It will affect jpackage error messages if the command line is malformed.
120-
.ignoreDefaultVerbose(true)
121-
// Ignore external runtime as it will interfer
122-
// with jpackage arguments in this test.
123-
.ignoreDefaultRuntime(true);
119+
var cmd = JPackageCommand.helloAppImage(javaAppDesc);
120+
121+
defaultInit(cmd, expectedErrors);
124122

125123
// Add arguments if requested.
126124
Optional.ofNullable(jpackageArgs).ifPresent(cmd::addArguments);
@@ -129,13 +127,42 @@ public static void test(String javaAppDesc, String[] jpackageArgs,
129127
Optional.ofNullable(removeArgs).map(List::of).ifPresent(
130128
args -> args.forEach(cmd::removeArgumentWithValue));
131129

130+
cmd.execute(1);
131+
}
132+
133+
@Test(ifOS = WINDOWS)
134+
public static void testWinService() {
135+
136+
CannedFormattedString[] expectedErrors = new CannedFormattedString[] {
137+
JPackageStringBundle.MAIN.cannedFormattedString("error.missing-service-installer"),
138+
JPackageStringBundle.MAIN.cannedFormattedString("error.missing-service-installer.advice")
139+
};
140+
141+
new PackageTest().configureHelloApp()
142+
.addInitializer(cmd -> {
143+
defaultInit(cmd, expectedErrors);
144+
cmd.addArgument("--launcher-as-service");
145+
})
146+
.setExpectedExitCode(1)
147+
.run(RunnablePackageTest.Action.CREATE);
148+
}
149+
150+
private static void defaultInit(JPackageCommand cmd, CannedFormattedString... expectedErrors) {
151+
152+
// Disable default logic adding `--verbose` option
153+
// to jpackage command line.
154+
// It will affect jpackage error messages if the command line is malformed.
155+
cmd.ignoreDefaultVerbose(true);
156+
157+
// Ignore external runtime as it will interfer
158+
// with jpackage arguments in this test.
159+
cmd.ignoreDefaultRuntime(true);
160+
132161
// Configure jpackage output verifier to look up the list of provided
133-
// errors in the order they specified.
162+
// errors in the order they are specified.
134163
cmd.validateOutput(Stream.of(expectedErrors)
135164
.map(CannedFormattedString::getValue)
136165
.map(TKit::assertTextStream)
137166
.reduce(TKit.TextStreamVerifier::andThen).get());
138-
139-
cmd.execute(1);
140167
}
141168
}

0 commit comments

Comments
 (0)