001package org.apache.maven.plugin; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.List; 023 024import org.apache.maven.execution.MavenSession; 025import org.apache.maven.model.Plugin; 026import org.apache.maven.plugin.descriptor.MojoDescriptor; 027import org.apache.maven.plugin.descriptor.PluginDescriptor; 028import org.apache.maven.project.MavenProject; 029import org.eclipse.aether.RepositorySystemSession; 030import org.eclipse.aether.graph.DependencyFilter; 031import org.eclipse.aether.repository.RemoteRepository; 032 033/** 034 * Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such 035 * that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build 036 * plugins as well as special purpose plugins like reports. 037 * 038 * @since 3.0 039 * @author Benjamin Bentmann 040 */ 041public interface MavenPluginManager 042{ 043 044 /** 045 * Retrieves the descriptor for the specified plugin from its main artifact. 046 * 047 * @param plugin The plugin whose descriptor should be retrieved, must not be {@code null}. 048 * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code 049 * null}. 050 * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}. 051 * @return The plugin descriptor, never {@code null}. 052 */ 053 PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, 054 RepositorySystemSession session ) 055 throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException; 056 057 /** 058 * Retrieves the descriptor for the specified plugin goal from the plugin's main artifact. 059 * 060 * @param plugin The plugin whose mojo descriptor should be retrieved, must not be {@code null}. 061 * @param goal The simple name of the mojo whose descriptor should be retrieved, must not be {@code null}. 062 * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code 063 * null}. 064 * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}. 065 * @return The mojo descriptor, never {@code null}. 066 */ 067 MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories, 068 RepositorySystemSession session ) 069 throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, 070 InvalidPluginDescriptorException; 071 072 /** 073 * Verifies the specified plugin is compatible with the current Maven runtime. 074 * 075 * @param pluginDescriptor The descriptor of the plugin to check, must not be {@code null}. 076 */ 077 void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor ) 078 throws PluginIncompatibleException; 079 080 /** 081 * Sets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute 082 * it will be stored in the plugin descriptor. 083 * 084 * @param pluginDescriptor The plugin descriptor in which to save the class realm and the plugin artifacts, must not 085 * be {@code null}. 086 * @param session The build session from which to pick the current project and repository settings, must not be 087 * {@code null}. 088 * @param parent The parent class realm for the plugin, may be {@code null} to use the Maven core realm. 089 * @param imports The packages/types to import from the parent realm, may be {@code null}. 090 * @param filter The filter used to exclude certain plugin dependencies, may be {@code null}. 091 */ 092 void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, 093 List<String> imports, DependencyFilter filter ) 094 throws PluginResolutionException, PluginContainerException; 095 096 /** 097 * Sets up class realm for the specified build extensions plugin. 098 * 099 * @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}