57038
|
1 |
/*
|
|
2 |
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. 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 |
|
57039
|
28 |
import jdk.jpackage.internal.*;
|
|
29 |
import jdk.jpackage.internal.Arguments;
|
|
30 |
import jdk.jpackage.internal.resources.LinuxResources;
|
57038
|
31 |
|
|
32 |
import javax.imageio.ImageIO;
|
|
33 |
import java.awt.image.BufferedImage;
|
|
34 |
import java.io.*;
|
|
35 |
import java.nio.file.Files;
|
|
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.logging.Level;
|
|
41 |
import java.util.logging.Logger;
|
|
42 |
import java.util.regex.Matcher;
|
|
43 |
import java.util.regex.Pattern;
|
|
44 |
|
57039
|
45 |
import static jdk.jpackage.internal.StandardBundlerParam.*;
|
|
46 |
import static jdk.jpackage.internal.LinuxAppBundler.LINUX_INSTALL_DIR;
|
57038
|
47 |
import static
|
57039
|
48 |
jdk.jpackage.internal.LinuxAppBundler.LINUX_PACKAGE_DEPENDENCIES;
|
57038
|
49 |
|
|
50 |
public class LinuxRpmBundler extends AbstractBundler {
|
|
51 |
|
|
52 |
private static final ResourceBundle I18N = ResourceBundle.getBundle(
|
57039
|
53 |
"jdk.jpackage.internal.resources.LinuxRpmBundler");
|
57038
|
54 |
|
|
55 |
public static final BundlerParamInfo<LinuxAppBundler> APP_BUNDLER =
|
|
56 |
new StandardBundlerParam<>(
|
|
57 |
I18N.getString("param.app-bundler.name"),
|
|
58 |
I18N.getString("param.app-bundler.description"),
|
|
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 |
I18N.getString("param.image-dir.name"),
|
|
67 |
I18N.getString("param.image-dir.description"),
|
|
68 |
"linux.rpm.imageDir",
|
|
69 |
File.class,
|
|
70 |
params -> {
|
|
71 |
File imagesRoot = IMAGES_ROOT.fetchFrom(params);
|
|
72 |
if (!imagesRoot.exists()) imagesRoot.mkdirs();
|
|
73 |
return new File(imagesRoot, "linux-rpm.image");
|
|
74 |
},
|
|
75 |
(s, p) -> new File(s));
|
|
76 |
|
|
77 |
public static final BundlerParamInfo<File> CONFIG_ROOT =
|
|
78 |
new StandardBundlerParam<>(
|
|
79 |
I18N.getString("param.config-root.name"),
|
|
80 |
I18N.getString("param.config-root.description"),
|
|
81 |
"configRoot",
|
|
82 |
File.class,
|
|
83 |
params -> new File(BUILD_ROOT.fetchFrom(params), "linux"),
|
|
84 |
(s, p) -> new File(s));
|
|
85 |
|
|
86 |
// Fedora rules for package naming are used here
|
|
87 |
// https://fedoraproject.org/wiki/Packaging:NamingGuidelines?rd=Packaging/NamingGuidelines
|
|
88 |
//
|
|
89 |
// all Fedora packages must be named using only the following ASCII
|
|
90 |
// characters. These characters are displayed here:
|
|
91 |
//
|
|
92 |
// abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._+
|
|
93 |
//
|
|
94 |
private static final Pattern RPM_BUNDLE_NAME_PATTERN =
|
|
95 |
Pattern.compile("[a-z\\d\\+\\-\\.\\_]+", Pattern.CASE_INSENSITIVE);
|
|
96 |
|
|
97 |
public static final BundlerParamInfo<String> BUNDLE_NAME =
|
|
98 |
new StandardBundlerParam<> (
|
|
99 |
I18N.getString("param.bundle-name.name"),
|
|
100 |
I18N.getString("param.bundle-name.description"),
|
|
101 |
Arguments.CLIOptions.LINUX_BUNDLE_NAME.getId(),
|
|
102 |
String.class,
|
|
103 |
params -> {
|
|
104 |
String nm = APP_NAME.fetchFrom(params);
|
|
105 |
if (nm == null) return null;
|
|
106 |
|
|
107 |
// make sure to lower case and spaces become dashes
|
|
108 |
nm = nm.toLowerCase().replaceAll("[ ]", "-");
|
|
109 |
|
|
110 |
return nm;
|
|
111 |
},
|
|
112 |
(s, p) -> {
|
|
113 |
if (!RPM_BUNDLE_NAME_PATTERN.matcher(s).matches()) {
|
|
114 |
String msgKey = "error.invalid-value-for-package-name";
|
|
115 |
throw new IllegalArgumentException(
|
|
116 |
new ConfigException(MessageFormat.format(
|
|
117 |
I18N.getString(msgKey), s),
|
|
118 |
I18N.getString(msgKey + ".advice")));
|
|
119 |
}
|
|
120 |
|
|
121 |
return s;
|
|
122 |
}
|
|
123 |
);
|
|
124 |
|
|
125 |
public static final BundlerParamInfo<String> LICENSE_TYPE =
|
|
126 |
new StandardBundlerParam<>(
|
|
127 |
I18N.getString("param.license-type.name"),
|
|
128 |
I18N.getString("param.license-type.description"),
|
|
129 |
Arguments.CLIOptions.LINUX_RPM_LICENSE_TYPE.getId(),
|
|
130 |
String.class,
|
|
131 |
params -> I18N.getString("param.license-type.default"),
|
|
132 |
(s, p) -> s
|
|
133 |
);
|
|
134 |
|
|
135 |
public static final BundlerParamInfo<String> XDG_FILE_PREFIX =
|
|
136 |
new StandardBundlerParam<> (
|
|
137 |
I18N.getString("param.xdg-prefix.name"),
|
|
138 |
I18N.getString("param.xdg-prefix.description"),
|
|
139 |
"linux.xdg-prefix",
|
|
140 |
String.class,
|
|
141 |
params -> {
|
|
142 |
try {
|
|
143 |
String vendor;
|
|
144 |
if (params.containsKey(VENDOR.getID())) {
|
|
145 |
vendor = VENDOR.fetchFrom(params);
|
|
146 |
} else {
|
57039
|
147 |
vendor = "jpackage";
|
57038
|
148 |
}
|
|
149 |
String appName = APP_FS_NAME.fetchFrom(params);
|
|
150 |
|
|
151 |
return (vendor + "-" + appName).replaceAll("\\s", "");
|
|
152 |
} catch (Exception e) {
|
|
153 |
if (Log.isDebug()) {
|
|
154 |
e.printStackTrace();
|
|
155 |
}
|
|
156 |
}
|
|
157 |
return "unknown-MimeInfo.xml";
|
|
158 |
},
|
|
159 |
(s, p) -> s);
|
|
160 |
|
|
161 |
private final static String DEFAULT_ICON = "javalogo_white_32.png";
|
|
162 |
private final static String DEFAULT_SPEC_TEMPLATE = "template.spec";
|
|
163 |
private final static String DEFAULT_DESKTOP_FILE_TEMPLATE =
|
|
164 |
"template.desktop";
|
|
165 |
|
|
166 |
public final static String TOOL_RPMBUILD = "rpmbuild";
|
|
167 |
public final static double TOOL_RPMBUILD_MIN_VERSION = 4.0d;
|
|
168 |
|
|
169 |
public LinuxRpmBundler() {
|
|
170 |
super();
|
|
171 |
baseResourceLoader = LinuxResources.class;
|
|
172 |
}
|
|
173 |
|
|
174 |
public static boolean testTool(String toolName, double minVersion) {
|
|
175 |
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
176 |
PrintStream ps = new PrintStream(baos)) {
|
|
177 |
ProcessBuilder pb = new ProcessBuilder(toolName, "--version");
|
|
178 |
IOUtils.exec(pb, Log.isDebug(), false, ps);
|
|
179 |
//not interested in the above's output
|
|
180 |
String content = new String(baos.toByteArray());
|
|
181 |
Pattern pattern = Pattern.compile(" (\\d+\\.\\d+)");
|
|
182 |
Matcher matcher = pattern.matcher(content);
|
|
183 |
|
|
184 |
if (matcher.find()) {
|
|
185 |
String v = matcher.group(1);
|
|
186 |
double version = Double.parseDouble(v);
|
|
187 |
return minVersion <= version;
|
|
188 |
} else {
|
|
189 |
return false;
|
|
190 |
}
|
|
191 |
} catch (Exception e) {
|
|
192 |
Log.verbose(MessageFormat.format(I18N.getString(
|
|
193 |
"message.test-for-tool"), toolName, e.getMessage()));
|
|
194 |
return false;
|
|
195 |
}
|
|
196 |
}
|
|
197 |
|
|
198 |
@Override
|
|
199 |
public boolean validate(Map<String, ? super Object> p)
|
|
200 |
throws UnsupportedPlatformException, ConfigException {
|
|
201 |
try {
|
|
202 |
if (p == null) throw new ConfigException(
|
|
203 |
I18N.getString("error.parameters-null"),
|
|
204 |
I18N.getString("error.parameters-null.advice"));
|
|
205 |
|
|
206 |
// run basic validation to ensure requirements are met
|
|
207 |
// we are not interested in return code, only possible exception
|
|
208 |
APP_BUNDLER.fetchFrom(p).doValidate(p);
|
|
209 |
|
|
210 |
// validate license file, if used, exists in the proper place
|
|
211 |
if (p.containsKey(LICENSE_FILE.getID())) {
|
|
212 |
List<RelativeFileSet> appResourcesList =
|
|
213 |
APP_RESOURCES_LIST.fetchFrom(p);
|
|
214 |
for (String license : LICENSE_FILE.fetchFrom(p)) {
|
|
215 |
boolean found = false;
|
|
216 |
for (RelativeFileSet appResources : appResourcesList) {
|
|
217 |
found = found || appResources.contains(license);
|
|
218 |
}
|
|
219 |
if (!found) {
|
|
220 |
throw new ConfigException(
|
|
221 |
I18N.getString("error.license-missing"),
|
|
222 |
MessageFormat.format(
|
|
223 |
I18N.getString("error.license-missing.advice"),
|
|
224 |
license));
|
|
225 |
}
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
// validate presense of required tools
|
|
230 |
if (!testTool(TOOL_RPMBUILD, TOOL_RPMBUILD_MIN_VERSION)){
|
|
231 |
throw new ConfigException(
|
|
232 |
MessageFormat.format(
|
|
233 |
I18N.getString("error.cannot-find-rpmbuild"),
|
|
234 |
TOOL_RPMBUILD_MIN_VERSION),
|
|
235 |
MessageFormat.format(
|
|
236 |
I18N.getString("error.cannot-find-rpmbuild.advice"),
|
|
237 |
TOOL_RPMBUILD_MIN_VERSION));
|
|
238 |
}
|
|
239 |
|
|
240 |
// only one mime type per association, at least one file extension
|
|
241 |
List<Map<String, ? super Object>> associations =
|
|
242 |
FILE_ASSOCIATIONS.fetchFrom(p);
|
|
243 |
if (associations != null) {
|
|
244 |
for (int i = 0; i < associations.size(); i++) {
|
|
245 |
Map<String, ? super Object> assoc = associations.get(i);
|
|
246 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
|
|
247 |
if (mimes == null || mimes.isEmpty()) {
|
|
248 |
String msgKey =
|
|
249 |
"error.no-content-types-for-file-association";
|
|
250 |
throw new ConfigException(
|
|
251 |
MessageFormat.format(I18N.getString(msgKey), i),
|
|
252 |
I18N.getString(msgKey + ".advice"));
|
|
253 |
} else if (mimes.size() > 1) {
|
|
254 |
String msgKey =
|
|
255 |
"error.no-content-types-for-file-association";
|
|
256 |
throw new ConfigException(
|
|
257 |
MessageFormat.format(I18N.getString(msgKey), i),
|
|
258 |
I18N.getString(msgKey + ".advice"));
|
|
259 |
}
|
|
260 |
}
|
|
261 |
}
|
|
262 |
|
|
263 |
// bundle name has some restrictions
|
|
264 |
// the string converter will throw an exception if invalid
|
|
265 |
BUNDLE_NAME.getStringConverter().apply(BUNDLE_NAME.fetchFrom(p), p);
|
|
266 |
|
|
267 |
return true;
|
|
268 |
} catch (RuntimeException re) {
|
|
269 |
if (re.getCause() instanceof ConfigException) {
|
|
270 |
throw (ConfigException) re.getCause();
|
|
271 |
} else {
|
|
272 |
throw new ConfigException(re);
|
|
273 |
}
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
private boolean prepareProto(Map<String, ? super Object> p)
|
|
278 |
throws IOException {
|
|
279 |
File appImage = StandardBundlerParam.getPredefinedAppImage(p);
|
|
280 |
File appDir = null;
|
|
281 |
|
|
282 |
// we either have an application image or need to build one
|
|
283 |
if (appImage != null) {
|
|
284 |
appDir = new File(RPM_IMAGE_DIR.fetchFrom(p),
|
|
285 |
APP_NAME.fetchFrom(p));
|
|
286 |
// copy everything from appImage dir into appDir/name
|
|
287 |
IOUtils.copyRecursive(appImage.toPath(), appDir.toPath());
|
|
288 |
} else {
|
|
289 |
appDir = APP_BUNDLER.fetchFrom(p).doBundle(p,
|
|
290 |
RPM_IMAGE_DIR.fetchFrom(p), true);
|
|
291 |
}
|
|
292 |
return appDir != null;
|
|
293 |
}
|
|
294 |
|
|
295 |
public File bundle(Map<String, ? super Object> p, File outdir) {
|
|
296 |
if (!outdir.isDirectory() && !outdir.mkdirs()) {
|
|
297 |
throw new RuntimeException(MessageFormat.format(
|
|
298 |
I18N.getString("error.cannot-create-output-dir"),
|
|
299 |
outdir.getAbsolutePath()));
|
|
300 |
}
|
|
301 |
if (!outdir.canWrite()) {
|
|
302 |
throw new RuntimeException(MessageFormat.format(
|
|
303 |
I18N.getString("error.cannot-write-to-output-dir"),
|
|
304 |
outdir.getAbsolutePath()));
|
|
305 |
}
|
|
306 |
|
|
307 |
File imageDir = RPM_IMAGE_DIR.fetchFrom(p);
|
|
308 |
try {
|
|
309 |
|
|
310 |
imageDir.mkdirs();
|
|
311 |
|
|
312 |
if (prepareProto(p) && prepareProjectConfig(p)) {
|
|
313 |
return buildRPM(p, outdir);
|
|
314 |
}
|
|
315 |
return null;
|
|
316 |
} catch (IOException ex) {
|
|
317 |
ex.printStackTrace();
|
|
318 |
return null;
|
|
319 |
} finally {
|
|
320 |
try {
|
|
321 |
if (imageDir != null &&
|
|
322 |
PREDEFINED_APP_IMAGE.fetchFrom(p) == null &&
|
|
323 |
(PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ||
|
|
324 |
!Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) &&
|
|
325 |
!Log.isDebug() &&
|
|
326 |
!Log.isVerbose()) {
|
|
327 |
IOUtils.deleteRecursive(imageDir);
|
|
328 |
} else if (imageDir != null) {
|
|
329 |
Log.verbose(MessageFormat.format(I18N.getString(
|
|
330 |
"message.debug-working-directory"),
|
|
331 |
imageDir.getAbsolutePath()));
|
|
332 |
}
|
|
333 |
} catch (IOException ex) {
|
|
334 |
// noinspection ReturnInsideFinallyBlock
|
|
335 |
Log.debug(ex.getMessage());
|
|
336 |
return null;
|
|
337 |
}
|
|
338 |
}
|
|
339 |
}
|
|
340 |
|
|
341 |
/*
|
|
342 |
* set permissions with a string like "rwxr-xr-x"
|
|
343 |
*
|
|
344 |
* This cannot be directly backport to 22u which is built with 1.6
|
|
345 |
*/
|
|
346 |
private void setPermissions(File file, String permissions) {
|
|
347 |
Set<PosixFilePermission> filePermissions =
|
|
348 |
PosixFilePermissions.fromString(permissions);
|
|
349 |
try {
|
|
350 |
if (file.exists()) {
|
|
351 |
Files.setPosixFilePermissions(file.toPath(), filePermissions);
|
|
352 |
}
|
|
353 |
} catch (IOException ex) {
|
|
354 |
Logger.getLogger(LinuxDebBundler.class.getName()).log(
|
|
355 |
Level.SEVERE, null, ex);
|
|
356 |
}
|
|
357 |
}
|
|
358 |
|
|
359 |
private String getLicenseFileString(Map<String, ? super Object> params) {
|
|
360 |
StringBuilder sb = new StringBuilder();
|
|
361 |
for (String f: LICENSE_FILE.fetchFrom(params)) {
|
|
362 |
if (sb.length() != 0) {
|
|
363 |
sb.append("\n");
|
|
364 |
}
|
|
365 |
sb.append("%doc ");
|
|
366 |
sb.append(LINUX_INSTALL_DIR.fetchFrom(params));
|
|
367 |
sb.append("/");
|
|
368 |
sb.append(APP_FS_NAME.fetchFrom(params));
|
|
369 |
sb.append("/app/");
|
|
370 |
sb.append(f);
|
|
371 |
}
|
|
372 |
return sb.toString();
|
|
373 |
}
|
|
374 |
|
|
375 |
private boolean prepareProjectConfig(Map<String, ? super Object> params)
|
|
376 |
throws IOException {
|
|
377 |
Map<String, String> data = createReplacementData(params);
|
|
378 |
File rootDir =
|
|
379 |
LinuxAppBundler.getRootDir(RPM_IMAGE_DIR.fetchFrom(params), params);
|
|
380 |
|
|
381 |
// prepare installer icon
|
|
382 |
File iconTarget = getConfig_IconFile(rootDir, params);
|
|
383 |
File icon = LinuxAppBundler.ICON_PNG.fetchFrom(params);
|
|
384 |
if (!Arguments.CREATE_JRE_INSTALLER.fetchFrom(params)) {
|
|
385 |
if (icon == null || !icon.exists()) {
|
|
386 |
fetchResource(LinuxAppBundler.BUNDLER_PREFIX
|
|
387 |
+ iconTarget.getName(),
|
|
388 |
I18N.getString("resource.menu-icon"),
|
|
389 |
DEFAULT_ICON,
|
|
390 |
iconTarget,
|
|
391 |
VERBOSE.fetchFrom(params),
|
|
392 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
393 |
} else {
|
|
394 |
fetchResource(LinuxAppBundler.BUNDLER_PREFIX
|
|
395 |
+ iconTarget.getName(),
|
|
396 |
I18N.getString("resource.menu-icon"),
|
|
397 |
icon,
|
|
398 |
iconTarget,
|
|
399 |
VERBOSE.fetchFrom(params),
|
|
400 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
401 |
}
|
|
402 |
}
|
|
403 |
|
|
404 |
StringBuilder installScripts = new StringBuilder();
|
|
405 |
StringBuilder removeScripts = new StringBuilder();
|
|
406 |
for (Map<String, ? super Object> secondaryLauncher :
|
|
407 |
SECONDARY_LAUNCHERS.fetchFrom(params)) {
|
|
408 |
Map<String, String> secondaryLauncherData =
|
|
409 |
createReplacementData(secondaryLauncher);
|
|
410 |
secondaryLauncherData.put("APPLICATION_FS_NAME",
|
|
411 |
data.get("APPLICATION_FS_NAME"));
|
|
412 |
secondaryLauncherData.put("DESKTOP_MIMES", "");
|
|
413 |
|
|
414 |
// prepare desktop shortcut
|
|
415 |
Writer w = new BufferedWriter(new FileWriter(
|
|
416 |
getConfig_DesktopShortcutFile(rootDir, secondaryLauncher)));
|
|
417 |
String content = preprocessTextResource(
|
|
418 |
LinuxAppBundler.BUNDLER_PREFIX
|
|
419 |
+ getConfig_DesktopShortcutFile(rootDir,
|
|
420 |
secondaryLauncher).getName(),
|
|
421 |
I18N.getString("resource.menu-shortcut-descriptor"),
|
|
422 |
DEFAULT_DESKTOP_FILE_TEMPLATE, secondaryLauncherData,
|
|
423 |
VERBOSE.fetchFrom(params),
|
|
424 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
425 |
w.write(content);
|
|
426 |
w.close();
|
|
427 |
|
|
428 |
// prepare installer icon
|
|
429 |
iconTarget = getConfig_IconFile(rootDir, secondaryLauncher);
|
|
430 |
icon = LinuxAppBundler.ICON_PNG.fetchFrom(secondaryLauncher);
|
|
431 |
if (icon == null || !icon.exists()) {
|
|
432 |
fetchResource(LinuxAppBundler.BUNDLER_PREFIX
|
|
433 |
+ iconTarget.getName(),
|
|
434 |
I18N.getString("resource.menu-icon"),
|
|
435 |
DEFAULT_ICON,
|
|
436 |
iconTarget,
|
|
437 |
VERBOSE.fetchFrom(params),
|
|
438 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
439 |
} else {
|
|
440 |
fetchResource(LinuxAppBundler.BUNDLER_PREFIX
|
|
441 |
+ iconTarget.getName(),
|
|
442 |
I18N.getString("resource.menu-icon"),
|
|
443 |
icon,
|
|
444 |
iconTarget,
|
|
445 |
VERBOSE.fetchFrom(params),
|
|
446 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
447 |
}
|
|
448 |
|
|
449 |
// post copying of desktop icon
|
|
450 |
installScripts.append("xdg-desktop-menu install --novendor ");
|
|
451 |
installScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
|
|
452 |
installScripts.append("/");
|
|
453 |
installScripts.append(data.get("APPLICATION_FS_NAME"));
|
|
454 |
installScripts.append("/");
|
|
455 |
installScripts.append(secondaryLauncherData.get(
|
|
456 |
"APPLICATION_LAUNCHER_FILENAME"));
|
|
457 |
installScripts.append(".desktop\n");
|
|
458 |
|
|
459 |
// preun cleanup of desktop icon
|
|
460 |
removeScripts.append("xdg-desktop-menu uninstall --novendor ");
|
|
461 |
removeScripts.append(LINUX_INSTALL_DIR.fetchFrom(params));
|
|
462 |
removeScripts.append("/");
|
|
463 |
removeScripts.append(data.get("APPLICATION_FS_NAME"));
|
|
464 |
removeScripts.append("/");
|
|
465 |
removeScripts.append(secondaryLauncherData.get(
|
|
466 |
"APPLICATION_LAUNCHER_FILENAME"));
|
|
467 |
removeScripts.append(".desktop\n");
|
|
468 |
|
|
469 |
}
|
|
470 |
data.put("SECONDARY_LAUNCHERS_INSTALL", installScripts.toString());
|
|
471 |
data.put("SECONDARY_LAUNCHERS_REMOVE", removeScripts.toString());
|
|
472 |
|
|
473 |
StringBuilder cdsScript = new StringBuilder();
|
|
474 |
|
|
475 |
data.put("APP_CDS_CACHE", cdsScript.toString());
|
|
476 |
|
|
477 |
List<Map<String, ? super Object>> associations =
|
|
478 |
FILE_ASSOCIATIONS.fetchFrom(params);
|
|
479 |
data.put("FILE_ASSOCIATION_INSTALL", "");
|
|
480 |
data.put("FILE_ASSOCIATION_REMOVE", "");
|
|
481 |
data.put("DESKTOP_MIMES", "");
|
|
482 |
if (associations != null) {
|
|
483 |
String mimeInfoFile = XDG_FILE_PREFIX.fetchFrom(params)
|
|
484 |
+ "-MimeInfo.xml";
|
|
485 |
StringBuilder mimeInfo = new StringBuilder(
|
|
486 |
"<?xml version=\"1.0\"?>\n<mime-info xmlns="
|
|
487 |
+"'http://www.freedesktop.org/standards/shared-mime-info'>\n");
|
|
488 |
StringBuilder registrations = new StringBuilder();
|
|
489 |
StringBuilder deregistrations = new StringBuilder();
|
|
490 |
StringBuilder desktopMimes = new StringBuilder("MimeType=");
|
|
491 |
boolean addedEntry = false;
|
|
492 |
|
|
493 |
for (Map<String, ? super Object> assoc : associations) {
|
|
494 |
// <mime-type type="application/x-vnd.awesome">
|
|
495 |
// <comment>Awesome document</comment>
|
|
496 |
// <glob pattern="*.awesome"/>
|
|
497 |
// <glob pattern="*.awe"/>
|
|
498 |
// </mime-type>
|
|
499 |
|
|
500 |
if (assoc == null) {
|
|
501 |
continue;
|
|
502 |
}
|
|
503 |
|
|
504 |
String description = FA_DESCRIPTION.fetchFrom(assoc);
|
|
505 |
File faIcon = FA_ICON.fetchFrom(assoc); //TODO FA_ICON_PNG
|
|
506 |
List<String> extensions = FA_EXTENSIONS.fetchFrom(assoc);
|
|
507 |
if (extensions == null) {
|
|
508 |
Log.verbose(I18N.getString(
|
|
509 |
"message.creating-association-with-null-extension"));
|
|
510 |
}
|
|
511 |
|
|
512 |
List<String> mimes = FA_CONTENT_TYPE.fetchFrom(assoc);
|
|
513 |
if (mimes == null || mimes.isEmpty()) {
|
|
514 |
continue;
|
|
515 |
}
|
|
516 |
String thisMime = mimes.get(0);
|
|
517 |
String dashMime = thisMime.replace('/', '-');
|
|
518 |
|
|
519 |
mimeInfo.append(" <mime-type type='")
|
|
520 |
.append(thisMime)
|
|
521 |
.append("'>\n");
|
|
522 |
if (description != null && !description.isEmpty()) {
|
|
523 |
mimeInfo.append(" <comment>")
|
|
524 |
.append(description)
|
|
525 |
.append("</comment>\n");
|
|
526 |
}
|
|
527 |
|
|
528 |
if (extensions != null) {
|
|
529 |
for (String ext : extensions) {
|
|
530 |
mimeInfo.append(" <glob pattern='*.")
|
|
531 |
.append(ext)
|
|
532 |
.append("'/>\n");
|
|
533 |
}
|
|
534 |
}
|
|
535 |
|
|
536 |
mimeInfo.append(" </mime-type>\n");
|
|
537 |
if (!addedEntry) {
|
|
538 |
registrations.append("xdg-mime install ")
|
|
539 |
.append(LINUX_INSTALL_DIR.fetchFrom(params))
|
|
540 |
.append("/")
|
|
541 |
.append(data.get("APPLICATION_FS_NAME"))
|
|
542 |
.append("/")
|
|
543 |
.append(mimeInfoFile)
|
|
544 |
.append("\n");
|
|
545 |
|
|
546 |
deregistrations.append("xdg-mime uninstall ")
|
|
547 |
.append(LINUX_INSTALL_DIR.fetchFrom(params))
|
|
548 |
.append("/")
|
|
549 |
.append(data.get("APPLICATION_FS_NAME"))
|
|
550 |
.append("/")
|
|
551 |
.append(mimeInfoFile)
|
|
552 |
.append("\n");
|
|
553 |
addedEntry = true;
|
|
554 |
} else {
|
|
555 |
desktopMimes.append(";");
|
|
556 |
}
|
|
557 |
desktopMimes.append(thisMime);
|
|
558 |
|
|
559 |
if (faIcon != null && faIcon.exists()) {
|
|
560 |
int size = getSquareSizeOfImage(faIcon);
|
|
561 |
|
|
562 |
if (size > 0) {
|
|
563 |
File target = new File(rootDir,
|
|
564 |
APP_FS_NAME.fetchFrom(params)
|
|
565 |
+ "_fa_" + faIcon.getName());
|
|
566 |
IOUtils.copyFile(faIcon, target);
|
|
567 |
|
|
568 |
// xdg-icon-resource install --context mimetypes
|
|
569 |
// --size 64 awesomeapp_fa_1.png
|
|
570 |
// application-x.vnd-awesome
|
|
571 |
registrations.append(
|
|
572 |
"xdg-icon-resource install "
|
|
573 |
+ "--context mimetypes --size ")
|
|
574 |
.append(size)
|
|
575 |
.append(" ")
|
|
576 |
.append(LINUX_INSTALL_DIR.fetchFrom(params))
|
|
577 |
.append("/")
|
|
578 |
.append(data.get("APPLICATION_FS_NAME"))
|
|
579 |
.append("/")
|
|
580 |
.append(target.getName())
|
|
581 |
.append(" ")
|
|
582 |
.append(dashMime)
|
|
583 |
.append("\n");
|
|
584 |
|
|
585 |
// xdg-icon-resource uninstall --context mimetypes
|
|
586 |
// --size 64 awesomeapp_fa_1.png
|
|
587 |
// application-x.vnd-awesome
|
|
588 |
deregistrations.append(
|
|
589 |
"xdg-icon-resource uninstall "
|
|
590 |
+ "--context mimetypes --size ")
|
|
591 |
.append(size)
|
|
592 |
.append(" ")
|
|
593 |
.append(LINUX_INSTALL_DIR.fetchFrom(params))
|
|
594 |
.append("/")
|
|
595 |
.append(data.get("APPLICATION_FS_NAME"))
|
|
596 |
.append("/")
|
|
597 |
.append(target.getName())
|
|
598 |
.append(" ")
|
|
599 |
.append(dashMime)
|
|
600 |
.append("\n");
|
|
601 |
}
|
|
602 |
}
|
|
603 |
}
|
|
604 |
mimeInfo.append("</mime-info>");
|
|
605 |
|
|
606 |
if (addedEntry) {
|
|
607 |
Writer w = new BufferedWriter(new FileWriter(
|
|
608 |
new File(rootDir, mimeInfoFile)));
|
|
609 |
w.write(mimeInfo.toString());
|
|
610 |
w.close();
|
|
611 |
data.put("FILE_ASSOCIATION_INSTALL", registrations.toString());
|
|
612 |
data.put("FILE_ASSOCIATION_REMOVE", deregistrations.toString());
|
|
613 |
data.put("DESKTOP_MIMES", desktopMimes.toString());
|
|
614 |
}
|
|
615 |
}
|
|
616 |
|
|
617 |
if (!Arguments.CREATE_JRE_INSTALLER.fetchFrom(params)) {
|
|
618 |
//prepare desktop shortcut
|
|
619 |
Writer w = new BufferedWriter(new FileWriter(
|
|
620 |
getConfig_DesktopShortcutFile(rootDir, params)));
|
|
621 |
String content = preprocessTextResource(
|
|
622 |
LinuxAppBundler.BUNDLER_PREFIX
|
|
623 |
+ getConfig_DesktopShortcutFile(rootDir,
|
|
624 |
params).getName(),
|
|
625 |
I18N.getString("resource.menu-shortcut-descriptor"),
|
|
626 |
DEFAULT_DESKTOP_FILE_TEMPLATE, data,
|
|
627 |
VERBOSE.fetchFrom(params),
|
|
628 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
629 |
w.write(content);
|
|
630 |
w.close();
|
|
631 |
}
|
|
632 |
|
|
633 |
// prepare spec file
|
|
634 |
Writer w = new BufferedWriter(
|
|
635 |
new FileWriter(getConfig_SpecFile(params)));
|
|
636 |
String content = preprocessTextResource(
|
|
637 |
LinuxAppBundler.BUNDLER_PREFIX
|
|
638 |
+ getConfig_SpecFile(params).getName(),
|
|
639 |
I18N.getString("resource.rpm-spec-file"),
|
|
640 |
DEFAULT_SPEC_TEMPLATE, data,
|
|
641 |
VERBOSE.fetchFrom(params),
|
|
642 |
DROP_IN_RESOURCES_ROOT.fetchFrom(params));
|
|
643 |
w.write(content);
|
|
644 |
w.close();
|
|
645 |
|
|
646 |
return true;
|
|
647 |
}
|
|
648 |
|
|
649 |
private Map<String, String> createReplacementData(
|
|
650 |
Map<String, ? super Object> params) {
|
|
651 |
Map<String, String> data = new HashMap<>();
|
|
652 |
|
|
653 |
data.put("APPLICATION_NAME", APP_NAME.fetchFrom(params));
|
|
654 |
data.put("APPLICATION_FS_NAME", APP_FS_NAME.fetchFrom(params));
|
|
655 |
data.put("APPLICATION_PACKAGE", BUNDLE_NAME.fetchFrom(params));
|
|
656 |
data.put("APPLICATION_VENDOR", VENDOR.fetchFrom(params));
|
|
657 |
data.put("APPLICATION_VERSION", VERSION.fetchFrom(params));
|
|
658 |
data.put("APPLICATION_LAUNCHER_FILENAME",
|
|
659 |
APP_FS_NAME.fetchFrom(params));
|
|
660 |
data.put("INSTALLATION_DIRECTORY", LINUX_INSTALL_DIR.fetchFrom(params));
|
|
661 |
data.put("XDG_PREFIX", XDG_FILE_PREFIX.fetchFrom(params));
|
|
662 |
data.put("DEPLOY_BUNDLE_CATEGORY", CATEGORY.fetchFrom(params));
|
|
663 |
// TODO rpm categories
|
|
664 |
data.put("APPLICATION_DESCRIPTION", DESCRIPTION.fetchFrom(params));
|
|
665 |
data.put("APPLICATION_SUMMARY", TITLE.fetchFrom(params));
|
|
666 |
data.put("APPLICATION_LICENSE_TYPE", LICENSE_TYPE.fetchFrom(params));
|
|
667 |
data.put("APPLICATION_LICENSE_FILE", getLicenseFileString(params));
|
|
668 |
String deps = LINUX_PACKAGE_DEPENDENCIES.fetchFrom(params);
|
|
669 |
data.put("PACKAGE_DEPENDENCIES",
|
|
670 |
deps.isEmpty() ? "" : "Requires: " + deps);
|
|
671 |
data.put("CREATE_JRE_INSTALLER",
|
|
672 |
Arguments.CREATE_JRE_INSTALLER.fetchFrom(params).toString());
|
|
673 |
return data;
|
|
674 |
}
|
|
675 |
|
|
676 |
private File getConfig_DesktopShortcutFile(File rootDir,
|
|
677 |
Map<String, ? super Object> params) {
|
|
678 |
return new File(rootDir,
|
|
679 |
APP_FS_NAME.fetchFrom(params) + ".desktop");
|
|
680 |
}
|
|
681 |
|
|
682 |
private File getConfig_IconFile(File rootDir,
|
|
683 |
Map<String, ? super Object> params) {
|
|
684 |
return new File(rootDir,
|
|
685 |
APP_FS_NAME.fetchFrom(params) + ".png");
|
|
686 |
}
|
|
687 |
|
|
688 |
private File getConfig_SpecFile(Map<String, ? super Object> params) {
|
|
689 |
return new File(RPM_IMAGE_DIR.fetchFrom(params),
|
|
690 |
APP_FS_NAME.fetchFrom(params) + ".spec");
|
|
691 |
}
|
|
692 |
|
|
693 |
private File buildRPM(Map<String, ? super Object> params,
|
|
694 |
File outdir) throws IOException {
|
|
695 |
Log.verbose(MessageFormat.format(I18N.getString(
|
|
696 |
"message.outputting-bundle-location"),
|
|
697 |
outdir.getAbsolutePath()));
|
|
698 |
|
|
699 |
File broot = new File(BUILD_ROOT.fetchFrom(params), "rmpbuildroot");
|
|
700 |
|
|
701 |
outdir.mkdirs();
|
|
702 |
|
|
703 |
//run rpmbuild
|
|
704 |
ProcessBuilder pb = new ProcessBuilder(
|
|
705 |
TOOL_RPMBUILD,
|
|
706 |
"-bb", getConfig_SpecFile(params).getAbsolutePath(),
|
|
707 |
"--define", "%_sourcedir "
|
|
708 |
+ RPM_IMAGE_DIR.fetchFrom(params).getAbsolutePath(),
|
|
709 |
// save result to output dir
|
|
710 |
"--define", "%_rpmdir " + outdir.getAbsolutePath(),
|
|
711 |
// do not use other system directories to build as current user
|
|
712 |
"--define", "%_topdir " + broot.getAbsolutePath()
|
|
713 |
);
|
|
714 |
pb = pb.directory(RPM_IMAGE_DIR.fetchFrom(params));
|
|
715 |
IOUtils.exec(pb, false);
|
|
716 |
|
|
717 |
if (!Log.isDebug() && !Log.isVerbose()) {
|
|
718 |
IOUtils.deleteRecursive(broot);
|
|
719 |
}
|
|
720 |
|
|
721 |
Log.verbose(MessageFormat.format(
|
|
722 |
I18N.getString("message.output-bundle-location"),
|
|
723 |
outdir.getAbsolutePath()));
|
|
724 |
|
|
725 |
// presume the result is the ".rpm" file with the newest modified time
|
|
726 |
// not the best solution, but it is the most reliable
|
|
727 |
File result = null;
|
|
728 |
long lastModified = 0;
|
|
729 |
File[] list = outdir.listFiles();
|
|
730 |
if (list != null) {
|
|
731 |
for (File f : list) {
|
|
732 |
if (f.getName().endsWith(".rpm") &&
|
|
733 |
f.lastModified() > lastModified) {
|
|
734 |
result = f;
|
|
735 |
lastModified = f.lastModified();
|
|
736 |
}
|
|
737 |
}
|
|
738 |
}
|
|
739 |
|
|
740 |
return result;
|
|
741 |
}
|
|
742 |
|
|
743 |
@Override
|
|
744 |
public String getName() {
|
|
745 |
return I18N.getString("bundler.name");
|
|
746 |
}
|
|
747 |
|
|
748 |
@Override
|
|
749 |
public String getDescription() {
|
|
750 |
return I18N.getString("bundler.description");
|
|
751 |
}
|
|
752 |
|
|
753 |
@Override
|
|
754 |
public String getID() {
|
|
755 |
return "rpm";
|
|
756 |
}
|
|
757 |
|
|
758 |
@Override
|
|
759 |
public String getBundleType() {
|
|
760 |
return "INSTALLER";
|
|
761 |
}
|
|
762 |
|
|
763 |
@Override
|
|
764 |
public Collection<BundlerParamInfo<?>> getBundleParameters() {
|
|
765 |
Collection<BundlerParamInfo<?>> results = new LinkedHashSet<>();
|
|
766 |
results.addAll(LinuxAppBundler.getAppBundleParameters());
|
|
767 |
results.addAll(getRpmBundleParameters());
|
|
768 |
return results;
|
|
769 |
}
|
|
770 |
|
|
771 |
public static Collection<BundlerParamInfo<?>> getRpmBundleParameters() {
|
|
772 |
return Arrays.asList(
|
|
773 |
BUNDLE_NAME,
|
|
774 |
CATEGORY,
|
|
775 |
DESCRIPTION,
|
|
776 |
LinuxAppBundler.ICON_PNG,
|
|
777 |
LICENSE_FILE,
|
|
778 |
LICENSE_TYPE,
|
|
779 |
TITLE,
|
|
780 |
VENDOR
|
|
781 |
);
|
|
782 |
}
|
|
783 |
|
|
784 |
@Override
|
|
785 |
public File execute(
|
|
786 |
Map<String, ? super Object> params, File outputParentDir) {
|
|
787 |
return bundle(params, outputParentDir);
|
|
788 |
}
|
|
789 |
|
|
790 |
@Override
|
|
791 |
public boolean supported() {
|
|
792 |
return (Platform.getPlatform() == Platform.LINUX);
|
|
793 |
}
|
|
794 |
|
|
795 |
public int getSquareSizeOfImage(File f) {
|
|
796 |
try {
|
|
797 |
BufferedImage bi = ImageIO.read(f);
|
|
798 |
if (bi.getWidth() == bi.getHeight()) {
|
|
799 |
return bi.getWidth();
|
|
800 |
} else {
|
|
801 |
return 0;
|
|
802 |
}
|
|
803 |
} catch (Exception e) {
|
|
804 |
e.printStackTrace();
|
|
805 |
return 0;
|
|
806 |
}
|
|
807 |
}
|
|
808 |
}
|