Skip to content

Commit 543163a

Browse files
akashcheAlexey Semenyuk
authored and
Alexey Semenyuk
committed
8291978: jpackage: allow to override primary l10n files on Windows
Reviewed-by: asemenyuk, almatvee, naoto
1 parent 68af7c1 commit 543163a

File tree

11 files changed

+136
-53
lines changed

11 files changed

+136
-53
lines changed

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/WinMsiBundler.java

+35-15
Original file line numberDiff line numberDiff line change
@@ -513,11 +513,11 @@ private Map<String, String> prepareMainProjectFile(
513513
}
514514

515515
// Copy standard l10n files.
516-
for (String loc : Arrays.asList("en", "ja", "zh_CN")) {
516+
for (String loc : Arrays.asList("de", "en", "ja", "zh_CN")) {
517517
String fname = "MsiInstallerStrings_" + loc + ".wxl";
518-
try (InputStream is = OverridableResource.readDefault(fname)) {
519-
Files.copy(is, CONFIG_ROOT.fetchFrom(params).resolve(fname));
520-
}
518+
createResource(fname, params)
519+
.setCategory(I18N.getString("resource.wxl-file"))
520+
.saveToFile(configDir.resolve(fname));
521521
}
522522

523523
createResource("main.wxs", params)
@@ -563,16 +563,36 @@ private Path buildMSI(Map<String, ? super Object> params,
563563
wixPipeline.addLightOptions("-sice:ICE91");
564564
}
565565

566-
final Path primaryWxlFile = CONFIG_ROOT.fetchFrom(params).resolve(
567-
I18N.getString("resource.wxl-file-name")).toAbsolutePath();
568-
569-
wixPipeline.addLightOptions("-loc", primaryWxlFile.toString());
566+
// Filter out custom l10n files that were already used to
567+
// override primary l10n files. Ignore case filename comparison,
568+
// both lists are expected to be short.
569+
List<Path> primaryWxlFiles = getWxlFilesFromDir(params, CONFIG_ROOT);
570+
List<Path> customWxlFiles = getWxlFilesFromDir(params, RESOURCE_DIR).stream()
571+
.filter(custom -> primaryWxlFiles.stream().noneMatch(primary ->
572+
primary.getFileName().toString().equalsIgnoreCase(
573+
custom.getFileName().toString())))
574+
.peek(custom -> Log.verbose(MessageFormat.format(
575+
I18N.getString("message.using-custom-resource"),
576+
String.format("[%s]", I18N.getString("resource.wxl-file")),
577+
custom.getFileName().toString())))
578+
.toList();
579+
580+
// All l10n files are supplied to WiX with "-loc", but only
581+
// Cultures from custom files and a single primary Culture are
582+
// included into "-cultures" list
583+
for (var wxl : primaryWxlFiles) {
584+
wixPipeline.addLightOptions("-loc", wxl.toAbsolutePath().normalize().toString());
585+
}
570586

571587
List<String> cultures = new ArrayList<>();
572-
for (var wxl : getCustomWxlFiles(params)) {
573-
wixPipeline.addLightOptions("-loc", wxl.toAbsolutePath().toString());
588+
for (var wxl : customWxlFiles) {
589+
wixPipeline.addLightOptions("-loc", wxl.toAbsolutePath().normalize().toString());
574590
cultures.add(getCultureFromWxlFile(wxl));
575591
}
592+
593+
// Append a primary culture bases on runtime locale.
594+
final Path primaryWxlFile = CONFIG_ROOT.fetchFrom(params).resolve(
595+
I18N.getString("resource.wxl-file-name"));
576596
cultures.add(getCultureFromWxlFile(primaryWxlFile));
577597

578598
// Build ordered list of unique cultures.
@@ -586,18 +606,18 @@ private Path buildMSI(Map<String, ? super Object> params,
586606
return msiOut;
587607
}
588608

589-
private static List<Path> getCustomWxlFiles(Map<String, ? super Object> params)
590-
throws IOException {
591-
Path resourceDir = RESOURCE_DIR.fetchFrom(params);
592-
if (resourceDir == null) {
609+
private static List<Path> getWxlFilesFromDir(Map<String, ? super Object> params,
610+
StandardBundlerParam<Path> pathParam) throws IOException {
611+
Path dir = pathParam.fetchFrom(params);
612+
if (dir == null) {
593613
return Collections.emptyList();
594614
}
595615

596616
final String glob = "glob:**/*.wxl";
597617
final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(
598618
glob);
599619

600-
try (var walk = Files.walk(resourceDir, 1)) {
620+
try (var walk = Files.walk(dir, 1)) {
601621
return walk
602622
.filter(Files::isReadable)
603623
.filter(pathMatcher::matches)

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/MsiInstallerStrings_de.wxl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version = '1.0' encoding = 'utf-8'?>
2-
<WixLocalization Culture="de" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="1252">
2+
<WixLocalization Culture="de-de" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="1252">
33
<String Id="message.install.dir.exist">Der Ordner [INSTALLDIR] ist bereits vorhanden. Möchten Sie diesen Ordner trotzdem installieren?</String>
44
<String Id="MainFeatureTitle">Hauptfeature</String>
55
<String Id="DowngradeErrorMessage">Eine höhere Version von [ProductName] ist bereits installiert. Downgrades sind deaktiviert. Setup wird jetzt beendet.</String>

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/MsiInstallerStrings_ja.wxl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version = '1.0' encoding = 'utf-8'?>
2-
<WixLocalization Culture="ja" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="932">
2+
<WixLocalization Culture="ja-jp" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="932">
33
<String Id="message.install.dir.exist">フォルダ[INSTALLDIR]はすでに存在します。そのフォルダにインストールしますか?</String>
44
<String Id="MainFeatureTitle">主な機能</String>
55
<String Id="DowngradeErrorMessage">[ProductName]のより上位のバージョンがすでにインストールされています。ダウングレードは無効です。セットアップを終了します。</String>

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/MsiInstallerStrings_zh_CN.wxl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version = '1.0' encoding = 'utf-8'?>
2-
<WixLocalization Culture="zh-CN" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="936">
2+
<WixLocalization Culture="zh-cn" xmlns="http://schemas.microsoft.com/wix/2006/localization" Codepage="936">
33
<String Id="message.install.dir.exist">文件夹 [INSTALLDIR] 已存在。是否仍要安装到该文件夹?</String>
44
<String Id="MainFeatureTitle">主要功能</String>
55
<String Id="DowngradeErrorMessage">已安装更高版本的 [ProductName]。降级已禁用。现在将退出安装。</String>

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources.properties

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ resource.executable-properties-template=Template for creating executable propert
3434
resource.setup-icon=setup dialog icon
3535
resource.post-app-image-script=script to run after application image is populated
3636
resource.post-msi-script=script to run after msi file for exe installer is created
37+
resource.wxl-file=WiX localization file
3738
resource.wxl-file-name=MsiInstallerStrings_en.wxl
3839
resource.main-wix-file=Main WiX project file
3940
resource.overrides-wix-file=Overrides WiX project file

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_de.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource.executable-properties-template=Vorlage f\u00FCr das Erstellen der ausf\
3434
resource.setup-icon=Symbol f\u00FCr Dialogfeld "Setup"
3535
resource.post-app-image-script=Auszuf\u00FChrendes Skript nach dem Auff\u00FCllen des Anwendungsimages
3636
resource.post-msi-script=Auszuf\u00FChrendes Skript nach dem Erstellen der MSI-Datei f\u00FCr das EXE-Installationsprogramm
37-
resource.wxl-file-name=MsiInstallerStrings_en.wxl
37+
resource.wxl-file-name=MsiInstallerStrings_de.wxl
3838
resource.main-wix-file=Haupt-WiX-Projektdatei
3939
resource.overrides-wix-file=\u00DCberschreibt WiX-Projektdatei
4040
resource.shortcutpromptdlg-wix-file=Dialogfeld f\u00FCr Verkn\u00FCpfungs-Prompt der WiX-Projektdatei

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_ja.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource.executable-properties-template=\u5B9F\u884C\u53EF\u80FD\u306A\u30D7\u30
3434
resource.setup-icon=\u8A2D\u5B9A\u30C0\u30A4\u30A2\u30ED\u30B0\u30FB\u30A2\u30A4\u30B3\u30F3
3535
resource.post-app-image-script=\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u30FB\u30A4\u30E1\u30FC\u30B8\u3092\u79FB\u5165\u3057\u305F\u5F8C\u306B\u5B9F\u884C\u3059\u308B\u30B9\u30AF\u30EA\u30D7\u30C8
3636
resource.post-msi-script=exe\u30A4\u30F3\u30B9\u30C8\u30FC\u30E9\u306Emsi\u30D5\u30A1\u30A4\u30EB\u304C\u4F5C\u6210\u3055\u308C\u305F\u5F8C\u306B\u5B9F\u884C\u3059\u308B\u30B9\u30AF\u30EA\u30D7\u30C8
37-
resource.wxl-file-name=MsiInstallerStrings_en.wxl
37+
resource.wxl-file-name=MsiInstallerStrings_ja.wxl
3838
resource.main-wix-file=\u30E1\u30A4\u30F3WiX\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30FB\u30D5\u30A1\u30A4\u30EB
3939
resource.overrides-wix-file=WiX\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30FB\u30D5\u30A1\u30A4\u30EB\u306E\u30AA\u30FC\u30D0\u30FC\u30E9\u30A4\u30C9
4040
resource.shortcutpromptdlg-wix-file=\u30B7\u30E7\u30FC\u30C8\u30AB\u30C3\u30C8\u30FB\u30D7\u30ED\u30F3\u30D7\u30C8\u30FB\u30C0\u30A4\u30A2\u30ED\u30B0WiX\u30D7\u30ED\u30B8\u30A7\u30AF\u30C8\u30FB\u30D5\u30A1\u30A4\u30EB

Diff for: src/jdk.jpackage/windows/classes/jdk/jpackage/internal/resources/WinResources_zh_CN.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ resource.executable-properties-template=\u7528\u4E8E\u521B\u5EFA\u53EF\u6267\u88
3434
resource.setup-icon=\u8BBE\u7F6E\u5BF9\u8BDD\u6846\u56FE\u6807
3535
resource.post-app-image-script=\u8981\u5728\u586B\u5145\u5E94\u7528\u7A0B\u5E8F\u6620\u50CF\u4E4B\u540E\u8FD0\u884C\u7684\u811A\u672C
3636
resource.post-msi-script=\u5728\u4E3A exe \u5B89\u88C5\u7A0B\u5E8F\u521B\u5EFA msi \u6587\u4EF6\u4E4B\u540E\u8981\u8FD0\u884C\u7684\u811A\u672C
37-
resource.wxl-file-name=MsiInstallerStrings_en.wxl
37+
resource.wxl-file-name=MsiInstallerStrings_zh_CN.wxl
3838
resource.main-wix-file=\u4E3B WiX \u9879\u76EE\u6587\u4EF6
3939
resource.overrides-wix-file=\u8986\u76D6 WiX \u9879\u76EE\u6587\u4EF6
4040
resource.shortcutpromptdlg-wix-file=\u5FEB\u6377\u65B9\u5F0F\u63D0\u793A\u5BF9\u8BDD\u6846 WiX \u9879\u76EE\u6587\u4EF6

Diff for: test/jdk/tools/jpackage/helpers/jdk/jpackage/test/WindowsHelper.java

+16
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ private static Path getInstallationSubDirectory(JPackageCommand cmd) {
6161
return Path.of(cmd.getArgumentValue("--install-dir", cmd::name));
6262
}
6363

64+
// Tests have problems on windows where path in the temp dir are too long
65+
// for the wix tools. We can't use a tempDir outside the TKit's WorkDir, so
66+
// we minimize both the tempRoot directory name (above) and the tempDir name
67+
// (below) to the extension part (which is necessary to differenciate between
68+
// the multiple PackageTypes that will be run for one JPackageCommand).
69+
// It might be beter if the whole work dir name was shortened from:
70+
// jtreg_open_test_jdk_tools_jpackage_share_jdk_jpackage_tests_BasicTest_java.
71+
public static Path getTempDirectory(JPackageCommand cmd, Path tempRoot) {
72+
String ext = cmd.outputBundle().getFileName().toString();
73+
int i = ext.lastIndexOf(".");
74+
if (i > 0 && i < (ext.length() - 1)) {
75+
ext = ext.substring(i+1);
76+
}
77+
return tempRoot.resolve(ext);
78+
}
79+
6480
private static void runMsiexecWithRetries(Executor misexec) {
6581
Executor.Result result = null;
6682
for (int attempt = 0; attempt < 8; ++attempt) {

Diff for: test/jdk/tools/jpackage/share/jdk/jpackage/tests/BasicTest.java

+4-17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import jdk.jpackage.test.Annotations.Test;
4444
import jdk.jpackage.test.Annotations.Parameter;
4545

46+
import static jdk.jpackage.test.WindowsHelper.getTempDirectory;
47+
4648
/*
4749
* @test
4850
* @summary jpackage basic testing
@@ -273,29 +275,14 @@ public void testAddModules(String... addModulesArg) {
273275
@Parameter("false")
274276
public void testTemp(boolean withExistingTempDir) throws IOException {
275277
final Path tempRoot = TKit.createTempDirectory("tmp");
276-
// This Test has problems on windows where path in the temp dir are too long
277-
// for the wix tools. We can't use a tempDir outside the TKit's WorkDir, so
278-
// we minimize both the tempRoot directory name (above) and the tempDir name
279-
// (below) to the extension part (which is necessary to differenciate between
280-
// the multiple PackageTypes that will be run for one JPackageCommand).
281-
// It might be beter if the whole work dir name was shortened from:
282-
// jtreg_open_test_jdk_tools_jpackage_share_jdk_jpackage_tests_BasicTest_java.
283-
Function<JPackageCommand, Path> getTempDir = cmd -> {
284-
String ext = cmd.outputBundle().getFileName().toString();
285-
int i = ext.lastIndexOf(".");
286-
if (i > 0 && i < (ext.length() - 1)) {
287-
ext = ext.substring(i+1);
288-
}
289-
return tempRoot.resolve(ext);
290-
};
291278

292279
Supplier<PackageTest> createTest = () -> {
293280
return new PackageTest()
294281
.configureHelloApp()
295282
// Force save of package bundle in test work directory.
296283
.addInitializer(JPackageCommand::setDefaultInputOutput)
297284
.addInitializer(cmd -> {
298-
Path tempDir = getTempDir.apply(cmd);
285+
Path tempDir = getTempDirectory(cmd, tempRoot);
299286
if (withExistingTempDir) {
300287
Files.createDirectories(tempDir);
301288
} else {
@@ -308,7 +295,7 @@ public void testTemp(boolean withExistingTempDir) throws IOException {
308295
createTest.get()
309296
.addBundleVerifier(cmd -> {
310297
// Check jpackage actually used the supplied directory.
311-
Path tempDir = getTempDir.apply(cmd);
298+
Path tempDir = getTempDirectory(cmd, tempRoot);
312299
TKit.assertNotEquals(0, tempDir.toFile().list().length,
313300
String.format(
314301
"Check jpackage wrote some data in the supplied temporary directory [%s]",

0 commit comments

Comments
 (0)