author | herrick |
Wed, 16 Oct 2019 10:32:08 -0400 | |
branch | JDK-8200758-branch |
changeset 58648 | 3bf53ffa9ae7 |
parent 58417 | 67ffaf3a2b75 |
child 58762 | 0fe62353385b |
permissions | -rw-r--r-- |
58113 | 1 |
/* |
2 |
* Copyright (c) 2019, 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 |
package jdk.jpackage.test; |
|
24 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
25 |
import java.io.IOException; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
26 |
import java.nio.file.Files; |
58113 | 27 |
import java.nio.file.Path; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
28 |
import java.util.Arrays; |
58113 | 29 |
import java.util.HashMap; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
30 |
import java.util.List; |
58113 | 31 |
import java.util.Map; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
32 |
import java.util.Set; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
33 |
import java.util.function.Function; |
58416 | 34 |
import java.util.stream.Collectors; |
58113 | 35 |
import java.util.stream.Stream; |
36 |
||
37 |
public class LinuxHelper { |
|
38 |
private static String getRelease(JPackageCommand cmd) { |
|
39 |
return cmd.getArgumentValue("--linux-app-release", () -> "1"); |
|
40 |
} |
|
41 |
||
42 |
public static String getPackageName(JPackageCommand cmd) { |
|
43 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
58115 | 44 |
return cmd.getArgumentValue("--linux-package-name", |
58113 | 45 |
() -> cmd.name().toLowerCase()); |
46 |
} |
|
47 |
||
48 |
static String getBundleName(JPackageCommand cmd) { |
|
49 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
50 |
||
51 |
final PackageType packageType = cmd.packageType(); |
|
52 |
String format = null; |
|
53 |
switch (packageType) { |
|
54 |
case LINUX_DEB: |
|
55 |
format = "%s_%s-%s_%s"; |
|
56 |
break; |
|
57 |
||
58 |
case LINUX_RPM: |
|
59 |
format = "%s-%s-%s.%s"; |
|
60 |
break; |
|
61 |
} |
|
62 |
||
63 |
final String release = getRelease(cmd); |
|
64 |
final String version = cmd.version(); |
|
65 |
||
66 |
return String.format(format, |
|
67 |
getPackageName(cmd), version, release, getPackageArch(packageType)) |
|
68 |
+ packageType.getSuffix(); |
|
69 |
} |
|
70 |
||
71 |
public static Stream<Path> getPackageFiles(JPackageCommand cmd) { |
|
72 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
73 |
||
74 |
final PackageType packageType = cmd.packageType(); |
|
75 |
final Path packageFile = cmd.outputBundle(); |
|
76 |
||
77 |
Executor exec = new Executor(); |
|
78 |
switch (packageType) { |
|
79 |
case LINUX_DEB: |
|
80 |
exec.setExecutable("dpkg") |
|
81 |
.addArgument("--contents") |
|
82 |
.addArgument(packageFile); |
|
83 |
break; |
|
84 |
||
85 |
case LINUX_RPM: |
|
86 |
exec.setExecutable("rpm") |
|
87 |
.addArgument("-qpl") |
|
88 |
.addArgument(packageFile); |
|
89 |
break; |
|
90 |
} |
|
91 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
92 |
Stream<String> lines = exec.executeAndGetOutput().stream(); |
58113 | 93 |
if (packageType == PackageType.LINUX_DEB) { |
94 |
// Typical text lines produced by dpkg look like: |
|
95 |
// drwxr-xr-x root/root 0 2019-08-30 05:30 ./opt/appcategorytest/runtime/lib/ |
|
96 |
// -rw-r--r-- root/root 574912 2019-08-30 05:30 ./opt/appcategorytest/runtime/lib/libmlib_image.so |
|
97 |
// Need to skip all fields but absolute path to file. |
|
98 |
lines = lines.map(line -> line.substring(line.indexOf(" ./") + 2)); |
|
99 |
} |
|
100 |
return lines.map(Path::of); |
|
101 |
} |
|
102 |
||
58416 | 103 |
public static List<String> getPrerequisitePackages(JPackageCommand cmd) { |
104 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
105 |
var packageType = cmd.packageType(); |
|
106 |
switch (packageType) { |
|
107 |
case LINUX_DEB: |
|
108 |
return Stream.of(getDebBundleProperty(cmd.outputBundle(), |
|
109 |
"Depends").split(",")).map(String::strip).collect( |
|
110 |
Collectors.toList()); |
|
111 |
||
112 |
case LINUX_RPM: |
|
113 |
return new Executor().setExecutable("rpm") |
|
114 |
.addArguments("-qp", "-R", cmd.outputBundle().toString()) |
|
115 |
.executeAndGetOutput(); |
|
116 |
} |
|
117 |
// Unreachable |
|
118 |
return null; |
|
119 |
} |
|
120 |
||
121 |
public static String getBundleProperty(JPackageCommand cmd, |
|
122 |
String propertyName) { |
|
123 |
return getBundleProperty(cmd, |
|
124 |
Map.of(PackageType.LINUX_DEB, propertyName, |
|
125 |
PackageType.LINUX_RPM, propertyName)); |
|
126 |
} |
|
127 |
||
128 |
public static String getBundleProperty(JPackageCommand cmd, |
|
129 |
Map<PackageType, String> propertyName) { |
|
130 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
131 |
var packageType = cmd.packageType(); |
|
132 |
switch (packageType) { |
|
133 |
case LINUX_DEB: |
|
134 |
return getDebBundleProperty(cmd.outputBundle(), propertyName.get( |
|
135 |
packageType)); |
|
136 |
||
137 |
case LINUX_RPM: |
|
138 |
return getRpmBundleProperty(cmd.outputBundle(), propertyName.get( |
|
139 |
packageType)); |
|
140 |
} |
|
141 |
// Unrechable |
|
142 |
return null; |
|
143 |
} |
|
144 |
||
58113 | 145 |
static Path getLauncherPath(JPackageCommand cmd) { |
146 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
147 |
||
148 |
final String launcherName = cmd.name(); |
|
149 |
final String launcherRelativePath = Path.of("/bin", launcherName).toString(); |
|
150 |
||
151 |
return getPackageFiles(cmd).filter(path -> path.toString().endsWith( |
|
152 |
launcherRelativePath)).findFirst().or(() -> { |
|
58416 | 153 |
TKit.assertUnexpected(String.format( |
58113 | 154 |
"Failed to find %s in %s package", launcherName, |
155 |
getPackageName(cmd))); |
|
156 |
return null; |
|
157 |
}).get(); |
|
158 |
} |
|
159 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
160 |
static long getInstalledPackageSizeKB(JPackageCommand cmd) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
161 |
cmd.verifyIsOfType(PackageType.LINUX); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
162 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
163 |
final Path packageFile = cmd.outputBundle(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
164 |
switch (cmd.packageType()) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
165 |
case LINUX_DEB: |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
166 |
return Long.parseLong(getDebBundleProperty(packageFile, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
167 |
"Installed-Size")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
168 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
169 |
case LINUX_RPM: |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
170 |
return Long.parseLong(getRpmBundleProperty(packageFile, "Size")) >> 10; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
171 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
172 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
173 |
return 0; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
174 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
175 |
|
58113 | 176 |
static String getDebBundleProperty(Path bundle, String fieldName) { |
177 |
return new Executor() |
|
178 |
.setExecutable("dpkg-deb") |
|
179 |
.addArguments("-f", bundle.toString(), fieldName) |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
180 |
.executeAndGetFirstLineOfOutput(); |
58113 | 181 |
} |
182 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
183 |
static String getRpmBundleProperty(Path bundle, String fieldName) { |
58113 | 184 |
return new Executor() |
185 |
.setExecutable("rpm") |
|
186 |
.addArguments( |
|
187 |
"-qp", |
|
188 |
"--queryformat", |
|
189 |
String.format("%%{%s}", fieldName), |
|
190 |
bundle.toString()) |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
191 |
.executeAndGetFirstLineOfOutput(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
192 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
193 |
|
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
194 |
static void verifyPackageBundleEssential(JPackageCommand cmd) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
195 |
String packageName = LinuxHelper.getPackageName(cmd); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
196 |
TKit.assertNotEquals(0L, LinuxHelper.getInstalledPackageSizeKB( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
197 |
cmd), String.format( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
198 |
"Check installed size of [%s] package in KB is not zero", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
199 |
packageName)); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
200 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
201 |
final boolean checkPrerequisites; |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
202 |
if (cmd.isRuntime()) { |
58648 | 203 |
Path runtimeDir = cmd.appRuntimeDirectory(); |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
204 |
Set<Path> expectedCriticalRuntimePaths = CRITICAL_RUNTIME_FILES.stream().map( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
205 |
runtimeDir::resolve).collect(Collectors.toSet()); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
206 |
Set<Path> actualCriticalRuntimePaths = getPackageFiles(cmd).filter( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
207 |
expectedCriticalRuntimePaths::contains).collect( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
208 |
Collectors.toSet()); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
209 |
checkPrerequisites = expectedCriticalRuntimePaths.equals( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
210 |
actualCriticalRuntimePaths); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
211 |
} else { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
212 |
checkPrerequisites = true; |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
213 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
214 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
215 |
List<String> prerequisites = LinuxHelper.getPrerequisitePackages(cmd); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
216 |
if (checkPrerequisites) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
217 |
final String vitalPackage = "libc"; |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
218 |
TKit.assertTrue(prerequisites.stream().filter( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
219 |
dep -> dep.contains(vitalPackage)).findAny().isPresent(), |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
220 |
String.format( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
221 |
"Check [%s] package is in the list of required packages %s of [%s] package", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
222 |
vitalPackage, prerequisites, packageName)); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
223 |
} else { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
224 |
TKit.trace(String.format( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
225 |
"Not cheking %s required packages of [%s] package", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
226 |
prerequisites, packageName)); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
227 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
228 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
229 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
230 |
static void addBundleDesktopIntegrationVerifier(PackageTest test, |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
231 |
boolean integrated) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
232 |
final String xdgUtils = "xdg-utils"; |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
233 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
234 |
test.addBundleVerifier(cmd -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
235 |
List<String> prerequisites = getPrerequisitePackages(cmd); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
236 |
boolean xdgUtilsFound = prerequisites.contains(xdgUtils); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
237 |
if (integrated) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
238 |
TKit.assertTrue(xdgUtilsFound, String.format( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
239 |
"Check [%s] is in the list of required packages %s", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
240 |
xdgUtils, prerequisites)); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
241 |
} else { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
242 |
TKit.assertFalse(xdgUtilsFound, String.format( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
243 |
"Check [%s] is NOT in the list of required packages %s", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
244 |
xdgUtils, prerequisites)); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
245 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
246 |
}); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
247 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
248 |
test.forTypes(PackageType.LINUX_DEB, () -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
249 |
addDebBundleDesktopIntegrationVerifier(test, integrated); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
250 |
}); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
251 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
252 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58416
diff
changeset
|
253 |
private static void addDebBundleDesktopIntegrationVerifier(PackageTest test, |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
254 |
boolean integrated) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
255 |
Function<List<String>, String> verifier = (lines) -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
256 |
// Lookup for xdg commands |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
257 |
return lines.stream().filter(line -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
258 |
Set<String> words = Set.of(line.split("\\s+")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
259 |
return words.contains("xdg-desktop-menu") || words.contains( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
260 |
"xdg-mime") || words.contains("xdg-icon-resource"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
261 |
}).findFirst().orElse(null); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
262 |
}; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
263 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
264 |
test.addBundleVerifier(cmd -> { |
58416 | 265 |
TKit.withTempDirectory("dpkg-control-files", tempDir -> { |
266 |
// Extract control Debian package files into temporary directory |
|
267 |
new Executor() |
|
268 |
.setExecutable("dpkg") |
|
269 |
.addArguments( |
|
270 |
"-e", |
|
271 |
cmd.outputBundle().toString(), |
|
272 |
tempDir.toString() |
|
273 |
).execute().assertExitCodeIsZero(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
274 |
|
58416 | 275 |
Path controlFile = Path.of("postinst"); |
276 |
||
277 |
// Lookup for xdg commands in postinstall script |
|
278 |
String lineWithXsdCommand = verifier.apply( |
|
279 |
Files.readAllLines(tempDir.resolve(controlFile))); |
|
280 |
String assertMsg = String.format( |
|
281 |
"Check if %s@%s control file uses xdg commands", |
|
282 |
cmd.outputBundle(), controlFile); |
|
283 |
if (integrated) { |
|
284 |
TKit.assertNotNull(lineWithXsdCommand, assertMsg); |
|
285 |
} else { |
|
286 |
TKit.assertNull(lineWithXsdCommand, assertMsg); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
287 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
288 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
289 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
290 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
291 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
292 |
static void initFileAssociationsTestFile(Path testFile) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
293 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
294 |
// Write something in test file. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
295 |
// On Ubuntu and Oracle Linux empty files are considered |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
296 |
// plain text. Seems like a system bug. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
297 |
// |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
298 |
// $ >foo.jptest1 |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
299 |
// $ xdg-mime query filetype foo.jptest1 |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
300 |
// text/plain |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
301 |
// $ echo > foo.jptest1 |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
302 |
// $ xdg-mime query filetype foo.jptest1 |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
303 |
// application/x-jpackage-jptest1 |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
304 |
// |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
305 |
Files.write(testFile, Arrays.asList("")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
306 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
307 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
308 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
309 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
310 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
311 |
private static Path getSystemDesktopFilesFolder() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
312 |
return Stream.of("/usr/share/applications", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
313 |
"/usr/local/share/applications").map(Path::of).filter(dir -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
314 |
return Files.exists(dir.resolve("defaults.list")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
315 |
}).findFirst().orElseThrow(() -> new RuntimeException( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
316 |
"Failed to locate system .desktop files folder")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
317 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
318 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
319 |
static void addFileAssociationsVerifier(PackageTest test, FileAssociations fa) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
320 |
test.addInstallVerifier(cmd -> { |
58416 | 321 |
PackageTest.withTestFileAssociationsFile(fa, testFile -> { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
322 |
String mimeType = queryFileMimeType(testFile); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
323 |
|
58416 | 324 |
TKit.assertEquals(fa.getMime(), mimeType, String.format( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
325 |
"Check mime type of [%s] file", testFile)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
326 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
327 |
String desktopFileName = queryMimeTypeDefaultHandler(mimeType); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
328 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
329 |
Path desktopFile = getSystemDesktopFilesFolder().resolve( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
330 |
desktopFileName); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
331 |
|
58416 | 332 |
TKit.assertFileExists(desktopFile); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
333 |
|
58416 | 334 |
TKit.trace(String.format("Reading [%s] file...", desktopFile)); |
335 |
String mimeHandler = Files.readAllLines(desktopFile).stream().peek( |
|
336 |
v -> TKit.trace(v)).filter( |
|
337 |
v -> v.startsWith("Exec=")).map( |
|
338 |
v -> v.split("=", 2)[1]).findFirst().orElseThrow(); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
339 |
|
58416 | 340 |
TKit.trace(String.format("Done")); |
341 |
||
58648 | 342 |
TKit.assertEquals(cmd.appLauncherPath().toString(), |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
343 |
mimeHandler, String.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
344 |
"Check mime type handler is the main application launcher")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
345 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
346 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
347 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
348 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
349 |
test.addUninstallVerifier(cmd -> { |
58416 | 350 |
PackageTest.withTestFileAssociationsFile(fa, testFile -> { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
351 |
String mimeType = queryFileMimeType(testFile); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
352 |
|
58416 | 353 |
TKit.assertNotEquals(fa.getMime(), mimeType, String.format( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
354 |
"Check mime type of [%s] file", testFile)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
355 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
356 |
String desktopFileName = queryMimeTypeDefaultHandler(fa.getMime()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
357 |
|
58416 | 358 |
TKit.assertNull(desktopFileName, String.format( |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
359 |
"Check there is no default handler for [%s] mime type", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
360 |
fa.getMime())); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
361 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
362 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
363 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
364 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
365 |
private static String queryFileMimeType(Path file) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
366 |
return new Executor() |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
367 |
.setExecutable("xdg-mime") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
368 |
.addArguments("query", "filetype", file.toString()) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
369 |
.executeAndGetFirstLineOfOutput(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
370 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
371 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
372 |
private static String queryMimeTypeDefaultHandler(String mimeType) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
373 |
return new Executor() |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
374 |
.setExecutable("xdg-mime") |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
375 |
.addArguments("query", "default", mimeType) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
376 |
.executeAndGetFirstLineOfOutput(); |
58113 | 377 |
} |
378 |
||
379 |
private static String getPackageArch(PackageType type) { |
|
380 |
if (archs == null) { |
|
381 |
archs = new HashMap<>(); |
|
382 |
} |
|
383 |
||
384 |
String arch = archs.get(type); |
|
385 |
if (arch == null) { |
|
386 |
Executor exec = new Executor(); |
|
387 |
switch (type) { |
|
388 |
case LINUX_DEB: |
|
389 |
exec.setExecutable("dpkg").addArgument( |
|
390 |
"--print-architecture"); |
|
391 |
break; |
|
392 |
||
393 |
case LINUX_RPM: |
|
394 |
exec.setExecutable("rpmbuild").addArgument( |
|
395 |
"--eval=%{_target_cpu}"); |
|
396 |
break; |
|
397 |
} |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58115
diff
changeset
|
398 |
arch = exec.executeAndGetFirstLineOfOutput(); |
58113 | 399 |
archs.put(type, arch); |
400 |
} |
|
401 |
return arch; |
|
402 |
} |
|
403 |
||
58416 | 404 |
static final Set<Path> CRITICAL_RUNTIME_FILES = Set.of(Path.of( |
405 |
"lib/server/libjvm.so")); |
|
406 |
||
58113 | 407 |
static private Map<PackageType, String> archs; |
408 |
} |