author | redestad |
Thu, 23 Feb 2017 18:37:51 +0100 | |
changeset 43987 | 068a2419b5a7 |
parent 43712 | 5dfd0950317c |
child 44367 | a81c9c6619fb |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 |
package jdk.tools.jlink.internal; |
|
26 |
||
27 |
import java.io.File; |
|
28 |
import java.io.IOException; |
|
29 |
import java.io.PrintWriter; |
|
30 |
import java.lang.module.Configuration; |
|
31 |
import java.lang.module.ModuleFinder; |
|
32 |
import java.lang.reflect.Layer; |
|
33 |
import java.nio.file.Files; |
|
34 |
import java.nio.file.Path; |
|
35 |
import java.nio.file.Paths; |
|
36 |
import java.text.MessageFormat; |
|
37 |
import java.util.ArrayList; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.Collections; |
|
40 |
import java.util.HashMap; |
|
41 |
import java.util.HashSet; |
|
42 |
import java.util.List; |
|
43 |
import java.util.Locale; |
|
44 |
import java.util.Map; |
|
45 |
import java.util.Map.Entry; |
|
46 |
import java.util.MissingResourceException; |
|
47 |
import java.util.ResourceBundle; |
|
48 |
import java.util.Set; |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
49 |
import java.util.stream.Stream; |
36511 | 50 |
|
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
51 |
import jdk.tools.jlink.internal.plugins.ExcludeJmodSectionPlugin; |
36511 | 52 |
import jdk.tools.jlink.plugin.Plugin; |
38320 | 53 |
import jdk.tools.jlink.plugin.Plugin.Category; |
36511 | 54 |
import jdk.tools.jlink.builder.DefaultImageBuilder; |
55 |
import jdk.tools.jlink.builder.ImageBuilder; |
|
56 |
import jdk.tools.jlink.plugin.PluginException; |
|
41559
5b33f33df1fb
8168091: jlink should check security permission early when programmatic access is used
sundar
parents:
40261
diff
changeset
|
57 |
import jdk.tools.jlink.internal.Jlink.PluginsConfiguration; |
36511 | 58 |
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle; |
59 |
import jdk.tools.jlink.internal.plugins.DefaultCompressPlugin; |
|
60 |
import jdk.tools.jlink.internal.plugins.StripDebugPlugin; |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42330
diff
changeset
|
61 |
import jdk.internal.module.ModulePath; |
36511 | 62 |
|
63 |
/** |
|
64 |
* |
|
65 |
* JLink and JImage tools shared helper. |
|
66 |
*/ |
|
67 |
public final class TaskHelper { |
|
68 |
||
69 |
public static final String JLINK_BUNDLE = "jdk.tools.jlink.resources.jlink"; |
|
70 |
public static final String JIMAGE_BUNDLE = "jdk.tools.jimage.resources.jimage"; |
|
71 |
||
72 |
private static final String DEFAULTS_PROPERTY = "jdk.jlink.defaults"; |
|
73 |
||
74 |
public final class BadArgs extends Exception { |
|
75 |
||
76 |
static final long serialVersionUID = 8765093759964640721L; |
|
77 |
||
78 |
private BadArgs(String key, Object... args) { |
|
79 |
super(bundleHelper.getMessage(key, args)); |
|
80 |
this.key = key; |
|
81 |
this.args = args; |
|
82 |
} |
|
83 |
||
84 |
public BadArgs showUsage(boolean b) { |
|
85 |
showUsage = b; |
|
86 |
return this; |
|
87 |
} |
|
88 |
public final String key; |
|
89 |
public final Object[] args; |
|
90 |
public boolean showUsage; |
|
91 |
} |
|
92 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
93 |
public static class Option<T> implements Comparable<T> { |
36511 | 94 |
public interface Processing<T> { |
95 |
||
96 |
void process(T task, String opt, String arg) throws BadArgs; |
|
97 |
} |
|
98 |
||
99 |
final boolean hasArg; |
|
100 |
final Processing<T> processing; |
|
101 |
final boolean hidden; |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
102 |
final String name; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
103 |
final String shortname; |
36511 | 104 |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
105 |
public Option(boolean hasArg, Processing<T> processing, boolean hidden, String name, String shortname) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
106 |
if (!name.startsWith("--")) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
107 |
throw new RuntimeException("option name missing --, " + name); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
108 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
109 |
if (!shortname.isEmpty() && !shortname.startsWith("-")) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
110 |
throw new RuntimeException("short name missing -, " + shortname); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
111 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
112 |
|
36511 | 113 |
this.hasArg = hasArg; |
114 |
this.processing = processing; |
|
115 |
this.hidden = hidden; |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
116 |
this.name = name; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
117 |
this.shortname = shortname; |
36511 | 118 |
} |
119 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
120 |
public Option(boolean hasArg, Processing<T> processing, String name, String shortname) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
121 |
this(hasArg, processing, false, name, shortname); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
122 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
123 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
124 |
public Option(boolean hasArg, Processing<T> processing, boolean hidden, String name) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
125 |
this(hasArg, processing, hidden, name, ""); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
126 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
127 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
128 |
public Option(boolean hasArg, Processing<T> processing, String name) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
129 |
this(hasArg, processing, false, name, ""); |
36511 | 130 |
} |
131 |
||
132 |
public boolean isHidden() { |
|
133 |
return hidden; |
|
134 |
} |
|
135 |
||
136 |
public boolean matches(String opt) { |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
137 |
return opt.equals(name) || |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
138 |
opt.equals(shortname) || |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
139 |
hasArg && opt.startsWith("--") && opt.startsWith(name + "="); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
140 |
} |
36511 | 141 |
|
142 |
public boolean ignoreRest() { |
|
143 |
return false; |
|
144 |
} |
|
145 |
||
146 |
void process(T task, String opt, String arg) throws BadArgs { |
|
147 |
processing.process(task, opt, arg); |
|
148 |
} |
|
38869 | 149 |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
150 |
public String getName() { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
151 |
return name; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
152 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
153 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
154 |
public String resourceName() { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
155 |
return resourcePrefix() + name.substring(2); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
156 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
157 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
158 |
public String getShortname() { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
159 |
return shortname; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
160 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
161 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
162 |
public String resourcePrefix() { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
163 |
return "main.opt."; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
164 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
165 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
166 |
@Override |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
167 |
public int compareTo(Object object) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
168 |
if (!(object instanceof Option<?>)) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
169 |
throw new RuntimeException("comparing non-Option"); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
170 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
171 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
172 |
Option<?> option = (Option<?>)object; |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
173 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
174 |
return name.compareTo(option.name); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
175 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
176 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
177 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
178 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
179 |
private static class PluginOption extends Option<PluginsHelper> { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
180 |
public PluginOption(boolean hasArg, |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
181 |
Processing<PluginsHelper> processing, boolean hidden, String name, String shortname) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
182 |
super(hasArg, processing, hidden, name, shortname); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
183 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
184 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
185 |
public PluginOption(boolean hasArg, |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
186 |
Processing<PluginsHelper> processing, boolean hidden, String name) { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
187 |
super(hasArg, processing, hidden, name, ""); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
188 |
} |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
189 |
|
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
190 |
public String resourcePrefix() { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
191 |
return "plugin.opt."; |
38869 | 192 |
} |
36511 | 193 |
} |
194 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
195 |
private final class PluginsHelper { |
36511 | 196 |
|
197 |
private Layer pluginsLayer = Layer.boot(); |
|
41831
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
198 |
private final List<Plugin> plugins; |
36511 | 199 |
private String lastSorter; |
200 |
private boolean listPlugins; |
|
201 |
private Path existingImage; |
|
202 |
||
203 |
// plugin to args maps. Each plugin may be used more than once in command line. |
|
204 |
// Each such occurrence results in a Map of arguments. So, there could be multiple |
|
205 |
// args maps per plugin instance. |
|
206 |
private final Map<Plugin, List<Map<String, String>>> pluginToMaps = new HashMap<>(); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
207 |
private final List<PluginOption> pluginsOptions = new ArrayList<>(); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
208 |
private final List<PluginOption> mainOptions = new ArrayList<>(); |
36511 | 209 |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
210 |
private PluginsHelper(String pp) throws BadArgs { |
36511 | 211 |
|
212 |
if (pp != null) { |
|
213 |
String[] dirs = pp.split(File.pathSeparator); |
|
214 |
List<Path> paths = new ArrayList<>(dirs.length); |
|
215 |
for (String dir : dirs) { |
|
216 |
paths.add(Paths.get(dir)); |
|
217 |
} |
|
218 |
||
219 |
pluginsLayer = createPluginsLayer(paths); |
|
220 |
} |
|
221 |
||
41831
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
222 |
plugins = PluginRepository.getPlugins(pluginsLayer); |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
223 |
|
36511 | 224 |
Set<String> optionsSeen = new HashSet<>(); |
41831
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
225 |
for (Plugin plugin : plugins) { |
36511 | 226 |
if (!Utils.isDisabled(plugin)) { |
227 |
addOrderedPluginOptions(plugin, optionsSeen); |
|
228 |
} |
|
229 |
} |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
230 |
mainOptions.add(new PluginOption(true, (task, opt, arg) -> { |
41831
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
231 |
for (Plugin plugin : plugins) { |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
232 |
if (plugin.getName().equals(arg)) { |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
233 |
pluginToMaps.remove(plugin); |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
234 |
return; |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
235 |
} |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
236 |
} |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
237 |
throw newBadArgs("err.no.such.plugin", arg); |
2dd91b18195b
8160063: Provide a means to disable a plugin via the command line
sundar
parents:
41817
diff
changeset
|
238 |
}, |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
239 |
false, "--disable-plugin")); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
240 |
mainOptions.add(new PluginOption(true, (task, opt, arg) -> { |
36511 | 241 |
Path path = Paths.get(arg); |
242 |
if (!Files.exists(path) || !Files.isDirectory(path)) { |
|
41953
3e89e6103470
8155756: Better context for some jlink exceptions
jlaskey
parents:
41919
diff
changeset
|
243 |
throw newBadArgs("err.image.must.exist", path); |
36511 | 244 |
} |
245 |
existingImage = path.toAbsolutePath(); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
246 |
}, true, "--post-process-path")); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
247 |
mainOptions.add(new PluginOption(true, |
36511 | 248 |
(task, opt, arg) -> { |
249 |
lastSorter = arg; |
|
250 |
}, |
|
251 |
true, "--resources-last-sorter")); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
252 |
mainOptions.add(new PluginOption(false, |
36511 | 253 |
(task, opt, arg) -> { |
254 |
listPlugins = true; |
|
255 |
}, |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
256 |
false, "--list-plugins")); |
36511 | 257 |
} |
258 |
||
259 |
private List<Map<String, String>> argListFor(Plugin plugin) { |
|
260 |
List<Map<String, String>> mapList = pluginToMaps.get(plugin); |
|
261 |
if (mapList == null) { |
|
262 |
mapList = new ArrayList<>(); |
|
263 |
pluginToMaps.put(plugin, mapList); |
|
264 |
} |
|
265 |
return mapList; |
|
266 |
} |
|
267 |
||
268 |
private void addEmptyArgumentMap(Plugin plugin) { |
|
269 |
argListFor(plugin).add(Collections.emptyMap()); |
|
270 |
} |
|
271 |
||
272 |
private Map<String, String> addArgumentMap(Plugin plugin) { |
|
273 |
Map<String, String> map = new HashMap<>(); |
|
274 |
argListFor(plugin).add(map); |
|
275 |
return map; |
|
276 |
} |
|
277 |
||
278 |
private void addOrderedPluginOptions(Plugin plugin, |
|
279 |
Set<String> optionsSeen) throws BadArgs { |
|
280 |
String option = plugin.getOption(); |
|
281 |
if (option == null) { |
|
282 |
return; |
|
283 |
} |
|
284 |
||
285 |
// make sure that more than one plugin does not use the same option! |
|
286 |
if (optionsSeen.contains(option)) { |
|
287 |
throw new BadArgs("err.plugin.mutiple.options", |
|
288 |
option); |
|
289 |
} |
|
290 |
optionsSeen.add(option); |
|
291 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
292 |
PluginOption plugOption |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
293 |
= new PluginOption(plugin.hasArguments(), |
36511 | 294 |
(task, opt, arg) -> { |
295 |
if (!Utils.isFunctional(plugin)) { |
|
296 |
throw newBadArgs("err.provider.not.functional", |
|
297 |
option); |
|
298 |
} |
|
299 |
||
300 |
if (! plugin.hasArguments()) { |
|
301 |
addEmptyArgumentMap(plugin); |
|
302 |
return; |
|
303 |
} |
|
304 |
||
305 |
Map<String, String> m = addArgumentMap(plugin); |
|
306 |
// handle one or more arguments |
|
307 |
if (arg.indexOf(':') == -1) { |
|
308 |
// single argument case |
|
309 |
m.put(option, arg); |
|
310 |
} else { |
|
311 |
// This option can accept more than one arguments |
|
312 |
// like --option_name=arg_value:arg2=value2:arg3=value3 |
|
313 |
||
314 |
// ":" followed by word char condition takes care of args that |
|
315 |
// like Windows absolute paths "C:\foo", "C:/foo" [cygwin] etc. |
|
316 |
// This enforces that key names start with a word character. |
|
317 |
String[] args = arg.split(":(?=\\w)", -1); |
|
318 |
String firstArg = args[0]; |
|
319 |
if (firstArg.isEmpty()) { |
|
320 |
throw newBadArgs("err.provider.additional.arg.error", |
|
321 |
option, arg); |
|
322 |
} |
|
323 |
m.put(option, firstArg); |
|
324 |
// process the additional arguments |
|
325 |
for (int i = 1; i < args.length; i++) { |
|
326 |
String addArg = args[i]; |
|
327 |
int eqIdx = addArg.indexOf('='); |
|
328 |
if (eqIdx == -1) { |
|
329 |
throw newBadArgs("err.provider.additional.arg.error", |
|
330 |
option, arg); |
|
331 |
} |
|
332 |
||
333 |
String addArgName = addArg.substring(0, eqIdx); |
|
334 |
String addArgValue = addArg.substring(eqIdx+1); |
|
335 |
if (addArgName.isEmpty() || addArgValue.isEmpty()) { |
|
336 |
throw newBadArgs("err.provider.additional.arg.error", |
|
337 |
option, arg); |
|
338 |
} |
|
339 |
m.put(addArgName, addArgValue); |
|
340 |
} |
|
341 |
} |
|
342 |
}, |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
343 |
false, "--" + option); |
36511 | 344 |
pluginsOptions.add(plugOption); |
345 |
||
346 |
if (Utils.isFunctional(plugin)) { |
|
347 |
if (Utils.isAutoEnabled(plugin)) { |
|
348 |
addEmptyArgumentMap(plugin); |
|
349 |
} |
|
350 |
||
351 |
if (plugin instanceof DefaultCompressPlugin) { |
|
352 |
plugOption |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
353 |
= new PluginOption(false, |
36511 | 354 |
(task, opt, arg) -> { |
355 |
Map<String, String> m = addArgumentMap(plugin); |
|
356 |
m.put(DefaultCompressPlugin.NAME, DefaultCompressPlugin.LEVEL_2); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
357 |
}, false, "--compress", "-c"); |
36511 | 358 |
mainOptions.add(plugOption); |
359 |
} else if (plugin instanceof StripDebugPlugin) { |
|
360 |
plugOption |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
361 |
= new PluginOption(false, |
36511 | 362 |
(task, opt, arg) -> { |
363 |
addArgumentMap(plugin); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
364 |
}, false, "--strip-debug", "-G"); |
36511 | 365 |
mainOptions.add(plugOption); |
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
366 |
} else if (plugin instanceof ExcludeJmodSectionPlugin) { |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
367 |
plugOption = new PluginOption(false, (task, opt, arg) -> { |
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
368 |
Map<String, String> m = addArgumentMap(plugin); |
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
369 |
m.put(ExcludeJmodSectionPlugin.NAME, |
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
370 |
ExcludeJmodSectionPlugin.MAN_PAGES); |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
371 |
}, false, "--no-man-pages"); |
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
372 |
mainOptions.add(plugOption); |
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
373 |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
374 |
plugOption = new PluginOption(false, (task, opt, arg) -> { |
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
375 |
Map<String, String> m = addArgumentMap(plugin); |
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
376 |
m.put(ExcludeJmodSectionPlugin.NAME, |
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
377 |
ExcludeJmodSectionPlugin.INCLUDE_HEADER_FILES); |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
378 |
}, false, "--no-header-files"); |
41561
0c6942d13f2e
8167558: Add new JMOD section for header files and man pages
mchung
parents:
41559
diff
changeset
|
379 |
mainOptions.add(plugOption); |
36511 | 380 |
} |
381 |
} |
|
382 |
} |
|
383 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
384 |
private PluginOption getOption(String name) throws BadArgs { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
385 |
for (PluginOption o : pluginsOptions) { |
36511 | 386 |
if (o.matches(name)) { |
387 |
return o; |
|
388 |
} |
|
389 |
} |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
390 |
for (PluginOption o : mainOptions) { |
36511 | 391 |
if (o.matches(name)) { |
392 |
return o; |
|
393 |
} |
|
394 |
} |
|
395 |
return null; |
|
396 |
} |
|
397 |
||
42762 | 398 |
private PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers |
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
399 |
) throws IOException, BadArgs { |
36511 | 400 |
if (output != null) { |
401 |
if (Files.exists(output)) { |
|
402 |
throw new PluginException(PluginsResourceBundle. |
|
403 |
getMessage("err.dir.already.exits", output)); |
|
404 |
} |
|
405 |
} |
|
406 |
||
407 |
List<Plugin> pluginsList = new ArrayList<>(); |
|
408 |
for (Entry<Plugin, List<Map<String, String>>> entry : pluginToMaps.entrySet()) { |
|
409 |
Plugin plugin = entry.getKey(); |
|
410 |
List<Map<String, String>> argsMaps = entry.getValue(); |
|
411 |
||
412 |
// same plugin option may be used multiple times in command line. |
|
413 |
// we call configure once for each occurrence. It is upto the plugin |
|
414 |
// to 'merge' and/or 'override' arguments. |
|
415 |
for (Map<String, String> map : argsMaps) { |
|
42330
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
416 |
try { |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
417 |
plugin.configure(Collections.unmodifiableMap(map)); |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
418 |
} catch (IllegalArgumentException e) { |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
419 |
if (JlinkTask.DEBUG) { |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
420 |
System.err.println("Plugin " + plugin.getName() + " threw exception with config: " + map); |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
421 |
e.printStackTrace(); |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
422 |
} |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
423 |
throw e; |
bd999576b78d
8160359: Improve jlink logging for cases when a plugin throws exception
sundar
parents:
42174
diff
changeset
|
424 |
} |
36511 | 425 |
} |
426 |
||
427 |
if (!Utils.isDisabled(plugin)) { |
|
428 |
pluginsList.add(plugin); |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
// recreate or postprocessing don't require an output directory. |
|
433 |
ImageBuilder builder = null; |
|
434 |
if (output != null) { |
|
42762 | 435 |
builder = new DefaultImageBuilder(output, launchers); |
436 |
} |
|
36511 | 437 |
|
438 |
return new Jlink.PluginsConfiguration(pluginsList, |
|
38320 | 439 |
builder, lastSorter); |
36511 | 440 |
} |
441 |
} |
|
442 |
||
443 |
private static final class ResourceBundleHelper { |
|
444 |
||
445 |
private final ResourceBundle bundle; |
|
446 |
private final ResourceBundle pluginBundle; |
|
447 |
||
448 |
ResourceBundleHelper(String path) { |
|
449 |
Locale locale = Locale.getDefault(); |
|
450 |
try { |
|
451 |
bundle = ResourceBundle.getBundle(path, locale); |
|
452 |
pluginBundle = ResourceBundle.getBundle("jdk.tools.jlink.resources.plugins", locale); |
|
453 |
} catch (MissingResourceException e) { |
|
454 |
throw new InternalError("Cannot find jlink resource bundle for locale " + locale); |
|
455 |
} |
|
456 |
} |
|
457 |
||
458 |
String getMessage(String key, Object... args) { |
|
459 |
String val; |
|
460 |
try { |
|
461 |
val = bundle.getString(key); |
|
462 |
} catch (MissingResourceException e) { |
|
463 |
// XXX OK, check in plugin bundle |
|
464 |
val = pluginBundle.getString(key); |
|
465 |
} |
|
466 |
return MessageFormat.format(val, args); |
|
467 |
} |
|
468 |
||
469 |
} |
|
470 |
||
471 |
public final class OptionsHelper<T> { |
|
472 |
||
473 |
private final List<Option<T>> options; |
|
474 |
private String[] command; |
|
475 |
private String defaults; |
|
476 |
||
477 |
OptionsHelper(List<Option<T>> options) { |
|
478 |
this.options = options; |
|
479 |
} |
|
480 |
||
481 |
private boolean hasArgument(String optionName) throws BadArgs { |
|
482 |
Option<?> opt = getOption(optionName); |
|
483 |
if (opt == null) { |
|
484 |
opt = pluginOptions.getOption(optionName); |
|
485 |
if (opt == null) { |
|
486 |
throw new BadArgs("err.unknown.option", optionName). |
|
487 |
showUsage(true); |
|
488 |
} |
|
489 |
} |
|
490 |
return opt.hasArg; |
|
491 |
} |
|
492 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
493 |
public boolean shouldListPlugins() { |
36511 | 494 |
return pluginOptions.listPlugins; |
495 |
} |
|
496 |
||
497 |
private String getPluginsPath(String[] args) throws BadArgs { |
|
43328 | 498 |
return null; |
36511 | 499 |
} |
500 |
||
41766 | 501 |
// used by jimage. Return unhandled arguments like "create", "describe". |
36511 | 502 |
public List<String> handleOptions(T task, String[] args) throws BadArgs { |
41766 | 503 |
return handleOptions(task, args, true); |
504 |
} |
|
505 |
||
506 |
// used by jlink. No unhandled arguments like "create", "describe". |
|
507 |
void handleOptionsNoUnhandled(T task, String[] args) throws BadArgs { |
|
508 |
handleOptions(task, args, false); |
|
509 |
} |
|
510 |
||
511 |
// shared code that handles options for both jlink and jimage. jimage uses arguments like |
|
512 |
// "create", "describe" etc. as "task names". Those arguments are unhandled here and returned |
|
513 |
// as "unhandled arguments list". jlink does not want such arguments. "collectUnhandled" flag |
|
514 |
// tells whether to allow for unhandled arguments or not. |
|
515 |
private List<String> handleOptions(T task, String[] args, boolean collectUnhandled) throws BadArgs { |
|
36511 | 516 |
// findbugs warning, copy instead of keeping a reference. |
517 |
command = Arrays.copyOf(args, args.length); |
|
518 |
||
519 |
// Must extract it prior to do any option analysis. |
|
520 |
// Required to interpret custom plugin options. |
|
521 |
// Unit tests can call Task multiple time in same JVM. |
|
43328 | 522 |
pluginOptions = new PluginsHelper(null); |
36511 | 523 |
|
41766 | 524 |
List<String> rest = collectUnhandled? new ArrayList<>() : null; |
36511 | 525 |
// process options |
526 |
for (int i = 0; i < args.length; i++) { |
|
43987
068a2419b5a7
8169713: jimage fails with StringIndexOutOfBoundsException when path to the inspected image is an empty string
redestad
parents:
43712
diff
changeset
|
527 |
if (args[i].startsWith("-")) { |
36511 | 528 |
String name = args[i]; |
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
529 |
PluginOption pluginOption = null; |
36511 | 530 |
Option<T> option = getOption(name); |
531 |
if (option == null) { |
|
532 |
pluginOption = pluginOptions.getOption(name); |
|
533 |
if (pluginOption == null) { |
|
534 |
||
535 |
throw new BadArgs("err.unknown.option", name). |
|
536 |
showUsage(true); |
|
537 |
} |
|
538 |
} |
|
539 |
Option<?> opt = pluginOption == null ? option : pluginOption; |
|
540 |
String param = null; |
|
541 |
if (opt.hasArg) { |
|
542 |
if (name.startsWith("--") && name.indexOf('=') > 0) { |
|
543 |
param = name.substring(name.indexOf('=') + 1, |
|
544 |
name.length()); |
|
545 |
} else if (i + 1 < args.length) { |
|
546 |
param = args[++i]; |
|
547 |
} |
|
548 |
if (param == null || param.isEmpty() |
|
549 |
|| (param.length() >= 2 && param.charAt(0) == '-' |
|
550 |
&& param.charAt(1) == '-')) { |
|
551 |
throw new BadArgs("err.missing.arg", name). |
|
552 |
showUsage(true); |
|
553 |
} |
|
554 |
} |
|
555 |
if (pluginOption != null) { |
|
556 |
pluginOption.process(pluginOptions, name, param); |
|
557 |
} else { |
|
558 |
option.process(task, name, param); |
|
559 |
} |
|
560 |
if (opt.ignoreRest()) { |
|
561 |
i = args.length; |
|
562 |
} |
|
563 |
} else { |
|
41766 | 564 |
if (collectUnhandled) { |
565 |
rest.add(args[i]); |
|
566 |
} else { |
|
567 |
throw new BadArgs("err.orphan.argument", args[i]). |
|
568 |
showUsage(true); |
|
569 |
} |
|
36511 | 570 |
} |
571 |
} |
|
572 |
return rest; |
|
573 |
} |
|
574 |
||
575 |
private Option<T> getOption(String name) { |
|
576 |
for (Option<T> o : options) { |
|
577 |
if (o.matches(name)) { |
|
578 |
return o; |
|
579 |
} |
|
580 |
} |
|
581 |
return null; |
|
582 |
} |
|
583 |
||
584 |
public void showHelp(String progName) { |
|
585 |
log.println(bundleHelper.getMessage("main.usage", progName)); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
586 |
Stream.concat(options.stream(), pluginOptions.mainOptions.stream()) |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
587 |
.filter(option -> !option.isHidden()) |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
588 |
.sorted() |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
589 |
.forEach(option -> { |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
590 |
log.println(bundleHelper.getMessage(option.resourceName())); |
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
591 |
}); |
36511 | 592 |
|
593 |
log.println(bundleHelper.getMessage("main.command.files")); |
|
594 |
} |
|
595 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
596 |
public void listPlugins() { |
36511 | 597 |
log.println("\n" + bundleHelper.getMessage("main.extended.help")); |
598 |
List<Plugin> pluginList = PluginRepository. |
|
599 |
getPlugins(pluginOptions.pluginsLayer); |
|
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
600 |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
601 |
for (Plugin plugin : Utils.getSortedPlugins(pluginList)) { |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
602 |
showPlugin(plugin, log); |
36511 | 603 |
} |
39150
cb99396625b4
8159172: Update usage of jlink/jimage/jmod to show option patterns
jlaskey
parents:
38869
diff
changeset
|
604 |
|
cb99396625b4
8159172: Update usage of jlink/jimage/jmod to show option patterns
jlaskey
parents:
38869
diff
changeset
|
605 |
log.println("\n" + bundleHelper.getMessage("main.extended.help.footer")); |
36511 | 606 |
} |
607 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
608 |
private void showPlugin(Plugin plugin, PrintWriter log) { |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
609 |
if (showsPlugin(plugin)) { |
36511 | 610 |
log.println("\n" + bundleHelper.getMessage("main.plugin.name") |
611 |
+ ": " + plugin.getName()); |
|
612 |
||
613 |
// print verbose details for non-builtin plugins |
|
614 |
if (!Utils.isBuiltin(plugin)) { |
|
615 |
log.println(bundleHelper.getMessage("main.plugin.class") |
|
616 |
+ ": " + plugin.getClass().getName()); |
|
617 |
log.println(bundleHelper.getMessage("main.plugin.module") |
|
618 |
+ ": " + plugin.getClass().getModule().getName()); |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
619 |
Category category = plugin.getType(); |
36511 | 620 |
log.println(bundleHelper.getMessage("main.plugin.category") |
621 |
+ ": " + category.getName()); |
|
622 |
log.println(bundleHelper.getMessage("main.plugin.state") |
|
623 |
+ ": " + plugin.getStateDescription()); |
|
624 |
} |
|
625 |
||
626 |
String option = plugin.getOption(); |
|
627 |
if (option != null) { |
|
628 |
log.println(bundleHelper.getMessage("main.plugin.option") |
|
629 |
+ ": --" + plugin.getOption() |
|
630 |
+ (plugin.hasArguments()? ("=" + plugin.getArgumentsDescription()) : "")); |
|
631 |
} |
|
632 |
||
633 |
// description can be long spanning more than one line and so |
|
634 |
// print a newline after description label. |
|
635 |
log.println(bundleHelper.getMessage("main.plugin.description") |
|
636 |
+ ": " + plugin.getDescription()); |
|
637 |
} |
|
638 |
} |
|
639 |
||
640 |
String[] getInputCommand() { |
|
641 |
return command; |
|
642 |
} |
|
643 |
||
644 |
String getDefaults() { |
|
645 |
return defaults; |
|
646 |
} |
|
647 |
||
648 |
public Layer getPluginsLayer() { |
|
649 |
return pluginOptions.pluginsLayer; |
|
650 |
} |
|
651 |
} |
|
652 |
||
42174
fa763b059501
8168256: Plugin alias options in jlink --help output seems to be in an arbitrary order
jlaskey
parents:
41953
diff
changeset
|
653 |
private PluginsHelper pluginOptions; |
36511 | 654 |
private PrintWriter log; |
655 |
private final ResourceBundleHelper bundleHelper; |
|
656 |
||
657 |
public TaskHelper(String path) { |
|
658 |
if (!JLINK_BUNDLE.equals(path) && !JIMAGE_BUNDLE.equals(path)) { |
|
659 |
throw new IllegalArgumentException("Invalid Bundle"); |
|
660 |
} |
|
661 |
this.bundleHelper = new ResourceBundleHelper(path); |
|
662 |
} |
|
663 |
||
664 |
public <T> OptionsHelper<T> newOptionsHelper(Class<T> clazz, |
|
665 |
Option<?>[] options) { |
|
666 |
List<Option<T>> optionsList = new ArrayList<>(); |
|
667 |
for (Option<?> o : options) { |
|
668 |
@SuppressWarnings("unchecked") |
|
669 |
Option<T> opt = (Option<T>) o; |
|
670 |
optionsList.add(opt); |
|
671 |
} |
|
672 |
return new OptionsHelper<>(optionsList); |
|
673 |
} |
|
674 |
||
675 |
public BadArgs newBadArgs(String key, Object... args) { |
|
676 |
return new BadArgs(key, args); |
|
677 |
} |
|
678 |
||
679 |
public String getMessage(String key, Object... args) { |
|
680 |
return bundleHelper.getMessage(key, args); |
|
681 |
} |
|
682 |
||
683 |
public void setLog(PrintWriter log) { |
|
684 |
this.log = log; |
|
685 |
} |
|
686 |
||
687 |
public void reportError(String key, Object... args) { |
|
688 |
log.println(bundleHelper.getMessage("error.prefix") + " " |
|
689 |
+ bundleHelper.getMessage(key, args)); |
|
690 |
} |
|
691 |
||
692 |
public void reportUnknownError(String message) { |
|
693 |
log.println(bundleHelper.getMessage("error.prefix") + " " + message); |
|
694 |
} |
|
695 |
||
696 |
public void warning(String key, Object... args) { |
|
697 |
log.println(bundleHelper.getMessage("warn.prefix") + " " |
|
698 |
+ bundleHelper.getMessage(key, args)); |
|
699 |
} |
|
700 |
||
42762 | 701 |
public PluginsConfiguration getPluginsConfig(Path output, Map<String, String> launchers) |
36511 | 702 |
throws IOException, BadArgs { |
42762 | 703 |
return pluginOptions.getPluginsConfig(output, launchers); |
36511 | 704 |
} |
705 |
||
706 |
public Path getExistingImage() { |
|
707 |
return pluginOptions.existingImage; |
|
708 |
} |
|
709 |
||
710 |
public void showVersion(boolean full) { |
|
711 |
log.println(version(full ? "full" : "release")); |
|
712 |
} |
|
713 |
||
714 |
public String version(String key) { |
|
715 |
return System.getProperty("java.version"); |
|
716 |
} |
|
717 |
||
718 |
static Layer createPluginsLayer(List<Path> paths) { |
|
719 |
||
41817
b90ad1de93ea
8168789: ModuleReader.list and ModuleFinder.of update
alanb
parents:
41766
diff
changeset
|
720 |
Path[] dirs = paths.toArray(new Path[0]); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43495
diff
changeset
|
721 |
ModuleFinder finder = ModulePath.of(Runtime.version(), true, dirs); |
36511 | 722 |
Configuration bootConfiguration = Layer.boot().configuration(); |
723 |
try { |
|
724 |
Configuration cf = bootConfiguration |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43495
diff
changeset
|
725 |
.resolveAndBind(ModuleFinder.of(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43495
diff
changeset
|
726 |
finder, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
43495
diff
changeset
|
727 |
Collections.emptySet()); |
36511 | 728 |
ClassLoader scl = ClassLoader.getSystemClassLoader(); |
729 |
return Layer.boot().defineModulesWithOneLoader(cf, scl); |
|
730 |
} catch (Exception ex) { |
|
731 |
// Malformed plugin modules (e.g.: same package in multiple modules). |
|
732 |
throw new PluginException("Invalid modules in the plugins path: " + ex); |
|
733 |
} |
|
734 |
} |
|
735 |
||
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
736 |
// Display all plugins |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
737 |
private static boolean showsPlugin(Plugin plugin) { |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39150
diff
changeset
|
738 |
return (!Utils.isDisabled(plugin) && plugin.getOption() != null); |
36511 | 739 |
} |
740 |
} |