author | mr |
Tue, 29 Oct 2019 08:26:55 -0700 | |
changeset 58842 | 6c255334120d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
58842
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
36511 | 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 |
/** |
|
42471
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
39834
diff
changeset
|
39 |
* Order of categories matches the plugin sort order. |
36511 | 40 |
* <ol> |
41 |
* <li>FILTER: Filter in/out resources or files.</li> |
|
58842
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
42 |
* <li>ADDER: Add resources or files.</li> |
36511 | 43 |
* <li>TRANSFORMER: Transform resources or files(eg: refactoring, bytecode |
44 |
* manipulation).</li> |
|
45 |
* <li>MODULEINFO_TRANSFORMER: Transform only module-info.class</li> |
|
46 |
* <li>SORTER: Sort resources within the resource container.</li> |
|
42471
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
39834
diff
changeset
|
47 |
* <li>METAINFO_ADDER: Added meta info (like release, copyright etc.)</li> |
36511 | 48 |
* <li>COMPRESSOR: Compress resource within the resouce containers.</li> |
49 |
* <li>VERIFIER: Does some image verification.</li> |
|
50 |
* <li>PROCESSOR: Does some post processing on image.</li> |
|
51 |
* <li>PACKAGER: Final processing</li> |
|
52 |
* </ol> |
|
53 |
*/ |
|
38320 | 54 |
public enum Category { |
36511 | 55 |
FILTER("FILTER"), |
58842
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
56 |
ADDER("ADDER"), |
36511 | 57 |
TRANSFORMER("TRANSFORMER"), |
58 |
MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"), |
|
59 |
SORTER("SORTER"), |
|
42471
86b1da05a4b0
8168925: MODULES property should be topologically ordered and space-separated list
sundar
parents:
39834
diff
changeset
|
60 |
METAINFO_ADDER("METAINFO_ADDER"), |
36511 | 61 |
COMPRESSOR("COMPRESSOR"), |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
62 |
VERIFIER("VERIFIER"), |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
63 |
PROCESSOR("PROCESSOR"), |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
64 |
PACKAGER("PACKAGER"); |
36511 | 65 |
|
66 |
private final String name; |
|
67 |
||
38320 | 68 |
Category(String name) { |
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
69 |
this.name = name; |
36511 | 70 |
} |
71 |
||
72 |
public String getName() { |
|
73 |
return name; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
/** |
|
78 |
* Plugin state: |
|
79 |
* <ul> |
|
80 |
* <li>DISABLED: The plugin is not exposed in help and will be not called.</li> |
|
81 |
* <li>AUTO_ENABLED: The plugin is enabled by default. It doesn't require its |
|
82 |
* option to be present to be called.<li> |
|
83 |
* <li>FUNCTIONAL: The plugin is properly configured and can operate. |
|
84 |
* Non functional plugin must advertise their status in the |
|
85 |
* {@link #getStateDescription() getStateDescription} method</li> |
|
86 |
* </ul> |
|
87 |
*/ |
|
38320 | 88 |
public enum State { |
36511 | 89 |
DISABLED, |
90 |
AUTO_ENABLED, |
|
91 |
FUNCTIONAL |
|
92 |
} |
|
93 |
||
94 |
/** |
|
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
95 |
* The type of this plugin. |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
96 |
* |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
97 |
* @return The type of this plugin |
36511 | 98 |
*/ |
39129
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
99 |
public default Category getType() { |
4b2086305b68
8159593: Plugin Set<Category> getType() should return a Category
sundar
parents:
38320
diff
changeset
|
100 |
return Category.TRANSFORMER; |
36511 | 101 |
} |
102 |
||
103 |
/** |
|
104 |
* The Plugin set of states. |
|
105 |
* @return The set of states. |
|
106 |
*/ |
|
38320 | 107 |
public default Set<State> getState() { |
108 |
return EnumSet.of(State.FUNCTIONAL); |
|
36511 | 109 |
} |
110 |
||
111 |
/** |
|
112 |
* The plugin name. |
|
113 |
* @return The name. |
|
114 |
*/ |
|
115 |
public default String getName() { |
|
116 |
return getClass().getName().replace('.', '-'); |
|
117 |
} |
|
118 |
||
119 |
/** |
|
120 |
* The plugin description. |
|
121 |
* @return The description. |
|
122 |
*/ |
|
123 |
public default String getDescription() { |
|
124 |
return ""; |
|
125 |
} |
|
126 |
||
127 |
/** |
|
128 |
* The option that identifies this plugin. This may be null. |
|
129 |
* "--" is prefixed to the String (when non-null) when invoking |
|
130 |
* this plugin from jlink command line. |
|
131 |
* |
|
132 |
* @return The plugin option. |
|
133 |
*/ |
|
134 |
public default String getOption() { |
|
135 |
return getName(); |
|
136 |
} |
|
137 |
||
138 |
/** |
|
139 |
* Has this plugin require one or more arguments? |
|
140 |
* A plugin can have one or more optional arguments. |
|
141 |
* <br> |
|
142 |
* A plugin option with a single argument is specified as follows: |
|
143 |
* <pre> |
|
144 |
* --plugin-option=arg_value |
|
145 |
* </pre> |
|
146 |
* If there are more than arguments, command line option looks like: |
|
147 |
* <pre> |
|
148 |
* --plugin-option=arg_value:arg2=value2:arg3=value3... |
|
149 |
*</pre> |
|
150 |
* |
|
151 |
* @return true if arguments are needed. |
|
152 |
*/ |
|
153 |
public default boolean hasArguments() { |
|
154 |
return false; |
|
155 |
} |
|
156 |
||
58842
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
157 |
public default boolean hasRawArgument() { |
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
158 |
return false; |
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
159 |
} |
6c255334120d
8232080: jlink plugins for vendor information and run-time options
mr
parents:
47216
diff
changeset
|
160 |
|
36511 | 161 |
/** |
162 |
* The plugin argument(s) description. |
|
163 |
* @return The argument(s) description. |
|
164 |
*/ |
|
165 |
public default String getArgumentsDescription() { |
|
166 |
return ""; |
|
167 |
} |
|
168 |
||
169 |
/** |
|
170 |
* Return a message indicating the status of the provider. |
|
171 |
* |
|
172 |
* @return A status description. |
|
173 |
*/ |
|
174 |
public default String getStateDescription() { |
|
38320 | 175 |
return getState().contains(State.FUNCTIONAL) |
36511 | 176 |
? PluginsResourceBundle.getMessage("main.status.ok") |
177 |
: PluginsResourceBundle.getMessage("main.status.not.ok"); |
|
178 |
} |
|
179 |
||
180 |
/** |
|
181 |
* Configure the plugin based on the passed configuration. |
|
182 |
* This method is called prior to invoke the plugin. |
|
183 |
* |
|
184 |
* @param config The plugin configuration. |
|
37779
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
185 |
* @throws IllegalArgumentException if a mandatory argument is missing or |
7c84df693837
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36511
diff
changeset
|
186 |
* if an argument has invalid value. |
36511 | 187 |
*/ |
188 |
public default void configure(Map<String, String> config) { |
|
189 |
} |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
190 |
|
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
191 |
/** |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
192 |
* 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
|
193 |
* |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
194 |
* @param in Read only content. |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
195 |
* @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
|
196 |
* the result of the visit. |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
197 |
* |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
198 |
* @throws PluginException |
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39129
diff
changeset
|
199 |
*/ |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39505
diff
changeset
|
200 |
public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out); |
36511 | 201 |
} |