/* * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package jdk.tools.jlink.plugin; import java.util.Collections; import java.util.EnumSet; import java.util.Map; import java.util.Set; import jdk.tools.jlink.internal.plugins.PluginsResourceBundle; /** * Base interface that jlink plugins should implement. */ public interface Plugin { /** * Order of categories: *
    *
  1. FILTER: Filter in/out resources or files.
  2. *
  3. TRANSFORMER: Transform resources or files(eg: refactoring, bytecode * manipulation).
  4. *
  5. MODULEINFO_TRANSFORMER: Transform only module-info.class
  6. *
  7. SORTER: Sort resources within the resource container.
  8. *
  9. COMPRESSOR: Compress resource within the resouce containers.
  10. *
  11. METAINFO_ADDER: Added meta info (like release, copyright etc.)
  12. *
  13. VERIFIER: Does some image verification.
  14. *
  15. PROCESSOR: Does some post processing on image.
  16. *
  17. PACKAGER: Final processing
  18. *
*/ public enum Category { FILTER("FILTER"), TRANSFORMER("TRANSFORMER"), MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"), SORTER("SORTER"), COMPRESSOR("COMPRESSOR"), METAINFO_ADDER("METAINFO_ADDER"), VERIFIER("VERIFIER"), PROCESSOR("PROCESSOR"), PACKAGER("PACKAGER"); private final String name; Category(String name) { this.name = name; } public String getName() { return name; } } /** * Plugin state: * */ public enum State { DISABLED, AUTO_ENABLED, FUNCTIONAL } /** * The type of this plugin. * * @return The type of this plugin */ public default Category getType() { return Category.TRANSFORMER; } /** * The Plugin set of states. * @return The set of states. */ public default Set getState() { return EnumSet.of(State.FUNCTIONAL); } /** * The plugin name. * @return The name. */ public default String getName() { return getClass().getName().replace('.', '-'); } /** * The plugin description. * @return The description. */ public default String getDescription() { return ""; } /** * The option that identifies this plugin. This may be null. * "--" is prefixed to the String (when non-null) when invoking * this plugin from jlink command line. * * @return The plugin option. */ public default String getOption() { return getName(); } /** * Has this plugin require one or more arguments? * A plugin can have one or more optional arguments. *
* A plugin option with a single argument is specified as follows: *
     *     --plugin-option=arg_value
     * 
* If there are more than arguments, command line option looks like: *
     *     --plugin-option=arg_value:arg2=value2:arg3=value3...
     *
* * @return true if arguments are needed. */ public default boolean hasArguments() { return false; } /** * The plugin argument(s) description. * @return The argument(s) description. */ public default String getArgumentsDescription() { return ""; } /** * Return a message indicating the status of the provider. * * @return A status description. */ public default String getStateDescription() { return getState().contains(State.FUNCTIONAL) ? PluginsResourceBundle.getMessage("main.status.ok") : PluginsResourceBundle.getMessage("main.status.not.ok"); } /** * Configure the plugin based on the passed configuration. * This method is called prior to invoke the plugin. * * @param config The plugin configuration. * @throws IllegalArgumentException if a mandatory argument is missing or * if an argument has invalid value. */ public default void configure(Map config) { } /** * Visit the content of the modules that are composing the image. * * @param in Read only content. * @param out The pool to fill with content. This pool must contain * the result of the visit. * * @throws PluginException */ public void visit(ModulePool in, ModulePool out); }