Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/share/AddLauncherTest.java
41149 views
1
/*
2
* Copyright (c) 2018, 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.nio.file.Path;
25
import java.io.File;
26
import java.util.Map;
27
import java.lang.invoke.MethodHandles;
28
import jdk.jpackage.test.PackageTest;
29
import jdk.jpackage.test.FileAssociations;
30
import jdk.jpackage.test.AdditionalLauncher;
31
import jdk.jpackage.test.JPackageCommand;
32
import jdk.jpackage.test.JavaAppDesc;
33
import jdk.jpackage.test.TKit;
34
import jdk.jpackage.test.Annotations.Test;
35
import jdk.jpackage.test.Annotations.Parameter;
36
import jdk.jpackage.test.CfgFile;
37
38
/**
39
* Test --add-launcher parameter. Output of the test should be
40
* AddLauncherTest*.* installer. The output installer should provide the
41
* same functionality as the default installer (see description of the default
42
* installer in SimplePackageTest.java) plus install three extra application
43
* launchers.
44
*/
45
46
/*
47
* @test
48
* @summary jpackage with --add-launcher
49
* @key jpackagePlatformPackage
50
* @requires (jpackage.test.SQETest != null)
51
* @library ../helpers
52
* @build jdk.jpackage.test.*
53
* @modules jdk.jpackage/jdk.jpackage.internal
54
* @compile AddLauncherTest.java
55
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
56
* --jpt-run=AddLauncherTest.test
57
*/
58
59
/*
60
* @test
61
* @summary jpackage with --add-launcher
62
* @key jpackagePlatformPackage
63
* @requires (jpackage.test.SQETest == null)
64
* @library ../helpers
65
* @build jdk.jpackage.test.*
66
* @modules jdk.jpackage/jdk.jpackage.internal
67
* @compile AddLauncherTest.java
68
* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
69
* --jpt-run=AddLauncherTest
70
*/
71
72
public class AddLauncherTest {
73
74
@Test
75
public void test() {
76
// Configure a bunch of additional launchers and also setup
77
// file association to make sure it will be linked only to the main
78
// launcher.
79
80
PackageTest packageTest = new PackageTest().configureHelloApp();
81
packageTest.addInitializer(cmd -> {
82
cmd.addArguments("--arguments", "Duke", "--arguments", "is",
83
"--arguments", "the", "--arguments", "King");
84
});
85
86
new FileAssociations(
87
MethodHandles.lookup().lookupClass().getSimpleName()).applyTo(
88
packageTest);
89
90
new AdditionalLauncher("Baz2")
91
.setDefaultArguments()
92
.applyTo(packageTest);
93
94
new AdditionalLauncher("foo")
95
.setDefaultArguments("yep!")
96
.applyTo(packageTest);
97
98
new AdditionalLauncher("Bar")
99
.setDefaultArguments("one", "two", "three")
100
.setIcon(GOLDEN_ICON)
101
.applyTo(packageTest);
102
103
packageTest.run();
104
}
105
106
@Test
107
public void bug8230933() {
108
PackageTest packageTest = new PackageTest().configureHelloApp();
109
110
new AdditionalLauncher("default_icon")
111
.applyTo(packageTest);
112
113
new AdditionalLauncher("no_icon")
114
.setNoIcon().applyTo(packageTest);
115
116
new AdditionalLauncher("custom_icon")
117
.setIcon(GOLDEN_ICON)
118
.applyTo(packageTest);
119
120
packageTest.run();
121
}
122
123
@Test
124
// Regular app
125
@Parameter("Hello")
126
// Modular app
127
@Parameter("com.other/com.other.CiaoBella")
128
public void testJavaOptions(String javaAppDesc) {
129
JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc)
130
.addArguments("--arguments", "courageous")
131
.addArguments("--java-options", "-Dparam1=xxx")
132
.addArguments("--java-options", "-Dparam2=yyy")
133
.addArguments("--java-options", "-Dparam3=zzz");
134
135
new AdditionalLauncher("Jack")
136
.addDefaultArguments("Jack of All Trades", "Master of None")
137
.setJavaOptions("-Dparam1=Contractor")
138
.applyTo(cmd);
139
140
new AdditionalLauncher("Monday")
141
.addDefaultArguments("Knock Your", "Socks Off")
142
.setJavaOptions("-Dparam2=Surprise workers!")
143
.applyTo(cmd);
144
145
// Should inherit default arguments and java options from the main launcher
146
new AdditionalLauncher("void").applyTo(cmd);
147
148
cmd.executeAndAssertHelloAppImageCreated();
149
}
150
151
/**
152
* Test usage of modular and non modular apps in additional launchers.
153
*/
154
@Test
155
@Parameter("true")
156
@Parameter("fase")
157
public void testMainLauncherIsModular(boolean mainLauncherIsModular) {
158
final var nonModularAppDesc = JavaAppDesc.parse("a.b.c.Hello");
159
final var modularAppDesc = JavaAppDesc.parse(
160
"module.jar:com.that/com.that.main.Florence");
161
162
final var nonModularJarCmd = JPackageCommand.helloAppImage(nonModularAppDesc);
163
final var modularJarCmd = JPackageCommand.helloAppImage(modularAppDesc);
164
165
final JPackageCommand cmd;
166
if (mainLauncherIsModular) {
167
// Create non modular jar.
168
nonModularJarCmd.executePrerequisiteActions();
169
170
cmd = modularJarCmd;
171
cmd.addArguments("--description",
172
"Test modular app with multiple add-launchers where one is modular app and other is non modular app");
173
cmd.addArguments("--input", nonModularJarCmd.getArgumentValue(
174
"--input"));
175
} else {
176
// Create modular jar.
177
modularJarCmd.executePrerequisiteActions();
178
179
cmd = nonModularJarCmd;
180
cmd.addArguments("--description",
181
"Test non modular app with multiple add-launchers where one is modular app and other is non modular app");
182
cmd.addArguments("--module-path", modularJarCmd.getArgumentValue(
183
"--module-path"));
184
cmd.addArguments("--add-modules", modularAppDesc.moduleName());
185
cmd.ignoreDefaultRuntime(true); // because of --add-modules
186
}
187
188
new AdditionalLauncher("ModularAppLauncher")
189
.addRawProperties(Map.entry("module", JavaAppDesc.parse(
190
modularAppDesc.toString()).setBundleFileName(null).toString()))
191
.addRawProperties(Map.entry("main-jar", ""))
192
.applyTo(cmd);
193
194
new AdditionalLauncher("NonModularAppLauncher")
195
// Use space ( ) character instead of equality sign (=) as
196
// a key/value separator
197
.setPersistenceHandler((path, properties) -> TKit.createTextFile(path,
198
properties.stream().map(entry -> String.join(" ", entry.getKey(),
199
entry.getValue()))))
200
.addRawProperties(Map.entry("main-class", nonModularAppDesc.className()))
201
.addRawProperties(Map.entry("main-jar", nonModularAppDesc.jarFileName()))
202
.applyTo(cmd);
203
204
cmd.executeAndAssertHelloAppImageCreated();
205
206
// check value of app.mainmodule in ModularAppLauncher's cfg file
207
CfgFile cfg = cmd.readLauncherCfgFile("ModularAppLauncher");
208
String moduleValue = cfg.getValue("Application", "app.mainmodule");
209
String mainClass = null;
210
String classpath = null;
211
String expectedMod = JavaAppDesc.parse(
212
modularAppDesc.toString()).setBundleFileName(null).toString();
213
TKit.assertEquals(expectedMod, moduleValue,
214
String.format("Check value of app.mainmodule=[%s]" +
215
"in ModularAppLauncher cfg file is as expected", expectedMod));
216
217
// check values of app.mainclass and app.classpath in cfg file
218
cfg = cmd.readLauncherCfgFile("NonModularAppLauncher");
219
moduleValue = null;
220
mainClass = cfg.getValue("Application", "app.mainclass");
221
classpath = cfg.getValue("Application", "app.classpath");
222
String ExpectedCN = nonModularAppDesc.className();
223
TKit.assertEquals(ExpectedCN, mainClass,
224
String.format("Check value of app.mainclass=[%s]" +
225
"in NonModularAppLauncher cfg file is as expected", ExpectedCN));
226
TKit.assertTrue(classpath.startsWith("$APPDIR" + File.separator
227
+ nonModularAppDesc.jarFileName()),
228
"Check app.classpath value in ModularAppLauncher cfg file");
229
}
230
231
private final static Path GOLDEN_ICON = TKit.TEST_SRC_ROOT.resolve(Path.of(
232
"resources", "icon" + TKit.ICON_SUFFIX));
233
}
234
235