View Javadoc
1   package org.apache.maven.plugin;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.List;
23  
24  import org.apache.maven.execution.MavenSession;
25  import org.apache.maven.model.Plugin;
26  import org.apache.maven.plugin.descriptor.MojoDescriptor;
27  import org.apache.maven.plugin.descriptor.PluginDescriptor;
28  import org.eclipse.aether.RepositorySystemSession;
29  import org.eclipse.aether.graph.DependencyFilter;
30  import org.eclipse.aether.repository.RemoteRepository;
31  
32  /**
33   * Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
34   * that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build
35   * plugins as well as special purpose plugins like reports.
36   *
37   * @since 3.0
38   * @author Benjamin Bentmann
39   */
40  public interface MavenPluginManager
41  {
42  
43      /**
44       * Retrieves the descriptor for the specified plugin from its main artifact.
45       *
46       * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
47       * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
48       *            null}.
49       * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
50       * @return The plugin descriptor, never {@code null}.
51       */
52      PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session )
53          throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
54  
55      /**
56       * Retrieves the descriptor for the specified plugin goal from the plugin's main artifact.
57       *
58       * @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}.
59       * @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}.
60       * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
61       *            null}.
62       * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
63       * @return The mojo descriptor, never {@code null}.
64       */
65      MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories,
66                                        RepositorySystemSession session )
67          throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
68          InvalidPluginDescriptorException;
69  
70      /**
71       * Verifies the specified plugin is compatible with the current Maven runtime.
72       *
73       * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}.
74       */
75      void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor )
76          throws PluginIncompatibleException;
77  
78      /**
79       * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute
80       * it will be stored in the plugin descriptor.
81       *
82       * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not
83       *            be {@code null}.
84       * @param session The build session from which to pick the current project and repository settings, must not be
85       *            {@code null}.
86       * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
87       * @param imports The packages/types to import from the parent realm, may be {@code null}.
88       * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
89       */
90      void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
91                             List<String> imports, DependencyFilter filter )
92          throws PluginResolutionException, PluginContainerException;
93  
94      /**
95       * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by
96       * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to
97       * lookup the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via
98       * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for
99       * 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 }