|
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 |
|
24 import java.io.IOException; |
|
25 import java.nio.file.Path; |
|
26 import jdk.jpackage.test.TKit; |
|
27 import jdk.jpackage.test.PackageTest; |
|
28 import jdk.jpackage.test.PackageType; |
|
29 import jdk.jpackage.test.LinuxHelper; |
|
30 import jdk.jpackage.test.Annotations.Test; |
|
31 import java.util.List; |
|
32 |
|
33 /* |
|
34 * @test |
|
35 * @summary jpackage with --resource-dir |
|
36 * @library ../helpers |
|
37 * @build jdk.jpackage.test.* |
|
38 * @requires (os.family == "linux") |
|
39 * @modules jdk.jpackage/jdk.jpackage.internal |
|
40 * @compile LinuxResourceTest.java |
|
41 * @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main |
|
42 * --jpt-run=LinuxResourceTest |
|
43 */ |
|
44 |
|
45 public class LinuxResourceTest { |
|
46 @Test |
|
47 public static void testHardcodedProperties() throws IOException { |
|
48 new PackageTest() |
|
49 .forTypes(PackageType.LINUX) |
|
50 .configureHelloApp() |
|
51 .addInitializer(cmd -> { |
|
52 cmd |
|
53 .setFakeRuntime() |
|
54 .saveConsoleOutput(true) |
|
55 .addArguments("--resource-dir", TKit.createTempDirectory("resources")); |
|
56 }) |
|
57 .forTypes(PackageType.LINUX_DEB) |
|
58 .addInitializer(cmd -> { |
|
59 Path controlFile = Path.of(cmd.getArgumentValue("--resource-dir"), |
|
60 "control"); |
|
61 TKit.createTextFile(controlFile, List.of( |
|
62 "Package: dont-install-me", |
|
63 "Version: 1.2.3-R2", |
|
64 "Section: APPLICATION_SECTION", |
|
65 "Maintainer: APPLICATION_MAINTAINER", |
|
66 "Priority: optional", |
|
67 "Architecture: bar", |
|
68 "Provides: dont-install-me", |
|
69 "Description: APPLICATION_DESCRIPTION", |
|
70 "Installed-Size: APPLICATION_INSTALLED_SIZE", |
|
71 "Depends: PACKAGE_DEFAULT_DEPENDENCIES" |
|
72 )); |
|
73 }) |
|
74 .addBundleVerifier((cmd, result) -> { |
|
75 TKit.assertTextStream("Using custom package resource [DEB control file]") |
|
76 .predicate(String::startsWith) |
|
77 .apply(result.getOutput().stream()); |
|
78 TKit.assertTextStream(String.format( |
|
79 "Expected value of \"Package\" property is [%s]. Actual value in output package is [dont-install-me]", |
|
80 LinuxHelper.getPackageName(cmd))) |
|
81 .predicate(String::startsWith) |
|
82 .apply(result.getOutput().stream()); |
|
83 TKit.assertTextStream( |
|
84 "Expected value of \"Version\" property is [1.0-1]. Actual value in output package is [1.2.3-R2]") |
|
85 .predicate(String::startsWith) |
|
86 .apply(result.getOutput().stream()); |
|
87 TKit.assertTextStream(String.format( |
|
88 "Expected value of \"Architecture\" property is [%s]. Actual value in output package is [bar]", |
|
89 LinuxHelper.getDefaultPackageArch(cmd.packageType()))) |
|
90 .predicate(String::startsWith) |
|
91 .apply(result.getOutput().stream()); |
|
92 }) |
|
93 .forTypes(PackageType.LINUX_RPM) |
|
94 .addInitializer(cmd -> { |
|
95 Path specFile = Path.of(cmd.getArgumentValue("--resource-dir"), |
|
96 LinuxHelper.getPackageName(cmd) + ".spec"); |
|
97 TKit.createTextFile(specFile, List.of( |
|
98 "Name: dont-install-me", |
|
99 "Version: 1.2.3", |
|
100 "Release: R2", |
|
101 "Summary: APPLICATION_SUMMARY", |
|
102 "License: APPLICATION_LICENSE_TYPE", |
|
103 "Prefix: %{dirname:APPLICATION_DIRECTORY}", |
|
104 "Provides: dont-install-me", |
|
105 "%description", |
|
106 "APPLICATION_DESCRIPTION", |
|
107 "%prep", |
|
108 "%build", |
|
109 "%install", |
|
110 "rm -rf %{buildroot}", |
|
111 "install -d -m 755 %{buildroot}APPLICATION_DIRECTORY", |
|
112 "cp -r %{_sourcedir}APPLICATION_DIRECTORY/* %{buildroot}APPLICATION_DIRECTORY", |
|
113 "%files", |
|
114 "APPLICATION_DIRECTORY" |
|
115 )); |
|
116 }) |
|
117 .addBundleVerifier((cmd, result) -> { |
|
118 TKit.assertTextStream("Using custom package resource [RPM spec file]") |
|
119 .predicate(String::startsWith) |
|
120 .apply(result.getOutput().stream()); |
|
121 TKit.assertTextStream(String.format( |
|
122 "Expected value of \"Name\" property is [%s]. Actual value in output package is [dont-install-me]", |
|
123 LinuxHelper.getPackageName(cmd))) |
|
124 .predicate(String::startsWith) |
|
125 .apply(result.getOutput().stream()); |
|
126 TKit.assertTextStream( |
|
127 "Expected value of \"Version\" property is [1.0]. Actual value in output package is [1.2.3]") |
|
128 .predicate(String::startsWith) |
|
129 .apply(result.getOutput().stream()); |
|
130 TKit.assertTextStream( |
|
131 "Expected value of \"Release\" property is [1]. Actual value in output package is [R2]") |
|
132 .predicate(String::startsWith) |
|
133 .apply(result.getOutput().stream()); |
|
134 }) |
|
135 .run(); |
|
136 } |
|
137 } |