author | herrick |
Tue, 24 Sep 2019 13:41:16 -0400 | |
branch | JDK-8200758-branch |
changeset 58301 | e0efb29609bd |
parent 58113 | 885b0543f6e4 |
child 58303 | 88453b906981 |
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; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
27 |
import java.util.List; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
28 |
import java.util.Arrays; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
29 |
import java.util.function.Function; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
30 |
import java.util.stream.Collectors; |
58113 | 31 |
import jdk.jpackage.test.JPackageCommand; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
32 |
import jdk.jpackage.test.PackageType; |
58113 | 33 |
import jdk.jpackage.test.PackageTest; |
34 |
import jdk.jpackage.test.LinuxHelper; |
|
35 |
import jdk.jpackage.test.Executor; |
|
36 |
import jdk.jpackage.test.Test; |
|
37 |
||
38 |
/** |
|
39 |
* Test --license-file parameter. Output of the test should be licensetest*.* |
|
40 |
* package bundle. The output package should provide the same functionality as |
|
41 |
* the default package and also incorporate license information from |
|
42 |
* test/jdk/tools/jpackage/resources/license.txt file from OpenJDK repo. |
|
43 |
* |
|
44 |
* deb: |
|
45 |
* |
|
46 |
* Package should install license file /usr/share/doc/licensetest/copyright |
|
47 |
* file. |
|
48 |
* |
|
49 |
* rpm: |
|
50 |
* |
|
51 |
* Package should install license file in |
|
52 |
* %{_defaultlicensedir}/licensetest-1.0/license.txt file. |
|
53 |
* |
|
54 |
* Mac: |
|
55 |
* |
|
56 |
* Windows |
|
57 |
* |
|
58 |
* Installer should display license text matching contents of the license file |
|
59 |
* during installation. |
|
60 |
*/ |
|
61 |
||
62 |
/* |
|
63 |
* @test |
|
64 |
* @summary jpackage with --license-file |
|
65 |
* @library ../helpers |
|
66 |
* @modules jdk.jpackage/jdk.jpackage.internal |
|
67 |
* @run main/othervm/timeout=360 -Xmx512m LicenseTest |
|
68 |
*/ |
|
69 |
public class LicenseTest { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
70 |
public static void main(String[] args) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
71 |
Test.run(args, () -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
72 |
new PackageTest().configureHelloApp() |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
73 |
.addInitializer(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
74 |
cmd.addArguments("--license-file", LICENSE_FILE); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
75 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
76 |
.forTypes(PackageType.LINUX_DEB) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
77 |
.addBundleVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
78 |
verifyLicenseFileInLinuxPackage(cmd, debLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
79 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
80 |
.addInstallVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
81 |
verifyLicenseFileInstalledDebian(debLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
82 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
83 |
.addUninstallVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
84 |
verifyLicenseFileNotInstalledLinux(debLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
85 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
86 |
.forTypes(PackageType.LINUX_RPM) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
87 |
.addBundleVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
88 |
verifyLicenseFileInLinuxPackage(cmd,rpmLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
89 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
90 |
.addInstallVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
91 |
verifyLicenseFileInstalledRpm(rpmLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
92 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
93 |
.addUninstallVerifier(cmd -> { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
94 |
verifyLicenseFileNotInstalledLinux(rpmLicenseFile(cmd)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
95 |
}) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
96 |
.run(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
97 |
}); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
98 |
} |
58113 | 99 |
|
100 |
private static Path rpmLicenseFile(JPackageCommand cmd) { |
|
101 |
final Path licenseRoot = Path.of( |
|
102 |
new Executor() |
|
103 |
.setExecutable("rpm") |
|
104 |
.addArguments("--eval", "%{_defaultlicensedir}") |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
105 |
.executeAndGetFirstLineOfOutput()); |
58113 | 106 |
final Path licensePath = licenseRoot.resolve(String.format("%s-%s", |
107 |
LinuxHelper.getPackageName(cmd), cmd.version())).resolve( |
|
108 |
LICENSE_FILE.getFileName()); |
|
109 |
return licensePath; |
|
110 |
} |
|
111 |
||
112 |
private static Path debLicenseFile(JPackageCommand cmd) { |
|
113 |
final Path licensePath = Path.of("/usr", "share", "doc", |
|
114 |
LinuxHelper.getPackageName(cmd), "copyright"); |
|
115 |
return licensePath; |
|
116 |
} |
|
117 |
||
118 |
private static void verifyLicenseFileInLinuxPackage(JPackageCommand cmd, |
|
119 |
Path expectedLicensePath) { |
|
120 |
Test.assertTrue(LinuxHelper.getPackageFiles(cmd).filter(path -> path.equals( |
|
121 |
expectedLicensePath)).findFirst().orElse(null) != null, |
|
122 |
String.format("Check license file [%s] is in %s package", |
|
123 |
expectedLicensePath, LinuxHelper.getPackageName(cmd))); |
|
124 |
} |
|
125 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
126 |
private static void verifyLicenseFileInstalledRpm(Path licenseFile) { |
58113 | 127 |
Test.assertTrue(Files.isReadable(licenseFile), String.format( |
128 |
"Check license file [%s] is readable", licenseFile)); |
|
129 |
try { |
|
130 |
Test.assertTrue(Files.readAllLines(licenseFile).equals( |
|
131 |
Files.readAllLines(LICENSE_FILE)), String.format( |
|
132 |
"Check contents of package license file [%s] are the same as contents of source license file [%s]", |
|
133 |
licenseFile, LICENSE_FILE)); |
|
134 |
} catch (IOException ex) { |
|
135 |
throw new RuntimeException(ex); |
|
136 |
} |
|
137 |
} |
|
138 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
139 |
private static void verifyLicenseFileInstalledDebian(Path licenseFile) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
140 |
Test.assertTrue(Files.isReadable(licenseFile), String.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
141 |
"Check license file [%s] is readable", licenseFile)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
142 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
143 |
Function<List<String>, List<String>> stripper = (lines) -> Arrays.asList( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
144 |
String.join("\n", lines).stripTrailing().split("\n")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
145 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
146 |
try { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
147 |
List<String> actualLines = Files.readAllLines(licenseFile).stream().dropWhile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
148 |
line -> !line.startsWith("License:")).collect( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
149 |
Collectors.toList()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
150 |
// Remove leading `License:` followed by the whitespace from the first text line. |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
151 |
actualLines.set(0, actualLines.get(0).split("\\s+", 2)[1]); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
152 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
153 |
actualLines = stripper.apply(actualLines); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
154 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
155 |
Test.assertNotEquals(0, String.join("\n", actualLines).length(), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
156 |
"Check stripped license text is not empty"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
157 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
158 |
Test.assertTrue(actualLines.equals( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
159 |
stripper.apply(Files.readAllLines(LICENSE_FILE))), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
160 |
String.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
161 |
"Check subset of package license file [%s] is a match of the source license file [%s]", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
162 |
licenseFile, LICENSE_FILE)); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
163 |
} catch (IOException ex) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
164 |
throw new RuntimeException(ex); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
165 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
166 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58113
diff
changeset
|
167 |
|
58113 | 168 |
private static void verifyLicenseFileNotInstalledLinux(Path licenseFile) { |
169 |
Test.assertDirectoryExists(licenseFile.getParent(), false); |
|
170 |
} |
|
171 |
||
172 |
private static final Path LICENSE_FILE = Test.TEST_SRC_ROOT.resolve( |
|
173 |
Path.of("resources", "license.txt")); |
|
174 |
} |