82 * @requires (os.family == "linux")
83 * @requires (jpackage.test.SQETest == null)
84 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
85 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
86 * --jpt-run=LicenseTest.testCustomDebianCopyright
87 * --jpt-run=LicenseTest.testCustomDebianCopyrightSubst
88 */
89
90 public class LicenseTest {
91 public static void testCommon() {
92 new PackageTest().configureHelloApp()
93 .addInitializer(cmd -> {
94 cmd.addArguments("--license-file", TKit.createRelativePathCopy(
95 LICENSE_FILE));
96 })
97 .forTypes(PackageType.LINUX)
98 .addBundleVerifier(cmd -> {
99 verifyLicenseFileInLinuxPackage(cmd, linuxLicenseFile(cmd));
100 })
101 .addInstallVerifier(cmd -> {
102 TKit.assertReadableFileExists(linuxLicenseFile(cmd));
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 }
125
126 private static Path rpmLicenseFile(JPackageCommand cmd) {
127 final Path licenseRoot = Path.of(
128 new Executor()
129 .setExecutable("rpm")
130 .addArguments("--eval", "%{_defaultlicensedir}")
131 .executeAndGetFirstLineOfOutput());
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
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
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() {
238 final Path srcLicenseFile = TKit.workDir().resolve("license");
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);
|
82 * @requires (os.family == "linux")
83 * @requires (jpackage.test.SQETest == null)
84 * @modules jdk.incubator.jpackage/jdk.incubator.jpackage.internal
85 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
86 * --jpt-run=LicenseTest.testCustomDebianCopyright
87 * --jpt-run=LicenseTest.testCustomDebianCopyrightSubst
88 */
89
90 public class LicenseTest {
91 public static void testCommon() {
92 new PackageTest().configureHelloApp()
93 .addInitializer(cmd -> {
94 cmd.addArguments("--license-file", TKit.createRelativePathCopy(
95 LICENSE_FILE));
96 })
97 .forTypes(PackageType.LINUX)
98 .addBundleVerifier(cmd -> {
99 verifyLicenseFileInLinuxPackage(cmd, linuxLicenseFile(cmd));
100 })
101 .addInstallVerifier(cmd -> {
102 Path path = linuxLicenseFile(cmd);
103 if (path != null) {
104 TKit.assertReadableFileExists(path);
105 }
106 })
107 .addUninstallVerifier(cmd -> {
108 verifyLicenseFileNotInstalledLinux(linuxLicenseFile(cmd));
109 })
110 .forTypes(PackageType.LINUX_DEB)
111 .addInstallVerifier(cmd -> {
112 verifyLicenseFileInstalledDebian(debLicenseFile(cmd));
113 })
114 .forTypes(PackageType.LINUX_RPM)
115 .addInstallVerifier(cmd -> {
116 Path path = rpmLicenseFile(cmd);
117 if (path != null) {
118 verifyLicenseFileInstalledRpm(path);
119 }
120 })
121 .run();
122 }
123
124 public static void testCustomDebianCopyright() {
125 new CustomDebianCopyrightTest().run();
126 }
127
128 public static void testCustomDebianCopyrightSubst() {
129 new CustomDebianCopyrightTest().withSubstitution(true).run();
130 }
131
132 private static Path rpmLicenseFile(JPackageCommand cmd) {
133 if (cmd.isPackageUnpacked("Not checking for rpm license file")) {
134 return null;
135 }
136
137 final Path licenseRoot = Path.of(
138 new Executor()
139 .setExecutable("rpm")
140 .addArguments("--eval", "%{_defaultlicensedir}")
141 .executeAndGetFirstLineOfOutput());
142 final Path licensePath = licenseRoot.resolve(String.format("%s-%s",
143 LinuxHelper.getPackageName(cmd), cmd.version())).resolve(
144 LICENSE_FILE.getFileName());
145 return licensePath;
146 }
147
148 private static Path linuxLicenseFile(JPackageCommand cmd) {
149 cmd.verifyIsOfType(PackageType.LINUX);
150 switch (cmd.packageType()) {
151 case LINUX_DEB:
152 return debLicenseFile(cmd);
153
154 case LINUX_RPM:
155 return rpmLicenseFile(cmd);
156
229
230 private List<String> expetedLicenseFileText() {
231 return licenseFileText(copyright, licenseText);
232 }
233
234 CustomDebianCopyrightTest withSubstitution(boolean v) {
235 withSubstitution = v;
236 // Different values just to make easy to figure out from the test log which test was executed.
237 if (v) {
238 copyright = "Duke (C)";
239 licenseText = "The quick brown fox\n jumps over the lazy dog";
240 } else {
241 copyright = "Java (C)";
242 licenseText = "How vexingly quick daft zebras jump!";
243 }
244 return this;
245 }
246
247 void run() {
248 final Path srcLicenseFile = TKit.workDir().resolve("license");
249 new PackageTest().forTypes(PackageType.LINUX_DEB).configureHelloApp()
250 .addInitializer(cmd -> {
251 // Create source license file.
252 Files.write(srcLicenseFile, List.of(
253 licenseText.split("\\R", -1)));
254
255 cmd.setFakeRuntime();
256 cmd.setArgumentValue("--name", String.format("%s%s",
257 withSubstitution ? "CustomDebianCopyrightWithSubst" : "CustomDebianCopyright",
258 cmd.name()));
259 cmd.addArguments("--license-file", srcLicenseFile);
260 cmd.addArguments("--copyright", copyright);
261 cmd.addArguments("--resource-dir", RESOURCE_DIR);
262
263 // Create copyright template file in a resource dir.
264 Files.createDirectories(RESOURCE_DIR);
265 Files.write(RESOURCE_DIR.resolve("copyright"),
266 licenseFileText());
267 })
268 .addInstallVerifier(cmd -> {
269 Path installedLicenseFile = debLicenseFile(cmd);
|