author | herrick |
Wed, 23 Oct 2019 10:37:54 -0400 | |
branch | JDK-8200758-branch |
changeset 58762 | 0fe62353385b |
parent 58414 | a5f66aa04f68 |
child 58922 | fbaf2e6402ad |
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; |
|
57218
8018ecf829bc
8217902: jpackage fails with --app-image option on mac
herrick
parents:
57213
diff
changeset
|
29 |
import java.nio.file.Path; |
57038 | 30 |
import java.text.MessageFormat; |
58762
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58414
diff
changeset
|
31 |
import java.util.*; |
57038 | 32 |
|
57039 | 33 |
import static jdk.jpackage.internal.WindowsBundlerParam.*; |
34 |
import static jdk.jpackage.internal.WinMsiBundler.WIN_APP_IMAGE; |
|
57038 | 35 |
|
36 |
public class WinAppBundler extends AbstractImageBundler { |
|
37 |
||
57059 | 38 |
private static final ResourceBundle I18N = ResourceBundle.getBundle( |
39 |
"jdk.jpackage.internal.resources.WinResources"); |
|
57038 | 40 |
|
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
41 |
static final BundlerParamInfo<File> ICON_ICO = |
57038 | 42 |
new StandardBundlerParam<>( |
43 |
"icon.ico", |
|
44 |
File.class, |
|
45 |
params -> { |
|
46 |
File f = ICON.fetchFrom(params); |
|
47 |
if (f != null && !f.getName().toLowerCase().endsWith(".ico")) { |
|
48 |
Log.error(MessageFormat.format( |
|
49 |
I18N.getString("message.icon-not-ico"), f)); |
|
50 |
return null; |
|
51 |
} |
|
52 |
return f; |
|
53 |
}, |
|
54 |
(s, p) -> new File(s)); |
|
55 |
||
56 |
@Override |
|
57 |
public boolean validate(Map<String, ? super Object> params) |
|
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
58 |
throws ConfigException { |
57038 | 59 |
try { |
58762
0fe62353385b
8232281: jpackage is not always reporting an error when no main class specified
herrick
parents:
58414
diff
changeset
|
60 |
Objects.requireNonNull(params); |
57038 | 61 |
return doValidate(params); |
62 |
} catch (RuntimeException re) { |
|
63 |
if (re.getCause() instanceof ConfigException) { |
|
64 |
throw (ConfigException) re.getCause(); |
|
65 |
} else { |
|
66 |
throw new ConfigException(re); |
|
67 |
} |
|
68 |
} |
|
69 |
} |
|
70 |
||
71 |
// to be used by chained bundlers, e.g. by EXE bundler to avoid |
|
72 |
// skipping validation if p.type does not include "image" |
|
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57059
diff
changeset
|
73 |
private boolean doValidate(Map<String, ? super Object> p) |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
74 |
throws ConfigException { |
57038 | 75 |
|
76 |
imageBundleValidation(p); |
|
77 |
return true; |
|
78 |
} |
|
79 |
||
57140 | 80 |
public boolean bundle(Map<String, ? super Object> p, File outputDirectory) |
81 |
throws PackagerException { |
|
57038 | 82 |
return doBundle(p, outputDirectory, false) != null; |
83 |
} |
|
84 |
||
57140 | 85 |
File doBundle(Map<String, ? super Object> p, File outputDirectory, |
86 |
boolean dependentTask) throws PackagerException { |
|
57256 | 87 |
if (StandardBundlerParam.isRuntimeInstaller(p)) { |
88 |
return PREDEFINED_RUNTIME_IMAGE.fetchFrom(p); |
|
57038 | 89 |
} else { |
90 |
return doAppBundle(p, outputDirectory, dependentTask); |
|
91 |
} |
|
92 |
} |
|
93 |
||
57140 | 94 |
File doAppBundle(Map<String, ? super Object> p, File outputDirectory, |
95 |
boolean dependentTask) throws PackagerException { |
|
57038 | 96 |
try { |
97 |
File rootDirectory = createRoot(p, outputDirectory, dependentTask, |
|
57256 | 98 |
APP_NAME.fetchFrom(p)); |
57038 | 99 |
AbstractAppImageBuilder appBuilder = |
100 |
new WindowsAppImageBuilder(p, outputDirectory.toPath()); |
|
101 |
if (PREDEFINED_RUNTIME_IMAGE.fetchFrom(p) == null ) { |
|
102 |
JLinkBundlerHelper.execute(p, appBuilder); |
|
103 |
} else { |
|
104 |
StandardBundlerParam.copyPredefinedRuntimeImage(p, appBuilder); |
|
105 |
} |
|
106 |
if (!dependentTask) { |
|
107 |
Log.verbose(MessageFormat.format( |
|
108 |
I18N.getString("message.result-dir"), |
|
109 |
outputDirectory.getAbsolutePath())); |
|
110 |
} |
|
111 |
return rootDirectory; |
|
57140 | 112 |
} catch (PackagerException pe) { |
113 |
throw pe; |
|
114 |
} catch (Exception e) { |
|
115 |
Log.verbose(e); |
|
116 |
throw new PackagerException(e); |
|
57038 | 117 |
} |
118 |
} |
|
119 |
||
120 |
@Override |
|
121 |
public String getName() { |
|
57059 | 122 |
return I18N.getString("app.bundler.name"); |
57038 | 123 |
} |
124 |
||
125 |
@Override |
|
126 |
public String getID() { |
|
127 |
return "windows.app"; |
|
128 |
} |
|
129 |
||
130 |
@Override |
|
131 |
public String getBundleType() { |
|
132 |
return "IMAGE"; |
|
133 |
} |
|
134 |
||
135 |
@Override |
|
57140 | 136 |
public File execute(Map<String, ? super Object> params, |
137 |
File outputParentDir) throws PackagerException { |
|
57038 | 138 |
return doBundle(params, outputParentDir, false); |
139 |
} |
|
140 |
||
141 |
@Override |
|
57150 | 142 |
public boolean supported(boolean platformInstaller) { |
57438
4a31db8d42bd
8226599: use code coverage results to remove dead code
herrick
parents:
57407
diff
changeset
|
143 |
return true; |
57038 | 144 |
} |
145 |
||
58114
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57740
diff
changeset
|
146 |
@Override |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57740
diff
changeset
|
147 |
public boolean isDefault() { |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57740
diff
changeset
|
148 |
return false; |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57740
diff
changeset
|
149 |
} |
42df7de58e39
8230519: jpackage "--package-type" values and default
herrick
parents:
57740
diff
changeset
|
150 |
|
57038 | 151 |
} |