author | herrick |
Thu, 31 Oct 2019 11:07:01 -0400 | |
branch | JDK-8200758-branch |
changeset 58886 | 45bb0bebd36f |
parent 58791 | fca9cb5f4953 |
child 58890 | 6539ad1d90aa |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57103
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
28 |
import java.io.*; |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
29 |
import java.nio.file.Path; |
57038 | 30 |
import java.text.MessageFormat; |
31 |
import java.util.*; |
|
32 |
import java.util.regex.Matcher; |
|
33 |
import java.util.regex.Pattern; |
|
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
34 |
import java.util.stream.Collectors; |
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
35 |
import java.util.stream.Stream; |
57038 | 36 |
|
57039 | 37 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
38 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR; |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
39 |
import static jdk.jpackage.internal.OverridableResource.createResource; |
57038 | 40 |
|
57742
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
41 |
/** |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
42 |
* There are two command line options to configure license information for RPM |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
43 |
* packaging: --linux-rpm-license-type and --license-file. Value of |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
44 |
* --linux-rpm-license-type command line option configures "License:" section |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
45 |
* of RPM spec. Value of --license-file command line option specifies a license |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
46 |
* file to be added to the package. License file is a sort of documentation file |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
47 |
* but it will be installed even if user selects an option to install the |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
48 |
* package without documentation. --linux-rpm-license-type is the primary option |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
49 |
* to set license information. --license-file makes little sense in case of RPM |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
50 |
* packaging. |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
51 |
*/ |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
52 |
public class LinuxRpmBundler extends LinuxPackageBundler { |
57038 | 53 |
|
54 |
// Fedora rules for package naming are used here |
|
55 |
// https://fedoraproject.org/wiki/Packaging:NamingGuidelines?rd=Packaging/NamingGuidelines |
|
56 |
// |
|
57 |
// all Fedora packages must be named using only the following ASCII |
|
58 |
// characters. These characters are displayed here: |
|
59 |
// |
|
60 |
// abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+ |
|
61 |
// |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
62 |
private static final Pattern RPM_PACKAGE_NAME_PATTERN = |
57038 | 63 |
Pattern.compile("[a-z\\d\\+\\-\\.\\_]+", Pattern.CASE_INSENSITIVE); |
64 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
65 |
public static final BundlerParamInfo<String> PACKAGE_NAME = |
57038 | 66 |
new StandardBundlerParam<> ( |
67 |
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(), |
|
68 |
String.class, |
|
69 |
params -> { |
|
70 |
String nm = APP_NAME.fetchFrom(params); |
|
71 |
if (nm == null) return null; |
|
72 |
||
73 |
// make sure to lower case and spaces become dashes |
|
74 |
nm = nm.toLowerCase().replaceAll("[ ]", "-"); |
|
75 |
||
76 |
return nm; |
|
77 |
}, |
|
78 |
(s, p) -> { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
79 |
if (!RPM_PACKAGE_NAME_PATTERN.matcher(s).matches()) { |
57038 | 80 |
String msgKey = "error.invalid-value-for-package-name"; |
81 |
throw new IllegalArgumentException( |
|
82 |
new ConfigException(MessageFormat.format( |
|
83 |
I18N.getString(msgKey), s), |
|
84 |
I18N.getString(msgKey + ".advice"))); |
|
85 |
} |
|
86 |
||
87 |
return s; |
|
88 |
} |
|
89 |
); |
|
90 |
||
91 |
public static final BundlerParamInfo<String> LICENSE_TYPE = |
|
92 |
new StandardBundlerParam<>( |
|
93 |
Arguments.CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(), |
|
94 |
String.class, |
|
95 |
params -> I18N.getString("param.license-type.default"), |
|
96 |
(s, p) -> s |
|
97 |
); |
|
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
98 |
|
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57908
diff
changeset
|
99 |
public static final BundlerParamInfo<String> GROUP = |
57790 | 100 |
new StandardBundlerParam<>( |
101 |
Arguments.CLIOptions.LINUX_CATEGORY.getId(), |
|
102 |
String.class, |
|
103 |
params -> null, |
|
104 |
(s, p) -> s); |
|
57038 | 105 |
|
106 |
private final static String DEFAULT_SPEC_TEMPLATE = "template.spec"; |
|
107 |
||
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
108 |
public final static String TOOL_RPM = "rpm"; |
57038 | 109 |
public final static String TOOL_RPMBUILD = "rpmbuild"; |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
110 |
public final static String TOOL_RPMBUILD_MIN_VERSION = "4.0"; |
57038 | 111 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
112 |
public LinuxRpmBundler() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
113 |
super(PACKAGE_NAME); |
57038 | 114 |
} |
115 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
116 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
117 |
public void doValidate(Map<String, ? super Object> params) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
118 |
throws ConfigException { |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
119 |
} |
57038 | 120 |
|
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
121 |
private static ToolValidator createRpmbuildToolValidator() { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
122 |
Pattern pattern = Pattern.compile(" (\\d+\\.\\d+)"); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
123 |
return new ToolValidator(TOOL_RPMBUILD).setMinimalVersion( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
124 |
TOOL_RPMBUILD_MIN_VERSION).setVersionParser(lines -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
125 |
String versionString = lines.limit(1).collect( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
126 |
Collectors.toList()).get(0); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
127 |
Matcher matcher = pattern.matcher(versionString); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
128 |
if (matcher.find()) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
129 |
return matcher.group(1); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
130 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
131 |
return null; |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
132 |
}); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
133 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
134 |
|
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
135 |
@Override |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
136 |
protected List<ToolValidator> getToolValidators( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
137 |
Map<String, ? super Object> params) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
138 |
return List.of(createRpmbuildToolValidator()); |
57038 | 139 |
} |
140 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
141 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
142 |
protected File buildPackageBundle( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
143 |
Map<String, String> replacementData, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
144 |
Map<String, ? super Object> params, File outputParentDir) throws |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
145 |
PackagerException, IOException { |
57038 | 146 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
147 |
Path specFile = specFile(params); |
57390 | 148 |
|
149 |
// prepare spec file |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
150 |
createResource(DEFAULT_SPEC_TEMPLATE, params) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
151 |
.setCategory(I18N.getString("resource.rpm-spec-file")) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
152 |
.setSubstitutionData(replacementData) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
153 |
.saveToFile(specFile); |
57038 | 154 |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
155 |
return buildRPM(params, outputParentDir.toPath()).toFile(); |
57038 | 156 |
} |
157 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
158 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
159 |
protected Map<String, String> createReplacementData( |
57080 | 160 |
Map<String, ? super Object> params) throws IOException { |
57038 | 161 |
Map<String, String> data = new HashMap<>(); |
162 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
163 |
data.put("APPLICATION_DIRECTORY", Path.of(LINUX_INSTALL_DIR.fetchFrom( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
164 |
params), PACKAGE_NAME.fetchFrom(params)).toString()); |
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
165 |
data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params)); |
57038 | 166 |
data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params)); |
58418
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58417
diff
changeset
|
167 |
|
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58417
diff
changeset
|
168 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
169 |
if (licenseFile != null) { |
58418
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58417
diff
changeset
|
170 |
licenseFile = Path.of(licenseFile).toAbsolutePath().normalize().toString(); |
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58417
diff
changeset
|
171 |
} |
7cd20dbeee36
8230974: creating rpm, get error for relative path to the license.txt
herrick
parents:
58417
diff
changeset
|
172 |
data.put("APPLICATION_LICENSE_FILE", licenseFile); |
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58418
diff
changeset
|
173 |
data.put("APPLICATION_GROUP", GROUP.fetchFrom(params)); |
57742
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
174 |
|
57038 | 175 |
return data; |
176 |
} |
|
177 |
||
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
178 |
@Override |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
179 |
protected void initLibProvidersLookup( |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
180 |
Map<String, ? super Object> params, |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
181 |
LibProvidersLookup libProvidersLookup) { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
182 |
libProvidersLookup.setPackageLookup(file -> { |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
183 |
return Executor.of(TOOL_RPM, |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
184 |
"-q", "--queryformat", "%{name}\\n", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
185 |
"-q", "--whatprovides", file.toString()) |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
186 |
.saveOutput(true).executeExpectSuccess().getOutput().stream(); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
187 |
}); |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
188 |
} |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
189 |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
190 |
@Override |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
191 |
protected List<ConfigException> verifyOutputBundle( |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
192 |
Map<String, ? super Object> params, Path packageBundle) { |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
193 |
List<ConfigException> errors = new ArrayList<>(); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
194 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
195 |
String specFileName = specFile(params).getFileName().toString(); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
196 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
197 |
try { |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
198 |
List<PackageProperty> properties = List.of( |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
199 |
new PackageProperty("Name", PACKAGE_NAME.fetchFrom(params), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
200 |
"APPLICATION_PACKAGE", specFileName), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
201 |
new PackageProperty("Version", VERSION.fetchFrom(params), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
202 |
"APPLICATION_VERSION", specFileName), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
203 |
new PackageProperty("Release", RELEASE.fetchFrom(params), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
204 |
"APPLICATION_RELEASE", specFileName), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
205 |
new PackageProperty("Arch", rpmArch(), null, specFileName)); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
206 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
207 |
List<String> actualValues = Executor.of(TOOL_RPM, "-qp", "--queryformat", |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
208 |
properties.stream().map(entry -> String.format("%%{%s}", |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
209 |
entry.name)).collect(Collectors.joining("\\n")), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
210 |
packageBundle.toString()).saveOutput(true).executeExpectSuccess().getOutput(); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
211 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
212 |
Iterator<String> actualValuesIt = actualValues.iterator(); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
213 |
properties.forEach(property -> errors.add(property.verifyValue( |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
214 |
actualValuesIt.next()))); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
215 |
} catch (IOException ex) { |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
216 |
// Ignore error as it is not critical. Just report it. |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
217 |
Log.verbose(ex); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
218 |
} |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
219 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
220 |
return errors; |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
221 |
} |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
222 |
|
58886
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
223 |
/** |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
224 |
* Various ways to get rpm arch. Needed to address JDK-8233143. rpmbuild is |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
225 |
* mandatory for rpm packaging, try it first. rpm is optional and may not be |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
226 |
* available, use as the last resort. |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
227 |
*/ |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
228 |
private enum RpmArchReader { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
229 |
Rpmbuild(TOOL_RPMBUILD, "--eval=%{_target_cpu}"), |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
230 |
Rpm(TOOL_RPM, "--eval=%{_target_cpu}"); |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
231 |
|
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
232 |
RpmArchReader(String... cmdline) { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
233 |
this.cmdline = cmdline; |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
234 |
} |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
235 |
|
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
236 |
String getRpmArch() throws IOException { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
237 |
Executor exec = Executor.of(cmdline).saveOutput(true); |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
238 |
if (this == values()[values().length - 1]) { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
239 |
exec.executeExpectSuccess(); |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
240 |
} else if (exec.execute() != 0) { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
241 |
return null; |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
242 |
} |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
243 |
|
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
244 |
return exec.getOutput().get(0); |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
245 |
} |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
246 |
|
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
247 |
private final String[] cmdline; |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
248 |
} |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
249 |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
250 |
private String rpmArch() throws IOException { |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
251 |
if (rpmArch == null) { |
58886
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
252 |
for (var rpmArchReader : RpmArchReader.values()) { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
253 |
rpmArch = rpmArchReader.getRpmArch(); |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
254 |
if (rpmArch != null) { |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
255 |
break; |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
256 |
} |
45bb0bebd36f
8233143 : RPM errors: rpmbuild: no spec files given for build
herrick
parents:
58791
diff
changeset
|
257 |
} |
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
258 |
} |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
259 |
return rpmArch; |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
260 |
} |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
261 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
262 |
private Path specFile(Map<String, ? super Object> params) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
263 |
return TEMP_ROOT.fetchFrom(params).toPath().resolve(Path.of("SPECS", |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
264 |
PACKAGE_NAME.fetchFrom(params) + ".spec")); |
57038 | 265 |
} |
266 |
||
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
267 |
private Path buildRPM(Map<String, ? super Object> params, |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
268 |
Path outdir) throws IOException { |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
269 |
|
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
270 |
Path rpmFile = outdir.toAbsolutePath().resolve(String.format( |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
271 |
"%s-%s-%s.%s.rpm", PACKAGE_NAME.fetchFrom(params), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
272 |
VERSION.fetchFrom(params), RELEASE.fetchFrom(params), rpmArch())); |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
273 |
|
57038 | 274 |
Log.verbose(MessageFormat.format(I18N.getString( |
275 |
"message.outputting-bundle-location"), |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
276 |
rpmFile.getParent())); |
57038 | 277 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
278 |
PlatformPackage thePackage = createMetaPackage(params); |
57038 | 279 |
|
280 |
//run rpmbuild |
|
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
281 |
Executor.of( |
57038 | 282 |
TOOL_RPMBUILD, |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
283 |
"-bb", specFile(params).toAbsolutePath().toString(), |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
284 |
"--define", String.format("%%_sourcedir %s", |
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
285 |
thePackage.sourceRoot()), |
57038 | 286 |
// save result to output dir |
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
287 |
"--define", String.format("%%_rpmdir %s", rpmFile.getParent()), |
57038 | 288 |
// do not use other system directories to build as current user |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
289 |
"--define", String.format("%%_topdir %s", |
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
290 |
TEMP_ROOT.fetchFrom(params).toPath().toAbsolutePath()), |
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
291 |
"--define", String.format("%%_rpmfilename %s", rpmFile.getFileName()) |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
292 |
).executeExpectSuccess(); |
57038 | 293 |
|
294 |
Log.verbose(MessageFormat.format( |
|
295 |
I18N.getString("message.output-bundle-location"), |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
296 |
rpmFile.getParent())); |
57038 | 297 |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
298 |
return rpmFile; |
57038 | 299 |
} |
300 |
||
301 |
@Override |
|
302 |
public String getName() { |
|
57059 | 303 |
return I18N.getString("rpm.bundler.name"); |
57038 | 304 |
} |
305 |
||
306 |
@Override |
|
307 |
public String getID() { |
|
308 |
return "rpm"; |
|
309 |
} |
|
310 |
||
311 |
@Override |
|
57150 | 312 |
public boolean supported(boolean runtimeInstaller) { |
58417
67ffaf3a2b75
8231280: Linux packages produced by jpackage should have correct dependencies
herrick
parents:
58301
diff
changeset
|
313 |
return Platform.isLinux() && (createRpmbuildToolValidator().validate() == null); |
57038 | 314 |
} |
315 |
||
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
316 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
317 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
318 |
return !LinuxDebBundler.isDebian(); |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
319 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
320 |
|
58791
fca9cb5f4953
8230612: Debian packaging ignores version and release in custom control file
herrick
parents:
58647
diff
changeset
|
321 |
private String rpmArch; |
57038 | 322 |
} |