author | herrick |
Tue, 24 Sep 2019 13:50:40 -0400 | |
branch | JDK-8200758-branch |
changeset 58303 | 88453b906981 |
parent 58301 | e0efb29609bd |
child 58304 | 7a61351edad2 |
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.*; |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
29 |
import java.nio.charset.StandardCharsets; |
57808 | 30 |
import java.nio.file.FileVisitResult; |
57038 | 31 |
import java.nio.file.Files; |
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
32 |
import java.nio.file.Path; |
57808 | 33 |
import java.nio.file.SimpleFileVisitor; |
34 |
import java.nio.file.attribute.BasicFileAttributes; |
|
35 |
||
57038 | 36 |
import java.nio.file.attribute.PosixFilePermission; |
37 |
import java.nio.file.attribute.PosixFilePermissions; |
|
38 |
import java.text.MessageFormat; |
|
39 |
import java.util.*; |
|
40 |
import java.util.regex.Pattern; |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
41 |
import java.util.stream.Stream; |
58303
88453b906981
8231279 : Change install location for copyright file for Debian package
herrick
parents:
58301
diff
changeset
|
42 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR; |
57038 | 43 |
|
57039 | 44 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
45 |
import static jdk.jpackage.internal.LinuxPackageBundler.I18N; |
57038 | 46 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
47 |
public class LinuxDebBundler extends LinuxPackageBundler { |
57038 | 48 |
|
49 |
// Debian rules for package naming are used here |
|
50 |
// https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source |
|
51 |
// |
|
52 |
// Package names must consist only of lower case letters (a-z), |
|
53 |
// digits (0-9), plus (+) and minus (-) signs, and periods (.). |
|
54 |
// They must be at least two characters long and |
|
55 |
// must start with an alphanumeric character. |
|
56 |
// |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
57 |
private static final Pattern DEB_PACKAGE_NAME_PATTERN = |
57038 | 58 |
Pattern.compile("^[a-z][a-z\\d\\+\\-\\.]+"); |
59 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
60 |
private static final BundlerParamInfo<String> PACKAGE_NAME = |
57038 | 61 |
new StandardBundlerParam<> ( |
62 |
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(), |
|
63 |
String.class, |
|
64 |
params -> { |
|
65 |
String nm = APP_NAME.fetchFrom(params); |
|
66 |
||
67 |
if (nm == null) return null; |
|
68 |
||
69 |
// make sure to lower case and spaces/underscores become dashes |
|
70 |
nm = nm.toLowerCase().replaceAll("[ _]", "-"); |
|
71 |
return nm; |
|
72 |
}, |
|
73 |
(s, p) -> { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
74 |
if (!DEB_PACKAGE_NAME_PATTERN.matcher(s).matches()) { |
57038 | 75 |
throw new IllegalArgumentException(new ConfigException( |
76 |
MessageFormat.format(I18N.getString( |
|
77 |
"error.invalid-value-for-package-name"), s), |
|
78 |
I18N.getString( |
|
79 |
"error.invalid-value-for-package-name.advice"))); |
|
80 |
} |
|
81 |
||
82 |
return s; |
|
83 |
}); |
|
84 |
||
57910
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
85 |
private static final BundlerParamInfo<String> FULL_PACKAGE_NAME = |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
86 |
new StandardBundlerParam<>( |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
87 |
"linux.deb.fullPackageName", String.class, params -> { |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
88 |
try { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
89 |
return PACKAGE_NAME.fetchFrom(params) |
57910
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
90 |
+ "_" + VERSION.fetchFrom(params) |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
91 |
+ "-" + RELEASE.fetchFrom(params) |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
92 |
+ "_" + getDebArch(); |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
93 |
} catch (IOException ex) { |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
94 |
Log.verbose(ex); |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
95 |
return null; |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
96 |
} |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
97 |
}, (s, p) -> s); |
57038 | 98 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
99 |
private static final BundlerParamInfo<String> EMAIL = |
57038 | 100 |
new StandardBundlerParam<> ( |
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
101 |
Arguments.CLIOptions.LINUX_DEB_MAINTAINER.getId(), |
57038 | 102 |
String.class, |
103 |
params -> "Unknown", |
|
104 |
(s, p) -> s); |
|
105 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
106 |
private static final BundlerParamInfo<String> MAINTAINER = |
57038 | 107 |
new StandardBundlerParam<> ( |
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
108 |
BundleParams.PARAM_MAINTAINER, |
57038 | 109 |
String.class, |
110 |
params -> VENDOR.fetchFrom(params) + " <" |
|
111 |
+ EMAIL.fetchFrom(params) + ">", |
|
112 |
(s, p) -> s); |
|
113 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
114 |
private static final BundlerParamInfo<String> SECTION = |
57790 | 115 |
new StandardBundlerParam<>( |
116 |
Arguments.CLIOptions.LINUX_CATEGORY.getId(), |
|
117 |
String.class, |
|
118 |
params -> "misc", |
|
119 |
(s, p) -> s); |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
120 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
121 |
private static final BundlerParamInfo<String> LICENSE_TEXT = |
57038 | 122 |
new StandardBundlerParam<> ( |
123 |
"linux.deb.licenseText", |
|
124 |
String.class, |
|
125 |
params -> { |
|
126 |
try { |
|
57080 | 127 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
128 |
if (licenseFile != null) { |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
129 |
StringBuilder contentBuilder = new StringBuilder(); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
130 |
try (Stream<String> stream = Files.lines(Path.of( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
131 |
licenseFile), StandardCharsets.UTF_8)) { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
132 |
stream.forEach(s -> contentBuilder.append(s).append( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
133 |
"\n")); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
134 |
} |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
135 |
return contentBuilder.toString(); |
57038 | 136 |
} |
137 |
} catch (Exception e) { |
|
57140 | 138 |
Log.verbose(e); |
57038 | 139 |
} |
140 |
return "Unknown"; |
|
141 |
}, |
|
142 |
(s, p) -> s); |
|
143 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
144 |
private static final BundlerParamInfo<String> COPYRIGHT_FILE = |
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
145 |
new StandardBundlerParam<>( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
146 |
Arguments.CLIOptions.LINUX_DEB_COPYRIGHT_FILE.getId(), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
147 |
String.class, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
148 |
params -> null, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
149 |
(s, p) -> s); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
150 |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
151 |
private final static String TOOL_DPKG_DEB = "dpkg-deb"; |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
152 |
private final static String TOOL_DPKG = "dpkg"; |
57038 | 153 |
|
154 |
public static boolean testTool(String toolName, String minVersion) { |
|
155 |
try { |
|
156 |
ProcessBuilder pb = new ProcessBuilder( |
|
157 |
toolName, |
|
158 |
"--version"); |
|
159 |
// not interested in the output |
|
57391 | 160 |
IOUtils.exec(pb, true, null); |
57038 | 161 |
} catch (Exception e) { |
162 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
163 |
"message.test-for-tool"), toolName, e.getMessage())); |
|
164 |
return false; |
|
165 |
} |
|
166 |
return true; |
|
167 |
} |
|
168 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
169 |
public LinuxDebBundler() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
170 |
super(PACKAGE_NAME); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
171 |
} |
57038 | 172 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
173 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
174 |
public void doValidate(Map<String, ? super Object> params) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
175 |
throws ConfigException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
176 |
// NOTE: Can we validate that the required tools are available |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
177 |
// before we start? |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
178 |
if (!testTool(TOOL_DPKG_DEB, "1")){ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
179 |
throw new ConfigException(MessageFormat.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
180 |
I18N.getString("error.tool-not-found"), TOOL_DPKG_DEB), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
181 |
I18N.getString("error.tool-not-found.advice")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
182 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
183 |
if (!testTool(TOOL_DPKG, "1")){ |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
184 |
throw new ConfigException(MessageFormat.format( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
185 |
I18N.getString("error.tool-not-found"), TOOL_DPKG), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
186 |
I18N.getString("error.tool-not-found.advice")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
187 |
} |
57038 | 188 |
|
189 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
190 |
// Show warning is license file is missing |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
191 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
192 |
if (licenseFile == null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
193 |
Log.verbose(I18N.getString("message.debs-like-licenses")); |
57038 | 194 |
} |
195 |
} |
|
196 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
197 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
198 |
protected File buildPackageBundle( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
199 |
Map<String, String> replacementData, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
200 |
Map<String, ? super Object> params, File outputParentDir) throws |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
201 |
PackagerException, IOException { |
57038 | 202 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
203 |
prepareProjectConfig(replacementData, params); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
204 |
adjustPermissionsRecursive(createMetaPackage(params).sourceRoot().toFile()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
205 |
return buildDeb(params, outputParentDir); |
57038 | 206 |
} |
207 |
||
208 |
/* |
|
209 |
* set permissions with a string like "rwxr-xr-x" |
|
210 |
* |
|
211 |
* This cannot be directly backport to 22u which is built with 1.6 |
|
212 |
*/ |
|
213 |
private void setPermissions(File file, String permissions) { |
|
214 |
Set<PosixFilePermission> filePermissions = |
|
215 |
PosixFilePermissions.fromString(permissions); |
|
216 |
try { |
|
217 |
if (file.exists()) { |
|
218 |
Files.setPosixFilePermissions(file.toPath(), filePermissions); |
|
219 |
} |
|
220 |
} catch (IOException ex) { |
|
57392 | 221 |
Log.error(ex.getMessage()); |
222 |
Log.verbose(ex); |
|
57038 | 223 |
} |
224 |
||
225 |
} |
|
226 |
||
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
227 |
private static String getDebArch() throws IOException { |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
228 |
try (var baos = new ByteArrayOutputStream(); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
229 |
var ps = new PrintStream(baos)) { |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
230 |
var pb = new ProcessBuilder(TOOL_DPKG, "--print-architecture"); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
231 |
IOUtils.exec(pb, false, ps); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
232 |
return baos.toString().split("\n", 2)[0]; |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
233 |
} |
57038 | 234 |
} |
235 |
||
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
236 |
public static boolean isDebian() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
237 |
// we are just going to run "dpkg -s coreutils" and assume Debian |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
238 |
// or deritive if no error is returned. |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
239 |
var pb = new ProcessBuilder(TOOL_DPKG, "-s", "coreutils"); |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
240 |
try { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
241 |
int ret = pb.start().waitFor(); |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
242 |
return (ret == 0); |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
243 |
} catch (IOException | InterruptedException e) { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
244 |
// just fall thru |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
245 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
246 |
return false; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
247 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
248 |
|
57808 | 249 |
private void adjustPermissionsRecursive(File dir) throws IOException { |
250 |
Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() { |
|
251 |
@Override |
|
252 |
public FileVisitResult visitFile(Path file, |
|
253 |
BasicFileAttributes attrs) |
|
254 |
throws IOException { |
|
255 |
if (file.endsWith(".so") || !Files.isExecutable(file)) { |
|
256 |
setPermissions(file.toFile(), "rw-r--r--"); |
|
257 |
} else if (Files.isExecutable(file)) { |
|
258 |
setPermissions(file.toFile(), "rwxr-xr-x"); |
|
259 |
} |
|
260 |
return FileVisitResult.CONTINUE; |
|
261 |
} |
|
262 |
||
263 |
@Override |
|
264 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
|
265 |
throws IOException { |
|
266 |
if (e == null) { |
|
267 |
setPermissions(dir.toFile(), "rwxr-xr-x"); |
|
268 |
return FileVisitResult.CONTINUE; |
|
269 |
} else { |
|
270 |
// directory iteration failed |
|
271 |
throw e; |
|
272 |
} |
|
273 |
} |
|
274 |
}); |
|
275 |
} |
|
276 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
277 |
private class DebianFile { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
278 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
279 |
DebianFile(Path dstFilePath, String comment) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
280 |
this.dstFilePath = dstFilePath; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
281 |
this.comment = comment; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
282 |
} |
57038 | 283 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
284 |
DebianFile setExecutable() { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
285 |
permissions = "rwxr-xr-x"; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
286 |
return this; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
287 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
288 |
|
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
289 |
void create(Map<String, String> data, Map<String, ? super Object> params) |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
290 |
throws IOException { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
291 |
Files.createDirectories(dstFilePath.getParent()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
292 |
try (Writer w = Files.newBufferedWriter(dstFilePath)) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
293 |
String content = preprocessTextResource( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
294 |
dstFilePath.getFileName().toString(), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
295 |
I18N.getString(comment), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
296 |
"template." + dstFilePath.getFileName().toString(), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
297 |
data, |
57038 | 298 |
VERBOSE.fetchFrom(params), |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
299 |
RESOURCE_DIR.fetchFrom(params)); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
300 |
w.write(content); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
301 |
} |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
302 |
if (permissions != null) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
303 |
setPermissions(dstFilePath.toFile(), permissions); |
57038 | 304 |
} |
305 |
} |
|
306 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
307 |
private final Path dstFilePath; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
308 |
private final String comment; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
309 |
private String permissions; |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
310 |
} |
57038 | 311 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
312 |
private void prepareProjectConfig(Map<String, String> data, |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
313 |
Map<String, ? super Object> params) throws IOException { |
57038 | 314 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
315 |
Path configDir = createMetaPackage(params).sourceRoot().resolve("DEBIAN"); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
316 |
List<DebianFile> debianFiles = new ArrayList<>(); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
317 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
318 |
configDir.resolve("control"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
319 |
"resource.deb-control-file")); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
320 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
321 |
configDir.resolve("preinst"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
322 |
"resource.deb-preinstall-script").setExecutable()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
323 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
324 |
configDir.resolve("prerm"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
325 |
"resource.deb-prerm-script").setExecutable()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
326 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
327 |
configDir.resolve("postinst"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
328 |
"resource.deb-postinstall-script").setExecutable()); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
329 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
330 |
configDir.resolve("postrm"), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
331 |
"resource.deb-postrm-script").setExecutable()); |
57038 | 332 |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
333 |
getConfig_CopyrightFile(params).getParentFile().mkdirs(); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
334 |
String customCopyrightFile = COPYRIGHT_FILE.fetchFrom(params); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
335 |
if (customCopyrightFile != null) { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
336 |
IOUtils.copyFile(new File(customCopyrightFile), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
337 |
getConfig_CopyrightFile(params)); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
338 |
} else { |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
339 |
debianFiles.add(new DebianFile( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
340 |
getConfig_CopyrightFile(params).toPath(), |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
341 |
"resource.copyright-file")); |
57390 | 342 |
} |
57038 | 343 |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
344 |
for (DebianFile debianFile : debianFiles) { |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
345 |
debianFile.create(data, params); |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
346 |
} |
57038 | 347 |
} |
348 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
349 |
@Override |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
350 |
protected Map<String, String> createReplacementData( |
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
351 |
Map<String, ? super Object> params) throws IOException { |
57038 | 352 |
Map<String, String> data = new HashMap<>(); |
353 |
||
354 |
data.put("APPLICATION_MAINTAINER", MAINTAINER.fetchFrom(params)); |
|
57790 | 355 |
data.put("APPLICATION_SECTION", SECTION.fetchFrom(params)); |
57038 | 356 |
data.put("APPLICATION_COPYRIGHT", COPYRIGHT.fetchFrom(params)); |
357 |
data.put("APPLICATION_LICENSE_TEXT", LICENSE_TEXT.fetchFrom(params)); |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
358 |
data.put("APPLICATION_ARCH", getDebArch()); |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
359 |
data.put("APPLICATION_INSTALLED_SIZE", Long.toString( |
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
360 |
createMetaPackage(params).sourceApplicationLayout().sizeInBytes() >> 10)); |
57038 | 361 |
|
362 |
return data; |
|
363 |
} |
|
364 |
||
365 |
private File getConfig_CopyrightFile(Map<String, ? super Object> params) { |
|
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
366 |
PlatformPackage thePackage = createMetaPackage(params); |
58303
88453b906981
8231279 : Change install location for copyright file for Debian package
herrick
parents:
58301
diff
changeset
|
367 |
return thePackage.sourceRoot().resolve(Path.of(".", |
88453b906981
8231279 : Change install location for copyright file for Debian package
herrick
parents:
58301
diff
changeset
|
368 |
LINUX_INSTALL_DIR.fetchFrom(params), PACKAGE_NAME.fetchFrom( |
88453b906981
8231279 : Change install location for copyright file for Debian package
herrick
parents:
58301
diff
changeset
|
369 |
params), "share/doc/copyright")).toFile(); |
57808 | 370 |
} |
371 |
||
57038 | 372 |
private File buildDeb(Map<String, ? super Object> params, |
373 |
File outdir) throws IOException { |
|
374 |
File outFile = new File(outdir, |
|
375 |
FULL_PACKAGE_NAME.fetchFrom(params)+".deb"); |
|
376 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
377 |
"message.outputting-to-location"), outFile.getAbsolutePath())); |
|
378 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
379 |
PlatformPackage thePackage = createMetaPackage(params); |
57038 | 380 |
|
381 |
// run dpkg |
|
382 |
ProcessBuilder pb = new ProcessBuilder( |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
383 |
"fakeroot", TOOL_DPKG_DEB, "-b", |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
58116
diff
changeset
|
384 |
thePackage.sourceRoot().toString(), |
57038 | 385 |
outFile.getAbsolutePath()); |
57391 | 386 |
IOUtils.exec(pb); |
57038 | 387 |
|
388 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
389 |
"message.output-to-location"), outFile.getAbsolutePath())); |
|
390 |
||
391 |
return outFile; |
|
392 |
} |
|
393 |
||
394 |
@Override |
|
395 |
public String getName() { |
|
57059 | 396 |
return I18N.getString("deb.bundler.name"); |
57038 | 397 |
} |
398 |
||
399 |
@Override |
|
400 |
public String getID() { |
|
401 |
return "deb"; |
|
402 |
} |
|
403 |
||
404 |
@Override |
|
57150 | 405 |
public boolean supported(boolean runtimeInstaller) { |
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
406 |
if (Platform.getPlatform() == Platform.LINUX) { |
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
407 |
if (testTool(TOOL_DPKG_DEB, "1")) { |
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
408 |
return true; |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
409 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
410 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
411 |
return false; |
57038 | 412 |
} |
413 |
||
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
414 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
415 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
416 |
return isDebian(); |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
417 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57910
diff
changeset
|
418 |
|
57038 | 419 |
} |