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.apache.maven.project.MavenProject; 29 import org.eclipse.aether.RepositorySystemSession; 30 import org.eclipse.aether.graph.DependencyFilter; 31 import org.eclipse.aether.repository.RemoteRepository; 32 33 /** 34 * Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such 35 * that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build 36 * plugins as well as special purpose plugins like reports. 37 * 38 * @since 3.0 39 * @author Benjamin Bentmann 40 */ 41 public interface MavenPluginManager 42 { 43 44 /** 45 * Retrieves the descriptor for the specified plugin from its main artifact. 46 * 47 * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}. 48 * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code 49 * null}. 50 * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}. 51 * @return The plugin descriptor, never {@code null}. 52 */ 53 PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, 54 RepositorySystemSession session ) 55 throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException; 56 57 /** 58 * Retrieves the descriptor for the specified plugin goal from the plugin's main artifact. 59 * 60 * @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}. 61 * @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}. 62 * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code 63 * null}. 64 * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}. 65 * @return The mojo descriptor, never {@code null}. 66 */ 67 MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories, 68 RepositorySystemSession session ) 69 throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, 70 InvalidPluginDescriptorException; 71 72 /** 73 * Verifies the specified plugin is compatible with the current Maven runtime. 74 * 75 * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}. 76 */ 77 void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor ) 78 throws PluginIncompatibleException; 79 80 /** 81 * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute 82 * it will be stored in the plugin descriptor. 83 * 84 * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not 85 * be {@code null}. 86 * @param session The build session from which to pick the current project and repository settings, must not be 87 * {@code null}. 88 * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm. 89 * @param imports The packages/types to import from the parent realm, may be {@code null}. 90 * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}. 91 */ 92 void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, 93 List<String> imports, 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( MavenProject project, Plugin plugin, 102 RepositorySystemSession session ) 103 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 128 }