mirror of https://github.com/apache/maven.git
o a test which demonstrates the difficulting in testing the execution of a single mojo, indicates some work to isolate the system and make it easier
for people to reuse this code. igor had to jump through these same hoops to get isolated mojo execution working in m2e. needs some love. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@751582 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
51e30e4640
commit
da776815ac
|
@ -63,6 +63,17 @@ public class MavenSession
|
||||||
|
|
||||||
private Map reports = new LinkedHashMap();
|
private Map reports = new LinkedHashMap();
|
||||||
|
|
||||||
|
//For testing
|
||||||
|
private ArtifactRepository localRepository;
|
||||||
|
|
||||||
|
private MavenRealmManager realmManager;
|
||||||
|
|
||||||
|
public MavenSession( ArtifactRepository localRepository, MavenRealmManager realmManager )
|
||||||
|
{
|
||||||
|
this.localRepository = localRepository;
|
||||||
|
this.realmManager = realmManager;
|
||||||
|
}
|
||||||
|
|
||||||
public MavenSession( PlexusContainer container, MavenExecutionRequest request, EventDispatcher eventDispatcher, ReactorManager reactorManager )
|
public MavenSession( PlexusContainer container, MavenExecutionRequest request, EventDispatcher eventDispatcher, ReactorManager reactorManager )
|
||||||
{
|
{
|
||||||
this.container = container;
|
this.container = container;
|
||||||
|
@ -76,11 +87,15 @@ public class MavenSession
|
||||||
|
|
||||||
public MavenRealmManager getRealmManager()
|
public MavenRealmManager getRealmManager()
|
||||||
{
|
{
|
||||||
|
if ( realmManager != null )
|
||||||
|
{
|
||||||
|
return realmManager;
|
||||||
|
}
|
||||||
|
|
||||||
return request.getRealmManager();
|
return request.getRealmManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map getPluginContext( PluginDescriptor pluginDescriptor,
|
public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
|
||||||
MavenProject project )
|
|
||||||
{
|
{
|
||||||
return reactorManager.getPluginContext( pluginDescriptor, project );
|
return reactorManager.getPluginContext( pluginDescriptor, project );
|
||||||
}
|
}
|
||||||
|
@ -89,9 +104,14 @@ public class MavenSession
|
||||||
{
|
{
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository getLocalRepository()
|
public ArtifactRepository getLocalRepository()
|
||||||
{
|
{
|
||||||
|
if ( localRepository != null )
|
||||||
|
{
|
||||||
|
return localRepository;
|
||||||
|
}
|
||||||
|
|
||||||
return request.getLocalRepository();
|
return request.getLocalRepository();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -927,7 +927,7 @@ public class DefaultLifecycleExecutor
|
||||||
return lifecycle;
|
return lifecycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal )
|
MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
{
|
{
|
||||||
MojoDescriptor desc = pluginDescriptor.getMojo( goal );
|
MojoDescriptor desc = pluginDescriptor.getMojo( goal );
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class DefaultPluginManager
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pluginRealm = realmManager.createPluginRealm( projectPlugin, pluginArtifact, artifacts, coreArtifactFilterManager.getArtifactFilter() );
|
pluginRealm = realmManager.createPluginRealm( projectPlugin, pluginArtifact, artifacts, coreArtifactFilterManager.getArtifactFilter() );
|
||||||
|
|
||||||
logger.debug( "Created realm: " + pluginRealm + " for plugin: " + projectPlugin.getKey() );
|
logger.debug( "Created realm: " + pluginRealm + " for plugin: " + projectPlugin.getKey() );
|
||||||
}
|
}
|
||||||
catch ( RealmManagementException e )
|
catch ( RealmManagementException e )
|
||||||
|
@ -288,7 +288,7 @@ public class DefaultPluginManager
|
||||||
logger.debug( "Checking for plugin descriptor for: " + projectPlugin.getKey() + " with version: " + projectPlugin.getVersion() + " in collector: " + pluginCollector );
|
logger.debug( "Checking for plugin descriptor for: " + projectPlugin.getKey() + " with version: " + projectPlugin.getVersion() + " in collector: " + pluginCollector );
|
||||||
|
|
||||||
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin );
|
PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin );
|
||||||
|
|
||||||
if ( pluginDescriptor == null )
|
if ( pluginDescriptor == null )
|
||||||
{
|
{
|
||||||
if ( ( pluginRealm != null ) && logger.isDebugEnabled() )
|
if ( ( pluginRealm != null ) && logger.isDebugEnabled() )
|
||||||
|
@ -1825,8 +1825,7 @@ public class DefaultPluginManager
|
||||||
|
|
||||||
// Plugin Mapping Manager
|
// Plugin Mapping Manager
|
||||||
|
|
||||||
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories,
|
public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, ArtifactRepository localRepository )
|
||||||
ArtifactRepository localRepository )
|
|
||||||
{
|
{
|
||||||
// if not found, try from the remote repository
|
// if not found, try from the remote repository
|
||||||
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
|
if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) )
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package org.apache.maven.lifecycle;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
|
import org.apache.maven.model.Plugin;
|
||||||
|
import org.apache.maven.plugin.MavenPluginCollector;
|
||||||
|
import org.apache.maven.plugin.MavenPluginDiscoverer;
|
||||||
|
import org.apache.maven.plugin.PluginManager;
|
||||||
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.project.MavenProjectBuilder;
|
||||||
|
import org.apache.maven.project.ProjectBuilderConfiguration;
|
||||||
|
import org.apache.maven.realm.DefaultMavenRealmManager;
|
||||||
|
import org.apache.maven.realm.MavenRealmManager;
|
||||||
|
import org.apache.maven.repository.RepositorySystem;
|
||||||
|
import org.codehaus.plexus.ContainerConfiguration;
|
||||||
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
import org.codehaus.plexus.logging.console.ConsoleLogger;
|
||||||
|
|
||||||
|
public class LifecycleExecutorTest
|
||||||
|
extends PlexusTestCase
|
||||||
|
{
|
||||||
|
private MavenProjectBuilder projectBuilder;
|
||||||
|
|
||||||
|
private RepositorySystem repositorySystem;
|
||||||
|
|
||||||
|
private PluginManager pluginManager;
|
||||||
|
|
||||||
|
private DefaultLifecycleExecutor lifecycleExecutor;
|
||||||
|
|
||||||
|
protected void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
projectBuilder = lookup( MavenProjectBuilder.class );
|
||||||
|
repositorySystem = lookup( RepositorySystem.class );
|
||||||
|
pluginManager = lookup( PluginManager.class );
|
||||||
|
lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testMojoExecution()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
// - find the plugin [extension point: any client may wish to do whatever they choose]
|
||||||
|
// - load the plugin into a classloader [extension point: we want to take them from a repository, some may take from disk or whatever]
|
||||||
|
// - configure the plugin [extension point]
|
||||||
|
// - execute the plugin
|
||||||
|
|
||||||
|
File pom = new File( getBasedir(), "src/test/pom.xml" );
|
||||||
|
|
||||||
|
// For testing I want to use my standard local repository and settings.
|
||||||
|
|
||||||
|
ArtifactRepository localRepository = repositorySystem.createLocalRepository( new File( "/Users/jvanzyl/.m2/repository" ) );
|
||||||
|
|
||||||
|
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration()
|
||||||
|
.setLocalRepository( localRepository )
|
||||||
|
.setRemoteRepositories( null );
|
||||||
|
|
||||||
|
MavenProject project = projectBuilder.build( pom, configuration );
|
||||||
|
|
||||||
|
// now i want to grab the configuration for the remote resources plugin
|
||||||
|
|
||||||
|
assertEquals( "maven", project.getArtifactId() );
|
||||||
|
|
||||||
|
Plugin plugin = new Plugin();
|
||||||
|
plugin.setGroupId( "org.apache.maven.plugins" );
|
||||||
|
plugin.setArtifactId( "maven-remote-resources-plugin" );
|
||||||
|
// The version should be specified in the POM.
|
||||||
|
|
||||||
|
MavenRealmManager realmManager = new DefaultMavenRealmManager( getContainer(), new ConsoleLogger( 0, "logger" ) );
|
||||||
|
MavenSession session = new MavenSession( localRepository, realmManager );
|
||||||
|
|
||||||
|
PluginDescriptor pd = pluginManager.loadPlugin( plugin, project, session );
|
||||||
|
assertNotNull( pd );
|
||||||
|
assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
|
||||||
|
assertEquals( "maven-remote-resources-plugin", pd.getArtifactId() );
|
||||||
|
assertEquals( "1.0", pd.getVersion() );
|
||||||
|
|
||||||
|
MojoDescriptor mojoDescriptor = pd.getMojo( "process" );
|
||||||
|
assertNotNull( mojoDescriptor );
|
||||||
|
System.out.println( "configuration >>> " + mojoDescriptor.getConfiguration() );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
|
||||||
|
{
|
||||||
|
containerConfiguration.addComponentDiscoverer( new MavenPluginDiscoverer() );
|
||||||
|
containerConfiguration.addComponentDiscoveryListener( new MavenPluginCollector() );
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,28 +0,0 @@
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<component-set>
|
|
||||||
<components>
|
|
||||||
<component>
|
|
||||||
<role>org.apache.maven.plugin.PluginLoader</role>
|
|
||||||
<role-hint>default</role-hint>
|
|
||||||
<implementation>org.apache.maven.lifecycle.plan.testutils.TestPluginLoader</implementation>
|
|
||||||
</component>
|
|
||||||
</components>
|
|
||||||
</component-set>
|
|
Binary file not shown.
|
@ -482,7 +482,8 @@ public class MavenEmbedder
|
||||||
ContainerConfiguration cc = new DefaultContainerConfiguration()
|
ContainerConfiguration cc = new DefaultContainerConfiguration()
|
||||||
.addComponentDiscoverer( new MavenPluginDiscoverer() )
|
.addComponentDiscoverer( new MavenPluginDiscoverer() )
|
||||||
.addComponentDiscoveryListener( new MavenPluginCollector() )
|
.addComponentDiscoveryListener( new MavenPluginCollector() )
|
||||||
.setClassWorld( classWorld ).setName( "embedder" );
|
.setClassWorld( classWorld )
|
||||||
|
.setName( "embedder" );
|
||||||
|
|
||||||
container = new DefaultPlexusContainer( cc );
|
container = new DefaultPlexusContainer( cc );
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.repository;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -96,7 +97,7 @@ public class LegacyRepositorySystem
|
||||||
private Map<String, AuthenticationInfo> authenticationInfoMap = new HashMap<String, AuthenticationInfo>();
|
private Map<String, AuthenticationInfo> authenticationInfoMap = new HashMap<String, AuthenticationInfo>();
|
||||||
|
|
||||||
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
|
private Map<String, RepositoryPermissions> serverPermissionsMap = new HashMap<String, RepositoryPermissions>();
|
||||||
|
|
||||||
// Artifact Creation
|
// Artifact Creation
|
||||||
|
|
||||||
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
|
||||||
|
@ -171,17 +172,17 @@ public class LegacyRepositorySystem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return {@link Set} < {@link Artifact} >
|
* @return {@link Set} < {@link Artifact} >
|
||||||
* @todo desperately needs refactoring. It's just here because it's implementation is maven-project specific
|
* @todo desperately needs refactoring. It's just here because it's implementation is
|
||||||
|
* maven-project specific
|
||||||
*/
|
*/
|
||||||
public Set<Artifact> createArtifacts( List<Dependency> dependencies, String inheritedScope,
|
public Set<Artifact> createArtifacts( List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
|
||||||
ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
|
|
||||||
throws VersionNotFoundException
|
throws VersionNotFoundException
|
||||||
{
|
{
|
||||||
return createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, reactor );
|
return createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, reactor );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory,List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
|
public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor )
|
||||||
throws VersionNotFoundException
|
throws VersionNotFoundException
|
||||||
{
|
{
|
||||||
Set<Artifact> projectArtifacts = new LinkedHashSet<Artifact>( dependencies.size() );
|
Set<Artifact> projectArtifacts = new LinkedHashSet<Artifact>( dependencies.size() );
|
||||||
|
@ -208,9 +209,7 @@ public class LegacyRepositorySystem
|
||||||
{
|
{
|
||||||
throw new VersionNotFoundException( reactor.getId(), d, reactor.getFile(), e );
|
throw new VersionNotFoundException( reactor.getId(), d, reactor.getFile(), e );
|
||||||
}
|
}
|
||||||
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(),
|
Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), scope, inheritedScope, d.isOptional() );
|
||||||
versionRange, d.getType(), d.getClassifier(),
|
|
||||||
scope, inheritedScope, d.isOptional() );
|
|
||||||
|
|
||||||
if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
|
if ( Artifact.SCOPE_SYSTEM.equals( scope ) )
|
||||||
{
|
{
|
||||||
|
@ -257,8 +256,8 @@ public class LegacyRepositorySystem
|
||||||
}
|
}
|
||||||
|
|
||||||
return projectArtifacts;
|
return projectArtifacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactRepository buildArtifactRepository( Repository repo )
|
public ArtifactRepository buildArtifactRepository( Repository repo )
|
||||||
throws InvalidRepositoryException
|
throws InvalidRepositoryException
|
||||||
{
|
{
|
||||||
|
@ -319,6 +318,19 @@ public class LegacyRepositorySystem
|
||||||
|
|
||||||
// From MavenExecutionRequestPopulator
|
// From MavenExecutionRequestPopulator
|
||||||
|
|
||||||
|
public ArtifactRepository createLocalRepository( File localRepository )
|
||||||
|
throws InvalidRepositoryException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return createRepository( localRepository.toURI().toURL().toString(), "maven.repo.local" );
|
||||||
|
}
|
||||||
|
catch ( MalformedURLException e )
|
||||||
|
{
|
||||||
|
throw new InvalidRepositoryException( "Error creating local repository.", "maven.repo.local", e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ArtifactRepository createLocalRepository( String url, String repositoryId )
|
public ArtifactRepository createLocalRepository( String url, String repositoryId )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
|
@ -373,7 +385,7 @@ public class LegacyRepositorySystem
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
||||||
{
|
{
|
||||||
return artifactResolver.resolve( request );
|
return artifactResolver.resolve( request );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -400,8 +412,7 @@ public class LegacyRepositorySystem
|
||||||
proxies.put( protocol, proxyInfo );
|
proxies.put( protocol, proxyInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey,
|
public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase )
|
||||||
String passphrase )
|
|
||||||
{
|
{
|
||||||
AuthenticationInfo authInfo = new AuthenticationInfo();
|
AuthenticationInfo authInfo = new AuthenticationInfo();
|
||||||
authInfo.setUserName( username );
|
authInfo.setUserName( username );
|
||||||
|
@ -437,14 +448,14 @@ public class LegacyRepositorySystem
|
||||||
serverPermissionsMap.put( repositoryId, permissions );
|
serverPermissionsMap.put( repositoryId, permissions );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirror
|
// Mirror
|
||||||
|
|
||||||
public void addMirror( String id, String mirrorOf, String url )
|
public void addMirror( String id, String mirrorOf, String url )
|
||||||
{
|
{
|
||||||
mirrorBuilder.addMirror( id, mirrorOf, url );
|
mirrorBuilder.addMirror( id, mirrorOf, url );
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories )
|
public List<ArtifactRepository> getMirrors( List<ArtifactRepository> repositories )
|
||||||
{
|
{
|
||||||
return mirrorBuilder.getMirrors( repositories );
|
return mirrorBuilder.getMirrors( repositories );
|
||||||
|
|
|
@ -15,6 +15,7 @@ package org.apache.maven.repository;
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -61,9 +62,13 @@ public interface RepositorySystem
|
||||||
ArtifactRepository buildArtifactRepository( Repository repository )
|
ArtifactRepository buildArtifactRepository( Repository repository )
|
||||||
throws InvalidRepositoryException;
|
throws InvalidRepositoryException;
|
||||||
|
|
||||||
|
//!!jvz Change this to use a file
|
||||||
ArtifactRepository createLocalRepository( String url, String repositoryId )
|
ArtifactRepository createLocalRepository( String url, String repositoryId )
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
|
||||||
|
ArtifactRepository createLocalRepository( File localRepository )
|
||||||
|
throws InvalidRepositoryException;
|
||||||
|
|
||||||
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
|
ArtifactResolutionResult resolve( ArtifactResolutionRequest request );
|
||||||
|
|
||||||
//MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request );
|
//MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request );
|
||||||
|
|
Loading…
Reference in New Issue