Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jpackage/share/RuntimePackageTest.java
41152 views
1
/*
2
* Copyright (c) 2018, 2021, 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.HashSet;
28
import java.util.Optional;
29
import java.util.Set;
30
import java.util.function.Predicate;
31
import java.util.stream.Collectors;
32
import jdk.jpackage.test.PackageType;
33
import jdk.jpackage.test.PackageTest;
34
import jdk.jpackage.test.JPackageCommand;
35
import jdk.jpackage.test.TKit;
36
import jdk.jpackage.test.Annotations.Test;
37
import jdk.jpackage.test.LinuxHelper;
38
import static jdk.jpackage.test.TKit.assertTrue;
39
import static jdk.jpackage.test.TKit.assertFalse;
40
41
/**
42
* Test --runtime-image parameter.
43
* Output of the test should be RuntimePackageTest*.* installer.
44
* The installer should install Java Runtime without an application.
45
* Installation directory should not have "app" subfolder and should not have
46
* an application launcher.
47
*
48
*
49
* Windows:
50
*
51
* Java runtime should be installed in %ProgramFiles%\RuntimePackageTest directory.
52
*/
53
54
/*
55
* @test
56
* @summary jpackage with --runtime-image
57
* @library ../helpers
58
* @key jpackagePlatformPackage
59
* @build jdk.jpackage.test.*
60
* @requires (jpackage.test.SQETest == null)
61
* @modules jdk.jpackage/jdk.jpackage.internal
62
* @compile RuntimePackageTest.java
63
* @run main/othervm/timeout=1400 -Xmx512m jdk.jpackage.test.Main
64
* --jpt-run=RuntimePackageTest
65
*/
66
67
/*
68
* @test
69
* @summary jpackage with --runtime-image
70
* @library ../helpers
71
* @key jpackagePlatformPackage
72
* @build jdk.jpackage.test.*
73
* @requires (jpackage.test.SQETest != null)
74
* @modules jdk.jpackage/jdk.jpackage.internal
75
* @compile RuntimePackageTest.java
76
* @run main/othervm/timeout=720 -Xmx512m jdk.jpackage.test.Main
77
* --jpt-run=RuntimePackageTest.test
78
*/
79
public class RuntimePackageTest {
80
81
@Test
82
public static void test() {
83
init(PackageType.NATIVE).run();
84
}
85
86
@Test
87
public static void testUsrInstallDir() {
88
init(PackageType.LINUX)
89
.addInitializer(cmd -> cmd.addArguments("--install-dir", "/usr"))
90
.run();
91
}
92
93
@Test
94
public static void testUsrInstallDir2() {
95
init(PackageType.LINUX)
96
.addInitializer(cmd -> cmd.addArguments("--install-dir", "/usr/lib/Java"))
97
.run();
98
}
99
100
private static PackageTest init(Set<PackageType> types) {
101
return new PackageTest()
102
.forTypes(types)
103
.addInitializer(cmd -> {
104
cmd.addArguments("--runtime-image", Optional.ofNullable(
105
JPackageCommand.DEFAULT_RUNTIME_IMAGE).orElse(Path.of(
106
System.getProperty("java.home"))));
107
// Remove --input parameter from jpackage command line as we don't
108
// create input directory in the test and jpackage fails
109
// if --input references non existant directory.
110
cmd.removeArgumentWithValue("--input");
111
})
112
.addInstallVerifier(cmd -> {
113
Set<Path> srcRuntime = listFiles(Path.of(cmd.getArgumentValue("--runtime-image")));
114
Path dest = cmd.appRuntimeDirectory();
115
if (TKit.isOSX()) {
116
dest = dest.resolve("Contents/Home");
117
}
118
Set<Path> dstRuntime = listFiles(dest);
119
120
Set<Path> intersection = new HashSet<>(srcRuntime);
121
intersection.retainAll(dstRuntime);
122
123
srcRuntime.removeAll(intersection);
124
dstRuntime.removeAll(intersection);
125
126
assertFileListEmpty(srcRuntime, "Missing");
127
assertFileListEmpty(dstRuntime, "Unexpected");
128
})
129
.forTypes(PackageType.LINUX_DEB)
130
.addInstallVerifier(cmd -> {
131
String installDir = cmd.getArgumentValue("--install-dir", () -> "/opt");
132
Path copyright = Path.of("/usr/share/doc",
133
LinuxHelper.getPackageName(cmd), "copyright");
134
boolean withCopyright = LinuxHelper.getPackageFiles(cmd).anyMatch(
135
Predicate.isEqual(copyright));
136
if (installDir.startsWith("/usr/") || installDir.equals("/usr")) {
137
assertTrue(withCopyright, String.format(
138
"Check the package delivers [%s] copyright file",
139
copyright));
140
} else {
141
assertFalse(withCopyright, String.format(
142
"Check the package doesn't deliver [%s] copyright file",
143
copyright));
144
}
145
});
146
}
147
148
private static Set<Path> listFiles(Path root) throws IOException {
149
try (var files = Files.walk(root)) {
150
// Ignore files created by system prefs if any.
151
final Path prefsDir = Path.of(".systemPrefs");
152
return files.map(root::relativize)
153
.filter(x -> !x.startsWith(prefsDir))
154
.filter(x -> !x.endsWith(".DS_Store"))
155
.collect(Collectors.toSet());
156
}
157
}
158
159
private static void assertFileListEmpty(Set<Path> paths, String msg) {
160
TKit.assertTrue(paths.isEmpty(), String.format(
161
"Check there are no %s files in installed image",
162
msg.toLowerCase()), () -> {
163
String msg2 = String.format("%s %d files", msg, paths.size());
164
TKit.trace(msg2 + ":");
165
paths.stream().map(Path::toString).sorted().forEachOrdered(
166
TKit::trace);
167
TKit.trace("Done");
168
});
169
}
170
}
171
172