Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/windows/WinUpgradeUUIDTest.java
41149 views
1
/*
2
* Copyright (c) 2019, 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.util.HashMap;
25
import java.util.List;
26
import java.util.Map;
27
import java.util.UUID;
28
import java.util.function.Supplier;
29
import jdk.jpackage.test.Annotations.Test;
30
import jdk.jpackage.test.PackageTest;
31
import jdk.jpackage.test.PackageType;
32
import jdk.jpackage.test.WindowsHelper;
33
import jdk.jpackage.test.TKit;
34
35
/**
36
* Test both --win-upgrade-uuid and --app-version parameters. Output of the test
37
* should be WinUpgradeUUIDTest-1.0.exe and WinUpgradeUUIDTest-2.0.exe
38
* installers. Both output installers should provide the same functionality as
39
* the default installer (see description of the default installer in
40
* SimplePackageTest.java) but have the same product code and different
41
* versions. Running WinUpgradeUUIDTest-2.0.exe installer should automatically
42
* uninstall older version of the test application previously installed with
43
* WinUpgradeUUIDTest-1.0.exe installer.
44
*/
45
46
/*
47
* @test
48
* @summary jpackage with --win-upgrade-uuid and --app-version
49
* @library ../helpers
50
* @key jpackagePlatformPackage
51
* @requires (jpackage.test.SQETest != null)
52
* @build jdk.jpackage.test.*
53
* @requires (os.family == "windows")
54
* @modules jdk.jpackage/jdk.jpackage.internal
55
* @compile WinUpgradeUUIDTest.java
56
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
57
* --jpt-run=WinUpgradeUUIDTest.test
58
*/
59
60
/*
61
* @test
62
* @summary jpackage with --win-upgrade-uuid and --app-version
63
* @library ../helpers
64
* @key jpackagePlatformPackage
65
* @requires (jpackage.test.SQETest == null)
66
* @build jdk.jpackage.test.*
67
* @requires (os.family == "windows")
68
* @modules jdk.jpackage/jdk.jpackage.internal
69
* @compile WinUpgradeUUIDTest.java
70
* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
71
* --jpt-run=WinUpgradeUUIDTest
72
*/
73
74
public class WinUpgradeUUIDTest {
75
76
@Test
77
public static void test() {
78
Supplier<PackageTest> init = () -> {
79
final UUID upgradeCode = UUID.fromString(
80
"F0B18E75-52AD-41A2-BC86-6BE4FCD50BEB");
81
return new PackageTest()
82
.forTypes(PackageType.WIN_MSI)
83
.addBundlePropertyVerifier("UpgradeCode", value -> {
84
if (value.startsWith("{")) {
85
value = value.substring(1);
86
}
87
if (value.endsWith("}")) {
88
value = value.substring(0, value.length() - 1);
89
}
90
return UUID.fromString(value).equals(upgradeCode);
91
}, "is a match with")
92
.forTypes(PackageType.WINDOWS)
93
.configureHelloApp()
94
.addInitializer(cmd -> cmd.addArguments("--win-upgrade-uuid",
95
upgradeCode.toString())) ;
96
97
};
98
99
// Replace real uninstall command for the first package with nop action.
100
// It will be uninstalled automatically when the second
101
// package will be installed.
102
// However uninstall verification for the first package will be executed.
103
PackageTest test1 = init.get().setPackageUninstaller(cmd -> {});
104
105
PackageTest test2 = init.get().addInitializer(cmd -> {
106
cmd.setArgumentValue("--app-version", "2.0");
107
cmd.setArgumentValue("--arguments", "bar");
108
});
109
110
new PackageTest.Group(test1, test2).run();
111
}
112
113
/**
114
* Running jpackage multiple times with the same parameters should produce
115
* MSI packages with the same UpgradeCode and ProductCode values.
116
*/
117
@Test
118
public static void testUUIDs() {
119
Supplier<PackageTest> init = () -> {
120
return new PackageTest()
121
.forTypes(PackageType.WIN_MSI)
122
.configureHelloApp()
123
.addInitializer(cmd -> {
124
cmd.setFakeRuntime();
125
cmd.setArgumentValue("--dest", TKit.createTempDirectory("output"));
126
});
127
};
128
129
PackageTest test1 = init.get();
130
PackageTest test2 = init.get();
131
PackageTest test3 = init.get().addInitializer(cmd -> {
132
cmd.addArguments("--app-version", "2.0");
133
});
134
PackageTest test4 = init.get().addInitializer(cmd -> {
135
cmd.addArguments("--app-version", "2.0");
136
cmd.addArguments("--vendor", "Foo Inc.");
137
});
138
139
PackageTest[] tests = new PackageTest[] { test1, test2, test3, test4 };
140
141
var productCodeVerifier = createPropertyVerifier("ProductCode", tests);
142
var upgradeCodeVerifier = createPropertyVerifier("UpgradeCode", tests);
143
144
List.of(tests).forEach(test -> {
145
test.run(PackageTest.Action.CREATE);
146
});
147
148
productCodeVerifier.assertEquals(test1, test2);
149
productCodeVerifier.assertNotEquals(test1, test3);
150
productCodeVerifier.assertNotEquals(test1, test4);
151
productCodeVerifier.assertNotEquals(test3, test4);
152
153
upgradeCodeVerifier.assertEquals(test1, test2);
154
upgradeCodeVerifier.assertEquals(test1, test3);
155
upgradeCodeVerifier.assertNotEquals(test1, test4);
156
}
157
158
private static PropertyVerifier createPropertyVerifier(String propertyName,
159
PackageTest... tests) {
160
Map<PackageTest, Map.Entry<String, String>> properties = new HashMap<>();
161
List.of(tests).forEach(test -> {
162
test.addBundleVerifier(cmd -> {
163
properties.put(test, Map.entry(cmd.getPrintableCommandLine(),
164
WindowsHelper.getMsiProperty(cmd, propertyName)));
165
});
166
});
167
168
return new PropertyVerifier() {
169
@Override
170
protected String propertyName() {
171
return propertyName;
172
}
173
174
@Override
175
protected Map<PackageTest, Map.Entry<String, String>> propertyValues() {
176
return properties;
177
}
178
};
179
}
180
181
static abstract class PropertyVerifier {
182
void assertEquals(PackageTest x, PackageTest y) {
183
var entryX = propertyValues().get(x);
184
var entryY = propertyValues().get(y);
185
// if MsiBundler is not supported, these will be null
186
if (entryX != null && entryY != null) {
187
TKit.assertEquals(entryX.getValue(), entryY.getValue(),
188
String.format(
189
"Check %s is the same for %s and %s command lines",
190
propertyName(), entryX.getKey(), entryY.getKey()));
191
}
192
}
193
194
void assertNotEquals(PackageTest x, PackageTest y) {
195
var entryX = propertyValues().get(x);
196
var entryY = propertyValues().get(y);
197
// if MsiBundler is not supported, these will be null
198
if (entryX != null && entryY != null) {
199
TKit.assertNotEquals(entryX.getValue(), entryY.getValue(),
200
String.format(
201
"Check %s is different for %s and %s command lines",
202
propertyName(), entryX.getKey(), entryY.getKey()));
203
}
204
}
205
206
protected abstract String propertyName();
207
protected abstract Map<PackageTest, Map.Entry<String, String>> propertyValues();
208
}
209
}
210
211