Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/linux/ShortcutHintTest.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.io.IOException;
25
import java.nio.file.Files;
26
import java.nio.file.Path;
27
import java.util.List;
28
import jdk.jpackage.test.AdditionalLauncher;
29
import jdk.jpackage.test.FileAssociations;
30
import jdk.jpackage.test.PackageType;
31
import jdk.jpackage.test.PackageTest;
32
import jdk.jpackage.test.TKit;
33
import jdk.jpackage.test.JPackageCommand;
34
import jdk.jpackage.test.LinuxHelper;
35
import jdk.jpackage.test.Annotations.Test;
36
37
/**
38
* Test --linux-shortcut parameter. Output of the test should be
39
* shortcuthinttest_1.0-1_amd64.deb or shortcuthinttest-1.0-1.amd64.rpm package
40
* bundle. The output package should provide the same functionality as the
41
* default package and also create a desktop shortcut.
42
*
43
* Finding a shortcut of the application launcher through GUI depends on desktop
44
* environment.
45
*
46
* deb:
47
* Search online for `Ways To Open A Ubuntu Application` for instructions.
48
*
49
* rpm:
50
*
51
*/
52
53
/*
54
* @test
55
* @summary jpackage with --linux-shortcut
56
* @library ../helpers
57
* @key jpackagePlatformPackage
58
* @requires jpackage.test.SQETest == null
59
* @build jdk.jpackage.test.*
60
* @requires (os.family == "linux")
61
* @modules jdk.jpackage/jdk.jpackage.internal
62
* @compile ShortcutHintTest.java
63
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
64
* --jpt-run=ShortcutHintTest
65
*/
66
67
/*
68
* @test
69
* @summary jpackage with --linux-shortcut
70
* @library ../helpers
71
* @key jpackagePlatformPackage
72
* @build jdk.jpackage.test.*
73
* @requires (os.family == "linux")
74
* @requires jpackage.test.SQETest != null
75
* @modules jdk.jpackage/jdk.jpackage.internal
76
* @compile ShortcutHintTest.java
77
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
78
* --jpt-run=ShortcutHintTest.testBasic
79
*/
80
81
public class ShortcutHintTest {
82
83
@Test
84
public static void testBasic() {
85
createTest().addInitializer(cmd -> {
86
cmd.addArgument("--linux-shortcut");
87
}).run();
88
}
89
90
private static PackageTest createTest() {
91
return new PackageTest()
92
.forTypes(PackageType.LINUX)
93
.configureHelloApp()
94
.addBundleDesktopIntegrationVerifier(true)
95
.addInitializer(cmd -> {
96
String defaultAppName = cmd.name();
97
String appName = defaultAppName.replace(
98
ShortcutHintTest.class.getSimpleName(),
99
"Shortcut Hint Test");
100
cmd.setArgumentValue("--name", appName);
101
cmd.addArguments("--linux-package-name",
102
defaultAppName.toLowerCase());
103
});
104
}
105
106
/**
107
* Adding `--icon` to jpackage command line should create desktop shortcut
108
* even though `--linux-shortcut` is omitted.
109
*/
110
@Test
111
public static void testCustomIcon() {
112
createTest().addInitializer(cmd -> {
113
cmd.setFakeRuntime();
114
cmd.addArguments("--icon", TKit.TEST_SRC_ROOT.resolve(
115
"apps/dukeplug.png"));
116
}).run();
117
}
118
119
/**
120
* Adding `--file-associations` to jpackage command line should create
121
* desktop shortcut even though `--linux-shortcut` is omitted.
122
*/
123
@Test
124
public static void testFileAssociations() {
125
PackageTest test = createTest().addInitializer(
126
JPackageCommand::setFakeRuntime);
127
new FileAssociations("ShortcutHintTest_testFileAssociations").applyTo(
128
test);
129
test.run();
130
}
131
132
/**
133
* Additional launcher with icon should create desktop shortcut even though
134
* `--linux-shortcut` is omitted.
135
*/
136
@Test
137
public static void testAdditionaltLaunchers() {
138
PackageTest test = createTest();
139
140
new AdditionalLauncher("Foo").setIcon(TKit.TEST_SRC_ROOT.resolve(
141
"apps/dukeplug.png")).applyTo(test);
142
143
test.addInitializer(JPackageCommand::setFakeRuntime).run();
144
}
145
146
/**
147
* .desktop file from resource dir.
148
*/
149
@Test
150
public static void testDesktopFileFromResourceDir() throws IOException {
151
final String expectedVersionString = "Version=12345678";
152
153
final Path tempDir = TKit.createTempDirectory("resources");
154
155
createTest().addInitializer(cmd -> {
156
cmd.setFakeRuntime();
157
158
cmd.addArgument("--linux-shortcut");
159
cmd.addArguments("--resource-dir", tempDir);
160
161
// Create custom .desktop file in resource directory
162
TKit.createTextFile(tempDir.resolve(cmd.name() + ".desktop"),
163
List.of(
164
"[Desktop Entry]",
165
"Name=APPLICATION_NAME",
166
"Exec=APPLICATION_LAUNCHER",
167
"Terminal=false",
168
"Type=Application",
169
"Comment=",
170
"Icon=APPLICATION_ICON",
171
"Categories=DEPLOY_BUNDLE_CATEGORY",
172
expectedVersionString
173
));
174
})
175
.addInstallVerifier(cmd -> {
176
Path desktopFile = LinuxHelper.getDesktopFile(cmd);
177
TKit.assertFileExists(desktopFile);
178
TKit.assertTextStream(expectedVersionString)
179
.label(String.format("[%s] file", desktopFile))
180
.predicate(String::equals)
181
.apply(Files.readAllLines(desktopFile).stream());
182
}).run();
183
}
184
}
185
186