Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/windows/WinL10nTest.java
41149 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.IOException;
25
import java.nio.file.Path;
26
import jdk.jpackage.test.TKit;
27
import jdk.jpackage.test.PackageTest;
28
import jdk.jpackage.test.PackageType;
29
import jdk.jpackage.test.Annotations.Test;
30
import jdk.jpackage.test.Annotations.Parameters;
31
import java.util.List;
32
import java.util.function.Predicate;
33
import java.util.stream.Stream;
34
import java.util.stream.Collectors;
35
import jdk.jpackage.test.Executor;
36
37
/*
38
* @test
39
* @summary Custom l10n of msi installers in jpackage
40
* @library ../helpers
41
* @key jpackagePlatformPackage
42
* @requires (jpackage.test.SQETest == null)
43
* @build jdk.jpackage.test.*
44
* @requires (os.family == "windows")
45
* @modules jdk.jpackage/jdk.jpackage.internal
46
* @compile WinL10nTest.java
47
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
48
* --jpt-run=WinL10nTest
49
*/
50
51
public class WinL10nTest {
52
53
public WinL10nTest(WixFileInitializer wxlFileInitializers[],
54
String expectedCulture, String expectedErrorMessage) {
55
this.wxlFileInitializers = wxlFileInitializers;
56
this.expectedCulture = expectedCulture;
57
this.expectedErrorMessage = expectedErrorMessage;
58
}
59
60
@Parameters
61
public static List<Object[]> data() {
62
return List.of(new Object[][]{
63
{null, "en-us", null},
64
{new WixFileInitializer[] {
65
WixFileInitializer.create("a.wxl", "en-us")
66
}, "en-us", null},
67
{new WixFileInitializer[] {
68
WixFileInitializer.create("a.wxl", "fr")
69
}, "fr;en-us", null},
70
{new WixFileInitializer[] {
71
WixFileInitializer.create("a.wxl", "fr"),
72
WixFileInitializer.create("b.wxl", "fr")
73
}, "fr;en-us", null},
74
{new WixFileInitializer[] {
75
WixFileInitializer.create("a.wxl", "it"),
76
WixFileInitializer.create("b.wxl", "fr")
77
}, "it;fr;en-us", null},
78
{new WixFileInitializer[] {
79
WixFileInitializer.create("c.wxl", "it"),
80
WixFileInitializer.create("b.wxl", "fr")
81
}, "fr;it;en-us", null},
82
{new WixFileInitializer[] {
83
WixFileInitializer.create("a.wxl", "fr"),
84
WixFileInitializer.create("b.wxl", "it"),
85
WixFileInitializer.create("c.wxl", "fr"),
86
WixFileInitializer.create("d.wxl", "it")
87
}, "fr;it;en-us", null},
88
{new WixFileInitializer[] {
89
WixFileInitializer.create("c.wxl", "it"),
90
WixFileInitializer.createMalformed("b.wxl")
91
}, null, null}
92
});
93
}
94
95
private final static Stream<String> getLightCommandLine(
96
Executor.Result result) {
97
return result.getOutput().stream()
98
.filter(s -> s.trim().startsWith("light.exe"));
99
}
100
101
@Test
102
public void test() throws IOException {
103
104
final boolean allWxlFilesValid;
105
if (wxlFileInitializers != null) {
106
allWxlFilesValid = Stream.of(wxlFileInitializers).allMatch(
107
WixFileInitializer::isValid);
108
} else {
109
allWxlFilesValid = true;
110
}
111
112
PackageTest test = new PackageTest()
113
.forTypes(PackageType.WINDOWS)
114
.configureHelloApp()
115
.addInitializer(cmd -> {
116
// 1. Set fake run time to save time by skipping jlink step of jpackage.
117
// 2. Instruct test to save jpackage output.
118
cmd.setFakeRuntime().saveConsoleOutput(true);
119
})
120
.addBundleVerifier((cmd, result) -> {
121
if (expectedCulture != null) {
122
TKit.assertTextStream("-cultures:" + expectedCulture).apply(
123
getLightCommandLine(result));
124
}
125
126
if (expectedErrorMessage != null) {
127
TKit.assertTextStream(expectedErrorMessage)
128
.apply(result.getOutput().stream());
129
}
130
131
if (wxlFileInitializers != null) {
132
if (allWxlFilesValid) {
133
for (var v : wxlFileInitializers) {
134
v.createCmdOutputVerifier(resourceDir).apply(
135
getLightCommandLine(result));
136
}
137
} else {
138
Stream.of(wxlFileInitializers)
139
.filter(Predicate.not(WixFileInitializer::isValid))
140
.forEach(v -> v.createCmdOutputVerifier(
141
resourceDir).apply(result.getOutput().stream()));
142
TKit.assertFalse(
143
getLightCommandLine(result).findAny().isPresent(),
144
"Check light.exe was not invoked");
145
}
146
}
147
});
148
149
if (wxlFileInitializers != null) {
150
test.addInitializer(cmd -> {
151
resourceDir = TKit.createTempDirectory("resources");
152
153
cmd.addArguments("--resource-dir", resourceDir);
154
155
for (var v : wxlFileInitializers) {
156
v.apply(resourceDir);
157
}
158
});
159
}
160
161
if (expectedErrorMessage != null || !allWxlFilesValid) {
162
test.setExpectedExitCode(1);
163
}
164
165
test.run();
166
}
167
168
final private WixFileInitializer wxlFileInitializers[];
169
final private String expectedCulture;
170
final private String expectedErrorMessage;
171
private Path resourceDir;
172
173
private static class WixFileInitializer {
174
static WixFileInitializer create(String name, String culture) {
175
return new WixFileInitializer(name, culture);
176
}
177
178
static WixFileInitializer createMalformed(String name) {
179
return new WixFileInitializer(name, null) {
180
@Override
181
public void apply(Path root) throws IOException {
182
TKit.createTextFile(root.resolve(name), List.of(
183
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
184
"<WixLocalization>"));
185
}
186
187
@Override
188
public String toString() {
189
return String.format("name=%s; malformed xml", name);
190
}
191
192
@Override
193
boolean isValid() {
194
return false;
195
}
196
197
@Override
198
TKit.TextStreamVerifier createCmdOutputVerifier(Path root) {
199
return TKit.assertTextStream(String.format(
200
"Failed to parse %s file",
201
root.resolve("b.wxl").toAbsolutePath()));
202
}
203
};
204
}
205
206
private WixFileInitializer(String name, String culture) {
207
this.name = name;
208
this.culture = culture;
209
}
210
211
void apply(Path root) throws IOException {
212
TKit.createTextFile(root.resolve(name), List.of(
213
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
214
culture == null ? "<WixLocalization/>" : "<WixLocalization Culture=\""
215
+ culture
216
+ "\" xmlns=\"http://schemas.microsoft.com/wix/2006/localization\" Codepage=\"1252\"/>"));
217
}
218
219
TKit.TextStreamVerifier createCmdOutputVerifier(Path root) {
220
return TKit.assertTextStream(
221
root.resolve(name).toAbsolutePath().toString());
222
}
223
224
boolean isValid() {
225
return true;
226
}
227
228
@Override
229
public String toString() {
230
return String.format("name=%s; culture=%s", name, culture);
231
}
232
233
private final String name;
234
private final String culture;
235
}
236
}
237
238