diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java index f5b2cbc359..df1b141b0a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java @@ -63,6 +63,17 @@ public class MavenSession 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 ) { this.container = container; @@ -76,11 +87,15 @@ public class MavenSession public MavenRealmManager getRealmManager() { + if ( realmManager != null ) + { + return realmManager; + } + return request.getRealmManager(); } - public Map getPluginContext( PluginDescriptor pluginDescriptor, - MavenProject project ) + public Map getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project ) { return reactorManager.getPluginContext( pluginDescriptor, project ); } @@ -89,9 +104,14 @@ public class MavenSession { return container; } - + public ArtifactRepository getLocalRepository() { + if ( localRepository != null ) + { + return localRepository; + } + return request.getLocalRepository(); } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index 0b1e70c762..c9e8be7079 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -927,7 +927,7 @@ public class DefaultLifecycleExecutor return lifecycle; } - private MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal ) + MojoDescriptor getMojoDescriptor( PluginDescriptor pluginDescriptor, String goal ) throws LifecycleExecutionException { MojoDescriptor desc = pluginDescriptor.getMojo( goal ); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index ca8872fd96..79258446b2 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -258,7 +258,7 @@ public class DefaultPluginManager try { pluginRealm = realmManager.createPluginRealm( projectPlugin, pluginArtifact, artifacts, coreArtifactFilterManager.getArtifactFilter() ); - + logger.debug( "Created realm: " + pluginRealm + " for plugin: " + projectPlugin.getKey() ); } 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 ); PluginDescriptor pluginDescriptor = pluginCollector.getPluginDescriptor( projectPlugin ); - + if ( pluginDescriptor == null ) { if ( ( pluginRealm != null ) && logger.isDebugEnabled() ) @@ -1825,8 +1825,7 @@ public class DefaultPluginManager // Plugin Mapping Manager - public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, - ArtifactRepository localRepository ) + public org.apache.maven.model.Plugin getByPrefix( String pluginPrefix, List groupIds, List pluginRepositories, ArtifactRepository localRepository ) { // if not found, try from the remote repository if ( !pluginDefinitionsByPrefix.containsKey( pluginPrefix ) ) diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java new file mode 100644 index 0000000000..ad65fbd0ca --- /dev/null +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -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() ); + } +} diff --git a/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.xml b/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.xml deleted file mode 100644 index a6ce99fff7..0000000000 --- a/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/DefaultBuildPlannerTest.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - org.apache.maven.plugin.PluginLoader - default - org.apache.maven.lifecycle.plan.testutils.TestPluginLoader - - - diff --git a/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar b/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar deleted file mode 100644 index 5c9bef6e8d..0000000000 Binary files a/maven-core/src/test/resources/org/apache/maven/lifecycle/plan/test-custom-lifecycle-buildPlan-1.jar and /dev/null differ diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index b7575cc34f..59e208ff82 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -482,7 +482,8 @@ public class MavenEmbedder ContainerConfiguration cc = new DefaultContainerConfiguration() .addComponentDiscoverer( new MavenPluginDiscoverer() ) .addComponentDiscoveryListener( new MavenPluginCollector() ) - .setClassWorld( classWorld ).setName( "embedder" ); + .setClassWorld( classWorld ) + .setName( "embedder" ); container = new DefaultPlexusContainer( cc ); } diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index 112e63af55..bb029a3bbf 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -17,6 +17,7 @@ package org.apache.maven.repository; import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -96,7 +97,7 @@ public class LegacyRepositorySystem private Map authenticationInfoMap = new HashMap(); private Map serverPermissionsMap = new HashMap(); - + // Artifact Creation 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} > - * @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 createArtifacts( List dependencies, String inheritedScope, - ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) + public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) throws VersionNotFoundException { return createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, reactor ); } @Deprecated - public static Set createArtifacts( ArtifactFactory artifactFactory,List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) + public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenRepositoryWrapper reactor ) throws VersionNotFoundException { Set projectArtifacts = new LinkedHashSet( dependencies.size() ); @@ -208,9 +209,7 @@ public class LegacyRepositorySystem { throw new VersionNotFoundException( reactor.getId(), d, reactor.getFile(), e ); } - Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), - versionRange, d.getType(), d.getClassifier(), - scope, inheritedScope, d.isOptional() ); + Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), scope, inheritedScope, d.isOptional() ); if ( Artifact.SCOPE_SYSTEM.equals( scope ) ) { @@ -257,8 +256,8 @@ public class LegacyRepositorySystem } return projectArtifacts; - } - + } + public ArtifactRepository buildArtifactRepository( Repository repo ) throws InvalidRepositoryException { @@ -319,6 +318,19 @@ public class LegacyRepositorySystem // 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 ) throws IOException { @@ -373,7 +385,7 @@ public class LegacyRepositorySystem } public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) - { + { return artifactResolver.resolve( request ); } @@ -400,8 +412,7 @@ public class LegacyRepositorySystem proxies.put( protocol, proxyInfo ); } - public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, - String passphrase ) + public void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase ) { AuthenticationInfo authInfo = new AuthenticationInfo(); authInfo.setUserName( username ); @@ -437,14 +448,14 @@ public class LegacyRepositorySystem serverPermissionsMap.put( repositoryId, permissions ); } } - + // Mirror - + public void addMirror( String id, String mirrorOf, String url ) { mirrorBuilder.addMirror( id, mirrorOf, url ); } - + public List getMirrors( List repositories ) { return mirrorBuilder.getMirrors( repositories ); diff --git a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java index 8b400c5a59..f47d07ec27 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -15,6 +15,7 @@ package org.apache.maven.repository; * the License. */ +import java.io.File; import java.io.IOException; import java.util.List; import java.util.Set; @@ -61,9 +62,13 @@ public interface RepositorySystem ArtifactRepository buildArtifactRepository( Repository repository ) throws InvalidRepositoryException; + //!!jvz Change this to use a file ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException; + ArtifactRepository createLocalRepository( File localRepository ) + throws InvalidRepositoryException; + ArtifactResolutionResult resolve( ArtifactResolutionRequest request ); //MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request );