author | herrick |
Wed, 28 Aug 2019 11:41:49 -0400 | |
branch | JDK-8200758-branch |
changeset 57910 | 28412b313c6b |
parent 57908 | 9a005146bc1c |
child 58114 | 42df7de58e39 |
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 javax.imageio.ImageIO; |
|
29 |
import java.awt.image.BufferedImage; |
|
30 |
import java.io.*; |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
31 |
import java.nio.charset.StandardCharsets; |
57808 | 32 |
import java.nio.file.FileVisitResult; |
57038 | 33 |
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
|
34 |
import java.nio.file.Path; |
57808 | 35 |
import java.nio.file.SimpleFileVisitor; |
36 |
import java.nio.file.StandardCopyOption; |
|
37 |
import java.nio.file.attribute.BasicFileAttributes; |
|
38 |
||
57038 | 39 |
import java.nio.file.attribute.PosixFilePermission; |
40 |
import java.nio.file.attribute.PosixFilePermissions; |
|
41 |
import java.text.MessageFormat; |
|
42 |
import java.util.*; |
|
43 |
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
|
44 |
import java.util.stream.Stream; |
57038 | 45 |
|
57039 | 46 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
47 |
import static jdk.jpackage.internal.LinuxAppBundler.ICON_PNG; |
|
48 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR; |
|
49 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES; |
|
57038 | 50 |
|
51 |
public class LinuxDebBundler extends AbstractBundler { |
|
52 |
||
53 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 54 |
"jdk.jpackage.internal.resources.LinuxResources"); |
57038 | 55 |
|
56 |
public static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER = |
|
57 |
new StandardBundlerParam<>( |
|
58 |
"linux.app.bundler", |
|
59 |
LinuxAppBundler.class, |
|
60 |
params -> new LinuxAppBundler(), |
|
61 |
(s, p) -> null); |
|
62 |
||
63 |
// Debian rules for package naming are used here |
|
64 |
// https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source |
|
65 |
// |
|
66 |
// Package names must consist only of lower case letters (a-z), |
|
67 |
// digits (0-9), plus (+) and minus (-) signs, and periods (.). |
|
68 |
// They must be at least two characters long and |
|
69 |
// must start with an alphanumeric character. |
|
70 |
// |
|
71 |
private static final Pattern DEB_BUNDLE_NAME_PATTERN = |
|
72 |
Pattern.compile("^[a-z][a-z\\d\\+\\-\\.]+"); |
|
73 |
||
74 |
public static final BundlerParamInfo<String> BUNDLE_NAME = |
|
75 |
new StandardBundlerParam<> ( |
|
76 |
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(), |
|
77 |
String.class, |
|
78 |
params -> { |
|
79 |
String nm = APP_NAME.fetchFrom(params); |
|
80 |
||
81 |
if (nm == null) return null; |
|
82 |
||
83 |
// make sure to lower case and spaces/underscores become dashes |
|
84 |
nm = nm.toLowerCase().replaceAll("[ _]", "-"); |
|
85 |
return nm; |
|
86 |
}, |
|
87 |
(s, p) -> { |
|
88 |
if (!DEB_BUNDLE_NAME_PATTERN.matcher(s).matches()) { |
|
89 |
throw new IllegalArgumentException(new ConfigException( |
|
90 |
MessageFormat.format(I18N.getString( |
|
91 |
"error.invalid-value-for-package-name"), s), |
|
92 |
I18N.getString( |
|
93 |
"error.invalid-value-for-package-name.advice"))); |
|
94 |
} |
|
95 |
||
96 |
return s; |
|
97 |
}); |
|
98 |
||
57910
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
99 |
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
|
100 |
new StandardBundlerParam<>( |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
101 |
"linux.deb.fullPackageName", String.class, params -> { |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
102 |
try { |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
103 |
return BUNDLE_NAME.fetchFrom(params) |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
104 |
+ "_" + VERSION.fetchFrom(params) |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
105 |
+ "-" + RELEASE.fetchFrom(params) |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
106 |
+ "_" + getDebArch(); |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
107 |
} catch (IOException ex) { |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
108 |
Log.verbose(ex); |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
109 |
return null; |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
110 |
} |
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
111 |
}, (s, p) -> s); |
57038 | 112 |
|
57910
28412b313c6b
8228660: .deb files generated by jpackage don't follow naming convention
herrick
parents:
57908
diff
changeset
|
113 |
private static final BundlerParamInfo<File> DEB_IMAGE_DIR = |
57038 | 114 |
new StandardBundlerParam<>( |
115 |
"linux.deb.imageDir", |
|
116 |
File.class, |
|
117 |
params -> { |
|
118 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
|
119 |
if (!imagesRoot.exists()) imagesRoot.mkdirs(); |
|
120 |
return new File(new File(imagesRoot, "linux-deb.image"), |
|
121 |
FULL_PACKAGE_NAME.fetchFrom(params)); |
|
122 |
}, |
|
123 |
(s, p) -> new File(s)); |
|
124 |
||
125 |
public static final BundlerParamInfo<File> APP_IMAGE_ROOT = |
|
126 |
new StandardBundlerParam<>( |
|
127 |
"linux.deb.imageRoot", |
|
128 |
File.class, |
|
129 |
params -> { |
|
130 |
File imageDir = DEB_IMAGE_DIR.fetchFrom(params); |
|
131 |
return new File(imageDir, LINUX_INSTALL_DIR.fetchFrom(params)); |
|
132 |
}, |
|
133 |
(s, p) -> new File(s)); |
|
134 |
||
135 |
public static final BundlerParamInfo<File> CONFIG_DIR = |
|
136 |
new StandardBundlerParam<>( |
|
137 |
"linux.deb.configDir", |
|
138 |
File.class, |
|
139 |
params -> new File(DEB_IMAGE_DIR.fetchFrom(params), "DEBIAN"), |
|
140 |
(s, p) -> new File(s)); |
|
141 |
||
142 |
public static final BundlerParamInfo<String> EMAIL = |
|
143 |
new StandardBundlerParam<> ( |
|
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
144 |
Arguments.CLIOptions.LINUX_DEB_MAINTAINER.getId(), |
57038 | 145 |
String.class, |
146 |
params -> "Unknown", |
|
147 |
(s, p) -> s); |
|
148 |
||
149 |
public static final BundlerParamInfo<String> MAINTAINER = |
|
150 |
new StandardBundlerParam<> ( |
|
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
151 |
BundleParams.PARAM_MAINTAINER, |
57038 | 152 |
String.class, |
153 |
params -> VENDOR.fetchFrom(params) + " <" |
|
154 |
+ EMAIL.fetchFrom(params) + ">", |
|
155 |
(s, p) -> s); |
|
156 |
||
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
157 |
public static final BundlerParamInfo<String> SECTION = |
57790 | 158 |
new StandardBundlerParam<>( |
159 |
Arguments.CLIOptions.LINUX_CATEGORY.getId(), |
|
160 |
String.class, |
|
161 |
params -> "misc", |
|
162 |
(s, p) -> s); |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
163 |
|
57038 | 164 |
public static final BundlerParamInfo<String> LICENSE_TEXT = |
165 |
new StandardBundlerParam<> ( |
|
166 |
"linux.deb.licenseText", |
|
167 |
String.class, |
|
168 |
params -> { |
|
169 |
try { |
|
57080 | 170 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
171 |
if (licenseFile != null) { |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
172 |
StringBuilder contentBuilder = new StringBuilder(); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
173 |
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
|
174 |
licenseFile), StandardCharsets.UTF_8)) { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
175 |
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
|
176 |
"\n")); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
177 |
} |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
178 |
return contentBuilder.toString(); |
57038 | 179 |
} |
180 |
} catch (Exception e) { |
|
57140 | 181 |
Log.verbose(e); |
57038 | 182 |
} |
183 |
return "Unknown"; |
|
184 |
}, |
|
185 |
(s, p) -> s); |
|
186 |
||
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
187 |
public static final BundlerParamInfo<String> COPYRIGHT_FILE = |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
188 |
new StandardBundlerParam<>( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
189 |
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
|
190 |
String.class, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
191 |
params -> null, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
192 |
(s, p) -> s); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
193 |
|
57038 | 194 |
public static final BundlerParamInfo<String> XDG_FILE_PREFIX = |
195 |
new StandardBundlerParam<> ( |
|
196 |
"linux.xdg-prefix", |
|
197 |
String.class, |
|
198 |
params -> { |
|
199 |
try { |
|
200 |
String vendor; |
|
201 |
if (params.containsKey(VENDOR.getID())) { |
|
202 |
vendor = VENDOR.fetchFrom(params); |
|
203 |
} else { |
|
57039 | 204 |
vendor = "jpackage"; |
57038 | 205 |
} |
57119 | 206 |
String appName = APP_NAME.fetchFrom(params); |
57038 | 207 |
|
208 |
return (appName + "-" + vendor).replaceAll("\\s", ""); |
|
209 |
} catch (Exception e) { |
|
57140 | 210 |
Log.verbose(e); |
57038 | 211 |
} |
212 |
return "unknown-MimeInfo.xml"; |
|
213 |
}, |
|
214 |
(s, p) -> s); |
|
215 |
||
57256 | 216 |
public static final BundlerParamInfo<String> MENU_GROUP = |
217 |
new StandardBundlerParam<>( |
|
218 |
Arguments.CLIOptions.LINUX_MENU_GROUP.getId(), |
|
219 |
String.class, |
|
220 |
params -> I18N.getString("param.menu-group.default"), |
|
221 |
(s, p) -> s |
|
222 |
); |
|
223 |
||
57908
9a005146bc1c
8230191: Replace javacup logo with duke everywhere in jpackage
herrick
parents:
57808
diff
changeset
|
224 |
private final static String DEFAULT_ICON = "java32.png"; |
57038 | 225 |
private final static String DEFAULT_CONTROL_TEMPLATE = "template.control"; |
226 |
private final static String DEFAULT_PRERM_TEMPLATE = "template.prerm"; |
|
227 |
private final static String DEFAULT_PREINSTALL_TEMPLATE = |
|
228 |
"template.preinst"; |
|
229 |
private final static String DEFAULT_POSTRM_TEMPLATE = "template.postrm"; |
|
230 |
private final static String DEFAULT_POSTINSTALL_TEMPLATE = |
|
231 |
"template.postinst"; |
|
232 |
private final static String DEFAULT_COPYRIGHT_TEMPLATE = |
|
233 |
"template.copyright"; |
|
234 |
private final static String DEFAULT_DESKTOP_FILE_TEMPLATE = |
|
235 |
"template.desktop"; |
|
236 |
||
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
237 |
private final static String TOOL_DPKG_DEB = "dpkg-deb"; |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
238 |
private final static String TOOL_DPKG = "dpkg"; |
57038 | 239 |
|
240 |
public static boolean testTool(String toolName, String minVersion) { |
|
241 |
try { |
|
242 |
ProcessBuilder pb = new ProcessBuilder( |
|
243 |
toolName, |
|
244 |
"--version"); |
|
245 |
// not interested in the output |
|
57391 | 246 |
IOUtils.exec(pb, true, null); |
57038 | 247 |
} catch (Exception e) { |
248 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
249 |
"message.test-for-tool"), toolName, e.getMessage())); |
|
250 |
return false; |
|
251 |
} |
|
252 |
return true; |
|
253 |
} |
|
254 |
||
255 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
256 |
public boolean validate(Map<String, ? super Object> params) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
257 |
throws ConfigException { |
57038 | 258 |
try { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
259 |
if (params == null) throw new ConfigException( |
57038 | 260 |
I18N.getString("error.parameters-null"), |
261 |
I18N.getString("error.parameters-null.advice")); |
|
262 |
||
263 |
//run basic validation to ensure requirements are met |
|
264 |
//we are not interested in return code, only possible exception |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
265 |
APP_BUNDLER.fetchFrom(params).validate(params); |
57038 | 266 |
|
267 |
// NOTE: Can we validate that the required tools are available |
|
268 |
// before we start? |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
269 |
if (!testTool(TOOL_DPKG_DEB, "1")){ |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
270 |
throw new ConfigException(MessageFormat.format( |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
271 |
I18N.getString("error.tool-not-found"), TOOL_DPKG_DEB), |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
272 |
I18N.getString("error.tool-not-found.advice")); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
273 |
} |
57038 | 274 |
if (!testTool(TOOL_DPKG, "1")){ |
275 |
throw new ConfigException(MessageFormat.format( |
|
276 |
I18N.getString("error.tool-not-found"), TOOL_DPKG), |
|
277 |
I18N.getString("error.tool-not-found.advice")); |
|
278 |
} |
|
279 |
||
280 |
||
57080 | 281 |
// Show warning is license file is missing |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
282 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
57080 | 283 |
if (licenseFile == null) { |
57038 | 284 |
Log.verbose(I18N.getString("message.debs-like-licenses")); |
285 |
} |
|
286 |
||
287 |
// only one mime type per association, at least one file extention |
|
288 |
List<Map<String, ? super Object>> associations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
289 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 290 |
if (associations != null) { |
291 |
for (int i = 0; i < associations.size(); i++) { |
|
292 |
Map<String, ? super Object> assoc = associations.get(i); |
|
293 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
294 |
if (mimes == null || mimes.isEmpty()) { |
|
295 |
String msgKey = |
|
296 |
"error.no-content-types-for-file-association"; |
|
297 |
throw new ConfigException( |
|
298 |
MessageFormat.format(I18N.getString(msgKey), i), |
|
299 |
I18N.getString(msgKey + ".advise")); |
|
300 |
||
301 |
} else if (mimes.size() > 1) { |
|
302 |
String msgKey = |
|
303 |
"error.too-many-content-types-for-file-association"; |
|
304 |
throw new ConfigException( |
|
305 |
MessageFormat.format(I18N.getString(msgKey), i), |
|
306 |
I18N.getString(msgKey + ".advise")); |
|
307 |
} |
|
308 |
} |
|
309 |
} |
|
310 |
||
311 |
// bundle name has some restrictions |
|
312 |
// the string converter will throw an exception if invalid |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
313 |
BUNDLE_NAME.getStringConverter().apply( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
314 |
BUNDLE_NAME.fetchFrom(params), params); |
57038 | 315 |
|
316 |
return true; |
|
317 |
} catch (RuntimeException re) { |
|
318 |
if (re.getCause() instanceof ConfigException) { |
|
319 |
throw (ConfigException) re.getCause(); |
|
320 |
} else { |
|
321 |
throw new ConfigException(re); |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
326 |
private boolean prepareProto(Map<String, ? super Object> params) |
57140 | 327 |
throws PackagerException, IOException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
328 |
File appImage = StandardBundlerParam.getPredefinedAppImage(params); |
57038 | 329 |
|
330 |
// we either have an application image or need to build one |
|
331 |
if (appImage != null) { |
|
332 |
// copy everything from appImage dir into appDir/name |
|
57808 | 333 |
IOUtils.copyRecursive(appImage.toPath(), |
334 |
getConfig_RootDirectory(params).toPath()); |
|
57038 | 335 |
} else { |
57808 | 336 |
File bundleDir = APP_BUNDLER.fetchFrom(params).doBundle(params, |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
337 |
APP_IMAGE_ROOT.fetchFrom(params), true); |
57808 | 338 |
if (bundleDir == null) { |
339 |
return false; |
|
340 |
} |
|
341 |
Files.move(bundleDir.toPath(), getConfig_RootDirectory( |
|
342 |
params).toPath(), StandardCopyOption.REPLACE_EXISTING); |
|
57038 | 343 |
} |
57808 | 344 |
return true; |
57038 | 345 |
} |
346 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
347 |
public File bundle(Map<String, ? super Object> params, |
57140 | 348 |
File outdir) throws PackagerException { |
57407 | 349 |
|
350 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 351 |
|
352 |
// we want to create following structure |
|
353 |
// <package-name> |
|
354 |
// DEBIAN |
|
355 |
// control (file with main package details) |
|
356 |
// menu (request to create menu) |
|
357 |
// ... other control files if needed .... |
|
358 |
// opt (by default) |
|
359 |
// AppFolder (this is where app image goes) |
|
360 |
// launcher executable |
|
361 |
// app |
|
362 |
// runtime |
|
363 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
364 |
File imageDir = DEB_IMAGE_DIR.fetchFrom(params); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
365 |
File configDir = CONFIG_DIR.fetchFrom(params); |
57038 | 366 |
|
367 |
try { |
|
368 |
||
369 |
imageDir.mkdirs(); |
|
370 |
configDir.mkdirs(); |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
371 |
if (prepareProto(params) && prepareProjectConfig(params)) { |
57808 | 372 |
adjustPermissionsRecursive(imageDir); |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
373 |
return buildDeb(params, outdir); |
57038 | 374 |
} |
375 |
return null; |
|
376 |
} catch (IOException ex) { |
|
57140 | 377 |
Log.verbose(ex); |
378 |
throw new PackagerException(ex); |
|
57038 | 379 |
} |
380 |
} |
|
381 |
||
382 |
/* |
|
383 |
* set permissions with a string like "rwxr-xr-x" |
|
384 |
* |
|
385 |
* This cannot be directly backport to 22u which is built with 1.6 |
|
386 |
*/ |
|
387 |
private void setPermissions(File file, String permissions) { |
|
388 |
Set<PosixFilePermission> filePermissions = |
|
389 |
PosixFilePermissions.fromString(permissions); |
|
390 |
try { |
|
391 |
if (file.exists()) { |
|
392 |
Files.setPosixFilePermissions(file.toPath(), filePermissions); |
|
393 |
} |
|
394 |
} catch (IOException ex) { |
|
57392 | 395 |
Log.error(ex.getMessage()); |
396 |
Log.verbose(ex); |
|
57038 | 397 |
} |
398 |
||
399 |
} |
|
400 |
||
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
401 |
private static String getDebArch() throws IOException { |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
402 |
try (var baos = new ByteArrayOutputStream(); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
403 |
var ps = new PrintStream(baos)) { |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
404 |
var pb = new ProcessBuilder(TOOL_DPKG, "--print-architecture"); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
405 |
IOUtils.exec(pb, false, ps); |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
406 |
return baos.toString().split("\n", 2)[0]; |
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
407 |
} |
57038 | 408 |
} |
409 |
||
410 |
private long getInstalledSizeKB(Map<String, ? super Object> params) { |
|
411 |
return getInstalledSizeKB(APP_IMAGE_ROOT.fetchFrom(params)) >> 10; |
|
412 |
} |
|
413 |
||
414 |
private long getInstalledSizeKB(File dir) { |
|
415 |
long count = 0; |
|
416 |
File[] children = dir.listFiles(); |
|
417 |
if (children != null) { |
|
418 |
for (File file : children) { |
|
419 |
if (file.isFile()) { |
|
420 |
count += file.length(); |
|
421 |
} |
|
422 |
else if (file.isDirectory()) { |
|
423 |
count += getInstalledSizeKB(file); |
|
424 |
} |
|
425 |
} |
|
426 |
} |
|
427 |
return count; |
|
428 |
} |
|
429 |
||
57808 | 430 |
private void adjustPermissionsRecursive(File dir) throws IOException { |
431 |
Files.walkFileTree(dir.toPath(), new SimpleFileVisitor<Path>() { |
|
432 |
@Override |
|
433 |
public FileVisitResult visitFile(Path file, |
|
434 |
BasicFileAttributes attrs) |
|
435 |
throws IOException { |
|
436 |
if (file.endsWith(".so") || !Files.isExecutable(file)) { |
|
437 |
setPermissions(file.toFile(), "rw-r--r--"); |
|
438 |
} else if (Files.isExecutable(file)) { |
|
439 |
setPermissions(file.toFile(), "rwxr-xr-x"); |
|
440 |
} |
|
441 |
return FileVisitResult.CONTINUE; |
|
442 |
} |
|
443 |
||
444 |
@Override |
|
445 |
public FileVisitResult postVisitDirectory(Path dir, IOException e) |
|
446 |
throws IOException { |
|
447 |
if (e == null) { |
|
448 |
setPermissions(dir.toFile(), "rwxr-xr-x"); |
|
449 |
return FileVisitResult.CONTINUE; |
|
450 |
} else { |
|
451 |
// directory iteration failed |
|
452 |
throw e; |
|
453 |
} |
|
454 |
} |
|
455 |
}); |
|
456 |
} |
|
457 |
||
57038 | 458 |
private boolean prepareProjectConfig(Map<String, ? super Object> params) |
459 |
throws IOException { |
|
460 |
Map<String, String> data = createReplacementData(params); |
|
57808 | 461 |
File rootDir = getConfig_RootDirectory(params); |
57407 | 462 |
File binDir = new File(rootDir, "bin"); |
57038 | 463 |
|
57407 | 464 |
File iconTarget = getConfig_IconFile(binDir, params); |
57038 | 465 |
File icon = ICON_PNG.fetchFrom(params); |
57256 | 466 |
if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
57038 | 467 |
// prepare installer icon |
468 |
if (icon == null || !icon.exists()) { |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
469 |
fetchResource(iconTarget.getName(), |
57038 | 470 |
I18N.getString("resource.menu-icon"), |
471 |
DEFAULT_ICON, |
|
472 |
iconTarget, |
|
473 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
474 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 475 |
} else { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
476 |
fetchResource(iconTarget.getName(), |
57038 | 477 |
I18N.getString("resource.menu-icon"), |
478 |
icon, |
|
479 |
iconTarget, |
|
480 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
481 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 482 |
} |
483 |
} |
|
484 |
||
485 |
StringBuilder installScripts = new StringBuilder(); |
|
486 |
StringBuilder removeScripts = new StringBuilder(); |
|
57256 | 487 |
for (Map<String, ? super Object> addLauncher : |
488 |
ADD_LAUNCHERS.fetchFrom(params)) { |
|
489 |
Map<String, String> addLauncherData = |
|
490 |
createReplacementData(addLauncher); |
|
491 |
addLauncherData.put("APPLICATION_FS_NAME", |
|
57038 | 492 |
data.get("APPLICATION_FS_NAME")); |
57256 | 493 |
addLauncherData.put("DESKTOP_MIMES", ""); |
57038 | 494 |
|
57256 | 495 |
if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
57038 | 496 |
// prepare desktop shortcut |
57390 | 497 |
try (Writer w = Files.newBufferedWriter( |
57038 | 498 |
getConfig_DesktopShortcutFile( |
57407 | 499 |
binDir, addLauncher).toPath())) { |
57390 | 500 |
String content = preprocessTextResource( |
57407 | 501 |
getConfig_DesktopShortcutFile(binDir, |
57390 | 502 |
addLauncher).getName(), |
503 |
I18N.getString("resource.menu-shortcut-descriptor"), |
|
504 |
DEFAULT_DESKTOP_FILE_TEMPLATE, |
|
505 |
addLauncherData, |
|
506 |
VERBOSE.fetchFrom(params), |
|
507 |
RESOURCE_DIR.fetchFrom(params)); |
|
508 |
w.write(content); |
|
509 |
} |
|
57038 | 510 |
} |
511 |
||
512 |
// prepare installer icon |
|
57407 | 513 |
iconTarget = getConfig_IconFile(binDir, addLauncher); |
57256 | 514 |
icon = ICON_PNG.fetchFrom(addLauncher); |
57038 | 515 |
if (icon == null || !icon.exists()) { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
516 |
fetchResource(iconTarget.getName(), |
57038 | 517 |
I18N.getString("resource.menu-icon"), |
518 |
DEFAULT_ICON, |
|
519 |
iconTarget, |
|
520 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
521 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 522 |
} else { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
523 |
fetchResource(iconTarget.getName(), |
57038 | 524 |
I18N.getString("resource.menu-icon"), |
525 |
icon, |
|
526 |
iconTarget, |
|
527 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
528 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 529 |
} |
530 |
||
531 |
// postinst copying of desktop icon |
|
532 |
installScripts.append( |
|
533 |
" xdg-desktop-menu install --novendor "); |
|
534 |
installScripts.append(LINUX_INSTALL_DIR.fetchFrom(params)); |
|
535 |
installScripts.append("/"); |
|
536 |
installScripts.append(data.get("APPLICATION_FS_NAME")); |
|
57587 | 537 |
installScripts.append("/bin/"); |
57038 | 538 |
installScripts.append( |
57256 | 539 |
addLauncherData.get("APPLICATION_LAUNCHER_FILENAME")); |
57038 | 540 |
installScripts.append(".desktop\n"); |
541 |
||
57096
d06bec27f8c9
8215903: modify behavior of retaining temporary output dir
herrick
parents:
57091
diff
changeset
|
542 |
// postrm cleanup of desktop icon |
57038 | 543 |
removeScripts.append( |
544 |
" xdg-desktop-menu uninstall --novendor "); |
|
545 |
removeScripts.append(LINUX_INSTALL_DIR.fetchFrom(params)); |
|
546 |
removeScripts.append("/"); |
|
547 |
removeScripts.append(data.get("APPLICATION_FS_NAME")); |
|
57587 | 548 |
removeScripts.append("/bin/"); |
57038 | 549 |
removeScripts.append( |
57256 | 550 |
addLauncherData.get("APPLICATION_LAUNCHER_FILENAME")); |
57038 | 551 |
removeScripts.append(".desktop\n"); |
552 |
} |
|
57256 | 553 |
data.put("ADD_LAUNCHERS_INSTALL", installScripts.toString()); |
554 |
data.put("ADD_LAUNCHERS_REMOVE", removeScripts.toString()); |
|
57038 | 555 |
|
556 |
List<Map<String, ? super Object>> associations = |
|
557 |
FILE_ASSOCIATIONS.fetchFrom(params); |
|
558 |
data.put("FILE_ASSOCIATION_INSTALL", ""); |
|
559 |
data.put("FILE_ASSOCIATION_REMOVE", ""); |
|
560 |
data.put("DESKTOP_MIMES", ""); |
|
561 |
if (associations != null) { |
|
562 |
String mimeInfoFile = XDG_FILE_PREFIX.fetchFrom(params) |
|
563 |
+ "-MimeInfo.xml"; |
|
564 |
StringBuilder mimeInfo = new StringBuilder( |
|
565 |
"<?xml version=\"1.0\"?>\n<mime-info xmlns=" |
|
566 |
+ "'http://www.freedesktop.org/standards/shared-mime-info'>\n"); |
|
567 |
StringBuilder registrations = new StringBuilder(); |
|
568 |
StringBuilder deregistrations = new StringBuilder(); |
|
569 |
StringBuilder desktopMimes = new StringBuilder("MimeType="); |
|
570 |
boolean addedEntry = false; |
|
571 |
||
572 |
for (Map<String, ? super Object> assoc : associations) { |
|
573 |
// <mime-type type="application/x-vnd.awesome"> |
|
574 |
// <comment>Awesome document</comment> |
|
575 |
// <glob pattern="*.awesome"/> |
|
576 |
// <glob pattern="*.awe"/> |
|
577 |
// </mime-type> |
|
578 |
||
579 |
if (assoc == null) { |
|
580 |
continue; |
|
581 |
} |
|
582 |
||
583 |
String description = FA_DESCRIPTION.fetchFrom(assoc); |
|
584 |
File faIcon = FA_ICON.fetchFrom(assoc); |
|
585 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(assoc); |
|
586 |
if (extensions == null) { |
|
587 |
Log.error(I18N.getString( |
|
588 |
"message.creating-association-with-null-extension")); |
|
589 |
} |
|
590 |
||
591 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
592 |
if (mimes == null || mimes.isEmpty()) { |
|
593 |
continue; |
|
594 |
} |
|
595 |
String thisMime = mimes.get(0); |
|
596 |
String dashMime = thisMime.replace('/', '-'); |
|
597 |
||
598 |
mimeInfo.append(" <mime-type type='") |
|
599 |
.append(thisMime) |
|
600 |
.append("'>\n"); |
|
601 |
if (description != null && !description.isEmpty()) { |
|
602 |
mimeInfo.append(" <comment>") |
|
603 |
.append(description) |
|
604 |
.append("</comment>\n"); |
|
605 |
} |
|
606 |
||
607 |
if (extensions != null) { |
|
608 |
for (String ext : extensions) { |
|
609 |
mimeInfo.append(" <glob pattern='*.") |
|
610 |
.append(ext) |
|
611 |
.append("'/>\n"); |
|
612 |
} |
|
613 |
} |
|
614 |
||
615 |
mimeInfo.append(" </mime-type>\n"); |
|
616 |
if (!addedEntry) { |
|
617 |
registrations.append(" xdg-mime install ") |
|
618 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
619 |
.append("/") |
|
620 |
.append(data.get("APPLICATION_FS_NAME")) |
|
57808 | 621 |
.append("/bin/") |
57038 | 622 |
.append(mimeInfoFile) |
623 |
.append("\n"); |
|
624 |
||
625 |
deregistrations.append(" xdg-mime uninstall ") |
|
626 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
627 |
.append("/") |
|
628 |
.append(data.get("APPLICATION_FS_NAME")) |
|
57808 | 629 |
.append("/bin/") |
57038 | 630 |
.append(mimeInfoFile) |
631 |
.append("\n"); |
|
632 |
addedEntry = true; |
|
633 |
} else { |
|
634 |
desktopMimes.append(";"); |
|
635 |
} |
|
636 |
desktopMimes.append(thisMime); |
|
637 |
||
638 |
if (faIcon != null && faIcon.exists()) { |
|
639 |
int size = getSquareSizeOfImage(faIcon); |
|
640 |
||
641 |
if (size > 0) { |
|
57407 | 642 |
File target = new File(binDir, |
57119 | 643 |
APP_NAME.fetchFrom(params) |
57038 | 644 |
+ "_fa_" + faIcon.getName()); |
645 |
IOUtils.copyFile(faIcon, target); |
|
646 |
||
647 |
// xdg-icon-resource install --context mimetypes |
|
648 |
// --size 64 awesomeapp_fa_1.png |
|
649 |
// application-x.vnd-awesome |
|
650 |
registrations.append( |
|
651 |
" xdg-icon-resource install " |
|
652 |
+ "--context mimetypes --size ") |
|
653 |
.append(size) |
|
654 |
.append(" ") |
|
655 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
656 |
.append("/") |
|
657 |
.append(data.get("APPLICATION_FS_NAME")) |
|
658 |
.append("/") |
|
659 |
.append(target.getName()) |
|
660 |
.append(" ") |
|
661 |
.append(dashMime) |
|
662 |
.append("\n"); |
|
663 |
||
664 |
// x dg-icon-resource uninstall --context mimetypes |
|
665 |
// --size 64 awesomeapp_fa_1.png |
|
666 |
// application-x.vnd-awesome |
|
667 |
deregistrations.append( |
|
668 |
" xdg-icon-resource uninstall " |
|
669 |
+ "--context mimetypes --size ") |
|
670 |
.append(size) |
|
671 |
.append(" ") |
|
672 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
673 |
.append("/") |
|
674 |
.append(data.get("APPLICATION_FS_NAME")) |
|
675 |
.append("/") |
|
676 |
.append(target.getName()) |
|
677 |
.append(" ") |
|
678 |
.append(dashMime) |
|
679 |
.append("\n"); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
mimeInfo.append("</mime-info>"); |
|
684 |
||
685 |
if (addedEntry) { |
|
57390 | 686 |
try (Writer w = Files.newBufferedWriter( |
57407 | 687 |
new File(binDir, mimeInfoFile).toPath())) { |
57390 | 688 |
w.write(mimeInfo.toString()); |
689 |
} |
|
57038 | 690 |
data.put("FILE_ASSOCIATION_INSTALL", registrations.toString()); |
691 |
data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString()); |
|
692 |
data.put("DESKTOP_MIMES", desktopMimes.toString()); |
|
693 |
} |
|
694 |
} |
|
695 |
||
57256 | 696 |
if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
57038 | 697 |
//prepare desktop shortcut |
57390 | 698 |
try (Writer w = Files.newBufferedWriter( |
57407 | 699 |
getConfig_DesktopShortcutFile(binDir, params).toPath())) { |
57390 | 700 |
String content = preprocessTextResource( |
701 |
getConfig_DesktopShortcutFile( |
|
57407 | 702 |
binDir, params).getName(), |
57390 | 703 |
I18N.getString("resource.menu-shortcut-descriptor"), |
704 |
DEFAULT_DESKTOP_FILE_TEMPLATE, |
|
705 |
data, |
|
706 |
VERBOSE.fetchFrom(params), |
|
707 |
RESOURCE_DIR.fetchFrom(params)); |
|
708 |
w.write(content); |
|
709 |
} |
|
710 |
} |
|
711 |
// prepare control file |
|
712 |
try (Writer w = Files.newBufferedWriter( |
|
713 |
getConfig_ControlFile(params).toPath())) { |
|
57038 | 714 |
String content = preprocessTextResource( |
57390 | 715 |
getConfig_ControlFile(params).getName(), |
716 |
I18N.getString("resource.deb-control-file"), |
|
717 |
DEFAULT_CONTROL_TEMPLATE, |
|
718 |
data, |
|
719 |
VERBOSE.fetchFrom(params), |
|
720 |
RESOURCE_DIR.fetchFrom(params)); |
|
721 |
w.write(content); |
|
722 |
} |
|
723 |
||
724 |
try (Writer w = Files.newBufferedWriter( |
|
725 |
getConfig_PreinstallFile(params).toPath())) { |
|
726 |
String content = preprocessTextResource( |
|
727 |
getConfig_PreinstallFile(params).getName(), |
|
728 |
I18N.getString("resource.deb-preinstall-script"), |
|
729 |
DEFAULT_PREINSTALL_TEMPLATE, |
|
57038 | 730 |
data, |
731 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
732 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 733 |
w.write(content); |
734 |
} |
|
735 |
setPermissions(getConfig_PreinstallFile(params), "rwxr-xr-x"); |
|
736 |
||
57390 | 737 |
try (Writer w = Files.newBufferedWriter( |
738 |
getConfig_PrermFile(params).toPath())) { |
|
739 |
String content = preprocessTextResource( |
|
740 |
getConfig_PrermFile(params).getName(), |
|
741 |
I18N.getString("resource.deb-prerm-script"), |
|
742 |
DEFAULT_PRERM_TEMPLATE, |
|
743 |
data, |
|
744 |
VERBOSE.fetchFrom(params), |
|
745 |
RESOURCE_DIR.fetchFrom(params)); |
|
746 |
w.write(content); |
|
747 |
} |
|
57038 | 748 |
setPermissions(getConfig_PrermFile(params), "rwxr-xr-x"); |
749 |
||
57390 | 750 |
try (Writer w = Files.newBufferedWriter( |
751 |
getConfig_PostinstallFile(params).toPath())) { |
|
752 |
String content = preprocessTextResource( |
|
753 |
getConfig_PostinstallFile(params).getName(), |
|
754 |
I18N.getString("resource.deb-postinstall-script"), |
|
755 |
DEFAULT_POSTINSTALL_TEMPLATE, |
|
756 |
data, |
|
757 |
VERBOSE.fetchFrom(params), |
|
758 |
RESOURCE_DIR.fetchFrom(params)); |
|
759 |
w.write(content); |
|
760 |
} |
|
57038 | 761 |
setPermissions(getConfig_PostinstallFile(params), "rwxr-xr-x"); |
762 |
||
57390 | 763 |
try (Writer w = Files.newBufferedWriter( |
764 |
getConfig_PostrmFile(params).toPath())) { |
|
765 |
String content = preprocessTextResource( |
|
766 |
getConfig_PostrmFile(params).getName(), |
|
767 |
I18N.getString("resource.deb-postrm-script"), |
|
768 |
DEFAULT_POSTRM_TEMPLATE, |
|
769 |
data, |
|
770 |
VERBOSE.fetchFrom(params), |
|
771 |
RESOURCE_DIR.fetchFrom(params)); |
|
772 |
w.write(content); |
|
773 |
} |
|
57038 | 774 |
setPermissions(getConfig_PostrmFile(params), "rwxr-xr-x"); |
775 |
||
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
776 |
getConfig_CopyrightFile(params).getParentFile().mkdirs(); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
777 |
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
|
778 |
if (customCopyrightFile != null) { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
779 |
IOUtils.copyFile(new File(customCopyrightFile), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
780 |
getConfig_CopyrightFile(params)); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
781 |
} else { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
782 |
try (Writer w = Files.newBufferedWriter( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
783 |
getConfig_CopyrightFile(params).toPath())) { |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
784 |
String content = preprocessTextResource( |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
785 |
getConfig_CopyrightFile(params).getName(), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
786 |
I18N.getString("resource.copyright-file"), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
787 |
DEFAULT_COPYRIGHT_TEMPLATE, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
788 |
data, |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
789 |
VERBOSE.fetchFrom(params), |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
790 |
RESOURCE_DIR.fetchFrom(params)); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
791 |
w.write(content); |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
792 |
} |
57390 | 793 |
} |
57038 | 794 |
|
795 |
return true; |
|
796 |
} |
|
797 |
||
798 |
private Map<String, String> createReplacementData( |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
799 |
Map<String, ? super Object> params) throws IOException { |
57038 | 800 |
Map<String, String> data = new HashMap<>(); |
57407 | 801 |
String launcher = LinuxAppImageBuilder.getLauncherRelativePath(params); |
57038 | 802 |
|
803 |
data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
|
57808 | 804 |
data.put("APPLICATION_FS_NAME", |
805 |
getConfig_RootDirectory(params).getName()); |
|
57038 | 806 |
data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params)); |
807 |
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params)); |
|
808 |
data.put("APPLICATION_MAINTAINER", MAINTAINER.fetchFrom(params)); |
|
809 |
data.put("APPLICATION_VERSION", VERSION.fetchFrom(params)); |
|
57741
38856ef4a19c
8229138: Add --linux-app-release option for DEB and RPM packages
herrick
parents:
57587
diff
changeset
|
810 |
data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params)); |
57790 | 811 |
data.put("APPLICATION_SECTION", SECTION.fetchFrom(params)); |
57407 | 812 |
data.put("APPLICATION_LAUNCHER_FILENAME", launcher); |
57038 | 813 |
data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params)); |
814 |
data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params)); |
|
57256 | 815 |
data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params)); |
57038 | 816 |
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params)); |
817 |
data.put("APPLICATION_COPYRIGHT", COPYRIGHT.fetchFrom(params)); |
|
818 |
data.put("APPLICATION_LICENSE_TEXT", LICENSE_TEXT.fetchFrom(params)); |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
819 |
data.put("APPLICATION_ARCH", getDebArch()); |
57038 | 820 |
data.put("APPLICATION_INSTALLED_SIZE", |
821 |
Long.toString(getInstalledSizeKB(params))); |
|
57808 | 822 |
data.put("PACKAGE_DEPENDENCIES", LINUX_PACKAGE_DEPENDENCIES.fetchFrom( |
823 |
params)); |
|
57256 | 824 |
data.put("RUNTIME_INSTALLER", "" + |
825 |
StandardBundlerParam.isRuntimeInstaller(params)); |
|
57038 | 826 |
|
827 |
return data; |
|
828 |
} |
|
829 |
||
830 |
private File getConfig_DesktopShortcutFile(File rootDir, |
|
831 |
Map<String, ? super Object> params) { |
|
57119 | 832 |
return new File(rootDir, APP_NAME.fetchFrom(params) + ".desktop"); |
57038 | 833 |
} |
834 |
||
835 |
private File getConfig_IconFile(File rootDir, |
|
836 |
Map<String, ? super Object> params) { |
|
57119 | 837 |
return new File(rootDir, APP_NAME.fetchFrom(params) + ".png"); |
57038 | 838 |
} |
839 |
||
840 |
private File getConfig_ControlFile(Map<String, ? super Object> params) { |
|
841 |
return new File(CONFIG_DIR.fetchFrom(params), "control"); |
|
842 |
} |
|
843 |
||
844 |
private File getConfig_PreinstallFile(Map<String, ? super Object> params) { |
|
845 |
return new File(CONFIG_DIR.fetchFrom(params), "preinst"); |
|
846 |
} |
|
847 |
||
848 |
private File getConfig_PrermFile(Map<String, ? super Object> params) { |
|
849 |
return new File(CONFIG_DIR.fetchFrom(params), "prerm"); |
|
850 |
} |
|
851 |
||
852 |
private File getConfig_PostinstallFile(Map<String, ? super Object> params) { |
|
853 |
return new File(CONFIG_DIR.fetchFrom(params), "postinst"); |
|
854 |
} |
|
855 |
||
856 |
private File getConfig_PostrmFile(Map<String, ? super Object> params) { |
|
857 |
return new File(CONFIG_DIR.fetchFrom(params), "postrm"); |
|
858 |
} |
|
859 |
||
860 |
private File getConfig_CopyrightFile(Map<String, ? super Object> params) { |
|
57807
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
861 |
return Path.of(DEB_IMAGE_DIR.fetchFrom(params).getAbsolutePath(), "usr", |
4a15115716ea
8215381: Investigate if current implementation of --license-file is correct for Debian packages
herrick
parents:
57790
diff
changeset
|
862 |
"share", "doc", BUNDLE_NAME.fetchFrom(params), "copyright").toFile(); |
57038 | 863 |
} |
864 |
||
57808 | 865 |
private File getConfig_RootDirectory( |
866 |
Map<String, ? super Object> params) { |
|
867 |
return Path.of(APP_IMAGE_ROOT.fetchFrom(params).getAbsolutePath(), |
|
868 |
BUNDLE_NAME.fetchFrom(params)).toFile(); |
|
869 |
} |
|
870 |
||
57038 | 871 |
private File buildDeb(Map<String, ? super Object> params, |
872 |
File outdir) throws IOException { |
|
873 |
File outFile = new File(outdir, |
|
874 |
FULL_PACKAGE_NAME.fetchFrom(params)+".deb"); |
|
875 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
876 |
"message.outputting-to-location"), outFile.getAbsolutePath())); |
|
877 |
||
878 |
outFile.getParentFile().mkdirs(); |
|
879 |
||
880 |
// run dpkg |
|
881 |
ProcessBuilder pb = new ProcessBuilder( |
|
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
882 |
"fakeroot", TOOL_DPKG_DEB, "-b", |
57038 | 883 |
FULL_PACKAGE_NAME.fetchFrom(params), |
884 |
outFile.getAbsolutePath()); |
|
885 |
pb = pb.directory(DEB_IMAGE_DIR.fetchFrom(params).getParentFile()); |
|
57391 | 886 |
IOUtils.exec(pb); |
57038 | 887 |
|
888 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
889 |
"message.output-to-location"), outFile.getAbsolutePath())); |
|
890 |
||
891 |
return outFile; |
|
892 |
} |
|
893 |
||
894 |
@Override |
|
895 |
public String getName() { |
|
57059 | 896 |
return I18N.getString("deb.bundler.name"); |
57038 | 897 |
} |
898 |
||
899 |
@Override |
|
900 |
public String getID() { |
|
901 |
return "deb"; |
|
902 |
} |
|
903 |
||
904 |
@Override |
|
905 |
public String getBundleType() { |
|
906 |
return "INSTALLER"; |
|
907 |
} |
|
908 |
||
909 |
@Override |
|
910 |
public File execute(Map<String, ? super Object> params, |
|
57140 | 911 |
File outputParentDir) throws PackagerException { |
57038 | 912 |
return bundle(params, outputParentDir); |
913 |
} |
|
914 |
||
915 |
@Override |
|
57150 | 916 |
public boolean supported(boolean runtimeInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
917 |
return isSupported(); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
918 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
919 |
|
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
920 |
public static boolean isSupported() { |
57414
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
921 |
if (Platform.getPlatform() == Platform.LINUX) { |
57543
bcd1ab268a7d
8222778: Packaging Tool (JEP 343) on Linux/AArch64
dchuyko
parents:
57438
diff
changeset
|
922 |
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
|
923 |
return true; |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
924 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
925 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
926 |
return false; |
57038 | 927 |
} |
928 |
||
929 |
public int getSquareSizeOfImage(File f) { |
|
930 |
try { |
|
931 |
BufferedImage bi = ImageIO.read(f); |
|
932 |
if (bi.getWidth() == bi.getHeight()) { |
|
933 |
return bi.getWidth(); |
|
934 |
} else { |
|
935 |
return 0; |
|
936 |
} |
|
937 |
} catch (Exception e) { |
|
57140 | 938 |
Log.verbose(e); |
57038 | 939 |
return 0; |
940 |
} |
|
941 |
} |
|
942 |
} |