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   */
39  public interface MavenPluginManager {
40  
41      /**
42       * Retrieves the descriptor for the specified plugin from its main artifact.
43       *
44       * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}.
45       * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
46       *            null}.
47       * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
48       * @return The plugin descriptor, never {@code null}.
49       */
50      PluginDescriptor getPluginDescriptor(
51              Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session)
52              throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException;
53  
54      /**
55       * Retrieves the descriptor for the specified plugin goal from the plugin's main artifact.
56       *
57       * @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}.
58       * @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}.
59       * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code
60       *            null}.
61       * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}.
62       * @return The mojo descriptor, never {@code null}.
63       */
64      MojoDescriptor getMojoDescriptor(
65              Plugin plugin, String goal, List<RemoteRepository> repositories, RepositorySystemSession session)
66              throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
67                      InvalidPluginDescriptorException;
68  
69      /**
70       * Verifies the specified plugin is compatible with the current Maven runtime.
71       *
72       * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}.
73       * @deprecated Use {@link #checkPrerequisites(PluginDescriptor)} instead.
74       */
75      @Deprecated
76      void checkRequiredMavenVersion(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException;
77  
78      /**
79       * Verifies that the specified plugin's prerequisites are met.
80       *
81       * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}.
82       * @since 4.0.0
83       */
84      void checkPrerequisites(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException;
85  
86      /**
87       * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute
88       * it will be stored in the plugin descriptor.
89       *
90       * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not
91       *            be {@code null}.
92       * @param session The build session from which to pick the current project and repository settings, must not be
93       *            {@code null}.
94       * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm.
95       * @param imports The packages/types to import from the parent realm, may be {@code null}.
96       * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}.
97       */
98      void setupPluginRealm(
99              PluginDescriptor pluginDescriptor,
100             MavenSession session,
101             ClassLoader parent,
102             List<String> imports,
103             DependencyFilter filter)
104             throws PluginResolutionException, PluginContainerException;
105 
106     /**
107      * Sets up class realm for the specified build extensions plugin.
108      *
109      * @since 3.3.0
110      */
111     ExtensionRealmCache.CacheRecord setupExtensionsRealm(
112             MavenProject project, Plugin plugin, RepositorySystemSession session) throws PluginManagerException;
113 
114     /**
115      * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by
116      * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to
117      * look up the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via
118      * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for
119      * it.
120      *
121      * @param mojoInterface The component role of the mojo, must not be {@code null}.
122      * @param session The build session in whose context the mojo will be used, must not be {@code null}.
123      * @param mojoExecution The mojo execution to retrieve the mojo for, must not be {@code null}.
124      * @return The ready-to-execute mojo, never {@code null}.
125      */
126     <T> T getConfiguredMojo(Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution)
127             throws PluginConfigurationException, PluginContainerException;
128 
129     /**
130      * Releases the specified mojo back to the container.
131      *
132      * @param mojo The mojo to release, may be {@code null}.
133      * @param mojoExecution The mojo execution the mojo was originally retrieved for, must not be {@code null}.
134      */
135     void releaseMojo(Object mojo, MojoExecution mojoExecution);
136 }