diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal')
9 files changed, 0 insertions, 2059 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java deleted file mode 100644 index f397c1e8..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.concurrent.atomic.AtomicReference; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.LegacySupport; -import org.codehaus.plexus.component.annotations.Component; -import org.eclipse.aether.RepositorySystemSession; - -/** - * Helps to provide backward-compatibility with plugins that use legacy components. <strong>Warning:</strong> This is an - * internal utility component that is only public for technical reasons, it is not part of the public API. In - * particular, this component can be changed or deleted without prior notice. - * - * @since 3.0 - * @author Benjamin Bentmann - */ -@Component( role = LegacySupport.class ) -public class DefaultLegacySupport - implements LegacySupport -{ - - private static final ThreadLocal<AtomicReference<MavenSession>> SESSION = - new InheritableThreadLocal<AtomicReference<MavenSession>>(); - - public void setSession( MavenSession session ) - { - AtomicReference<MavenSession> reference = DefaultLegacySupport.SESSION.get(); - if ( reference != null ) - { - reference.set( null ); - } - - if ( session == null && reference != null ) - { - DefaultLegacySupport.SESSION.remove(); - } - else - { - DefaultLegacySupport.SESSION.set( new AtomicReference<MavenSession>( session ) ); - } - } - - public MavenSession getSession() - { - AtomicReference<MavenSession> currentSession = DefaultLegacySupport.SESSION.get(); - return currentSession != null ? currentSession.get() : null; - } - - public RepositorySystemSession getRepositorySession() - { - MavenSession session = getSession(); - return ( session != null ) ? session.getRepositorySession() : null; - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java deleted file mode 100644 index d32e04c1..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java +++ /dev/null @@ -1,946 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.PrintStream; -import java.io.Reader; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.classrealm.ClassRealmManager; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.execution.scope.internal.MojoExecutionScopeModule; -import org.apache.maven.model.Plugin; -import org.apache.maven.monitor.logging.DefaultLog; -import org.apache.maven.plugin.ContextEnabled; -import org.apache.maven.plugin.DebugConfigurationListener; -import org.apache.maven.plugin.ExtensionRealmCache; -import org.apache.maven.plugin.InvalidPluginDescriptorException; -import org.apache.maven.plugin.MavenPluginManager; -import org.apache.maven.plugin.MavenPluginValidator; -import org.apache.maven.plugin.Mojo; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoNotFoundException; -import org.apache.maven.plugin.PluginArtifactsCache; -import org.apache.maven.plugin.PluginConfigurationException; -import org.apache.maven.plugin.PluginContainerException; -import org.apache.maven.plugin.PluginDescriptorCache; -import org.apache.maven.plugin.PluginDescriptorParsingException; -import org.apache.maven.plugin.PluginIncompatibleException; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.PluginParameterException; -import org.apache.maven.plugin.PluginParameterExpressionEvaluator; -import org.apache.maven.plugin.PluginRealmCache; -import org.apache.maven.plugin.PluginResolutionException; -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; -import org.apache.maven.plugin.version.DefaultPluginVersionRequest; -import org.apache.maven.plugin.version.PluginVersionRequest; -import org.apache.maven.plugin.version.PluginVersionResolutionException; -import org.apache.maven.plugin.version.PluginVersionResolver; -import org.apache.maven.project.ExtensionDescriptor; -import org.apache.maven.project.ExtensionDescriptorBuilder; -import org.apache.maven.project.MavenProject; -import org.apache.maven.rtinfo.RuntimeInformation; -import org.apache.maven.session.scope.internal.SessionScopeModule; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.classworlds.realm.ClassRealm; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.component.repository.ComponentDescriptor; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.PlexusConfigurationException; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.logging.LoggerManager; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.util.filter.AndDependencyFilter; -import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator; - -/** - * 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 - * @author Benjamin Bentmann - */ -@Component( role = MavenPluginManager.class ) -public class DefaultMavenPluginManager - implements MavenPluginManager -{ - - /** - * 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. - * - * @noreference this is part of internal implementation and may be changed or removed without notice - * @since 3.3.0 - */ - public static final String KEY_EXTENSIONS_REALMS = DefaultMavenPluginManager.class.getName() + "/extensionsRealms"; - - @Requirement - private Logger logger; - - @Requirement - private LoggerManager loggerManager; - - @Requirement - private PlexusContainer container; - - @Requirement - private ClassRealmManager classRealmManager; - - @Requirement - private PluginDescriptorCache pluginDescriptorCache; - - @Requirement - private PluginRealmCache pluginRealmCache; - - @Requirement - private PluginDependenciesResolver pluginDependenciesResolver; - - @Requirement - private RuntimeInformation runtimeInformation; - - @Requirement - private ExtensionRealmCache extensionRealmCache; - - @Requirement - private PluginVersionResolver pluginVersionResolver; - - @Requirement - private PluginArtifactsCache pluginArtifactsCache; - - private ExtensionDescriptorBuilder extensionDescriptorBuilder = new ExtensionDescriptorBuilder(); - - private PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); - - public synchronized PluginDescriptor getPluginDescriptor( Plugin plugin, List<RemoteRepository> repositories, - RepositorySystemSession session ) - throws PluginResolutionException, PluginDescriptorParsingException, InvalidPluginDescriptorException - { - PluginDescriptorCache.Key cacheKey = pluginDescriptorCache.createKey( plugin, repositories, session ); - - PluginDescriptor pluginDescriptor = pluginDescriptorCache.get( cacheKey ); - - if ( pluginDescriptor == null ) - { - org.eclipse.aether.artifact.Artifact artifact = - pluginDependenciesResolver.resolve( plugin, repositories, session ); - - Artifact pluginArtifact = RepositoryUtils.toArtifact( artifact ); - - pluginDescriptor = extractPluginDescriptor( pluginArtifact, plugin ); - - pluginDescriptor.setRequiredMavenVersion( artifact.getProperty( "requiredMavenVersion", null ) ); - - pluginDescriptorCache.put( cacheKey, pluginDescriptor ); - } - - pluginDescriptor.setPlugin( plugin ); - - return pluginDescriptor; - } - - private PluginDescriptor extractPluginDescriptor( Artifact pluginArtifact, Plugin plugin ) - throws PluginDescriptorParsingException, InvalidPluginDescriptorException - { - PluginDescriptor pluginDescriptor = null; - - File pluginFile = pluginArtifact.getFile(); - - try - { - if ( pluginFile.isFile() ) - { - JarFile pluginJar = new JarFile( pluginFile, false ); - try - { - ZipEntry pluginDescriptorEntry = pluginJar.getEntry( getPluginDescriptorLocation() ); - - if ( pluginDescriptorEntry != null ) - { - InputStream is = pluginJar.getInputStream( pluginDescriptorEntry ); - - pluginDescriptor = parsePluginDescriptor( is, plugin, pluginFile.getAbsolutePath() ); - } - } - finally - { - pluginJar.close(); - } - } - else - { - File pluginXml = new File( pluginFile, getPluginDescriptorLocation() ); - - if ( pluginXml.isFile() ) - { - InputStream is = new BufferedInputStream( new FileInputStream( pluginXml ) ); - try - { - pluginDescriptor = parsePluginDescriptor( is, plugin, pluginXml.getAbsolutePath() ); - } - finally - { - IOUtil.close( is ); - } - } - } - - if ( pluginDescriptor == null ) - { - throw new IOException( "No plugin descriptor found at " + getPluginDescriptorLocation() ); - } - } - catch ( IOException e ) - { - throw new PluginDescriptorParsingException( plugin, pluginFile.getAbsolutePath(), e ); - } - - MavenPluginValidator validator = new MavenPluginValidator( pluginArtifact ); - - validator.validate( pluginDescriptor ); - - if ( validator.hasErrors() ) - { - throw new InvalidPluginDescriptorException( "Invalid plugin descriptor for " + plugin.getId() + " (" - + pluginFile + ")", validator.getErrors() ); - } - - pluginDescriptor.setPluginArtifact( pluginArtifact ); - - return pluginDescriptor; - } - - private String getPluginDescriptorLocation() - { - return "META-INF/maven/plugin.xml"; - } - - private PluginDescriptor parsePluginDescriptor( InputStream is, Plugin plugin, String descriptorLocation ) - throws PluginDescriptorParsingException - { - try - { - Reader reader = ReaderFactory.newXmlReader( is ); - - PluginDescriptor pluginDescriptor = builder.build( reader, descriptorLocation ); - - return pluginDescriptor; - } - catch ( IOException e ) - { - throw new PluginDescriptorParsingException( plugin, descriptorLocation, e ); - } - catch ( PlexusConfigurationException e ) - { - throw new PluginDescriptorParsingException( plugin, descriptorLocation, e ); - } - } - - public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, List<RemoteRepository> repositories, - RepositorySystemSession session ) - throws MojoNotFoundException, PluginResolutionException, PluginDescriptorParsingException, - InvalidPluginDescriptorException - { - PluginDescriptor pluginDescriptor = getPluginDescriptor( plugin, repositories, session ); - - MojoDescriptor mojoDescriptor = pluginDescriptor.getMojo( goal ); - - if ( mojoDescriptor == null ) - { - throw new MojoNotFoundException( goal, pluginDescriptor ); - } - - return mojoDescriptor; - } - - public void checkRequiredMavenVersion( PluginDescriptor pluginDescriptor ) - throws PluginIncompatibleException - { - String requiredMavenVersion = pluginDescriptor.getRequiredMavenVersion(); - if ( StringUtils.isNotBlank( requiredMavenVersion ) ) - { - try - { - if ( !runtimeInformation.isMavenVersion( requiredMavenVersion ) ) - { - throw new PluginIncompatibleException( pluginDescriptor.getPlugin(), "The plugin " - + pluginDescriptor.getId() + " requires Maven version " + requiredMavenVersion ); - } - } - catch ( RuntimeException e ) - { - logger.warn( "Could not verify plugin's Maven prerequisite: " + e.getMessage() ); - } - } - } - - public synchronized void setupPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, - ClassLoader parent, List<String> imports, DependencyFilter filter ) - throws PluginResolutionException, PluginContainerException - { - Plugin plugin = pluginDescriptor.getPlugin(); - MavenProject project = session.getCurrentProject(); - - if ( plugin.isExtensions() ) - { - ExtensionRealmCache.CacheRecord extensionRecord; - try - { - RepositorySystemSession repositorySession = session.getRepositorySession(); - extensionRecord = setupExtensionsRealm( project, plugin, repositorySession ); - } - catch ( PluginManagerException e ) - { - // extensions realm is expected to be fully setup at this point - // any exception means a problem in maven code, not a user error - throw new IllegalStateException( e ); - } - - ClassRealm pluginRealm = extensionRecord.realm; - List<Artifact> pluginArtifacts = extensionRecord.artifacts; - - for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() ) - { - componentDescriptor.setRealm( pluginRealm ); - } - - pluginDescriptor.setClassRealm( pluginRealm ); - pluginDescriptor.setArtifacts( pluginArtifacts ); - } - else - { - Map<String, ClassLoader> foreignImports = calcImports( project, parent, imports ); - - PluginRealmCache.Key cacheKey = - pluginRealmCache.createKey( plugin, parent, foreignImports, filter, - project.getRemotePluginRepositories(), session.getRepositorySession() ); - - PluginRealmCache.CacheRecord cacheRecord = pluginRealmCache.get( cacheKey ); - - if ( cacheRecord != null ) - { - pluginDescriptor.setClassRealm( cacheRecord.realm ); - pluginDescriptor.setArtifacts( new ArrayList<Artifact>( cacheRecord.artifacts ) ); - for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() ) - { - componentDescriptor.setRealm( cacheRecord.realm ); - } - } - else - { - createPluginRealm( pluginDescriptor, session, parent, foreignImports, filter ); - - cacheRecord = - pluginRealmCache.put( cacheKey, pluginDescriptor.getClassRealm(), pluginDescriptor.getArtifacts() ); - } - - pluginRealmCache.register( project, cacheKey, cacheRecord ); - } - } - - private void createPluginRealm( PluginDescriptor pluginDescriptor, MavenSession session, ClassLoader parent, - Map<String, ClassLoader> foreignImports, DependencyFilter filter ) - throws PluginResolutionException, PluginContainerException - { - Plugin plugin = pluginDescriptor.getPlugin(); - - if ( plugin == null ) - { - throw new IllegalArgumentException( "incomplete plugin descriptor, plugin missing" ); - } - - Artifact pluginArtifact = pluginDescriptor.getPluginArtifact(); - - if ( pluginArtifact == null ) - { - throw new IllegalArgumentException( "incomplete plugin descriptor, plugin artifact missing" ); - } - - MavenProject project = session.getCurrentProject(); - - final ClassRealm pluginRealm; - final List<Artifact> pluginArtifacts; - - RepositorySystemSession repositorySession = session.getRepositorySession(); - DependencyFilter dependencyFilter = project.getExtensionDependencyFilter(); - dependencyFilter = AndDependencyFilter.newInstance( dependencyFilter, filter ); - - DependencyNode root = - pluginDependenciesResolver.resolve( plugin, RepositoryUtils.toArtifact( pluginArtifact ), - dependencyFilter, project.getRemotePluginRepositories(), - repositorySession ); - - PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); - root.accept( nlg ); - - pluginArtifacts = toMavenArtifacts( root, nlg ); - - pluginRealm = - classRealmManager.createPluginRealm( plugin, parent, null, foreignImports, - toAetherArtifacts( pluginArtifacts ) ); - - discoverPluginComponents( pluginRealm, plugin, pluginDescriptor ); - - pluginDescriptor.setClassRealm( pluginRealm ); - pluginDescriptor.setArtifacts( pluginArtifacts ); - } - - private void discoverPluginComponents( final ClassRealm pluginRealm, Plugin plugin, - PluginDescriptor pluginDescriptor ) - throws PluginContainerException - { - try - { - if ( pluginDescriptor != null ) - { - for ( ComponentDescriptor<?> componentDescriptor : pluginDescriptor.getComponents() ) - { - componentDescriptor.setRealm( pluginRealm ); - container.addComponentDescriptor( componentDescriptor ); - } - } - - ( (DefaultPlexusContainer) container ).discoverComponents( pluginRealm, - new SessionScopeModule( container ), - new MojoExecutionScopeModule( container ) ); - } - catch ( ComponentLookupException e ) - { - throw new PluginContainerException( plugin, pluginRealm, "Error in component graph of plugin " - + plugin.getId() + ": " + e.getMessage(), e ); - } - catch ( CycleDetectedInComponentGraphException e ) - { - throw new PluginContainerException( plugin, pluginRealm, "Error in component graph of plugin " - + plugin.getId() + ": " + e.getMessage(), e ); - } - } - - private List<org.eclipse.aether.artifact.Artifact> toAetherArtifacts( final List<Artifact> pluginArtifacts ) - { - return new ArrayList<org.eclipse.aether.artifact.Artifact>( RepositoryUtils.toArtifacts( pluginArtifacts ) ); - } - - private List<Artifact> toMavenArtifacts( DependencyNode root, PreorderNodeListGenerator nlg ) - { - List<Artifact> artifacts = new ArrayList<Artifact>( nlg.getNodes().size() ); - RepositoryUtils.toArtifacts( artifacts, Collections.singleton( root ), Collections.<String>emptyList(), null ); - for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) - { - Artifact artifact = it.next(); - if ( artifact.getFile() == null ) - { - it.remove(); - } - } - return artifacts; - } - - private Map<String, ClassLoader> calcImports( MavenProject project, ClassLoader parent, List<String> imports ) - { - Map<String, ClassLoader> foreignImports = new HashMap<String, ClassLoader>(); - - ClassLoader projectRealm = project.getClassRealm(); - if ( projectRealm != null ) - { - foreignImports.put( "", projectRealm ); - } - else - { - foreignImports.put( "", classRealmManager.getMavenApiRealm() ); - } - - if ( parent != null && imports != null ) - { - for ( String parentImport : imports ) - { - foreignImports.put( parentImport, parent ); - } - } - - return foreignImports; - } - - public <T> T getConfiguredMojo( Class<T> mojoInterface, MavenSession session, MojoExecution mojoExecution ) - throws PluginConfigurationException, PluginContainerException - { - MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor(); - - PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); - - ClassRealm pluginRealm = pluginDescriptor.getClassRealm(); - - if ( logger.isDebugEnabled() ) - { - logger.debug( "Configuring mojo " + mojoDescriptor.getId() + " from plugin realm " + pluginRealm ); - } - - // We are forcing the use of the plugin realm for all lookups that might occur during - // the lifecycle that is part of the lookup. Here we are specifically trying to keep - // lookups that occur in contextualize calls in line with the right realm. - ClassRealm oldLookupRealm = container.setLookupRealm( pluginRealm ); - - ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader( pluginRealm ); - - try - { - T mojo; - - try - { - mojo = container.lookup( mojoInterface, mojoDescriptor.getRoleHint() ); - } - catch ( ComponentLookupException e ) - { - Throwable cause = e.getCause(); - while ( cause != null && !( cause instanceof LinkageError ) - && !( cause instanceof ClassNotFoundException ) ) - { - cause = cause.getCause(); - } - - if ( ( cause instanceof NoClassDefFoundError ) || ( cause instanceof ClassNotFoundException ) ) - { - ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); - PrintStream ps = new PrintStream( os ); - ps.println( "Unable to load the mojo '" + mojoDescriptor.getGoal() + "' in the plugin '" - + pluginDescriptor.getId() + "'. A required class is missing: " + cause.getMessage() ); - pluginRealm.display( ps ); - - throw new PluginContainerException( mojoDescriptor, pluginRealm, os.toString(), cause ); - } - else if ( cause instanceof LinkageError ) - { - ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); - PrintStream ps = new PrintStream( os ); - ps.println( "Unable to load the mojo '" + mojoDescriptor.getGoal() + "' in the plugin '" - + pluginDescriptor.getId() + "' due to an API incompatibility: " + e.getClass().getName() - + ": " + cause.getMessage() ); - pluginRealm.display( ps ); - - throw new PluginContainerException( mojoDescriptor, pluginRealm, os.toString(), cause ); - } - - throw new PluginContainerException( mojoDescriptor, pluginRealm, "Unable to load the mojo '" - + mojoDescriptor.getGoal() + "' (or one of its required components) from the plugin '" - + pluginDescriptor.getId() + "'", e ); - } - - if ( mojo instanceof ContextEnabled ) - { - MavenProject project = session.getCurrentProject(); - - Map<String, Object> pluginContext = session.getPluginContext( pluginDescriptor, project ); - - if ( pluginContext != null ) - { - pluginContext.put( "project", project ); - - pluginContext.put( "pluginDescriptor", pluginDescriptor ); - - ( (ContextEnabled) mojo ).setPluginContext( pluginContext ); - } - } - - if ( mojo instanceof Mojo ) - { - Logger mojoLogger = loggerManager.getLoggerForComponent( mojoDescriptor.getImplementation() ); - ( (Mojo) mojo ).setLog( new DefaultLog( mojoLogger ) ); - } - - Xpp3Dom dom = mojoExecution.getConfiguration(); - - PlexusConfiguration pomConfiguration; - - if ( dom == null ) - { - pomConfiguration = new XmlPlexusConfiguration( "configuration" ); - } - else - { - pomConfiguration = new XmlPlexusConfiguration( dom ); - } - - ExpressionEvaluator expressionEvaluator = new PluginParameterExpressionEvaluator( session, mojoExecution ); - - populatePluginFields( mojo, mojoDescriptor, pluginRealm, pomConfiguration, expressionEvaluator ); - - return mojo; - } - finally - { - Thread.currentThread().setContextClassLoader( oldClassLoader ); - container.setLookupRealm( oldLookupRealm ); - } - } - - private void populatePluginFields( Object mojo, MojoDescriptor mojoDescriptor, ClassRealm pluginRealm, - PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator ) - throws PluginConfigurationException - { - ComponentConfigurator configurator = null; - - String configuratorId = mojoDescriptor.getComponentConfigurator(); - - if ( StringUtils.isEmpty( configuratorId ) ) - { - configuratorId = "basic"; - } - - try - { - // TODO: could the configuration be passed to lookup and the configurator known to plexus via the descriptor - // so that this method could entirely be handled by a plexus lookup? - configurator = container.lookup( ComponentConfigurator.class, configuratorId ); - - ConfigurationListener listener = new DebugConfigurationListener( logger ); - - ValidatingConfigurationListener validator = - new ValidatingConfigurationListener( mojo, mojoDescriptor, listener ); - - logger.debug( "Configuring mojo '" + mojoDescriptor.getId() + "' with " + configuratorId - + " configurator -->" ); - - configurator.configureComponent( mojo, configuration, expressionEvaluator, pluginRealm, validator ); - - logger.debug( "-- end configuration --" ); - - Collection<Parameter> missingParameters = validator.getMissingParameters(); - if ( !missingParameters.isEmpty() ) - { - if ( "basic".equals( configuratorId ) ) - { - throw new PluginParameterException( mojoDescriptor, new ArrayList<Parameter>( missingParameters ) ); - } - else - { - /* - * NOTE: Other configurators like the map-oriented one don't call into the listener, so do it the - * hard way. - */ - validateParameters( mojoDescriptor, configuration, expressionEvaluator ); - } - } - } - catch ( ComponentConfigurationException e ) - { - String message = "Unable to parse configuration of mojo " + mojoDescriptor.getId(); - if ( e.getFailedConfiguration() != null ) - { - message += " for parameter " + e.getFailedConfiguration().getName(); - } - message += ": " + e.getMessage(); - - throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), message, e ); - } - catch ( ComponentLookupException e ) - { - throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), - "Unable to retrieve component configurator " + configuratorId - + " for configuration of mojo " + mojoDescriptor.getId(), e ); - } - catch ( NoClassDefFoundError e ) - { - ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); - PrintStream ps = new PrintStream( os ); - ps.println( "A required class was missing during configuration of mojo " + mojoDescriptor.getId() + ": " - + e.getMessage() ); - pluginRealm.display( ps ); - - throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), os.toString(), e ); - } - catch ( LinkageError e ) - { - ByteArrayOutputStream os = new ByteArrayOutputStream( 1024 ); - PrintStream ps = new PrintStream( os ); - ps.println( "An API incompatibility was encountered during configuration of mojo " + mojoDescriptor.getId() - + ": " + e.getClass().getName() + ": " + e.getMessage() ); - pluginRealm.display( ps ); - - throw new PluginConfigurationException( mojoDescriptor.getPluginDescriptor(), os.toString(), e ); - } - finally - { - if ( configurator != null ) - { - try - { - container.release( configurator ); - } - catch ( ComponentLifecycleException e ) - { - logger.debug( "Failed to release mojo configurator - ignoring." ); - } - } - } - } - - private void validateParameters( MojoDescriptor mojoDescriptor, PlexusConfiguration configuration, - ExpressionEvaluator expressionEvaluator ) - throws ComponentConfigurationException, PluginParameterException - { - if ( mojoDescriptor.getParameters() == null ) - { - return; - } - - List<Parameter> invalidParameters = new ArrayList<Parameter>(); - - for ( Parameter parameter : mojoDescriptor.getParameters() ) - { - if ( !parameter.isRequired() ) - { - continue; - } - - Object value = null; - - PlexusConfiguration config = configuration.getChild( parameter.getName(), false ); - if ( config != null ) - { - String expression = config.getValue( null ); - - try - { - value = expressionEvaluator.evaluate( expression ); - - if ( value == null ) - { - value = config.getAttribute( "default-value", null ); - } - } - catch ( ExpressionEvaluationException e ) - { - String msg = - "Error evaluating the expression '" + expression + "' for configuration value '" - + configuration.getName() + "'"; - throw new ComponentConfigurationException( configuration, msg, e ); - } - } - - if ( value == null && ( config == null || config.getChildCount() <= 0 ) ) - { - invalidParameters.add( parameter ); - } - } - - if ( !invalidParameters.isEmpty() ) - { - throw new PluginParameterException( mojoDescriptor, invalidParameters ); - } - } - - public void releaseMojo( Object mojo, MojoExecution mojoExecution ) - { - if ( mojo != null ) - { - try - { - container.release( mojo ); - } - catch ( ComponentLifecycleException e ) - { - String goalExecId = mojoExecution.getGoal(); - - if ( mojoExecution.getExecutionId() != null ) - { - goalExecId += " {execution: " + mojoExecution.getExecutionId() + "}"; - } - - logger.debug( "Error releasing mojo for " + goalExecId, e ); - } - } - } - - public ExtensionRealmCache.CacheRecord setupExtensionsRealm( MavenProject project, Plugin plugin, - RepositorySystemSession session ) - throws PluginManagerException - { - @SuppressWarnings( "unchecked" ) - Map<String, ExtensionRealmCache.CacheRecord> pluginRealms = - (Map<String, ExtensionRealmCache.CacheRecord>) project.getContextValue( KEY_EXTENSIONS_REALMS ); - if ( pluginRealms == null ) - { - pluginRealms = new HashMap<String, ExtensionRealmCache.CacheRecord>(); - project.setContextValue( KEY_EXTENSIONS_REALMS, pluginRealms ); - } - - final String pluginKey = plugin.getId(); - - ExtensionRealmCache.CacheRecord extensionRecord = pluginRealms.get( pluginKey ); - if ( extensionRecord != null ) - { - return extensionRecord; - } - - final List<RemoteRepository> repositories = project.getRemotePluginRepositories(); - - // resolve plugin version as necessary - if ( plugin.getVersion() == null ) - { - PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( plugin, session, repositories ); - try - { - plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() ); - } - catch ( PluginVersionResolutionException e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - } - - // resolve plugin artifacts - List<Artifact> artifacts; - PluginArtifactsCache.Key cacheKey = pluginArtifactsCache.createKey( plugin, null, repositories, session ); - PluginArtifactsCache.CacheRecord recordArtifacts; - try - { - recordArtifacts = pluginArtifactsCache.get( cacheKey ); - } - catch ( PluginResolutionException e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - if ( recordArtifacts != null ) - { - artifacts = recordArtifacts.artifacts; - } - else - { - try - { - artifacts = resolveExtensionArtifacts( plugin, repositories, session ); - recordArtifacts = pluginArtifactsCache.put( cacheKey, artifacts ); - } - catch ( PluginResolutionException e ) - { - pluginArtifactsCache.put( cacheKey, e ); - pluginArtifactsCache.register( project, cacheKey, recordArtifacts ); - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - } - pluginArtifactsCache.register( project, cacheKey, recordArtifacts ); - - // create and cache extensions realms - final ExtensionRealmCache.Key extensionKey = extensionRealmCache.createKey( artifacts ); - extensionRecord = extensionRealmCache.get( extensionKey ); - if ( extensionRecord == null ) - { - ClassRealm extensionRealm = classRealmManager.createExtensionRealm( plugin, - toAetherArtifacts( artifacts ) ); - - // TODO figure out how to use the same PluginDescriptor when running mojos - - PluginDescriptor pluginDescriptor = null; - if ( plugin.isExtensions() && !artifacts.isEmpty() ) - { - // ignore plugin descriptor parsing errors at this point - // these errors will reported during calculation of project build execution plan - try - { - pluginDescriptor = extractPluginDescriptor( artifacts.get( 0 ), plugin ); - } - catch ( PluginDescriptorParsingException e ) - { - // ignore, see above - } - catch ( InvalidPluginDescriptorException e ) - { - // ignore, see above - } - } - - discoverPluginComponents( extensionRealm, plugin, pluginDescriptor ); - - ExtensionDescriptor extensionDescriptor = null; - Artifact extensionArtifact = artifacts.get( 0 ); - try - { - extensionDescriptor = extensionDescriptorBuilder.build( extensionArtifact.getFile() ); - } - catch ( IOException e ) - { - String message = "Invalid extension descriptor for " + plugin.getId() + ": " + e.getMessage(); - if ( logger.isDebugEnabled() ) - { - logger.error( message, e ); - } - else - { - logger.error( message ); - } - } - extensionRecord = extensionRealmCache.put( extensionKey, extensionRealm, extensionDescriptor, artifacts ); - } - extensionRealmCache.register( project, extensionKey, extensionRecord ); - pluginRealms.put( pluginKey, extensionRecord ); - - return extensionRecord; - } - - private List<Artifact> resolveExtensionArtifacts( Plugin extensionPlugin, List<RemoteRepository> repositories, - RepositorySystemSession session ) - throws PluginResolutionException - { - DependencyNode root = pluginDependenciesResolver.resolve( extensionPlugin, null, null, repositories, session ); - PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); - root.accept( nlg ); - return toMavenArtifacts( root, nlg ); - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java deleted file mode 100644 index 5b0c2712..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ /dev/null @@ -1,256 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import org.apache.maven.RepositoryUtils; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.PluginResolutionException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.eclipse.aether.DefaultRepositorySystemSession; -import org.eclipse.aether.RepositorySystem; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.RequestTrace; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.collection.CollectRequest; -import org.eclipse.aether.collection.DependencyCollectionException; -import org.eclipse.aether.collection.DependencyGraphTransformer; -import org.eclipse.aether.collection.DependencySelector; -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.graph.DependencyVisitor; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.resolution.ArtifactDescriptorException; -import org.eclipse.aether.resolution.ArtifactDescriptorRequest; -import org.eclipse.aether.resolution.ArtifactDescriptorResult; -import org.eclipse.aether.resolution.ArtifactRequest; -import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.DependencyRequest; -import org.eclipse.aether.resolution.DependencyResolutionException; -import org.eclipse.aether.util.artifact.JavaScopes; -import org.eclipse.aether.util.filter.AndDependencyFilter; -import org.eclipse.aether.util.filter.ScopeDependencyFilter; -import org.eclipse.aether.util.graph.selector.AndDependencySelector; -import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer; -import org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy; - -/** - * Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility class that - * is only public for technical reasons, it is not part of the public API. In particular, this class can be changed or - * deleted without prior notice. - * - * @since 3.0 - * @author Benjamin Bentmann - */ -@Component( role = PluginDependenciesResolver.class ) -public class DefaultPluginDependenciesResolver - implements PluginDependenciesResolver -{ - - private static final String REPOSITORY_CONTEXT = "plugin"; - - @Requirement - private Logger logger; - - @Requirement - private RepositorySystem repoSystem; - - private Artifact toArtifact( Plugin plugin, RepositorySystemSession session ) - { - return new DefaultArtifact( plugin.getGroupId(), plugin.getArtifactId(), null, "jar", plugin.getVersion(), - session.getArtifactTypeRegistry().get( "maven-plugin" ) ); - } - - public Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException - { - RequestTrace trace = RequestTrace.newChild( null, plugin ); - - Artifact pluginArtifact = toArtifact( plugin, session ); - - try - { - DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSession( session ); - pluginSession.setArtifactDescriptorPolicy( new SimpleArtifactDescriptorPolicy( true, false ) ); - - ArtifactDescriptorRequest request = - new ArtifactDescriptorRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); - request.setTrace( trace ); - ArtifactDescriptorResult result = repoSystem.readArtifactDescriptor( pluginSession, request ); - - pluginArtifact = result.getArtifact(); - - String requiredMavenVersion = (String) result.getProperties().get( "prerequisites.maven" ); - if ( requiredMavenVersion != null ) - { - Map<String, String> props = new LinkedHashMap<String, String>( pluginArtifact.getProperties() ); - props.put( "requiredMavenVersion", requiredMavenVersion ); - pluginArtifact = pluginArtifact.setProperties( props ); - } - } - catch ( ArtifactDescriptorException e ) - { - throw new PluginResolutionException( plugin, e ); - } - - try - { - ArtifactRequest request = new ArtifactRequest( pluginArtifact, repositories, REPOSITORY_CONTEXT ); - request.setTrace( trace ); - pluginArtifact = repoSystem.resolveArtifact( session, request ).getArtifact(); - } - catch ( ArtifactResolutionException e ) - { - throw new PluginResolutionException( plugin, e ); - } - - return pluginArtifact; - } - - /** - * @since 3.3.0 - */ - public DependencyNode resolveCoreExtension( Plugin plugin, DependencyFilter dependencyFilter, - List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException - { - return resolveInternal( plugin, null /* pluginArtifact */, dependencyFilter, null /* transformer */, - repositories, session ); - } - - public DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, - List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException - { - return resolveInternal( plugin, pluginArtifact, dependencyFilter, new PlexusUtilsInjector(), repositories, - session ); - } - - private DependencyNode resolveInternal( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, - DependencyGraphTransformer transformer, - List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException - { - RequestTrace trace = RequestTrace.newChild( null, plugin ); - - if ( pluginArtifact == null ) - { - pluginArtifact = toArtifact( plugin, session ); - } - - DependencyFilter collectionFilter = new ScopeDependencyFilter( "provided", "test" ); - DependencyFilter resolutionFilter = AndDependencyFilter.newInstance( collectionFilter, dependencyFilter ); - - DependencyNode node; - - try - { - DependencySelector selector = - AndDependencySelector.newInstance( session.getDependencySelector(), new WagonExcluder() ); - - transformer = - ChainedDependencyGraphTransformer.newInstance( session.getDependencyGraphTransformer(), transformer ); - - DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSession( session ); - pluginSession.setDependencySelector( selector ); - pluginSession.setDependencyGraphTransformer( transformer ); - - CollectRequest request = new CollectRequest(); - request.setRequestContext( REPOSITORY_CONTEXT ); - request.setRepositories( repositories ); - request.setRoot( new org.eclipse.aether.graph.Dependency( pluginArtifact, null ) ); - for ( Dependency dependency : plugin.getDependencies() ) - { - org.eclipse.aether.graph.Dependency pluginDep = - RepositoryUtils.toDependency( dependency, session.getArtifactTypeRegistry() ); - if ( !JavaScopes.SYSTEM.equals( pluginDep.getScope() ) ) - { - pluginDep = pluginDep.setScope( JavaScopes.RUNTIME ); - } - request.addDependency( pluginDep ); - } - - DependencyRequest depRequest = new DependencyRequest( request, resolutionFilter ); - depRequest.setTrace( trace ); - - request.setTrace( RequestTrace.newChild( trace, depRequest ) ); - - node = repoSystem.collectDependencies( pluginSession, request ).getRoot(); - - if ( logger.isDebugEnabled() ) - { - node.accept( new GraphLogger() ); - } - - depRequest.setRoot( node ); - repoSystem.resolveDependencies( session, depRequest ); - } - catch ( DependencyCollectionException e ) - { - throw new PluginResolutionException( plugin, e ); - } - catch ( DependencyResolutionException e ) - { - throw new PluginResolutionException( plugin, e.getCause() ); - } - - return node; - } - - class GraphLogger - implements DependencyVisitor - { - - private String indent = ""; - - public boolean visitEnter( DependencyNode node ) - { - StringBuilder buffer = new StringBuilder( 128 ); - buffer.append( indent ); - org.eclipse.aether.graph.Dependency dep = node.getDependency(); - if ( dep != null ) - { - Artifact art = dep.getArtifact(); - - buffer.append( art ); - buffer.append( ':' ).append( dep.getScope() ); - } - - logger.debug( buffer.toString() ); - indent += " "; - return true; - } - - public boolean visitLeave( DependencyNode node ) - { - indent = indent.substring( 0, indent.length() - 3 ); - return true; - } - - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java deleted file mode 100644 index 015060f6..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginManager.java +++ /dev/null @@ -1,261 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Map; - -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.InvalidPluginDescriptorException; -import org.apache.maven.plugin.InvalidPluginException; -import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.plugin.MavenPluginManager; -import org.apache.maven.plugin.MojoExecution; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.PluginConfigurationException; -import org.apache.maven.plugin.PluginDescriptorParsingException; -import org.apache.maven.plugin.PluginManager; -import org.apache.maven.plugin.PluginManagerException; -import org.apache.maven.plugin.PluginNotFoundException; -import org.apache.maven.plugin.PluginResolutionException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; -import org.apache.maven.plugin.prefix.DefaultPluginPrefixRequest; -import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; -import org.apache.maven.plugin.prefix.PluginPrefixRequest; -import org.apache.maven.plugin.prefix.PluginPrefixResolver; -import org.apache.maven.plugin.prefix.PluginPrefixResult; -import org.apache.maven.plugin.version.DefaultPluginVersionRequest; -import org.apache.maven.plugin.version.PluginVersionNotFoundException; -import org.apache.maven.plugin.version.PluginVersionRequest; -import org.apache.maven.plugin.version.PluginVersionResolutionException; -import org.apache.maven.plugin.version.PluginVersionResolver; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.settings.Settings; -import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - -/** - * @author Benjamin Bentmann - */ -@Component( role = PluginManager.class ) -public class DefaultPluginManager - implements PluginManager -{ - - @Requirement - private PlexusContainer container; - - @Requirement - private MavenPluginManager pluginManager; - - @Requirement - private PluginVersionResolver pluginVersionResolver; - - @Requirement - private PluginPrefixResolver pluginPrefixResolver; - - @Requirement - private LegacySupport legacySupport; - - public void executeMojo( MavenProject project, MojoExecution execution, MavenSession session ) - throws MojoExecutionException, ArtifactResolutionException, MojoFailureException, ArtifactNotFoundException, - InvalidDependencyVersionException, PluginManagerException, PluginConfigurationException - { - throw new UnsupportedOperationException(); - } - - public Object getPluginComponent( Plugin plugin, String role, String roleHint ) - throws PluginManagerException, ComponentLookupException - { - MavenSession session = legacySupport.getSession(); - - PluginDescriptor pluginDescriptor; - try - { - pluginDescriptor = - pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), - session.getRepositorySession() ); - - pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); - } - catch ( Exception e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - - ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); - try - { - Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); - - return container.lookup( role, roleHint ); - } - finally - { - Thread.currentThread().setContextClassLoader( oldClassLoader ); - } - } - - public Map getPluginComponents( Plugin plugin, String role ) - throws ComponentLookupException, PluginManagerException - { - MavenSession session = legacySupport.getSession(); - - PluginDescriptor pluginDescriptor; - try - { - pluginDescriptor = - pluginManager.getPluginDescriptor( plugin, session.getCurrentProject().getRemotePluginRepositories(), - session.getRepositorySession() ); - - pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); - } - catch ( Exception e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - - ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); - try - { - Thread.currentThread().setContextClassLoader( pluginDescriptor.getClassRealm() ); - - return container.lookupMap( role ); - } - finally - { - Thread.currentThread().setContextClassLoader( oldClassLoader ); - } - } - - public Plugin getPluginDefinitionForPrefix( String prefix, MavenSession session, MavenProject project ) - { - PluginPrefixRequest request = new DefaultPluginPrefixRequest( prefix, session ); - request.setPom( project.getModel() ); - - try - { - PluginPrefixResult result = pluginPrefixResolver.resolve( request ); - - Plugin plugin = new Plugin(); - plugin.setGroupId( result.getGroupId() ); - plugin.setArtifactId( result.getArtifactId() ); - - return plugin; - } - catch ( NoPluginFoundForPrefixException e ) - { - return null; - } - } - - public PluginDescriptor getPluginDescriptorForPrefix( String prefix ) - { - MavenSession session = legacySupport.getSession(); - - PluginPrefixRequest request = new DefaultPluginPrefixRequest( prefix, session ); - - try - { - PluginPrefixResult result = pluginPrefixResolver.resolve( request ); - - Plugin plugin = new Plugin(); - plugin.setGroupId( result.getGroupId() ); - plugin.setArtifactId( result.getArtifactId() ); - - return loadPluginDescriptor( plugin, session.getCurrentProject(), session ); - } - catch ( Exception e ) - { - return null; - } - } - - public PluginDescriptor loadPluginDescriptor( Plugin plugin, MavenProject project, MavenSession session ) - throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, - InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, - PluginVersionNotFoundException - { - return verifyPlugin( plugin, project, session.getSettings(), session.getLocalRepository() ); - } - - public PluginDescriptor loadPluginFully( Plugin plugin, MavenProject project, MavenSession session ) - throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, - InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, - PluginVersionNotFoundException - { - PluginDescriptor pluginDescriptor = loadPluginDescriptor( plugin, project, session ); - - try - { - pluginManager.setupPluginRealm( pluginDescriptor, session, null, null, null ); - } - catch ( PluginResolutionException e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - - return pluginDescriptor; - } - - public PluginDescriptor verifyPlugin( Plugin plugin, MavenProject project, Settings settings, - ArtifactRepository localRepository ) - throws ArtifactResolutionException, PluginVersionResolutionException, ArtifactNotFoundException, - InvalidVersionSpecificationException, InvalidPluginException, PluginManagerException, PluginNotFoundException, - PluginVersionNotFoundException - { - MavenSession session = legacySupport.getSession(); - - if ( plugin.getVersion() == null ) - { - PluginVersionRequest versionRequest = - new DefaultPluginVersionRequest( plugin, session.getRepositorySession(), - project.getRemotePluginRepositories() ); - plugin.setVersion( pluginVersionResolver.resolve( versionRequest ).getVersion() ); - } - - try - { - return pluginManager.getPluginDescriptor( plugin, project.getRemotePluginRepositories(), - session.getRepositorySession() ); - } - catch ( PluginResolutionException e ) - { - throw new PluginNotFoundException( plugin, project.getPluginArtifactRepositories() ); - } - catch ( PluginDescriptorParsingException e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - catch ( InvalidPluginDescriptorException e ) - { - throw new PluginManagerException( plugin, e.getMessage(), e ); - } - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PlexusUtilsInjector.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PlexusUtilsInjector.java deleted file mode 100644 index 16a0b63c..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PlexusUtilsInjector.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.eclipse.aether.RepositoryException; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.artifact.DefaultArtifact; -import org.eclipse.aether.collection.DependencyGraphTransformationContext; -import org.eclipse.aether.collection.DependencyGraphTransformer; -import org.eclipse.aether.graph.DefaultDependencyNode; -import org.eclipse.aether.graph.Dependency; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.util.artifact.JavaScopes; - -/** - * Injects plexus-utils:1.1 into a plugin's class path if it doesn't already declare a dependency on plexus-utils. This - * is another legacy bit to provide backward-compat with Maven 2.x. - * - * @author Benjamin Bentmann - */ -class PlexusUtilsInjector - implements DependencyGraphTransformer -{ - - private static final String GID = "org.codehaus.plexus"; - - private static final String AID = "plexus-utils"; - - private static final String VER = "1.1"; - - private static final String EXT = "jar"; - - public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) - throws RepositoryException - { - if ( findPlexusUtils( node ) == null ) - { - Artifact pu = new DefaultArtifact( GID, AID, null, EXT, VER ); - DefaultDependencyNode child = new DefaultDependencyNode( new Dependency( pu, JavaScopes.RUNTIME ) ); - child.setRepositories( node.getRepositories() ); - child.setRequestContext( node.getRequestContext() ); - node.getChildren().add( child ); - } - - return node; - } - - private DependencyNode findPlexusUtils( DependencyNode node ) - { - Artifact artifact = node.getDependency().getArtifact(); - - if ( AID.equals( artifact.getArtifactId() ) && GID.equals( artifact.getGroupId() ) - && EXT.equals( artifact.getExtension() ) && "".equals( artifact.getClassifier() ) ) - { - return node; - } - - for ( DependencyNode child : node.getChildren() ) - { - DependencyNode result = findPlexusUtils( child ); - if ( result != null ) - { - return result; - } - } - - return null; - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java deleted file mode 100644 index 41942978..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependenciesResolver.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.List; - -import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.PluginResolutionException; -import org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.graph.DependencyFilter; -import org.eclipse.aether.graph.DependencyNode; -import org.eclipse.aether.repository.RemoteRepository; - -/** - * Assists in resolving the dependencies of a plugin. <strong>Warning:</strong> This is an internal utility interface - * that is only public for technical reasons, it is not part of the public API. In particular, this interface can be - * changed or deleted without prior notice. - * - * @since 3.0 - * @author Benjamin Bentmann - */ -public interface PluginDependenciesResolver -{ - - /** - * Resolves the main artifact of the specified plugin. - * - * @param plugin The plugin for which to resolve the main artifact, must not be {@code null}. - * @param repositories The plugin repositories to use for resolving the plugin's main artifact, must not be {@code - * null}. - * @param session The repository session to use for resolving the plugin's main artifact, must not be {@code null}. - * @return The resolved plugin artifact, never {@code null}. - * @throws PluginResolutionException If the plugin artifact could not be resolved. - */ - Artifact resolve( Plugin plugin, List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException; - - /** - * Resolves the runtime dependencies of the specified plugin. - * - * @param plugin The plugin for which to resolve the dependencies, must not be {@code null}. - * @param pluginArtifact The plugin's main artifact, may be {@code null}. - * @param dependencyFilter A filter to exclude artifacts from resolution (but not collection), may be {@code null}. - * @param repositories The plugin repositories to use for resolving the plugin artifacts, must not be {@code null}. - * @param session The repository session to use for resolving the plugin artifacts, must not be {@code null}. - * @return The dependency tree denoting the resolved plugin class path, never {@code null}. - * @throws PluginResolutionException If any dependency could not be resolved. - */ - DependencyNode resolve( Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, - List<RemoteRepository> repositories, RepositorySystemSession session ) - throws PluginResolutionException; - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependencyResolutionListener.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependencyResolutionListener.java deleted file mode 100644 index 533920a8..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/PluginDependencyResolutionListener.java +++ /dev/null @@ -1,158 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Collection; -import java.util.IdentityHashMap; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.resolver.ResolutionListener; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.versioning.VersionRange; - -/** - * Assists in detecting wagon providers brought into the plugin class path via legacy Maven core artifacts (e.g. - * maven-core:2.0.6) and excluding them. A plugin should be able to explicitly declare dependencies on specific wagons - * for its use. However, the (old) wagons pulled in transitively via legacy Maven core artifacts are usually not - * intended as dependencies and more importantly screw up artifact resolution because they would get preferred over the - * core wagon versions. This is a hack to provide backward-compat with Maven 2 (MNG-4528, MNG-4561). - * - * @since 3.0 - * @author Benjamin Bentmann - */ -class PluginDependencyResolutionListener - implements ResolutionListener -{ - - private ArtifactFilter coreFilter; - - private LinkedList<Artifact> coreArtifacts = new LinkedList<Artifact>(); - - private Artifact wagonProvider; - - private Map<Artifact, Object> bannedArtifacts = new IdentityHashMap<Artifact, Object>(); - - public PluginDependencyResolutionListener( ArtifactFilter coreFilter ) - { - this.coreFilter = coreFilter; - } - - public void removeBannedDependencies( Collection<Artifact> artifacts ) - { - if ( !bannedArtifacts.isEmpty() && artifacts != null ) - { - for ( Iterator<Artifact> it = artifacts.iterator(); it.hasNext(); ) - { - Artifact artifact = it.next(); - if ( bannedArtifacts.containsKey( artifact ) ) - { - it.remove(); - } - } - } - } - - public void startProcessChildren( Artifact artifact ) - { - if ( wagonProvider == null ) - { - if ( isLegacyCoreArtifact( artifact ) ) - { - coreArtifacts.addFirst( artifact ); - } - else if ( !coreArtifacts.isEmpty() && isWagonProvider( artifact ) ) - { - wagonProvider = artifact; - bannedArtifacts.put( artifact, null ); - } - } - } - - private boolean isLegacyCoreArtifact( Artifact artifact ) - { - String version = artifact.getVersion(); - return version != null && version.startsWith( "2." ) && !coreFilter.include( artifact ); - } - - public void endProcessChildren( Artifact artifact ) - { - if ( wagonProvider == artifact ) - { - wagonProvider = null; - } - else if ( coreArtifacts.peek() == artifact ) - { - coreArtifacts.removeFirst(); - } - } - - public void includeArtifact( Artifact artifact ) - { - if ( wagonProvider != null ) - { - bannedArtifacts.put( artifact, null ); - } - } - - private boolean isWagonProvider( Artifact artifact ) - { - if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) ) - { - return artifact.getArtifactId().startsWith( "wagon-" ); - } - return false; - } - - public void manageArtifact( Artifact artifact, Artifact replacement ) - { - } - - public void omitForCycle( Artifact artifact ) - { - } - - public void omitForNearer( Artifact omitted, Artifact kept ) - { - } - - public void restrictRange( Artifact artifact, Artifact replacement, VersionRange newRange ) - { - } - - public void selectVersionFromRange( Artifact artifact ) - { - } - - public void testArtifact( Artifact node ) - { - } - - public void updateScope( Artifact artifact, String scope ) - { - } - - public void updateScopeCurrentPom( Artifact artifact, String ignoredScope ) - { - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java deleted file mode 100644 index 706694b8..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/ValidatingConfigurationListener.java +++ /dev/null @@ -1,97 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.codehaus.plexus.component.configurator.ConfigurationListener; - -/** - * A configuration listener to help validate the plugin configuration. For instance, check for required but missing - * parameters. - * - * @author Benjamin Bentmann - */ -class ValidatingConfigurationListener - implements ConfigurationListener -{ - - private final Object mojo; - - private final ConfigurationListener delegate; - - private final Map<String, Parameter> missingParameters; - - public ValidatingConfigurationListener( Object mojo, MojoDescriptor mojoDescriptor, ConfigurationListener delegate ) - { - this.mojo = mojo; - this.delegate = delegate; - this.missingParameters = new HashMap<String, Parameter>(); - - if ( mojoDescriptor.getParameters() != null ) - { - for ( Parameter param : mojoDescriptor.getParameters() ) - { - if ( param.isRequired() ) - { - missingParameters.put( param.getName(), param ); - } - } - } - } - - public Collection<Parameter> getMissingParameters() - { - return missingParameters.values(); - } - - public void notifyFieldChangeUsingSetter( String fieldName, Object value, Object target ) - { - delegate.notifyFieldChangeUsingSetter( fieldName, value, target ); - - if ( mojo == target ) - { - notify( fieldName, value ); - } - } - - public void notifyFieldChangeUsingReflection( String fieldName, Object value, Object target ) - { - delegate.notifyFieldChangeUsingReflection( fieldName, value, target ); - - if ( mojo == target ) - { - notify( fieldName, value ); - } - } - - private void notify( String fieldName, Object value ) - { - if ( value != null ) - { - missingParameters.remove( fieldName ); - } - } - -} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/WagonExcluder.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/WagonExcluder.java deleted file mode 100644 index 43e8cfc4..00000000 --- a/framework/src/maven/apache-maven-3.3.3/maven-core/src/main/java/org/apache/maven/plugin/internal/WagonExcluder.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.apache.maven.plugin.internal; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.collection.DependencyCollectionContext; -import org.eclipse.aether.collection.DependencySelector; -import org.eclipse.aether.graph.Dependency; - -/** - * Assists in detecting wagon providers brought into the plugin class path via legacy Maven core artifacts (e.g. - * maven-core:2.0.6) and excluding them. A plugin should be able to explicitly declare dependencies on specific wagons - * for its use. However, the (old) wagons pulled in transitively via legacy Maven core artifacts are usually not - * intended as dependencies and more importantly screw up artifact resolution because they would get preferred over the - * core wagon versions. This is a hack to provide backward-compat with Maven 2 (MNG-4528, MNG-4561). - * - * @author Benjamin Bentmann - */ -class WagonExcluder - implements DependencySelector -{ - - private final boolean coreArtifact; - - public WagonExcluder() - { - this( false ); - } - - private WagonExcluder( boolean coreArtifact ) - { - this.coreArtifact = coreArtifact; - } - - public boolean selectDependency( Dependency dependency ) - { - return !coreArtifact || !isWagonProvider( dependency.getArtifact() ); - } - - public DependencySelector deriveChildSelector( DependencyCollectionContext context ) - { - if ( coreArtifact || !isLegacyCoreArtifact( context.getDependency().getArtifact() ) ) - { - return this; - } - else - { - return new WagonExcluder( true ); - } - } - - private boolean isLegacyCoreArtifact( Artifact artifact ) - { - String version = artifact.getVersion(); - return version != null && version.startsWith( "2." ) && artifact.getArtifactId().startsWith( "maven-" ) - && artifact.getGroupId().equals( "org.apache.maven" ); - } - - private boolean isWagonProvider( Artifact artifact ) - { - if ( "org.apache.maven.wagon".equals( artifact.getGroupId() ) ) - { - return artifact.getArtifactId().startsWith( "wagon-" ); - } - return false; - } - - @Override - public boolean equals( Object obj ) - { - if ( obj == this ) - { - return true; - } - else if ( obj == null || !getClass().equals( obj.getClass() ) ) - { - return false; - } - - WagonExcluder that = (WagonExcluder) obj; - return coreArtifact == that.coreArtifact; - } - - @Override - public int hashCode() - { - int hash = getClass().hashCode(); - hash = hash * 31 + ( coreArtifact ? 1 : 0 ); - return hash; - } - -} |