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