36511
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, 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.plugin;
|
|
26 |
|
|
27 |
import java.util.Collections;
|
|
28 |
import java.util.EnumSet;
|
|
29 |
import java.util.List;
|
|
30 |
import java.util.Map;
|
|
31 |
import java.util.Set;
|
|
32 |
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Base interface that jlink plugins should implement.
|
|
36 |
*/
|
|
37 |
public interface Plugin {
|
|
38 |
|
|
39 |
/**
|
|
40 |
* Type of plugin.
|
|
41 |
*/
|
|
42 |
public interface PluginType {
|
|
43 |
|
|
44 |
public String getName();
|
|
45 |
}
|
|
46 |
|
|
47 |
/**
|
|
48 |
* Order of categories:
|
|
49 |
* <ol>
|
|
50 |
* <li>FILTER: Filter in/out resources or files.</li>
|
|
51 |
* <li>TRANSFORMER: Transform resources or files(eg: refactoring, bytecode
|
|
52 |
* manipulation).</li>
|
|
53 |
* <li>MODULEINFO_TRANSFORMER: Transform only module-info.class</li>
|
|
54 |
* <li>SORTER: Sort resources within the resource container.</li>
|
|
55 |
* <li>COMPRESSOR: Compress resource within the resouce containers.</li>
|
|
56 |
* <li>VERIFIER: Does some image verification.</li>
|
|
57 |
* <li>PROCESSOR: Does some post processing on image.</li>
|
|
58 |
* <li>PACKAGER: Final processing</li>
|
|
59 |
* </ol>
|
|
60 |
*/
|
|
61 |
public enum CATEGORY implements PluginType {
|
|
62 |
FILTER("FILTER"),
|
|
63 |
TRANSFORMER("TRANSFORMER"),
|
|
64 |
MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"),
|
|
65 |
SORTER("SORTER"),
|
|
66 |
COMPRESSOR("COMPRESSOR"),
|
|
67 |
VERIFIER("VERIFIER"),
|
|
68 |
PROCESSOR("PROCESSOR"),
|
|
69 |
PACKAGER("PACKAGER");
|
|
70 |
|
|
71 |
private final String name;
|
|
72 |
|
|
73 |
CATEGORY(String name) {
|
|
74 |
this.name = name;
|
|
75 |
}
|
|
76 |
|
|
77 |
@Override
|
|
78 |
public String getName() {
|
|
79 |
return name;
|
|
80 |
}
|
|
81 |
}
|
|
82 |
|
|
83 |
/**
|
|
84 |
* Plugin state:
|
|
85 |
* <ul>
|
|
86 |
* <li>DISABLED: The plugin is not exposed in help and will be not called.</li>
|
|
87 |
* <li>AUTO_ENABLED: The plugin is enabled by default. It doesn't require its
|
|
88 |
* option to be present to be called.<li>
|
|
89 |
* <li>FUNCTIONAL: The plugin is properly configured and can operate.
|
|
90 |
* Non functional plugin must advertise their status in the
|
|
91 |
* {@link #getStateDescription() getStateDescription} method</li>
|
|
92 |
* </ul>
|
|
93 |
*/
|
|
94 |
public enum STATE {
|
|
95 |
DISABLED,
|
|
96 |
AUTO_ENABLED,
|
|
97 |
FUNCTIONAL
|
|
98 |
}
|
|
99 |
|
|
100 |
/**
|
|
101 |
* The Plugin set of types.
|
|
102 |
* @return The set of types.
|
|
103 |
*/
|
|
104 |
public default Set<PluginType> getType() {
|
|
105 |
return Collections.emptySet();
|
|
106 |
}
|
|
107 |
|
|
108 |
/**
|
|
109 |
* The Plugin set of states.
|
|
110 |
* @return The set of states.
|
|
111 |
*/
|
|
112 |
public default Set<STATE> getState() {
|
|
113 |
return EnumSet.of(STATE.FUNCTIONAL);
|
|
114 |
}
|
|
115 |
|
|
116 |
/**
|
|
117 |
* The set of plugin names that must be located, within the stack of plugins,
|
|
118 |
* before this plugin.
|
|
119 |
* @return The set of names. By default this set is empty.
|
|
120 |
*/
|
|
121 |
public default Set<String> isBefore() {
|
|
122 |
return Collections.emptySet();
|
|
123 |
}
|
|
124 |
|
|
125 |
/**
|
|
126 |
* The set of plugin names that must be located, within the stack of plugins,
|
|
127 |
* after this plugin.
|
|
128 |
* @return The set of names. By default this set is empty.
|
|
129 |
*/
|
|
130 |
public default Set<String> isAfter() {
|
|
131 |
return Collections.emptySet();
|
|
132 |
}
|
|
133 |
|
|
134 |
/**
|
|
135 |
* The plugin name.
|
|
136 |
* @return The name.
|
|
137 |
*/
|
|
138 |
public default String getName() {
|
|
139 |
return getClass().getName().replace('.', '-');
|
|
140 |
}
|
|
141 |
|
|
142 |
/**
|
|
143 |
* The plugin description.
|
|
144 |
* @return The description.
|
|
145 |
*/
|
|
146 |
public default String getDescription() {
|
|
147 |
return "";
|
|
148 |
}
|
|
149 |
|
|
150 |
/**
|
|
151 |
* The option that identifies this plugin. This may be null.
|
|
152 |
* "--" is prefixed to the String (when non-null) when invoking
|
|
153 |
* this plugin from jlink command line.
|
|
154 |
*
|
|
155 |
* @return The plugin option.
|
|
156 |
*/
|
|
157 |
public default String getOption() {
|
|
158 |
return getName();
|
|
159 |
}
|
|
160 |
|
|
161 |
/**
|
|
162 |
* Has this plugin require one or more arguments?
|
|
163 |
* A plugin can have one or more optional arguments.
|
|
164 |
* <br>
|
|
165 |
* A plugin option with a single argument is specified as follows:
|
|
166 |
* <pre>
|
|
167 |
* --plugin-option=arg_value
|
|
168 |
* </pre>
|
|
169 |
* If there are more than arguments, command line option looks like:
|
|
170 |
* <pre>
|
|
171 |
* --plugin-option=arg_value:arg2=value2:arg3=value3...
|
|
172 |
*</pre>
|
|
173 |
*
|
|
174 |
* @return true if arguments are needed.
|
|
175 |
*/
|
|
176 |
public default boolean hasArguments() {
|
|
177 |
return false;
|
|
178 |
}
|
|
179 |
|
|
180 |
/**
|
|
181 |
* The plugin argument(s) description.
|
|
182 |
* @return The argument(s) description.
|
|
183 |
*/
|
|
184 |
public default String getArgumentsDescription() {
|
|
185 |
return "";
|
|
186 |
}
|
|
187 |
|
|
188 |
/**
|
|
189 |
* Return a message indicating the status of the provider.
|
|
190 |
*
|
|
191 |
* @return A status description.
|
|
192 |
*/
|
|
193 |
public default String getStateDescription() {
|
|
194 |
return getState().contains(STATE.FUNCTIONAL)
|
|
195 |
? PluginsResourceBundle.getMessage("main.status.ok")
|
|
196 |
: PluginsResourceBundle.getMessage("main.status.not.ok");
|
|
197 |
}
|
|
198 |
|
|
199 |
/**
|
|
200 |
* Configure the plugin based on the passed configuration.
|
|
201 |
* This method is called prior to invoke the plugin.
|
|
202 |
*
|
|
203 |
* @param config The plugin configuration.
|
|
204 |
*/
|
|
205 |
public default void configure(Map<String, String> config) {
|
|
206 |
}
|
|
207 |
|
|
208 |
/**
|
|
209 |
* Configure the plugin based on the passed configuration.
|
|
210 |
* This method is called prior to invoke the plugin.
|
|
211 |
*
|
|
212 |
* @param config The plugin configuration.
|
|
213 |
* @param ctx The plugin context
|
|
214 |
*/
|
|
215 |
public default void configure(Map<String, String> config, PluginContext ctx) {
|
|
216 |
configure(config);
|
|
217 |
}
|
|
218 |
}
|