jdk/src/jdk.jlink/share/classes/jdk/tools/jlink/plugin/Plugin.java
author sundar
Mon, 16 May 2016 14:47:27 +0530
changeset 38320 e24c7029e8ba
parent 37779 7c84df693837
child 39129 4b2086305b68
permissions -rw-r--r--
8156914: jlink API minor cleanups Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     1
/*
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     4
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    10
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    15
 * accompanied this code).
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    16
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    20
 *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    23
 * questions.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    24
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    25
package jdk.tools.jlink.plugin;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    26
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    27
import java.util.Collections;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    28
import java.util.EnumSet;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    29
import java.util.Map;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    30
import java.util.Set;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    31
import jdk.tools.jlink.internal.plugins.PluginsResourceBundle;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    32
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    33
/**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    34
 * Base interface that jlink plugins should implement.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    35
 */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    36
public interface Plugin {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    37
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    38
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    39
     * Order of categories:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    40
     * <ol>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    41
     * <li>FILTER: Filter in/out resources or files.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    42
     * <li>TRANSFORMER: Transform resources or files(eg: refactoring, bytecode
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    43
     * manipulation).</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    44
     * <li>MODULEINFO_TRANSFORMER: Transform only module-info.class</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    45
     * <li>SORTER: Sort resources within the resource container.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    46
     * <li>COMPRESSOR: Compress resource within the resouce containers.</li>
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    47
     * <li>METAINFO_ADDER: Added meta info (like release, copyright etc.)</li>
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    48
     * <li>VERIFIER: Does some image verification.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    49
     * <li>PROCESSOR: Does some post processing on image.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    50
     * <li>PACKAGER: Final processing</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    51
     * </ol>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    52
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    53
    public enum Category {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    54
        FILTER("FILTER"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    55
        TRANSFORMER("TRANSFORMER"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    56
        MODULEINFO_TRANSFORMER("MODULEINFO_TRANSFORMER"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    57
        SORTER("SORTER"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    58
        COMPRESSOR("COMPRESSOR"),
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    59
        METAINFO_ADDER("METAINFO_ADDER"),
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    60
        VERIFIER("VERIFIER"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    61
        PROCESSOR("PROCESSOR"),
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    62
        PACKAGER("PACKAGER");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    63
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    64
        private final String name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    65
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    66
        Category(String name) {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    67
            this.name = name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    68
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    69
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    70
        public String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    71
            return name;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    72
        }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    73
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    74
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    75
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    76
     * Plugin state:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    77
     * <ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    78
     * <li>DISABLED: The plugin is not exposed in help and will be not called.</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    79
     * <li>AUTO_ENABLED: The plugin is enabled by default. It doesn't require its
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    80
     * option to be present to be called.<li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    81
     * <li>FUNCTIONAL: The plugin is properly configured and can operate.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    82
     * Non functional plugin must advertise their status in the
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    83
     * {@link #getStateDescription() getStateDescription} method</li>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    84
     * </ul>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    85
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    86
    public enum State {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    87
        DISABLED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    88
        AUTO_ENABLED,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    89
        FUNCTIONAL
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    90
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    91
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    92
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    93
     * The Plugin set of types.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    94
     * @return The set of types.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    95
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
    96
    public default Set<Category> getType() {
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    97
        return Collections.emptySet();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    98
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
    99
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   100
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   101
     * The Plugin set of states.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   102
     * @return The set of states.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   103
     */
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   104
    public default Set<State> getState() {
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   105
        return EnumSet.of(State.FUNCTIONAL);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   106
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   107
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   108
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   109
     * The set of plugin names that must be located, within the stack of plugins,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   110
     * before this plugin.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   111
     * @return The set of names. By default this set is empty.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   112
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   113
    public default Set<String> isBefore() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   114
        return Collections.emptySet();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   115
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   116
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   117
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   118
     * The set of plugin names that must be located, within the stack of plugins,
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   119
     * after this plugin.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   120
     * @return The set of names. By default this set is empty.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   121
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   122
    public default Set<String> isAfter() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   123
        return Collections.emptySet();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   124
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   125
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   126
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   127
     * The plugin name.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   128
     * @return The name.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   129
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   130
    public default String getName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   131
        return getClass().getName().replace('.', '-');
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   132
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   133
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   134
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   135
     * The plugin description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   136
     * @return  The description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   137
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   138
    public default String getDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   139
        return "";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   140
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   141
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   142
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   143
     * The option that identifies this plugin. This may be null.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   144
     * "--" is prefixed to the String (when non-null) when invoking
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   145
     * this plugin from jlink command line.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   146
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   147
     * @return The plugin option.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   148
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   149
    public default String getOption() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   150
        return getName();
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   151
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   152
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   153
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   154
     * Has this plugin require one or more arguments?
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   155
     * A plugin can have one or more optional arguments.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   156
     * <br>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   157
     * A plugin option with a single argument is specified as follows:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   158
     * <pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   159
     *     --plugin-option=arg_value
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   160
     * </pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   161
     * If there are more than arguments, command line option looks like:
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   162
     * <pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   163
     *     --plugin-option=arg_value:arg2=value2:arg3=value3...
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   164
     *</pre>
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   165
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   166
     * @return true if arguments are needed.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   167
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   168
    public default boolean hasArguments() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   169
        return false;
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   170
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   171
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   172
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   173
     * The plugin argument(s) description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   174
     * @return  The argument(s) description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   175
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   176
    public default String getArgumentsDescription() {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   177
        return "";
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   178
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   179
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   180
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   181
     * Return a message indicating the status of the provider.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   182
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   183
     * @return A status description.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   184
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   185
    public default String getStateDescription() {
38320
e24c7029e8ba 8156914: jlink API minor cleanups
sundar
parents: 37779
diff changeset
   186
        return getState().contains(State.FUNCTIONAL)
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   187
                ? PluginsResourceBundle.getMessage("main.status.ok")
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   188
                : PluginsResourceBundle.getMessage("main.status.not.ok");
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   189
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   190
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   191
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   192
     * Configure the plugin based on the passed configuration.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   193
     * This method is called prior to invoke the plugin.
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   194
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   195
     * @param config The plugin configuration.
37779
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   196
     * @throws IllegalArgumentException if a mandatory argument is missing or
7c84df693837 8154956: Module system implementation refresh (4/2016)
alanb
parents: 36511
diff changeset
   197
     * if an argument has invalid value.
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   198
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   199
    public default void configure(Map<String, String> config) {
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   200
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents:
diff changeset
   201
}