View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin;
20  
21  import java.util.List;
22  
23  import org.apache.maven.execution.MavenSession;
24  import org.apache.maven.model.Plugin;
25  import org.apache.maven.plugin.descriptor.MojoDescriptor;
26  import org.apache.maven.plugin.descriptor.PluginDescriptor;
27  import org.apache.maven.project.MavenProject;
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       * Retrieves the descriptor for the specified plugin from its main artifact.
44       *
45       * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
46       * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
47       *            null}.
48       * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
49       * @return The plugin descriptor, never {@code null}.
50       */
51      PluginDescriptor getPluginDescriptor(
52              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(
66              Plugin plugin, String goal, List<RemoteRepository> repositories, 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       * @deprecated Use {@link #checkPrerequisites(PluginDescriptor)} instead.
75       */
76      @Deprecated
77      void checkRequiredMavenVersion(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException;
78  
79      /**
80       * Verifies that the specified plugin's prerequisites are met.
81       *
82       * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}.
83       * @since 4.0.0
84       */
85      void checkPrerequisites(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException;
86  
87      /**
88       * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute
89       * it will be stored in the plugin descriptor.
90       *
91       * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not
92       *            be {@code null}.
93       * @param session The build session from which to pick the current project and repository settings, must not be
94       *            {@code null}.
95       * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
96       * @param imports The packages/types to import from the parent realm, may be {@code null}.
97       * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
98       */
99      void setupPluginRealm(
100             PluginDescriptor pluginDescriptor,
101             MavenSession session,
102             ClassLoader parent,
103             List<String> imports,
104             DependencyFilter filter)
105             throws PluginResolutionException, PluginContainerException;
106 
107     /**
108      * Sets up class realm for the specified build extensions plugin.
109      *
110      * @since 3.3.0
111      */
112     ExtensionRealmCache.CacheRecord setupExtensionsRealm(
113             MavenProject project, Plugin plugin, RepositorySystemSession session) throws PluginManagerException;
114 
115     /**
116      * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by
117      * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to
118      * look up the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via
119      * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for
120      * it.
121      *
122      * @param mojoInterface The component role of the mojo, must not be {@code null}.
123      * @param session The build session in whose context the mojo will be used, must not be {@code null}.
124      * @param mojoExecution The mojo execution to retrieve the mojo for, must not be {@code null}.
125      * @return The ready-to-execute mojo, never {@code null}.
126      */
127     <T> T getConfiguredMojo(Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution)
128             throws PluginConfigurationException, PluginContainerException;
129 
130     /**
131      * Releases the specified mojo back to the container.
132      *
133      * @param mojo The mojo to release, may be {@code null}.
134      * @param mojoExecution The mojo execution the mojo was originally retrieved for, must not be {@code null}.
135      */
136     void releaseMojo(Object mojo, MojoExecution mojoExecution);
137 }