Package org.apache.maven.plugin.internal
Class DefaultMavenPluginManager
java.lang.Object
org.apache.maven.plugin.internal.DefaultMavenPluginManager
- All Implemented Interfaces:
MavenPluginManager
@Component(role=MavenPluginManager.class)
public class DefaultMavenPluginManager
extends Object
implements MavenPluginManager
Provides basic services to manage Maven plugins and their mojos. This component is kept general in its design such
that the plugins/mojos can be used in arbitrary contexts. In particular, the mojos can be used for ordinary build
plugins as well as special purpose plugins like reports.
- Since:
- 3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate PluginDescriptorBuilderprivate ClassRealmManagerprivate List<MavenPluginConfigurationValidator> private org.codehaus.plexus.PlexusContainerprivate ExtensionDescriptorBuilderprivate ExtensionRealmCachestatic final StringPluginId => ExtensionRealmCache.CacheRecord map MavenProject context value key.private org.codehaus.plexus.logging.Loggerprivate org.codehaus.plexus.logging.LoggerManagerprivate PluginArtifactsCacheprivate PluginDependenciesResolverprivate PluginDescriptorCacheprivate PluginRealmCacheprivate PluginValidationManagerprivate PluginVersionResolverprivate RuntimeInformation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Map<String, ClassLoader> calcImports(MavenProject project, ClassLoader parent, List<String> imports) voidcheckRequiredMavenVersion(PluginDescriptor pluginDescriptor) Verifies the specified plugin is compatible with the current Maven runtime.private voidcreatePluginRealm(PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, Map<String, ClassLoader> foreignImports, org.eclipse.aether.graph.DependencyFilter filter) private voiddiscoverPluginComponents(org.codehaus.plexus.classworlds.realm.ClassRealm pluginRealm, Plugin plugin, PluginDescriptor pluginDescriptor) private PluginDescriptorextractPluginDescriptor(Artifact pluginArtifact, Plugin plugin) <T> TgetConfiguredMojo(Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution) Looks up the mojo for the specified mojo execution and populates its parameters from the configuration given by the mojo execution.getMojoDescriptor(Plugin plugin, String goal, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) Retrieves the descriptor for the specified plugin goal from the plugin's main artifact.getPluginDescriptor(Plugin plugin, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) Retrieves the descriptor for the specified plugin from its main artifact.private Stringprivate PluginDescriptorparsePluginDescriptor(InputStream is, Plugin plugin, String descriptorLocation) private voidpopulateMojoExecutionFields(Object mojo, String executionId, MojoDescriptor mojoDescriptor, org.codehaus.plexus.classworlds.realm.ClassRealm pluginRealm, org.codehaus.plexus.configuration.PlexusConfiguration configuration, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator) voidreleaseMojo(Object mojo, MojoExecution mojoExecution) Releases the specified mojo back to the container.resolveExtensionArtifacts(Plugin extensionPlugin, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) setupExtensionsRealm(MavenProject project, Plugin plugin, org.eclipse.aether.RepositorySystemSession session) Sets up class realm for the specified build extensions plugin.voidsetupPluginRealm(PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, List<String> imports, org.eclipse.aether.graph.DependencyFilter filter) Sets up the class realm for the specified plugin.private List<org.eclipse.aether.artifact.Artifact> toAetherArtifacts(List<Artifact> pluginArtifacts) toMavenArtifacts(org.eclipse.aether.graph.DependencyNode root, org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator nlg) private voidvalidateParameters(MojoDescriptor mojoDescriptor, org.codehaus.plexus.configuration.PlexusConfiguration configuration, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator)
-
Field Details
-
KEY_EXTENSIONS_REALMS
PluginId => ExtensionRealmCache.CacheRecord map MavenProject context value key. The map is used to ensure the same class realm is used to load build extensions and load mojos for extensions=true plugins.
Note: This is part of internal implementation and may be changed or removed without notice- Since:
- 3.3.0
-
logger
@Requirement private org.codehaus.plexus.logging.Logger logger -
loggerManager
@Requirement private org.codehaus.plexus.logging.LoggerManager loggerManager -
container
@Requirement private org.codehaus.plexus.PlexusContainer container -
classRealmManager
-
pluginDescriptorCache
-
pluginRealmCache
-
pluginDependenciesResolver
-
runtimeInformation
-
extensionRealmCache
-
pluginVersionResolver
-
pluginArtifactsCache
-
configurationValidators
-
pluginValidationManager
-
extensionDescriptorBuilder
-
builder
-
-
Constructor Details
-
DefaultMavenPluginManager
public DefaultMavenPluginManager()
-
-
Method Details
-
getPluginDescriptor
public PluginDescriptor getPluginDescriptor(Plugin plugin, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException Description copied from interface:MavenPluginManagerRetrieves the descriptor for the specified plugin from its main artifact.- Specified by:
getPluginDescriptorin interfaceMavenPluginManager- Parameters:
plugin- The plugin whose descriptor should be retrieved, must not benull.repositories- The plugin repositories to use for resolving the plugin's main artifact, must not benull.session- The repository session to use for resolving the plugin's main artifact, must not benull.- Returns:
- The plugin descriptor, never
null. - Throws:
PluginResolutionExceptionPluginDescriptorParsingExceptionInvalidPluginDescriptorException
-
extractPluginDescriptor
private PluginDescriptor extractPluginDescriptor(Artifact pluginArtifact, Plugin plugin) throws PluginDescriptorParsingException, InvalidPluginDescriptorException -
getPluginDescriptorLocation
-
parsePluginDescriptor
private PluginDescriptor parsePluginDescriptor(InputStream is, Plugin plugin, String descriptorLocation) throws PluginDescriptorParsingException - Throws:
PluginDescriptorParsingException
-
getMojoDescriptor
public MojoDescriptor getMojoDescriptor(Plugin plugin, String goal, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException Description copied from interface:MavenPluginManagerRetrieves the descriptor for the specified plugin goal from the plugin's main artifact.- Specified by:
getMojoDescriptorin interfaceMavenPluginManager- Parameters:
plugin- The plugin whose mojo descriptor should be retrieved, must not benull.goal- The simple name of the mojo whose descriptor should be retrieved, must not benull.repositories- The plugin repositories to use for resolving the plugin's main artifact, must not benull.session- The repository session to use for resolving the plugin's main artifact, must not benull.- Returns:
- The mojo descriptor, never
null. - Throws:
MojoNotFoundExceptionPluginResolutionExceptionPluginDescriptorParsingExceptionInvalidPluginDescriptorException
-
checkRequiredMavenVersion
public void checkRequiredMavenVersion(PluginDescriptor pluginDescriptor) throws PluginIncompatibleException Description copied from interface:MavenPluginManagerVerifies the specified plugin is compatible with the current Maven runtime.- Specified by:
checkRequiredMavenVersionin interfaceMavenPluginManager- Parameters:
pluginDescriptor- The descriptor of the plugin to check, must not benull.- Throws:
PluginIncompatibleException
-
setupPluginRealm
public void setupPluginRealm(PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, List<String> imports, org.eclipse.aether.graph.DependencyFilter filter) throws PluginResolutionException, PluginContainerException Description copied from interface:MavenPluginManagerSets up the class realm for the specified plugin. Both the class realm and the plugin artifacts that constitute it will be stored in the plugin descriptor.- Specified by:
setupPluginRealmin interfaceMavenPluginManager- Parameters:
pluginDescriptor- The plugin descriptor in which to save the class realm and the plugin artifacts, must not benull.session- The build session from which to pick the current project and repository settings, must not benull.parent- The parent class realm for the plugin, may benullto use the Maven core realm.imports- The packages/types to import from the parent realm, may benull.filter- The filter used to exclude certain plugin dependencies, may benull.- Throws:
PluginResolutionExceptionPluginContainerException
-
createPluginRealm
private void createPluginRealm(PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, Map<String, ClassLoader> foreignImports, org.eclipse.aether.graph.DependencyFilter filter) throws PluginResolutionException, PluginContainerException -
discoverPluginComponents
private void discoverPluginComponents(org.codehaus.plexus.classworlds.realm.ClassRealm pluginRealm, Plugin plugin, PluginDescriptor pluginDescriptor) throws PluginContainerException - Throws:
PluginContainerException
-
toAetherArtifacts
-
toMavenArtifacts
-
calcImports
private Map<String,ClassLoader> calcImports(MavenProject project, ClassLoader parent, List<String> imports) -
getConfiguredMojo
public <T> T getConfiguredMojo(Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution) throws PluginConfigurationException, PluginContainerException Description copied from interface:MavenPluginManagerLooks up the mojo for the specified mojo execution and populates its parameters from the configuration given by the mojo execution. The mojo/plugin descriptor associated with the mojo execution provides the class realm to lookup the mojo from. Warning: The returned mojo instance must be released viaMavenPluginManager.releaseMojo(Object, MojoExecution)when the mojo is no longer needed to free any resources allocated for it.- Specified by:
getConfiguredMojoin interfaceMavenPluginManager- Parameters:
mojoInterface- The component role of the mojo, must not benull.session- The build session in whose context the mojo will be used, must not benull.mojoExecution- The mojo execution to retrieve the mojo for, must not benull.- Returns:
- The ready-to-execute mojo, never
null. - Throws:
PluginConfigurationExceptionPluginContainerException
-
populateMojoExecutionFields
private void populateMojoExecutionFields(Object mojo, String executionId, MojoDescriptor mojoDescriptor, org.codehaus.plexus.classworlds.realm.ClassRealm pluginRealm, org.codehaus.plexus.configuration.PlexusConfiguration configuration, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator) throws PluginConfigurationException - Throws:
PluginConfigurationException
-
validateParameters
private void validateParameters(MojoDescriptor mojoDescriptor, org.codehaus.plexus.configuration.PlexusConfiguration configuration, org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator expressionEvaluator) throws org.codehaus.plexus.component.configurator.ComponentConfigurationException, PluginParameterException - Throws:
org.codehaus.plexus.component.configurator.ComponentConfigurationExceptionPluginParameterException
-
releaseMojo
Description copied from interface:MavenPluginManagerReleases the specified mojo back to the container.- Specified by:
releaseMojoin interfaceMavenPluginManager- Parameters:
mojo- The mojo to release, may benull.mojoExecution- The mojo execution the mojo was originally retrieved for, must not benull.
-
setupExtensionsRealm
public ExtensionRealmCache.CacheRecord setupExtensionsRealm(MavenProject project, Plugin plugin, org.eclipse.aether.RepositorySystemSession session) throws PluginManagerException Description copied from interface:MavenPluginManagerSets up class realm for the specified build extensions plugin.- Specified by:
setupExtensionsRealmin interfaceMavenPluginManager- Throws:
PluginManagerException
-
resolveExtensionArtifacts
private List<Artifact> resolveExtensionArtifacts(Plugin extensionPlugin, List<org.eclipse.aether.repository.RemoteRepository> repositories, org.eclipse.aether.RepositorySystemSession session) throws PluginResolutionException - Throws:
PluginResolutionException
-