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