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 |
|
|
26 |
package jdk.jpackager.internal;
|
|
27 |
|
|
28 |
import jdk.jpackager.internal.AbstractImageBundler;
|
|
29 |
import jdk.jpackager.internal.BundlerParamInfo;
|
|
30 |
import jdk.jpackager.internal.ConfigException;
|
|
31 |
import jdk.jpackager.internal.IOUtils;
|
|
32 |
import jdk.jpackager.internal.Log;
|
|
33 |
import jdk.jpackager.internal.Platform;
|
|
34 |
import jdk.jpackager.internal.RelativeFileSet;
|
|
35 |
import jdk.jpackager.internal.StandardBundlerParam;
|
|
36 |
import jdk.jpackager.internal.Arguments;
|
|
37 |
import jdk.jpackager.internal.UnsupportedPlatformException;
|
|
38 |
import jdk.jpackager.internal.BundleParams;
|
|
39 |
import jdk.jpackager.internal.LinuxAppImageBuilder;
|
|
40 |
import jdk.jpackager.internal.resources.LinuxResources;
|
|
41 |
import jdk.jpackager.internal.JLinkBundlerHelper;
|
|
42 |
import jdk.jpackager.internal.AbstractAppImageBuilder;
|
|
43 |
|
|
44 |
import java.io.File;
|
|
45 |
import java.io.IOException;
|
|
46 |
import java.net.MalformedURLException;
|
|
47 |
import java.net.URL;
|
|
48 |
import java.text.MessageFormat;
|
|
49 |
import java.util.Arrays;
|
|
50 |
import java.util.Collection;
|
|
51 |
import java.util.Map;
|
|
52 |
import java.util.ResourceBundle;
|
|
53 |
|
|
54 |
import static jdk.jpackager.internal.StandardBundlerParam.*;
|
|
55 |
|
|
56 |
public class LinuxAppBundler extends AbstractImageBundler {
|
|
57 |
|
|
58 |
private static final ResourceBundle I18N = ResourceBundle.getBundle(
|
|
59 |
"jdk.jpackager.internal.resources.LinuxAppBundler");
|
|
60 |
|
|
61 |
private static final String EXECUTABLE_NAME = "JavaAppLauncher";
|
|
62 |
|
|
63 |
public static final BundlerParamInfo<File> ICON_PNG =
|
|
64 |
new StandardBundlerParam<>(
|
|
65 |
I18N.getString("param.icon-png.name"),
|
|
66 |
I18N.getString("param.icon-png.description"),
|
|
67 |
"icon.png",
|
|
68 |
File.class,
|
|
69 |
params -> {
|
|
70 |
File f = ICON.fetchFrom(params);
|
|
71 |
if (f != null && !f.getName().toLowerCase().endsWith(".png")) {
|
|
72 |
Log.error(MessageFormat.format(
|
|
73 |
I18N.getString("message.icon-not-png"), f));
|
|
74 |
return null;
|
|
75 |
}
|
|
76 |
return f;
|
|
77 |
},
|
|
78 |
(s, p) -> new File(s));
|
|
79 |
|
|
80 |
public static final BundlerParamInfo<String> LINUX_INSTALL_DIR =
|
|
81 |
new StandardBundlerParam<>(
|
|
82 |
I18N.getString("param.linux-install-dir.name"),
|
|
83 |
I18N.getString("param.linux-install-dir.description"),
|
|
84 |
"linux-install-dir",
|
|
85 |
String.class,
|
|
86 |
params -> {
|
|
87 |
String dir = INSTALL_DIR.fetchFrom(params);
|
|
88 |
if (dir != null) {
|
|
89 |
if (dir.endsWith("/")) {
|
|
90 |
dir = dir.substring(0, dir.length()-1);
|
|
91 |
}
|
|
92 |
return dir;
|
|
93 |
}
|
|
94 |
return "/opt";
|
|
95 |
},
|
|
96 |
(s, p) -> s
|
|
97 |
);
|
|
98 |
|
|
99 |
public static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES =
|
|
100 |
new StandardBundlerParam<>(
|
|
101 |
I18N.getString("param.linux-package-dependencies.name"),
|
|
102 |
I18N.getString("param.linux-package-dependencies.description"),
|
|
103 |
Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(),
|
|
104 |
String.class,
|
|
105 |
params -> {
|
|
106 |
return "";
|
|
107 |
},
|
|
108 |
(s, p) -> s
|
|
109 |
);
|
|
110 |
|
|
111 |
@Override
|
|
112 |
public boolean validate(Map<String, ? super Object> p)
|
|
113 |
throws UnsupportedPlatformException, ConfigException {
|
|
114 |
try {
|
|
115 |
if (p == null) throw new ConfigException(
|
|
116 |
I18N.getString("error.parameters-null"),
|
|
117 |
I18N.getString("error.parameters-null.advice"));
|
|
118 |
|
|
119 |
return doValidate(p);
|
|
120 |
} catch (RuntimeException re) {
|
|
121 |
if (re.getCause() instanceof ConfigException) {
|
|
122 |
throw (ConfigException) re.getCause();
|
|
123 |
} else {
|
|
124 |
throw new ConfigException(re);
|
|
125 |
}
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
//used by chained bundlers to reuse validation logic
|
|
130 |
boolean doValidate(Map<String, ? super Object> p)
|
|
131 |
throws UnsupportedPlatformException, ConfigException {
|
|
132 |
if (Platform.getPlatform() != Platform.LINUX) {
|
|
133 |
throw new UnsupportedPlatformException();
|
|
134 |
}
|
|
135 |
|
|
136 |
imageBundleValidation(p);
|
|
137 |
|
|
138 |
return true;
|
|
139 |
}
|
|
140 |
|
|
141 |
// it is static for the sake of sharing with "installer" bundlers
|
|
142 |
// that may skip calls to validate/bundle in this class!
|
|
143 |
public static File getRootDir(File outDir, Map<String, ? super Object> p) {
|
|
144 |
return new File(outDir, APP_FS_NAME.fetchFrom(p));
|
|
145 |
}
|
|
146 |
|
|
147 |
public static String getLauncherCfgName(Map<String, ? super Object> p) {
|
|
148 |
return "app/" + APP_FS_NAME.fetchFrom(p) +".cfg";
|
|
149 |
}
|
|
150 |
|
|
151 |
File doBundle(Map<String, ? super Object> p, File outputDirectory,
|
|
152 |
boolean dependentTask) {
|
|
153 |
if (Arguments.CREATE_JRE_INSTALLER.fetchFrom(p)) {
|
|
154 |
return doJreBundle(p, outputDirectory, dependentTask);
|
|
155 |
} else {
|
|
156 |
return doAppBundle(p, outputDirectory, dependentTask);
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
private File doJreBundle(Map<String, ? super Object> p,
|
|
161 |
File outputDirectory, boolean dependentTask) {
|
|
162 |
try {
|
|
163 |
File rootDirectory = createRoot(p, outputDirectory, dependentTask,
|
|
164 |
APP_FS_NAME.fetchFrom(p), "linuxapp-image-builder");
|
|
165 |
AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(
|
|
166 |
APP_NAME.fetchFrom(p), outputDirectory.toPath());
|
|
167 |
File predefined = PREDEFINED_RUNTIME_IMAGE.fetchFrom(p);
|
|
168 |
if (predefined == null ) {
|
|
169 |
JLinkBundlerHelper.generateServerJre(p, appBuilder);
|
|
170 |
} else {
|
|
171 |
return predefined;
|
|
172 |
}
|
|
173 |
return rootDirectory;
|
|
174 |
} catch (Exception ex) {
|
|
175 |
Log.error("Exception: "+ex);
|
|
176 |
Log.debug(ex);
|
|
177 |
return null;
|
|
178 |
}
|
|
179 |
}
|
|
180 |
|
|
181 |
private File doAppBundle(Map<String, ? super Object> p,
|
|
182 |
File outputDirectory, boolean dependentTask) {
|
|
183 |
try {
|
|
184 |
File rootDirectory = createRoot(p, outputDirectory, dependentTask,
|
|
185 |
APP_FS_NAME.fetchFrom(p), "linuxapp-image-builder");
|
|
186 |
AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder(p,
|
|
187 |
outputDirectory.toPath());
|
|
188 |
if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) {
|
|
189 |
JLinkBundlerHelper.execute(p, appBuilder);
|
|
190 |
} else {
|
|
191 |
StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder);
|
|
192 |
}
|
|
193 |
return rootDirectory;
|
|
194 |
} catch (Exception ex) {
|
|
195 |
Log.error("Exception: "+ex);
|
|
196 |
Log.debug(ex);
|
|
197 |
return null;
|
|
198 |
}
|
|
199 |
}
|
|
200 |
|
|
201 |
@Override
|
|
202 |
public String getName() {
|
|
203 |
return I18N.getString("bundler.name");
|
|
204 |
}
|
|
205 |
|
|
206 |
@Override
|
|
207 |
public String getDescription() {
|
|
208 |
return I18N.getString("bundler.description");
|
|
209 |
}
|
|
210 |
|
|
211 |
@Override
|
|
212 |
public String getID() {
|
|
213 |
return "linux.app";
|
|
214 |
}
|
|
215 |
|
|
216 |
@Override
|
|
217 |
public String getBundleType() {
|
|
218 |
return "IMAGE";
|
|
219 |
}
|
|
220 |
|
|
221 |
@Override
|
|
222 |
public Collection<BundlerParamInfo<?>> getBundleParameters() {
|
|
223 |
return getAppBundleParameters();
|
|
224 |
}
|
|
225 |
|
|
226 |
public static Collection<BundlerParamInfo<?>> getAppBundleParameters() {
|
|
227 |
return Arrays.asList(
|
|
228 |
APP_NAME,
|
|
229 |
APP_RESOURCES,
|
|
230 |
ARGUMENTS,
|
|
231 |
CLASSPATH,
|
|
232 |
JVM_OPTIONS,
|
|
233 |
JVM_PROPERTIES,
|
|
234 |
MAIN_CLASS,
|
|
235 |
MAIN_JAR,
|
|
236 |
PREFERENCES_ID,
|
|
237 |
VERSION,
|
|
238 |
VERBOSE
|
|
239 |
);
|
|
240 |
}
|
|
241 |
|
|
242 |
@Override
|
|
243 |
public File execute(Map<String, ? super Object> params,
|
|
244 |
File outputParentDir) {
|
|
245 |
return doBundle(params, outputParentDir, false);
|
|
246 |
}
|
|
247 |
|
|
248 |
@Override
|
|
249 |
public boolean supported() {
|
|
250 |
return (Platform.getPlatform() == Platform.LINUX);
|
|
251 |
}
|
|
252 |
}
|