author | herrick |
Wed, 28 Aug 2019 07:32:23 -0400 | |
branch | JDK-8200758-branch |
changeset 57908 | 9a005146bc1c |
parent 57808 | 013547ae70ac |
child 57909 | c7de06ed4b54 |
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.*; |
|
31 |
import java.nio.file.Files; |
|
32 |
import java.text.MessageFormat; |
|
33 |
import java.util.*; |
|
34 |
import java.util.regex.Matcher; |
|
35 |
import java.util.regex.Pattern; |
|
36 |
||
57039 | 37 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
38 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR; |
|
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
39 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES; |
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 |
*/ |
57038 | 52 |
public class LinuxRpmBundler extends AbstractBundler { |
53 |
||
54 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 55 |
"jdk.jpackage.internal.resources.LinuxResources"); |
57038 | 56 |
|
57 |
public static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER = |
|
58 |
new StandardBundlerParam<>( |
|
59 |
"linux.app.bundler", |
|
60 |
LinuxAppBundler.class, |
|
61 |
params -> new LinuxAppBundler(), |
|
62 |
null); |
|
63 |
||
64 |
public static final BundlerParamInfo<File> RPM_IMAGE_DIR = |
|
65 |
new StandardBundlerParam<>( |
|
66 |
"linux.rpm.imageDir", |
|
67 |
File.class, |
|
68 |
params -> { |
|
69 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params); |
|
70 |
if (!imagesRoot.exists()) imagesRoot.mkdirs(); |
|
71 |
return new File(imagesRoot, "linux-rpm.image"); |
|
72 |
}, |
|
73 |
(s, p) -> new File(s)); |
|
74 |
||
75 |
// Fedora rules for package naming are used here |
|
76 |
// https://fedoraproject.org/wiki/Packaging:NamingGuidelines?rd=Packaging/NamingGuidelines |
|
77 |
// |
|
78 |
// all Fedora packages must be named using only the following ASCII |
|
79 |
// characters. These characters are displayed here: |
|
80 |
// |
|
81 |
// abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+ |
|
82 |
// |
|
83 |
private static final Pattern RPM_BUNDLE_NAME_PATTERN = |
|
84 |
Pattern.compile("[a-z\\d\\+\\-\\.\\_]+", Pattern.CASE_INSENSITIVE); |
|
85 |
||
86 |
public static final BundlerParamInfo<String> BUNDLE_NAME = |
|
87 |
new StandardBundlerParam<> ( |
|
88 |
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(), |
|
89 |
String.class, |
|
90 |
params -> { |
|
91 |
String nm = APP_NAME.fetchFrom(params); |
|
92 |
if (nm == null) return null; |
|
93 |
||
94 |
// make sure to lower case and spaces become dashes |
|
95 |
nm = nm.toLowerCase().replaceAll("[ ]", "-"); |
|
96 |
||
97 |
return nm; |
|
98 |
}, |
|
99 |
(s, p) -> { |
|
100 |
if (!RPM_BUNDLE_NAME_PATTERN.matcher(s).matches()) { |
|
101 |
String msgKey = "error.invalid-value-for-package-name"; |
|
102 |
throw new IllegalArgumentException( |
|
103 |
new ConfigException(MessageFormat.format( |
|
104 |
I18N.getString(msgKey), s), |
|
105 |
I18N.getString(msgKey + ".advice"))); |
|
106 |
} |
|
107 |
||
108 |
return s; |
|
109 |
} |
|
110 |
); |
|
111 |
||
57256 | 112 |
public static final BundlerParamInfo<String> MENU_GROUP = |
113 |
new StandardBundlerParam<>( |
|
114 |
Arguments.CLIOptions.LINUX_MENU_GROUP.getId(), |
|
115 |
String.class, |
|
116 |
params -> I18N.getString("param.menu-group.default"), |
|
117 |
(s, p) -> s |
|
118 |
); |
|
119 |
||
57038 | 120 |
public static final BundlerParamInfo<String> LICENSE_TYPE = |
121 |
new StandardBundlerParam<>( |
|
122 |
Arguments.CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(), |
|
123 |
String.class, |
|
124 |
params -> I18N.getString("param.license-type.default"), |
|
125 |
(s, p) -> s |
|
126 |
); |
|
57790 | 127 |
|
128 |
public static final BundlerParamInfo<String> GROUP = |
|
129 |
new StandardBundlerParam<>( |
|
130 |
Arguments.CLIOptions.LINUX_CATEGORY.getId(), |
|
131 |
String.class, |
|
132 |
params -> null, |
|
133 |
(s, p) -> s); |
|
57038 | 134 |
|
135 |
public static final BundlerParamInfo<String> XDG_FILE_PREFIX = |
|
136 |
new StandardBundlerParam<> ( |
|
137 |
"linux.xdg-prefix", |
|
138 |
String.class, |
|
139 |
params -> { |
|
140 |
try { |
|
141 |
String vendor; |
|
142 |
if (params.containsKey(VENDOR.getID())) { |
|
143 |
vendor = VENDOR.fetchFrom(params); |
|
144 |
} else { |
|
57039 | 145 |
vendor = "jpackage"; |
57038 | 146 |
} |
57119 | 147 |
String appName = APP_NAME.fetchFrom(params); |
57038 | 148 |
|
149 |
return (vendor + "-" + appName).replaceAll("\\s", ""); |
|
150 |
} catch (Exception e) { |
|
57776 | 151 |
Log.verbose(e); |
57038 | 152 |
} |
153 |
return "unknown-MimeInfo.xml"; |
|
154 |
}, |
|
155 |
(s, p) -> s); |
|
156 |
||
57908
9a005146bc1c
8230191: Replace javacup logo with duke everywhere in jpackage
herrick
parents:
57808
diff
changeset
|
157 |
private final static String DEFAULT_ICON = "java32.png"; |
57038 | 158 |
private final static String DEFAULT_SPEC_TEMPLATE = "template.spec"; |
159 |
private final static String DEFAULT_DESKTOP_FILE_TEMPLATE = |
|
160 |
"template.desktop"; |
|
161 |
||
162 |
public final static String TOOL_RPMBUILD = "rpmbuild"; |
|
163 |
public final static double TOOL_RPMBUILD_MIN_VERSION = 4.0d; |
|
164 |
||
165 |
public static boolean testTool(String toolName, double minVersion) { |
|
166 |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
167 |
PrintStream ps = new PrintStream(baos)) { |
|
168 |
ProcessBuilder pb = new ProcessBuilder(toolName, "--version"); |
|
57391 | 169 |
IOUtils.exec(pb, false, ps); |
57038 | 170 |
//not interested in the above's output |
171 |
String content = new String(baos.toByteArray()); |
|
172 |
Pattern pattern = Pattern.compile(" (\\d+\\.\\d+)"); |
|
173 |
Matcher matcher = pattern.matcher(content); |
|
174 |
||
175 |
if (matcher.find()) { |
|
176 |
String v = matcher.group(1); |
|
177 |
double version = Double.parseDouble(v); |
|
178 |
return minVersion <= version; |
|
179 |
} else { |
|
180 |
return false; |
|
181 |
} |
|
182 |
} catch (Exception e) { |
|
183 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
184 |
"message.test-for-tool"), toolName, e.getMessage())); |
|
185 |
return false; |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
190 |
public boolean validate(Map<String, ? super Object> params) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
191 |
throws ConfigException { |
57038 | 192 |
try { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
193 |
if (params == null) throw new ConfigException( |
57038 | 194 |
I18N.getString("error.parameters-null"), |
195 |
I18N.getString("error.parameters-null.advice")); |
|
196 |
||
197 |
// run basic validation to ensure requirements are met |
|
198 |
// 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
|
199 |
APP_BUNDLER.fetchFrom(params).validate(params); |
57038 | 200 |
|
201 |
// validate presense of required tools |
|
202 |
if (!testTool(TOOL_RPMBUILD, TOOL_RPMBUILD_MIN_VERSION)){ |
|
203 |
throw new ConfigException( |
|
204 |
MessageFormat.format( |
|
205 |
I18N.getString("error.cannot-find-rpmbuild"), |
|
206 |
TOOL_RPMBUILD_MIN_VERSION), |
|
207 |
MessageFormat.format( |
|
208 |
I18N.getString("error.cannot-find-rpmbuild.advice"), |
|
209 |
TOOL_RPMBUILD_MIN_VERSION)); |
|
210 |
} |
|
211 |
||
212 |
// only one mime type per association, at least one file extension |
|
213 |
List<Map<String, ? super Object>> associations = |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
214 |
FILE_ASSOCIATIONS.fetchFrom(params); |
57038 | 215 |
if (associations != null) { |
216 |
for (int i = 0; i < associations.size(); i++) { |
|
217 |
Map<String, ? super Object> assoc = associations.get(i); |
|
218 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
219 |
if (mimes == null || mimes.isEmpty()) { |
|
220 |
String msgKey = |
|
221 |
"error.no-content-types-for-file-association"; |
|
222 |
throw new ConfigException( |
|
223 |
MessageFormat.format(I18N.getString(msgKey), i), |
|
224 |
I18N.getString(msgKey + ".advice")); |
|
225 |
} else if (mimes.size() > 1) { |
|
226 |
String msgKey = |
|
227 |
"error.no-content-types-for-file-association"; |
|
228 |
throw new ConfigException( |
|
229 |
MessageFormat.format(I18N.getString(msgKey), i), |
|
230 |
I18N.getString(msgKey + ".advice")); |
|
231 |
} |
|
232 |
} |
|
233 |
} |
|
234 |
||
235 |
// bundle name has some restrictions |
|
236 |
// the string converter will throw an exception if invalid |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
237 |
BUNDLE_NAME.getStringConverter().apply( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
238 |
BUNDLE_NAME.fetchFrom(params), params); |
57038 | 239 |
|
240 |
return true; |
|
241 |
} catch (RuntimeException re) { |
|
242 |
if (re.getCause() instanceof ConfigException) { |
|
243 |
throw (ConfigException) re.getCause(); |
|
244 |
} else { |
|
245 |
throw new ConfigException(re); |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
250 |
private boolean prepareProto(Map<String, ? super Object> params) |
57140 | 251 |
throws PackagerException, IOException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
252 |
File appImage = StandardBundlerParam.getPredefinedAppImage(params); |
57038 | 253 |
File appDir = null; |
254 |
||
255 |
// we either have an application image or need to build one |
|
256 |
if (appImage != null) { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
257 |
appDir = new File(RPM_IMAGE_DIR.fetchFrom(params), |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
258 |
APP_NAME.fetchFrom(params)); |
57038 | 259 |
// copy everything from appImage dir into appDir/name |
260 |
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath()); |
|
261 |
} else { |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
262 |
appDir = APP_BUNDLER.fetchFrom(params).doBundle(params, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
263 |
RPM_IMAGE_DIR.fetchFrom(params), true); |
57038 | 264 |
} |
265 |
return appDir != null; |
|
266 |
} |
|
267 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
268 |
public File bundle(Map<String, ? super Object> params, |
57140 | 269 |
File outdir) throws PackagerException { |
57407 | 270 |
|
271 |
IOUtils.writableOutputDir(outdir.toPath()); |
|
57038 | 272 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
273 |
File imageDir = RPM_IMAGE_DIR.fetchFrom(params); |
57038 | 274 |
try { |
275 |
||
276 |
imageDir.mkdirs(); |
|
277 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
278 |
if (prepareProto(params) && prepareProjectConfig(params)) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
279 |
return buildRPM(params, outdir); |
57038 | 280 |
} |
281 |
return null; |
|
282 |
} catch (IOException ex) { |
|
57140 | 283 |
Log.verbose(ex); |
284 |
throw new PackagerException(ex); |
|
57038 | 285 |
} |
286 |
} |
|
287 |
||
288 |
private boolean prepareProjectConfig(Map<String, ? super Object> params) |
|
289 |
throws IOException { |
|
290 |
Map<String, String> data = createReplacementData(params); |
|
291 |
File rootDir = |
|
292 |
LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params); |
|
57407 | 293 |
File binDir = new File(rootDir, "bin"); |
57038 | 294 |
|
295 |
// prepare installer icon |
|
57407 | 296 |
File iconTarget = getConfig_IconFile(binDir, params); |
57038 | 297 |
File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params); |
57256 | 298 |
if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
57038 | 299 |
if (icon == null || !icon.exists()) { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
300 |
fetchResource(iconTarget.getName(), |
57038 | 301 |
I18N.getString("resource.menu-icon"), |
302 |
DEFAULT_ICON, |
|
303 |
iconTarget, |
|
304 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
305 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 306 |
} else { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
307 |
fetchResource(iconTarget.getName(), |
57038 | 308 |
I18N.getString("resource.menu-icon"), |
309 |
icon, |
|
310 |
iconTarget, |
|
311 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
312 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 313 |
} |
314 |
} |
|
315 |
||
316 |
StringBuilder installScripts = new StringBuilder(); |
|
317 |
StringBuilder removeScripts = new StringBuilder(); |
|
57256 | 318 |
for (Map<String, ? super Object> addLauncher : |
319 |
ADD_LAUNCHERS.fetchFrom(params)) { |
|
320 |
Map<String, String> addLauncherData = |
|
321 |
createReplacementData(addLauncher); |
|
322 |
addLauncherData.put("APPLICATION_FS_NAME", |
|
57038 | 323 |
data.get("APPLICATION_FS_NAME")); |
57256 | 324 |
addLauncherData.put("DESKTOP_MIMES", ""); |
57038 | 325 |
|
326 |
// prepare desktop shortcut |
|
57390 | 327 |
try (Writer w = Files.newBufferedWriter( |
57407 | 328 |
getConfig_DesktopShortcutFile(binDir, |
57390 | 329 |
addLauncher).toPath())) { |
330 |
String content = preprocessTextResource( |
|
57407 | 331 |
getConfig_DesktopShortcutFile(binDir, |
57390 | 332 |
addLauncher).getName(), |
333 |
I18N.getString("resource.menu-shortcut-descriptor"), |
|
334 |
DEFAULT_DESKTOP_FILE_TEMPLATE, addLauncherData, |
|
335 |
VERBOSE.fetchFrom(params), |
|
336 |
RESOURCE_DIR.fetchFrom(params)); |
|
337 |
w.write(content); |
|
338 |
} |
|
57038 | 339 |
|
340 |
// prepare installer icon |
|
57407 | 341 |
iconTarget = getConfig_IconFile(binDir, addLauncher); |
57256 | 342 |
icon = LinuxAppBundler.ICON_PNG.fetchFrom(addLauncher); |
57038 | 343 |
if (icon == null || !icon.exists()) { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
344 |
fetchResource(iconTarget.getName(), |
57038 | 345 |
I18N.getString("resource.menu-icon"), |
346 |
DEFAULT_ICON, |
|
347 |
iconTarget, |
|
348 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
349 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 350 |
} else { |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
351 |
fetchResource(iconTarget.getName(), |
57038 | 352 |
I18N.getString("resource.menu-icon"), |
353 |
icon, |
|
354 |
iconTarget, |
|
355 |
VERBOSE.fetchFrom(params), |
|
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
356 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 357 |
} |
358 |
||
359 |
// post copying of desktop icon |
|
360 |
installScripts.append("xdg-desktop-menu install --novendor "); |
|
361 |
installScripts.append(LINUX_INSTALL_DIR.fetchFrom(params)); |
|
362 |
installScripts.append("/"); |
|
363 |
installScripts.append(data.get("APPLICATION_FS_NAME")); |
|
57587 | 364 |
installScripts.append("/bin/"); |
57256 | 365 |
installScripts.append(addLauncherData.get( |
57038 | 366 |
"APPLICATION_LAUNCHER_FILENAME")); |
367 |
installScripts.append(".desktop\n"); |
|
368 |
||
369 |
// preun cleanup of desktop icon |
|
370 |
removeScripts.append("xdg-desktop-menu uninstall --novendor "); |
|
371 |
removeScripts.append(LINUX_INSTALL_DIR.fetchFrom(params)); |
|
372 |
removeScripts.append("/"); |
|
373 |
removeScripts.append(data.get("APPLICATION_FS_NAME")); |
|
57587 | 374 |
removeScripts.append("/bin/"); |
57256 | 375 |
removeScripts.append(addLauncherData.get( |
57038 | 376 |
"APPLICATION_LAUNCHER_FILENAME")); |
377 |
removeScripts.append(".desktop\n"); |
|
378 |
||
379 |
} |
|
57256 | 380 |
data.put("ADD_LAUNCHERS_INSTALL", installScripts.toString()); |
381 |
data.put("ADD_LAUNCHERS_REMOVE", removeScripts.toString()); |
|
57038 | 382 |
|
383 |
StringBuilder cdsScript = new StringBuilder(); |
|
384 |
||
385 |
data.put("APP_CDS_CACHE", cdsScript.toString()); |
|
386 |
||
387 |
List<Map<String, ? super Object>> associations = |
|
388 |
FILE_ASSOCIATIONS.fetchFrom(params); |
|
389 |
data.put("FILE_ASSOCIATION_INSTALL", ""); |
|
390 |
data.put("FILE_ASSOCIATION_REMOVE", ""); |
|
391 |
data.put("DESKTOP_MIMES", ""); |
|
392 |
if (associations != null) { |
|
393 |
String mimeInfoFile = XDG_FILE_PREFIX.fetchFrom(params) |
|
394 |
+ "-MimeInfo.xml"; |
|
395 |
StringBuilder mimeInfo = new StringBuilder( |
|
396 |
"<?xml version=\"1.0\"?>\n<mime-info xmlns=" |
|
397 |
+"'http://www.freedesktop.org/standards/shared-mime-info'>\n"); |
|
398 |
StringBuilder registrations = new StringBuilder(); |
|
399 |
StringBuilder deregistrations = new StringBuilder(); |
|
400 |
StringBuilder desktopMimes = new StringBuilder("MimeType="); |
|
401 |
boolean addedEntry = false; |
|
402 |
||
403 |
for (Map<String, ? super Object> assoc : associations) { |
|
404 |
// <mime-type type="application/x-vnd.awesome"> |
|
405 |
// <comment>Awesome document</comment> |
|
406 |
// <glob pattern="*.awesome"/> |
|
407 |
// <glob pattern="*.awe"/> |
|
408 |
// </mime-type> |
|
409 |
||
410 |
if (assoc == null) { |
|
411 |
continue; |
|
412 |
} |
|
413 |
||
414 |
String description = FA_DESCRIPTION.fetchFrom(assoc); |
|
57397
89549ecec1c7
8223212: Code cleanup found during jpackage review
herrick
parents:
57396
diff
changeset
|
415 |
File faIcon = FA_ICON.fetchFrom(assoc); |
57038 | 416 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(assoc); |
417 |
if (extensions == null) { |
|
418 |
Log.verbose(I18N.getString( |
|
419 |
"message.creating-association-with-null-extension")); |
|
420 |
} |
|
421 |
||
422 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc); |
|
423 |
if (mimes == null || mimes.isEmpty()) { |
|
424 |
continue; |
|
425 |
} |
|
426 |
String thisMime = mimes.get(0); |
|
427 |
String dashMime = thisMime.replace('/', '-'); |
|
428 |
||
429 |
mimeInfo.append(" <mime-type type='") |
|
430 |
.append(thisMime) |
|
431 |
.append("'>\n"); |
|
432 |
if (description != null && !description.isEmpty()) { |
|
433 |
mimeInfo.append(" <comment>") |
|
434 |
.append(description) |
|
435 |
.append("</comment>\n"); |
|
436 |
} |
|
437 |
||
438 |
if (extensions != null) { |
|
439 |
for (String ext : extensions) { |
|
440 |
mimeInfo.append(" <glob pattern='*.") |
|
441 |
.append(ext) |
|
442 |
.append("'/>\n"); |
|
443 |
} |
|
444 |
} |
|
445 |
||
446 |
mimeInfo.append(" </mime-type>\n"); |
|
447 |
if (!addedEntry) { |
|
448 |
registrations.append("xdg-mime install ") |
|
449 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
450 |
.append("/") |
|
451 |
.append(data.get("APPLICATION_FS_NAME")) |
|
57808 | 452 |
.append("/bin/") |
57038 | 453 |
.append(mimeInfoFile) |
454 |
.append("\n"); |
|
455 |
||
456 |
deregistrations.append("xdg-mime uninstall ") |
|
457 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
458 |
.append("/") |
|
459 |
.append(data.get("APPLICATION_FS_NAME")) |
|
57808 | 460 |
.append("/bin/") |
57038 | 461 |
.append(mimeInfoFile) |
462 |
.append("\n"); |
|
463 |
addedEntry = true; |
|
464 |
} else { |
|
465 |
desktopMimes.append(";"); |
|
466 |
} |
|
467 |
desktopMimes.append(thisMime); |
|
468 |
||
469 |
if (faIcon != null && faIcon.exists()) { |
|
470 |
int size = getSquareSizeOfImage(faIcon); |
|
471 |
||
472 |
if (size > 0) { |
|
57407 | 473 |
File target = new File(binDir, |
57119 | 474 |
APP_NAME.fetchFrom(params) |
475 |
+ "_fa_" + faIcon.getName()); |
|
57038 | 476 |
IOUtils.copyFile(faIcon, target); |
477 |
||
478 |
// xdg-icon-resource install --context mimetypes |
|
479 |
// --size 64 awesomeapp_fa_1.png |
|
480 |
// application-x.vnd-awesome |
|
481 |
registrations.append( |
|
482 |
"xdg-icon-resource install " |
|
483 |
+ "--context mimetypes --size ") |
|
484 |
.append(size) |
|
485 |
.append(" ") |
|
486 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
487 |
.append("/") |
|
488 |
.append(data.get("APPLICATION_FS_NAME")) |
|
489 |
.append("/") |
|
490 |
.append(target.getName()) |
|
491 |
.append(" ") |
|
492 |
.append(dashMime) |
|
493 |
.append("\n"); |
|
494 |
||
495 |
// xdg-icon-resource uninstall --context mimetypes |
|
496 |
// --size 64 awesomeapp_fa_1.png |
|
497 |
// application-x.vnd-awesome |
|
498 |
deregistrations.append( |
|
499 |
"xdg-icon-resource uninstall " |
|
500 |
+ "--context mimetypes --size ") |
|
501 |
.append(size) |
|
502 |
.append(" ") |
|
503 |
.append(LINUX_INSTALL_DIR.fetchFrom(params)) |
|
504 |
.append("/") |
|
505 |
.append(data.get("APPLICATION_FS_NAME")) |
|
506 |
.append("/") |
|
507 |
.append(target.getName()) |
|
508 |
.append(" ") |
|
509 |
.append(dashMime) |
|
510 |
.append("\n"); |
|
511 |
} |
|
512 |
} |
|
513 |
} |
|
514 |
mimeInfo.append("</mime-info>"); |
|
515 |
||
516 |
if (addedEntry) { |
|
57390 | 517 |
try (Writer w = Files.newBufferedWriter( |
57407 | 518 |
new File(binDir, mimeInfoFile).toPath())) { |
57390 | 519 |
w.write(mimeInfo.toString()); |
520 |
} |
|
57038 | 521 |
data.put("FILE_ASSOCIATION_INSTALL", registrations.toString()); |
522 |
data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString()); |
|
523 |
data.put("DESKTOP_MIMES", desktopMimes.toString()); |
|
524 |
} |
|
525 |
} |
|
526 |
||
57256 | 527 |
if (!StandardBundlerParam.isRuntimeInstaller(params)) { |
57038 | 528 |
//prepare desktop shortcut |
57390 | 529 |
try (Writer w = Files.newBufferedWriter( |
57407 | 530 |
getConfig_DesktopShortcutFile(binDir, params).toPath())) { |
57390 | 531 |
String content = preprocessTextResource( |
57407 | 532 |
getConfig_DesktopShortcutFile(binDir, |
57390 | 533 |
params).getName(), |
534 |
I18N.getString("resource.menu-shortcut-descriptor"), |
|
535 |
DEFAULT_DESKTOP_FILE_TEMPLATE, data, |
|
536 |
VERBOSE.fetchFrom(params), |
|
537 |
RESOURCE_DIR.fetchFrom(params)); |
|
538 |
w.write(content); |
|
539 |
} |
|
540 |
} |
|
541 |
||
542 |
// prepare spec file |
|
543 |
try (Writer w = Files.newBufferedWriter( |
|
544 |
getConfig_SpecFile(params).toPath())) { |
|
57038 | 545 |
String content = preprocessTextResource( |
57390 | 546 |
getConfig_SpecFile(params).getName(), |
547 |
I18N.getString("resource.rpm-spec-file"), |
|
548 |
DEFAULT_SPEC_TEMPLATE, data, |
|
57038 | 549 |
VERBOSE.fetchFrom(params), |
57091
06bc4bd64599
8215515: Add a command line option to override internal resources.
herrick
parents:
57080
diff
changeset
|
550 |
RESOURCE_DIR.fetchFrom(params)); |
57038 | 551 |
w.write(content); |
552 |
} |
|
553 |
||
554 |
return true; |
|
555 |
} |
|
556 |
||
557 |
private Map<String, String> createReplacementData( |
|
57080 | 558 |
Map<String, ? super Object> params) throws IOException { |
57038 | 559 |
Map<String, String> data = new HashMap<>(); |
57407 | 560 |
String launcher = LinuxAppImageBuilder.getLauncherRelativePath(params); |
57038 | 561 |
|
562 |
data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params)); |
|
57119 | 563 |
data.put("APPLICATION_FS_NAME", APP_NAME.fetchFrom(params)); |
57038 | 564 |
data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params)); |
565 |
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params)); |
|
566 |
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
|
567 |
data.put("APPLICATION_RELEASE", RELEASE.fetchFrom(params)); |
57407 | 568 |
data.put("APPLICATION_LAUNCHER_FILENAME", launcher); |
57038 | 569 |
data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params)); |
570 |
data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params)); |
|
57256 | 571 |
data.put("DEPLOY_BUNDLE_CATEGORY", MENU_GROUP.fetchFrom(params)); |
57038 | 572 |
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params)); |
57255
f686bda3b831
8215574: Investigate and document usage of --category, --copyright, --vendor and --description
herrick
parents:
57150
diff
changeset
|
573 |
data.put("APPLICATION_SUMMARY", APP_NAME.fetchFrom(params)); |
57038 | 574 |
data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params)); |
57742
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
575 |
|
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
576 |
String licenseFile = LICENSE_FILE.fetchFrom(params); |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
577 |
if (licenseFile == null) { |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
578 |
licenseFile = ""; |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
579 |
} |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
580 |
data.put("APPLICATION_LICENSE_FILE", licenseFile); |
e3d4b9bc5093
8215447: Investigate if current implementation of --license-file is correct for RPM packages
herrick
parents:
57741
diff
changeset
|
581 |
|
57790 | 582 |
String group = GROUP.fetchFrom(params); |
583 |
if (group == null) { |
|
584 |
group = ""; |
|
585 |
} |
|
586 |
data.put("APPLICATION_GROUP", group); |
|
587 |
||
57038 | 588 |
String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params); |
589 |
data.put("PACKAGE_DEPENDENCIES", |
|
590 |
deps.isEmpty() ? "" : "Requires: " + deps); |
|
57256 | 591 |
data.put("RUNTIME_INSTALLER", "" + |
592 |
StandardBundlerParam.isRuntimeInstaller(params)); |
|
57038 | 593 |
return data; |
594 |
} |
|
595 |
||
596 |
private File getConfig_DesktopShortcutFile(File rootDir, |
|
597 |
Map<String, ? super Object> params) { |
|
57119 | 598 |
return new File(rootDir, APP_NAME.fetchFrom(params) + ".desktop"); |
57038 | 599 |
} |
600 |
||
601 |
private File getConfig_IconFile(File rootDir, |
|
602 |
Map<String, ? super Object> params) { |
|
57119 | 603 |
return new File(rootDir, APP_NAME.fetchFrom(params) + ".png"); |
57038 | 604 |
} |
605 |
||
606 |
private File getConfig_SpecFile(Map<String, ? super Object> params) { |
|
607 |
return new File(RPM_IMAGE_DIR.fetchFrom(params), |
|
57119 | 608 |
APP_NAME.fetchFrom(params) + ".spec"); |
57038 | 609 |
} |
610 |
||
611 |
private File buildRPM(Map<String, ? super Object> params, |
|
612 |
File outdir) throws IOException { |
|
613 |
Log.verbose(MessageFormat.format(I18N.getString( |
|
614 |
"message.outputting-bundle-location"), |
|
615 |
outdir.getAbsolutePath())); |
|
616 |
||
57256 | 617 |
File broot = new File(TEMP_ROOT.fetchFrom(params), "rmpbuildroot"); |
57038 | 618 |
|
619 |
outdir.mkdirs(); |
|
620 |
||
621 |
//run rpmbuild |
|
622 |
ProcessBuilder pb = new ProcessBuilder( |
|
623 |
TOOL_RPMBUILD, |
|
624 |
"-bb", getConfig_SpecFile(params).getAbsolutePath(), |
|
625 |
"--define", "%_sourcedir " |
|
626 |
+ RPM_IMAGE_DIR.fetchFrom(params).getAbsolutePath(), |
|
627 |
// save result to output dir |
|
628 |
"--define", "%_rpmdir " + outdir.getAbsolutePath(), |
|
629 |
// do not use other system directories to build as current user |
|
630 |
"--define", "%_topdir " + broot.getAbsolutePath() |
|
631 |
); |
|
632 |
pb = pb.directory(RPM_IMAGE_DIR.fetchFrom(params)); |
|
57391 | 633 |
IOUtils.exec(pb); |
57038 | 634 |
|
635 |
Log.verbose(MessageFormat.format( |
|
636 |
I18N.getString("message.output-bundle-location"), |
|
637 |
outdir.getAbsolutePath())); |
|
638 |
||
639 |
// presume the result is the ".rpm" file with the newest modified time |
|
640 |
// not the best solution, but it is the most reliable |
|
641 |
File result = null; |
|
642 |
long lastModified = 0; |
|
643 |
File[] list = outdir.listFiles(); |
|
644 |
if (list != null) { |
|
645 |
for (File f : list) { |
|
646 |
if (f.getName().endsWith(".rpm") && |
|
647 |
f.lastModified() > lastModified) { |
|
648 |
result = f; |
|
649 |
lastModified = f.lastModified(); |
|
650 |
} |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
return result; |
|
655 |
} |
|
656 |
||
657 |
@Override |
|
658 |
public String getName() { |
|
57059 | 659 |
return I18N.getString("rpm.bundler.name"); |
57038 | 660 |
} |
661 |
||
662 |
@Override |
|
663 |
public String getID() { |
|
664 |
return "rpm"; |
|
665 |
} |
|
666 |
||
667 |
@Override |
|
668 |
public String getBundleType() { |
|
669 |
return "INSTALLER"; |
|
670 |
} |
|
671 |
||
672 |
@Override |
|
57140 | 673 |
public File execute(Map<String, ? super Object> params, |
674 |
File outputParentDir) throws PackagerException { |
|
57038 | 675 |
return bundle(params, outputParentDir); |
676 |
} |
|
677 |
||
678 |
@Override |
|
57150 | 679 |
public boolean supported(boolean runtimeInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
680 |
return isSupported(); |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
681 |
} |
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
682 |
|
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57414
diff
changeset
|
683 |
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
|
684 |
if (Platform.getPlatform() == Platform.LINUX) { |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
685 |
if (testTool(TOOL_RPMBUILD, TOOL_RPMBUILD_MIN_VERSION)) { |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
686 |
return true; |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
687 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
688 |
} |
6eda749d3117
8225428: CLI change to remove "mode", rename to "package", and build only one target
herrick
parents:
57407
diff
changeset
|
689 |
return false; |
57038 | 690 |
} |
691 |
||
692 |
public int getSquareSizeOfImage(File f) { |
|
693 |
try { |
|
694 |
BufferedImage bi = ImageIO.read(f); |
|
695 |
if (bi.getWidth() == bi.getHeight()) { |
|
696 |
return bi.getWidth(); |
|
697 |
} else { |
|
698 |
return 0; |
|
699 |
} |
|
700 |
} catch (Exception e) { |
|
701 |
e.printStackTrace(); |
|
702 |
return 0; |
|
703 |
} |
|
704 |
} |
|
705 |
} |