001package org.apache.maven.plugin;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.List;
023
024import org.apache.maven.execution.MavenSession;
025import org.apache.maven.model.Plugin;
026import org.apache.maven.plugin.descriptor.MojoDescriptor;
027import org.apache.maven.plugin.descriptor.PluginDescriptor;
028import org.eclipse.aether.RepositorySystemSession;
029import org.eclipse.aether.graph.DependencyFilter;
030import org.eclipse.aether.repository.RemoteRepository;
031
032/**
033 * Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
034 * that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build
035 * plugins as well as special purpose plugins like reports.
036 * 
037 * @since 3.0
038 * @author Benjamin Bentmann
039 */
040public interface MavenPluginManager
041{
042
043    /**
044     * Retrieves the descriptor for the specified plugin from its main artifact.
045     * 
046     * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
047     * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
048     *            null}.
049     * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
050     * @return The plugin descriptor, never {@code null}.
051     */
052    PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
053        throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
054
055    /**
056     * Retrieves the descriptor for the specified plugin goal from the plugin's main artifact.
057     * 
058     * @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}.
059     * @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}.
060     * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
061     *            null}.
062     * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
063     * @return The mojo descriptor, never {@code null}.
064     */
065    MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
066                                      RepositorySystemSession session )
067        throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
068        InvalidPluginDescriptorException;
069
070    /**
071     * Verifies the specified plugin is compatible with the current Maven runtime.
072     * 
073     * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}.
074     */
075    void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor )
076        throws PluginIncompatibleException;
077
078    /**
079     * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute
080     * it will be stored in the plugin descriptor.
081     * 
082     * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not
083     *            be {@code null}.
084     * @param session The build session from which to pick the current project and repository settings, must not be
085     *            {@code null}.
086     * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
087     * @param imports The packages/types to import from the parent realm, may be {@code null}.
088     * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
089     */
090    void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
091                           List<String> imports, DependencyFilter filter )
092        throws PluginResolutionException, PluginContainerException;
093
094    /**
095     * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by
096     * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to
097     * lookup the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via
098     * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for
099     * it.
100     * 
101     * @param mojoInterface The component role of the mojo, must not be {@code null}.
102     * @param session The build session in whose context the mojo will be used, must not be {@code null}.
103     * @param mojoExecution The mojo execution to retrieve the mojo for, must not be {@code null}.
104     * @return The ready-to-execute mojo, never {@code null}.
105     */
106    <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution )
107        throws PluginConfigurationException, PluginContainerException;
108
109    /**
110     * Releases the specified mojo back to the container.
111     * 
112     * @param mojo The mojo to release, may be {@code null}.
113     * @param mojoExecution The mojo execution the mojo was originally retrieved for, must not be {@code null}.
114     */
115    void releaseMojo( Object mojo, MojoExecution mojoExecution );
116
117}