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.sonatype.aether.RepositorySystemSession;
29  import org.sonatype.aether.graph.DependencyFilter;
30  import org.sonatype.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       * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute
72       * it will be stored in the plugin descriptor.
73       * 
74       * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not
75       *            be {@code null}.
76       * @param session The build session from which to pick the current project and repository settings, must not be
77       *            {@code null}.
78       * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
79       * @param imports The packages/types to import from the parent realm, may be {@code null}.
80       * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
81       */
82      void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent,
83                             List<String> imports, DependencyFilter filter )
84          throws PluginResolutionException, PluginContainerException;
85  
86      /**
87       * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by
88       * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to
89       * lookup the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via
90       * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for
91       * it.
92       * 
93       * @param mojoInterface The component role of the mojo, must not be {@code null}.
94       * @param session The build session in whose context the mojo will be used, must not be {@code null}.
95       * @param mojoExecution The mojo execution to retrieve the mojo for, must not be {@code null}.
96       * @return The ready-to-execute mojo, never {@code null}.
97       */
98      <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution )
99          throws PluginConfigurationException, PluginContainerException;
100 
101     /**
102      * Releases the specified mojo back to the container.
103      * 
104      * @param mojo The mojo to release, may be {@code null}.
105      * @param mojoExecution The mojo execution the mojo was originally retrieved for, must not be {@code null}.
106      */
107     void releaseMojo( Object mojo, MojoExecution mojoExecution );
108 
109 }