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 import org.apache.maven.execution.MavenSession; 23 import org.apache.maven.model.Plugin; 24 import org.apache.maven.plugin.descriptor.MojoDescriptor; 25 import org.apache.maven.plugin.descriptor.PluginDescriptor; 26 import org.apache.maven.project.MavenProject; 27 import org.eclipse.aether.RepositorySystemSession; 28 import org.eclipse.aether.graph.DependencyFilter; 29 import org.eclipse.aether.repository.RemoteRepository; 30 31 /** 32 * Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such 33 * that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build 34 * plugins as well as special purpose plugins like reports. 35 * 36 * @since 3.0 37 * @author Benjamin Bentmann 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 that the specified plugin's prerequisites are met. 71 * 72 * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}. 73 */ 74 void checkPrerequisites(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException; 75 76 /** 77 * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute 78 * it will be stored in the plugin descriptor. 79 * 80 * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not 81 * be {@code null}. 82 * @param session The build session from which to pick the current project and repository settings, must not be 83 * {@code null}. 84 * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm. 85 * @param imports The packages/types to import from the parent realm, may be {@code null}. 86 * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}. 87 */ 88 void setupPluginRealm( 89 PluginDescriptor pluginDescriptor, 90 MavenSession session, 91 ClassLoader parent, 92 List<String> imports, 93 DependencyFilter filter) 94 throws PluginResolutionException, PluginContainerException; 95 96 /** 97 * Sets up class realm for the specified build extensions plugin. 98 * 99 * @since 3.3.0 100 */ 101 ExtensionRealmCache.CacheRecord setupExtensionsRealm( 102 MavenProject project, Plugin plugin, RepositorySystemSession session) throws PluginManagerException; 103 104 /** 105 * Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by 106 * the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to 107 * look up the mojo from. <strong>Warning:</strong> The returned mojo instance must be released via 108 * {@link #releaseMojo(Object, MojoExecution)} when the mojo is no longer needed to free any resources allocated for 109 * it. 110 * 111 * @param mojoInterface The component role of the mojo, must not be {@code null}. 112 * @param session The build session in whose context the mojo will be used, must not be {@code null}. 113 * @param mojoExecution The mojo execution to retrieve the mojo for, must not be {@code null}. 114 * @return The ready-to-execute mojo, never {@code null}. 115 */ 116 <T> T getConfiguredMojo(Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution) 117 throws PluginConfigurationException, PluginContainerException; 118 119 /** 120 * Releases the specified mojo back to the container. 121 * 122 * @param mojo The mojo to release, may be {@code null}. 123 * @param mojoExecution The mojo execution the mojo was originally retrieved for, must not be {@code null}. 124 */ 125 void releaseMojo(Object mojo, MojoExecution mojoExecution); 126 }