author | herrick |
Tue, 24 Sep 2019 13:41:16 -0400 | |
branch | JDK-8200758-branch |
changeset 58301 | e0efb29609bd |
parent 58114 | 42df7de58e39 |
child 58417 | 67ffaf3a2b75 |
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) 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 java.io.File; |
|
29 |
import java.io.IOException; |
|
30 |
import java.net.MalformedURLException; |
|
31 |
import java.net.URL; |
|
32 |
import java.text.MessageFormat; |
|
33 |
import java.util.Arrays; |
|
34 |
import java.util.Collection; |
|
35 |
import java.util.Map; |
|
36 |
import java.util.ResourceBundle; |
|
37 |
||
57039 | 38 |
import static jdk.jpackage.internal.StandardBundlerParam.*; |
57038 | 39 |
|
40 |
public class LinuxAppBundler extends AbstractImageBundler { |
|
41 |
||
42 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
|
57059 | 43 |
"jdk.jpackage.internal.resources.LinuxResources"); |
57038 | 44 |
|
57392 | 45 |
static final BundlerParamInfo<File> ICON_PNG = |
57038 | 46 |
new StandardBundlerParam<>( |
47 |
"icon.png", |
|
48 |
File.class, |
|
49 |
params -> { |
|
50 |
File f = ICON.fetchFrom(params); |
|
51 |
if (f != null && !f.getName().toLowerCase().endsWith(".png")) { |
|
52 |
Log.error(MessageFormat.format( |
|
53 |
I18N.getString("message.icon-not-png"), f)); |
|
54 |
return null; |
|
55 |
} |
|
56 |
return f; |
|
57 |
}, |
|
58 |
(s, p) -> new File(s)); |
|
59 |
||
57392 | 60 |
static final BundlerParamInfo<String> LINUX_INSTALL_DIR = |
57038 | 61 |
new StandardBundlerParam<>( |
62 |
"linux-install-dir", |
|
63 |
String.class, |
|
64 |
params -> { |
|
65 |
String dir = INSTALL_DIR.fetchFrom(params); |
|
66 |
if (dir != null) { |
|
67 |
if (dir.endsWith("/")) { |
|
68 |
dir = dir.substring(0, dir.length()-1); |
|
69 |
} |
|
70 |
return dir; |
|
71 |
} |
|
72 |
return "/opt"; |
|
73 |
}, |
|
74 |
(s, p) -> s |
|
75 |
); |
|
57108 | 76 |
|
57392 | 77 |
static final BundlerParamInfo<String> LINUX_PACKAGE_DEPENDENCIES = |
57038 | 78 |
new StandardBundlerParam<>( |
79 |
Arguments.CLIOptions.LINUX_PACKAGE_DEPENDENCIES.getId(), |
|
80 |
String.class, |
|
81 |
params -> { |
|
82 |
return ""; |
|
83 |
}, |
|
84 |
(s, p) -> s |
|
85 |
); |
|
86 |
||
87 |
@Override |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
88 |
public boolean validate(Map<String, ? super Object> params) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57396
diff
changeset
|
89 |
throws ConfigException { |
57038 | 90 |
try { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
91 |
if (params == null) throw new ConfigException( |
57038 | 92 |
I18N.getString("error.parameters-null"), |
93 |
I18N.getString("error.parameters-null.advice")); |
|
94 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
95 |
return doValidate(params); |
57038 | 96 |
} catch (RuntimeException re) { |
97 |
if (re.getCause() instanceof ConfigException) { |
|
98 |
throw (ConfigException) re.getCause(); |
|
99 |
} else { |
|
100 |
throw new ConfigException(re); |
|
101 |
} |
|
102 |
} |
|
103 |
} |
|
104 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
105 |
private boolean doValidate(Map<String, ? super Object> params) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57396
diff
changeset
|
106 |
throws ConfigException { |
57038 | 107 |
|
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
108 |
imageBundleValidation(params); |
57038 | 109 |
|
110 |
return true; |
|
111 |
} |
|
112 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
113 |
File doBundle(Map<String, ? super Object> params, File outputDirectory, |
57140 | 114 |
boolean dependentTask) throws PackagerException { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
115 |
if (StandardBundlerParam.isRuntimeInstaller(params)) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
116 |
return PREDEFINED_RUNTIME_IMAGE.fetchFrom(params); |
57038 | 117 |
} else { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
118 |
return doAppBundle(params, outputDirectory, dependentTask); |
57038 | 119 |
} |
120 |
} |
|
121 |
||
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
122 |
private File doAppBundle(Map<String, ? super Object> params, |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
123 |
File outputDirectory, boolean dependentTask) |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57438
diff
changeset
|
124 |
throws PackagerException { |
57038 | 125 |
try { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
126 |
File rootDirectory = createRoot(params, outputDirectory, |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
127 |
dependentTask, APP_NAME.fetchFrom(params)); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
128 |
AbstractAppImageBuilder appBuilder = new LinuxAppImageBuilder( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
129 |
params, outputDirectory.toPath()); |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
130 |
if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(params) == null ) { |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
131 |
JLinkBundlerHelper.execute(params, appBuilder); |
57038 | 132 |
} else { |
57396
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
133 |
StandardBundlerParam.copyPredefinedRuntimeImage( |
3944e4c2f779
8223586: remove jpackage dead code and other cleanup
herrick
parents:
57392
diff
changeset
|
134 |
params, appBuilder); |
57038 | 135 |
} |
136 |
return rootDirectory; |
|
57140 | 137 |
} catch (PackagerException pe) { |
138 |
throw pe; |
|
57038 | 139 |
} catch (Exception ex) { |
57140 | 140 |
Log.verbose(ex); |
141 |
throw new PackagerException(ex); |
|
57038 | 142 |
} |
143 |
} |
|
144 |
||
145 |
@Override |
|
146 |
public String getName() { |
|
57059 | 147 |
return I18N.getString("app.bundler.name"); |
57038 | 148 |
} |
149 |
||
150 |
@Override |
|
151 |
public String getID() { |
|
152 |
return "linux.app"; |
|
153 |
} |
|
154 |
||
155 |
@Override |
|
156 |
public String getBundleType() { |
|
157 |
return "IMAGE"; |
|
158 |
} |
|
159 |
||
160 |
@Override |
|
161 |
public File execute(Map<String, ? super Object> params, |
|
57140 | 162 |
File outputParentDir) throws PackagerException { |
57038 | 163 |
return doBundle(params, outputParentDir, false); |
164 |
} |
|
57108 | 165 |
|
166 |
@Override |
|
57150 | 167 |
public boolean supported(boolean runtimeInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57396
diff
changeset
|
168 |
return true; |
57038 | 169 |
} |
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
170 |
|
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
171 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
172 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
173 |
return false; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
174 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57909
diff
changeset
|
175 |
|
57038 | 176 |
} |