author | herrick |
Wed, 16 Oct 2019 09:57:23 -0400 | |
branch | JDK-8200758-branch |
changeset 58647 | 2c43b89b1679 |
parent 58538 | 12c965587689 |
child 58762 | 0fe62353385b |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57091
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
28 |
import java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.io.InputStream; |
|
31 |
import java.nio.file.Files; |
|
32 |
import java.nio.file.Path; |
|
33 |
import java.text.MessageFormat; |
|
34 |
import java.util.HashMap; |
|
35 |
import java.util.List; |
|
36 |
import java.util.Map; |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
37 |
import static jdk.jpackage.internal.OverridableResource.createResource; |
57038 | 38 |
|
57039 | 39 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57038 | 40 |
|
41 |
public class LinuxAppImageBuilder extends AbstractAppImageBuilder { |
|
42 |
||
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
43 |
private static final String LIBRARY_NAME = "libapplauncher.so"; |
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
57911
diff
changeset
|
44 |
final static String DEFAULT_ICON = "java32.png"; |
57038 | 45 |
|
58302 | 46 |
private final ApplicationLayout appLayout; |
57038 | 47 |
|
48 |
public static final BundlerParamInfo<File> ICON_PNG = |
|
49 |
new StandardBundlerParam<>( |
|
50 |
"icon.png", |
|
51 |
File.class, |
|
52 |
params -> { |
|
53 |
File f = ICON.fetchFrom(params); |
|
54 |
if (f != null && !f.getName().toLowerCase().endsWith(".png")) { |
|
55 |
Log.error(MessageFormat.format(I18N.getString( |
|
56 |
"message.icon-not-png"), f)); |
|
57 |
return null; |
|
58 |
} |
|
59 |
return f; |
|
60 |
}, |
|
61 |
(s, p) -> new File(s)); |
|
62 |
||
58302 | 63 |
private static ApplicationLayout createAppLayout(Map<String, Object> params, |
64 |
Path imageOutDir) { |
|
58416 | 65 |
return ApplicationLayout.linuxAppImage().resolveAt( |
58302 | 66 |
imageOutDir.resolve(APP_NAME.fetchFrom(params))); |
67 |
} |
|
68 |
||
57789 | 69 |
public LinuxAppImageBuilder(Map<String, Object> params, Path imageOutDir) |
57038 | 70 |
throws IOException { |
58302 | 71 |
super(params, createAppLayout(params, imageOutDir).runtimeDirectory()); |
57038 | 72 |
|
58302 | 73 |
appLayout = createAppLayout(params, imageOutDir); |
57038 | 74 |
} |
75 |
||
76 |
private void writeEntry(InputStream in, Path dstFile) throws IOException { |
|
77 |
Files.createDirectories(dstFile.getParent()); |
|
78 |
Files.copy(in, dstFile); |
|
79 |
} |
|
80 |
||
58301
e0efb29609bd
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code
herrick
parents:
57911
diff
changeset
|
81 |
public static String getLauncherName(Map<String, ? super Object> params) { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
82 |
return APP_NAME.fetchFrom(params); |
57038 | 83 |
} |
84 |
||
58302 | 85 |
private Path getLauncherCfgPath(Map<String, ? super Object> params) { |
86 |
return appLayout.appDirectory().resolve( |
|
87 |
APP_NAME.fetchFrom(params) + ".cfg"); |
|
57038 | 88 |
} |
89 |
||
90 |
@Override |
|
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
91 |
public Path getAppDir() { |
58302 | 92 |
return appLayout.appDirectory(); |
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
93 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
94 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
95 |
@Override |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
96 |
public Path getAppModsDir() { |
58302 | 97 |
return appLayout.appModsDirectory(); |
98 |
} |
|
99 |
||
100 |
@Override |
|
101 |
protected String getCfgAppDir() { |
|
58538
12c965587689
8231910: Expose the APPDIR variable to applications that use jpackage
herrick
parents:
58417
diff
changeset
|
102 |
return Path.of("$ROOTDIR").resolve( |
12c965587689
8231910: Expose the APPDIR variable to applications that use jpackage
herrick
parents:
58417
diff
changeset
|
103 |
ApplicationLayout.linuxAppImage().appDirectory()).toString() |
12c965587689
8231910: Expose the APPDIR variable to applications that use jpackage
herrick
parents:
58417
diff
changeset
|
104 |
+ File.separator; |
58302 | 105 |
} |
106 |
||
107 |
@Override |
|
108 |
protected String getCfgRuntimeDir() { |
|
58538
12c965587689
8231910: Expose the APPDIR variable to applications that use jpackage
herrick
parents:
58417
diff
changeset
|
109 |
return Path.of("$ROOTDIR").resolve( |
12c965587689
8231910: Expose the APPDIR variable to applications that use jpackage
herrick
parents:
58417
diff
changeset
|
110 |
ApplicationLayout.linuxAppImage().runtimeDirectory()).toString(); |
57077
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
111 |
} |
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
112 |
|
8f9cf6ad59f0
8213962: JPackageCreateImageRuntimeModuleTest fails
herrick
parents:
57070
diff
changeset
|
113 |
@Override |
57789 | 114 |
public void prepareApplicationFiles(Map<String, ? super Object> params) |
115 |
throws IOException { |
|
57038 | 116 |
Map<String, ? super Object> originalParams = new HashMap<>(params); |
117 |
||
58302 | 118 |
appLayout.roots().stream().forEach(dir -> { |
119 |
try { |
|
120 |
IOUtils.writableOutputDir(dir); |
|
121 |
} catch (PackagerException pe) { |
|
122 |
throw new RuntimeException(pe); |
|
123 |
} |
|
124 |
}); |
|
57407 | 125 |
|
57038 | 126 |
// create the primary launcher |
57263 | 127 |
createLauncherForEntryPoint(params); |
57038 | 128 |
|
129 |
// Copy library to the launcher folder |
|
130 |
try (InputStream is_lib = getResourceAsStream(LIBRARY_NAME)) { |
|
58302 | 131 |
writeEntry(is_lib, appLayout.dllDirectory().resolve(LIBRARY_NAME)); |
57038 | 132 |
} |
133 |
||
57256 | 134 |
// create the additional launchers, if any |
57038 | 135 |
List<Map<String, ? super Object>> entryPoints |
57256 | 136 |
= StandardBundlerParam.ADD_LAUNCHERS.fetchFrom(params); |
57038 | 137 |
for (Map<String, ? super Object> entryPoint : entryPoints) { |
57259
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
138 |
createLauncherForEntryPoint( |
a84c657c713d
8171959: add-launcher is not working when normal jar is used for first launcher and module is used for second launcher
herrick
parents:
57256
diff
changeset
|
139 |
AddLauncherArguments.merge(originalParams, entryPoint)); |
57038 | 140 |
} |
141 |
||
142 |
// Copy class path entries to Java folder |
|
57789 | 143 |
copyApplication(params); |
57038 | 144 |
|
145 |
// Copy icon to Resources folder |
|
57789 | 146 |
copyIcon(params); |
57038 | 147 |
} |
148 |
||
149 |
@Override |
|
57789 | 150 |
public void prepareJreFiles(Map<String, ? super Object> params) |
151 |
throws IOException {} |
|
57038 | 152 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
153 |
private void createLauncherForEntryPoint( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
154 |
Map<String, ? super Object> params) throws IOException { |
58302 | 155 |
// Copy executable to launchers folder |
156 |
Path executableFile = appLayout.launchersDirectory().resolve(getLauncherName(params)); |
|
57064
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
157 |
try (InputStream is_launcher = |
a7fdadf67a92
8214899: rename papplauncher and it's library and move src to appropriate places
herrick
parents:
57059
diff
changeset
|
158 |
getResourceAsStream("jpackageapplauncher")) { |
57038 | 159 |
writeEntry(is_launcher, executableFile); |
160 |
} |
|
161 |
||
162 |
executableFile.toFile().setExecutable(true, false); |
|
163 |
executableFile.toFile().setWritable(true, true); |
|
164 |
||
58302 | 165 |
writeCfgFile(params, getLauncherCfgPath(params).toFile()); |
57038 | 166 |
} |
167 |
||
57789 | 168 |
private void copyIcon(Map<String, ? super Object> params) |
169 |
throws IOException { |
|
57911 | 170 |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
171 |
Path iconTarget = appLayout.destktopIntegrationDirectory().resolve( |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
172 |
APP_NAME.fetchFrom(params) + ".png"); |
57911 | 173 |
|
58647
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
174 |
createResource(DEFAULT_ICON, params) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
175 |
.setCategory("icon") |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
176 |
.setExternal(ICON_PNG.fetchFrom(params)) |
2c43b89b1679
8231862: Decouple DesktopIntegration and LinuxPackageBundler classes
herrick
parents:
58538
diff
changeset
|
177 |
.saveToFile(iconTarget); |
57038 | 178 |
} |
179 |
||
57789 | 180 |
private void copyApplication(Map<String, ? super Object> params) |
181 |
throws IOException { |
|
57038 | 182 |
for (RelativeFileSet appResources : |
183 |
APP_RESOURCES_LIST.fetchFrom(params)) { |
|
184 |
if (appResources == null) { |
|
185 |
throw new RuntimeException("Null app resources?"); |
|
186 |
} |
|
187 |
File srcdir = appResources.getBaseDirectory(); |
|
188 |
for (String fname : appResources.getIncludedFiles()) { |
|
58302 | 189 |
copyEntry(appLayout.appDirectory(), srcdir, fname); |
57038 | 190 |
} |
191 |
} |
|
192 |
} |
|
193 |
||
194 |
} |