author | herrick |
Wed, 23 Oct 2019 10:10:34 -0400 | |
branch | JDK-8200758-branch |
changeset 58761 | 88e2753a2334 |
parent 58648 | 3bf53ffa9ae7 |
child 58994 | b09ba68c6a19 |
permissions | -rw-r--r-- |
58113 | 1 |
/* |
2 |
* Copyright (c) 2018, 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 |
||
24 |
import java.io.IOException; |
|
25 |
import java.nio.file.Files; |
|
26 |
import java.nio.file.Path; |
|
58418
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58416
diff
changeset
|
27 |
import java.nio.file.StandardCopyOption; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
28 |
import java.util.List; |
58304 | 29 |
import java.util.ArrayList; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
30 |
import java.util.Arrays; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
31 |
import java.util.function.Function; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
32 |
import java.util.stream.Collectors; |
58113 | 33 |
import jdk.jpackage.test.JPackageCommand; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
34 |
import jdk.jpackage.test.PackageType; |
58113 | 35 |
import jdk.jpackage.test.PackageTest; |
36 |
import jdk.jpackage.test.LinuxHelper; |
|
37 |
import jdk.jpackage.test.Executor; |
|
58416 | 38 |
import jdk.jpackage.test.TKit; |
58113 | 39 |
|
40 |
/** |
|
58648 | 41 |
* Test --license-file parameter. Output of the test should be commonlicensetest*.* |
58113 | 42 |
* package bundle. The output package should provide the same functionality as |
43 |
* the default package and also incorporate license information from |
|
44 |
* test/jdk/tools/jpackage/resources/license.txt file from OpenJDK repo. |
|
45 |
* |
|
46 |
* deb: |
|
47 |
* |
|
58648 | 48 |
* Package should install license file /opt/commonlicensetest/share/doc/copyright |
58113 | 49 |
* file. |
50 |
* |
|
51 |
* rpm: |
|
52 |
* |
|
53 |
* Package should install license file in |
|
54 |
* %{_defaultlicensedir}/licensetest-1.0/license.txt file. |
|
55 |
* |
|
56 |
* Mac: |
|
57 |
* |
|
58 |
* Windows |
|
59 |
* |
|
60 |
* Installer should display license text matching contents of the license file |
|
61 |
* during installation. |
|
62 |
*/ |
|
63 |
||
64 |
/* |
|
65 |
* @test |
|
66 |
* @summary jpackage with --license-file |
|
67 |
* @library ../helpers |
|
58761
88e2753a2334
8231972: Build a stable list of jpackager tests for SQE
herrick
parents:
58648
diff
changeset
|
68 |
* @key jpackagePlatformPackage |
58416 | 69 |
* @build jdk.jpackage.test.* |
70 |
* @compile LicenseTest.java |
|
58113 | 71 |
* @modules jdk.jpackage/jdk.jpackage.internal |
58416 | 72 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
73 |
* --jpt-run=LicenseTest.testCommon |
|
58113 | 74 |
*/ |
58304 | 75 |
|
76 |
/* |
|
77 |
* @test |
|
78 |
* @summary jpackage with --license-file |
|
79 |
* @library ../helpers |
|
58761
88e2753a2334
8231972: Build a stable list of jpackager tests for SQE
herrick
parents:
58648
diff
changeset
|
80 |
* @key jpackagePlatformPackage |
58416 | 81 |
* @compile LicenseTest.java |
58304 | 82 |
* @requires (os.family == "linux") |
58761
88e2753a2334
8231972: Build a stable list of jpackager tests for SQE
herrick
parents:
58648
diff
changeset
|
83 |
* @requires (jpackage.test.SQETest == null) |
88e2753a2334
8231972: Build a stable list of jpackager tests for SQE
herrick
parents:
58648
diff
changeset
|
84 |
* @modules jdk.jpackage/jdk.jpackage.internal |
58416 | 85 |
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
86 |
* --jpt-run=LicenseTest.testCustomDebianCopyright |
|
87 |
* --jpt-run=LicenseTest.testCustomDebianCopyrightSubst |
|
58304 | 88 |
*/ |
89 |
||
58113 | 90 |
public class LicenseTest { |
58304 | 91 |
public static void testCommon() { |
92 |
new PackageTest().configureHelloApp() |
|
93 |
.addInitializer(cmd -> { |
|
58648 | 94 |
cmd.addArguments("--license-file", TKit.createRelativePathCopy( |
95 |
LICENSE_FILE)); |
|
58304 | 96 |
}) |
97 |
.forTypes(PackageType.LINUX) |
|
98 |
.addBundleVerifier(cmd -> { |
|
99 |
verifyLicenseFileInLinuxPackage(cmd, linuxLicenseFile(cmd)); |
|
100 |
}) |
|
101 |
.addInstallVerifier(cmd -> { |
|
58416 | 102 |
TKit.assertReadableFileExists(linuxLicenseFile(cmd)); |
58304 | 103 |
}) |
104 |
.addUninstallVerifier(cmd -> { |
|
105 |
verifyLicenseFileNotInstalledLinux(linuxLicenseFile(cmd)); |
|
106 |
}) |
|
107 |
.forTypes(PackageType.LINUX_DEB) |
|
108 |
.addInstallVerifier(cmd -> { |
|
109 |
verifyLicenseFileInstalledDebian(debLicenseFile(cmd)); |
|
110 |
}) |
|
111 |
.forTypes(PackageType.LINUX_RPM) |
|
112 |
.addInstallVerifier(cmd -> { |
|
113 |
verifyLicenseFileInstalledRpm(rpmLicenseFile(cmd)); |
|
114 |
}) |
|
115 |
.run(); |
|
116 |
} |
|
117 |
||
118 |
public static void testCustomDebianCopyright() { |
|
119 |
new CustomDebianCopyrightTest().run(); |
|
120 |
} |
|
121 |
||
122 |
public static void testCustomDebianCopyrightSubst() { |
|
123 |
new CustomDebianCopyrightTest().withSubstitution(true).run(); |
|
124 |
} |
|
58113 | 125 |
|
126 |
private static Path rpmLicenseFile(JPackageCommand cmd) { |
|
127 |
final Path licenseRoot = Path.of( |
|
128 |
new Executor() |
|
129 |
.setExecutable("rpm") |
|
130 |
.addArguments("--eval", "%{_defaultlicensedir}") |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
131 |
.executeAndGetFirstLineOfOutput()); |
58113 | 132 |
final Path licensePath = licenseRoot.resolve(String.format("%s-%s", |
133 |
LinuxHelper.getPackageName(cmd), cmd.version())).resolve( |
|
134 |
LICENSE_FILE.getFileName()); |
|
135 |
return licensePath; |
|
136 |
} |
|
137 |
||
58304 | 138 |
private static Path linuxLicenseFile(JPackageCommand cmd) { |
139 |
cmd.verifyIsOfType(PackageType.LINUX); |
|
140 |
switch (cmd.packageType()) { |
|
141 |
case LINUX_DEB: |
|
142 |
return debLicenseFile(cmd); |
|
143 |
||
144 |
case LINUX_RPM: |
|
145 |
return rpmLicenseFile(cmd); |
|
146 |
||
147 |
default: |
|
148 |
return null; |
|
149 |
} |
|
150 |
} |
|
151 |
||
58113 | 152 |
private static Path debLicenseFile(JPackageCommand cmd) { |
58303
88453b906981
8231279 : Change install location for copyright file for Debian package
herrick
parents:
58301
diff
changeset
|
153 |
return cmd.appInstallationDirectory().resolve("share/doc/copyright"); |
58113 | 154 |
} |
155 |
||
156 |
private static void verifyLicenseFileInLinuxPackage(JPackageCommand cmd, |
|
157 |
Path expectedLicensePath) { |
|
58416 | 158 |
TKit.assertTrue(LinuxHelper.getPackageFiles(cmd).filter(path -> path.equals( |
58113 | 159 |
expectedLicensePath)).findFirst().orElse(null) != null, |
160 |
String.format("Check license file [%s] is in %s package", |
|
161 |
expectedLicensePath, LinuxHelper.getPackageName(cmd))); |
|
162 |
} |
|
163 |
||
58304 | 164 |
private static void verifyLicenseFileInstalledRpm(Path licenseFile) throws |
165 |
IOException { |
|
58416 | 166 |
TKit.assertStringListEquals(Files.readAllLines(LICENSE_FILE), |
58304 | 167 |
Files.readAllLines(licenseFile), String.format( |
168 |
"Check contents of package license file [%s] are the same as contents of source license file [%s]", |
|
169 |
licenseFile, LICENSE_FILE)); |
|
58113 | 170 |
} |
171 |
||
58304 | 172 |
private static void verifyLicenseFileInstalledDebian(Path licenseFile) |
173 |
throws IOException { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
174 |
|
58304 | 175 |
List<String> actualLines = Files.readAllLines(licenseFile).stream().dropWhile( |
176 |
line -> !line.startsWith("License:")).collect( |
|
177 |
Collectors.toList()); |
|
178 |
// Remove leading `License:` followed by the whitespace from the first text line. |
|
179 |
actualLines.set(0, actualLines.get(0).split("\\s+", 2)[1]); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
180 |
|
58304 | 181 |
actualLines = DEBIAN_COPYRIGT_FILE_STRIPPER.apply(actualLines); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
182 |
|
58416 | 183 |
TKit.assertNotEquals(0, String.join("\n", actualLines).length(), |
58304 | 184 |
"Check stripped license text is not empty"); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
185 |
|
58416 | 186 |
TKit.assertStringListEquals(DEBIAN_COPYRIGT_FILE_STRIPPER.apply( |
58304 | 187 |
Files.readAllLines(LICENSE_FILE)), actualLines, String.format( |
188 |
"Check subset of package license file [%s] is a match of the source license file [%s]", |
|
189 |
licenseFile, LICENSE_FILE)); |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
190 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
191 |
|
58113 | 192 |
private static void verifyLicenseFileNotInstalledLinux(Path licenseFile) { |
58416 | 193 |
TKit.assertPathExists(licenseFile.getParent(), false); |
58304 | 194 |
} |
195 |
||
196 |
private static class CustomDebianCopyrightTest { |
|
197 |
CustomDebianCopyrightTest() { |
|
198 |
withSubstitution(false); |
|
199 |
} |
|
200 |
||
201 |
private List<String> licenseFileText(String copyright, String licenseText) { |
|
202 |
List<String> lines = new ArrayList(List.of( |
|
203 |
String.format("Copyright=%s", copyright), |
|
204 |
"Foo", |
|
205 |
"Bar", |
|
206 |
"Buz")); |
|
207 |
lines.addAll(List.of(licenseText.split("\\R", -1))); |
|
208 |
return lines; |
|
209 |
} |
|
210 |
||
211 |
private List<String> licenseFileText() { |
|
212 |
if (withSubstitution) { |
|
213 |
return licenseFileText("APPLICATION_COPYRIGHT", |
|
214 |
"APPLICATION_LICENSE_TEXT"); |
|
215 |
} else { |
|
216 |
return expetedLicenseFileText(); |
|
217 |
} |
|
218 |
} |
|
219 |
||
220 |
private List<String> expetedLicenseFileText() { |
|
221 |
return licenseFileText(copyright, licenseText); |
|
222 |
} |
|
223 |
||
224 |
CustomDebianCopyrightTest withSubstitution(boolean v) { |
|
225 |
withSubstitution = v; |
|
226 |
// Different values just to make easy to figure out from the test log which test was executed. |
|
227 |
if (v) { |
|
228 |
copyright = "Duke (C)"; |
|
229 |
licenseText = "The quick brown fox\n jumps over the lazy dog"; |
|
230 |
} else { |
|
231 |
copyright = "Java (C)"; |
|
232 |
licenseText = "How vexingly quick daft zebras jump!"; |
|
233 |
} |
|
234 |
return this; |
|
235 |
} |
|
236 |
||
237 |
void run() { |
|
58416 | 238 |
final Path srcLicenseFile = TKit.workDir().resolve("license"); |
58304 | 239 |
new PackageTest().configureHelloApp().forTypes(PackageType.LINUX_DEB) |
240 |
.addInitializer(cmd -> { |
|
241 |
// Create source license file. |
|
242 |
Files.write(srcLicenseFile, List.of( |
|
243 |
licenseText.split("\\R", -1))); |
|
244 |
||
245 |
cmd.setFakeRuntime(); |
|
246 |
cmd.setArgumentValue("--name", String.format("%s%s", |
|
247 |
withSubstitution ? "CustomDebianCopyrightWithSubst" : "CustomDebianCopyright", |
|
248 |
cmd.name())); |
|
249 |
cmd.addArguments("--license-file", srcLicenseFile); |
|
250 |
cmd.addArguments("--copyright", copyright); |
|
251 |
cmd.addArguments("--resource-dir", RESOURCE_DIR); |
|
252 |
||
253 |
// Create copyright template file in a resource dir. |
|
254 |
Files.createDirectories(RESOURCE_DIR); |
|
255 |
Files.write(RESOURCE_DIR.resolve("copyright"), |
|
256 |
licenseFileText()); |
|
257 |
}) |
|
258 |
.addInstallVerifier(cmd -> { |
|
259 |
Path installedLicenseFile = debLicenseFile(cmd); |
|
58416 | 260 |
TKit.assertStringListEquals(expetedLicenseFileText(), |
58304 | 261 |
DEBIAN_COPYRIGT_FILE_STRIPPER.apply(Files.readAllLines( |
262 |
installedLicenseFile)), String.format( |
|
263 |
"Check contents of package license file [%s] are the same as contents of source license file [%s]", |
|
264 |
installedLicenseFile, srcLicenseFile)); |
|
265 |
}) |
|
266 |
.run(); |
|
267 |
} |
|
268 |
||
269 |
private boolean withSubstitution; |
|
270 |
private String copyright; |
|
271 |
private String licenseText; |
|
272 |
||
58416 | 273 |
private final Path RESOURCE_DIR = TKit.workDir().resolve("resources"); |
58113 | 274 |
} |
275 |
||
58416 | 276 |
private static final Path LICENSE_FILE = TKit.TEST_SRC_ROOT.resolve( |
58113 | 277 |
Path.of("resources", "license.txt")); |
58304 | 278 |
|
279 |
private static final Function<List<String>, List<String>> DEBIAN_COPYRIGT_FILE_STRIPPER = (lines) -> Arrays.asList( |
|
280 |
String.join("\n", lines).stripTrailing().split("\n")); |
|
58113 | 281 |
} |