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