Plugin.java revision 13901:b2a69d66dc65
1238730Sdelphij/* 2238730Sdelphij * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3238730Sdelphij * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4238730Sdelphij * 5238730Sdelphij * This code is free software; you can redistribute it and/or modify it 6238730Sdelphij * under the terms of the GNU General Public License version 2 only, as 7238730Sdelphij * published by the Free Software Foundation. Oracle designates this 8238730Sdelphij * particular file as subject to the "Classpath" exception as provided 960786Sps * by Oracle in the LICENSE file that accompanied this code. 1060786Sps * 1160786Sps * This code is distributed in the hope that it will be useful, but WITHOUT 1260786Sps * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1360786Sps * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1460786Sps * version 2 for more details (a copy is included in the LICENSE file that 1560786Sps * accompanied this code). 1660786Sps * 1760786Sps * You should have received a copy of the GNU General Public License version 1860786Sps * 2 along with this work; if not, write to the Free Software Foundation, 1960786Sps * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2060786Sps * 2160786Sps * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2260786Sps * or visit www.oracle.com if you need additional information or have any 23128345Stjr * questions. 2460786Sps */ 2560786Spspackage jdk.tools.jlink.plugin; 2660786Sps 2760786Spsimport java.util.Collections; 2860786Spsimport java.util.EnumSet; 2960786Spsimport java.util.List; 30170256Sdelphijimport java.util.Map; 31170256Sdelphijimport java.util.Set; 3260786Spsimport jdk.tools.jlink.internal.plugins.PluginsResourceBundle; 3360786Sps 34221715Sdelphij/** 35221715Sdelphij * Base interface that jlink plugins should implement. 36221715Sdelphij */ 37221715Sdelphijpublic interface Plugin { 38221715Sdelphij 39221715Sdelphij /** 40221715Sdelphij * Type of plugin. 41221715Sdelphij */ 42221715Sdelphij public interface PluginType { 43221715Sdelphij 44221715Sdelphij public String getName(); 45221715Sdelphij } 46221715Sdelphij 47221715Sdelphij /** 48221715Sdelphij * Order of categories: 49221715Sdelphij * <ol> 50221715Sdelphij * <li>FILTER: Filter in/out resources or files.</li> 51221715Sdelphij * <li>TRANSFORMER: Transform resources or files(eg: refactoring, bytecode 52221715Sdelphij * manipulation).</li> 53221715Sdelphij * <li>MODULEINFO_TRANSFORMER: Transform only module-info.class</li> 54221715Sdelphij * <li>SORTER: Sort resources within the resource container.</li> 55221715Sdelphij * <li>COMPRESSOR: Compress resource within the resouce containers.</li> 56221715Sdelphij * <li>VERIFIER: Does some image verification.</li> 57221715Sdelphij * <li>PROCESSOR: Does some post processing on image.</li> 58221715Sdelphij * <li>PACKAGER: Final processing</li> 59221715Sdelphij * </ol> 60221715Sdelphij */ 61221715Sdelphij public enum CATEGORY implements PluginType { 62221715Sdelphij FILTER("FILTER"), 6360786Sps TRANSFORMER("TRANSFORMER"), 6460786Sps MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"), 6560786Sps SORTER("SORTER"), 6660786Sps COMPRESSOR("COMPRESSOR"), 6760786Sps VERIFIER("VERIFIER"), 6860786Sps PROCESSOR("PROCESSOR"), 6960786Sps PACKAGER("PACKAGER"); 7060786Sps 71128345Stjr private final String name; 7260786Sps 7360786Sps CATEGORY(String name) { 7460786Sps this.name = name; 7560786Sps } 7660786Sps 7760786Sps @Override 7860786Sps public String getName() { 7960786Sps return name; 8060786Sps } 8160786Sps } 8260786Sps 8360786Sps /** 8460786Sps * Plugin state: 8560786Sps * <ul> 8660786Sps * <li>DISABLED: The plugin is not exposed in help and will be not called.</li> 8760786Sps * <li>AUTO_ENABLED: The plugin is enabled by default. It doesn't require its 8860786Sps * option to be present to be called.<li> 8960786Sps * <li>FUNCTIONAL: The plugin is properly configured and can operate. 9060786Sps * Non functional plugin must advertise their status in the 9160786Sps * {@link #getStateDescription() getStateDescription} method</li> 9260786Sps * </ul> 9360786Sps */ 9460786Sps public enum STATE { 9560786Sps DISABLED, 9660786Sps AUTO_ENABLED, 9760786Sps FUNCTIONAL 9860786Sps } 99221715Sdelphij 10060786Sps /** 10160786Sps * The Plugin set of types. 10260786Sps * @return The set of types. 10360786Sps */ 10460786Sps public default Set<PluginType> getType() { 10560786Sps return Collections.emptySet(); 10660786Sps } 10760786Sps 10860786Sps /** 10960786Sps * The Plugin set of states. 11060786Sps * @return The set of states. 11160786Sps */ 11260786Sps public default Set<STATE> getState() { 11360786Sps return EnumSet.of(STATE.FUNCTIONAL); 11460786Sps } 11560786Sps 11660786Sps /** 11760786Sps * The set of plugin names that must be located, within the stack of plugins, 11860786Sps * before this plugin. 11960786Sps * @return The set of names. By default this set is empty. 12060786Sps */ 12160786Sps public default Set<String> isBefore() { 12260786Sps return Collections.emptySet(); 12360786Sps } 12460786Sps 12560786Sps /** 12660786Sps * The set of plugin names that must be located, within the stack of plugins, 12760786Sps * after this plugin. 12860786Sps * @return The set of names. By default this set is empty. 12960786Sps */ 13060786Sps public default Set<String> isAfter() { 13160786Sps return Collections.emptySet(); 13260786Sps } 13360786Sps 13460786Sps /** 13560786Sps * The plugin name. 13660786Sps * @return The name. 13760786Sps */ 13860786Sps public default String getName() { 13960786Sps return getClass().getName().replace('.', '-'); 14060786Sps } 14160786Sps 14260786Sps /** 14360786Sps * The plugin description. 14460786Sps * @return The description. 14560786Sps */ 14660786Sps public default String getDescription() { 14760786Sps return ""; 148128345Stjr } 14989019Sps 15089019Sps /** 15160786Sps * The option that identifies this plugin. This may be null. 15289019Sps * "--" is prefixed to the String (when non-null) when invoking 15360786Sps * this plugin from jlink command line. 15460786Sps * 15560786Sps * @return The plugin option. 15660786Sps */ 15760786Sps public default String getOption() { 15860786Sps return getName(); 15960786Sps } 16060786Sps 16160786Sps /** 16260786Sps * Has this plugin require one or more arguments? 16360786Sps * A plugin can have one or more optional arguments. 164170256Sdelphij * <br> 165170256Sdelphij * A plugin option with a single argument is specified as follows: 166170256Sdelphij * <pre> 167170256Sdelphij * --plugin-option=arg_value 16860786Sps * </pre> 16960786Sps * If there are more than arguments, command line option looks like: 17060786Sps * <pre> 17160786Sps * --plugin-option=arg_value:arg2=value2:arg3=value3... 17260786Sps *</pre> 17360786Sps * 17460786Sps * @return true if arguments are needed. 17560786Sps */ 17660786Sps public default boolean hasArguments() { 17760786Sps return false; 178161475Sdelphij } 17960786Sps 18060786Sps /** 18160786Sps * The plugin argument(s) description. 18260786Sps * @return The argument(s) description. 183161475Sdelphij */ 18460786Sps public default String getArgumentsDescription() { 18560786Sps return ""; 18660786Sps } 18760786Sps 18860786Sps /** 18960786Sps * Return a message indicating the status of the provider. 19060786Sps * 19160786Sps * @return A status description. 19260786Sps */ 19360786Sps public default String getStateDescription() { 19460786Sps return getState().contains(STATE.FUNCTIONAL) 19560786Sps ? PluginsResourceBundle.getMessage("main.status.ok") 19660786Sps : PluginsResourceBundle.getMessage("main.status.not.ok"); 19760786Sps } 19860786Sps 19960786Sps /** 20060786Sps * Configure the plugin based on the passed configuration. 20160786Sps * This method is called prior to invoke the plugin. 20260786Sps * 20360786Sps * @param config The plugin configuration. 20460786Sps */ 20560786Sps public default void configure(Map<String, String> config) { 20660786Sps } 20760786Sps 20860786Sps /** 20960786Sps * Configure the plugin based on the passed configuration. 21060786Sps * This method is called prior to invoke the plugin. 21160786Sps * 21260786Sps * @param config The plugin configuration. 21360786Sps * @param ctx The plugin context 21460786Sps */ 21560786Sps public default void configure(Map<String, String> config, PluginContext ctx) { 21660786Sps configure(config); 21760786Sps } 21860786Sps} 21960786Sps