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