diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java index bee4ab958b..872392601e 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionRequest.java @@ -6,7 +6,6 @@ import java.util.Map; import java.util.Set; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.wagon.events.TransferListener; @@ -39,9 +38,6 @@ public class ArtifactResolutionRequest // This is like a filter but overrides all transitive versions private Map managedVersionMap; - // This should not be in here, it's a component - private ArtifactMetadataSource metadataSource; - private TransferListener transferListener; private boolean resolveRoot = true; @@ -127,18 +123,6 @@ public class ArtifactResolutionRequest return this; } - public ArtifactMetadataSource getMetadataSource() - { - return metadataSource; - } - - public ArtifactResolutionRequest setMetadataSource( ArtifactMetadataSource metadataSource ) - { - this.metadataSource = metadataSource; - - return this; - } - public Map getManagedVersionMap() { return managedVersionMap; @@ -193,8 +177,7 @@ public class ArtifactResolutionRequest .append( "artifact: " ).append( artifact ).append( "\n" ) .append( artifactDependencies ).append( "\n" ) .append( "localRepository: " ).append( localRepository ).append( "\n" ) - .append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" ) - .append( "metadataSource: " ).append( metadataSource ).append( "\n" ); + .append( "remoteRepositories: " ).append( remoteRepositories ).append( "\n" ); return sb.toString(); } diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 1ca9d5af35..b68f188ccf 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -75,7 +75,7 @@ public class DefaultArtifactResolver private ResolutionErrorHandler resolutionErrorHandler; @Requirement - private PlexusContainer container; + private ArtifactMetadataSource source; public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository, TransferListener resolutionListener ) throws ArtifactResolutionException, ArtifactNotFoundException @@ -331,7 +331,6 @@ public class DefaultArtifactResolver .setManagedVersionMap( managedVersions ) .setLocalRepository( localRepository ) .setRemoteRepostories( remoteRepositories ) - .setMetadataSource( source ) .setFilter( filter ) .setListeners( listeners ); @@ -368,7 +367,6 @@ public class DefaultArtifactResolver Map managedVersions = request.getManagedVersionMap(); ArtifactRepository localRepository = request.getLocalRepository(); List remoteRepositories = request.getRemoteRepostories(); - ArtifactMetadataSource source = request.getMetadataSource(); List listeners = request.getListeners(); ArtifactFilter filter = request.getFilter(); @@ -379,19 +377,7 @@ public class DefaultArtifactResolver { request.setResolveRoot( false ); } - - if ( source == null ) - { - try - { - source = container.lookup( ArtifactMetadataSource.class ); - } - catch ( ComponentLookupException e ) - { - throw new IllegalStateException( "Failed to lookup metadata source implementation", e ); - } - } - + if ( listeners == null ) { listeners = new ArrayList(); diff --git a/maven-core/pom.xml b/maven-core/pom.xml index ca07fe2466..62c55abbe9 100644 --- a/maven-core/pom.xml +++ b/maven-core/pom.xml @@ -97,6 +97,15 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + **/ProjectClasspathTest.java + + + diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 1831d125d4..560481a24d 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -41,10 +41,13 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuilderConfiguration; import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.repository.RepositorySystem; +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; import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; /** * @author Jason van Zyl @@ -56,12 +59,17 @@ public class MavenMetadataSource @Requirement private RepositoryMetadataManager repositoryMetadataManager; + //TODO: this will also cause a cycle so we need to refactor some code @Requirement - private RepositorySystem repositorySystem; + private ArtifactFactory repositorySystem; - @Requirement + //TODO: This prevents a cycle in the composition which shows us another problem we need to deal with. + //@Requirement private MavenProjectBuilder projectBuilder; + @Requirement + private PlexusContainer container; + @Requirement private Logger logger; @@ -87,7 +95,7 @@ public class MavenMetadataSource try { - project = projectBuilder.buildFromRepository( pomArtifact, configuration ); + project = getProjectBuilder().buildFromRepository( pomArtifact, configuration ); if ( !artifact.getArtifactHandler().isIncludesDependencies() ) { @@ -248,4 +256,23 @@ public class MavenMetadataSource return artifacts; } + + public MavenProjectBuilder getProjectBuilder() + { + if ( projectBuilder != null ) + { + return projectBuilder; + } + + try + { + projectBuilder = container.lookup( MavenProjectBuilder.class ); + } + catch ( ComponentLookupException e ) + { + // Won't happen + } + + return projectBuilder; + } } 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 index 05ea03768b..ea74c1f560 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -70,7 +70,25 @@ public class LifecycleExecutorTest assertEquals( "maven-resources-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() ); assertEquals( "2.3", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); } - + + public void testCalculationOfBuildPlanWithIndividualTaskWherePluginIsNotSpecifiedInThePom() + throws Exception + { + // We are doing something like "mvn clean:clean" where no version is specified but this + // project we are working on has the version specified in the POM so the version should come from there. + File pom = getProject( "project-with-additional-lifecycle-elements" ); + MavenSession session = createMavenSession( pom ); + assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() ); + assertEquals( "1.0", session.getCurrentProject().getVersion() ); + List lifecyclePlan = lifecycleExecutor.calculateBuildPlan( "clean:clean", session ); + assertEquals( 1, lifecyclePlan.size() ); + MojoExecution mojoExecution = lifecyclePlan.get( 0 ); + assertNotNull( mojoExecution ); + assertEquals( "org.apache.maven.plugins", mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() ); + assertEquals( "maven-clean-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() ); + assertEquals( "2.2", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() ); + } + public void testLifecycleQueryingUsingADefaultLifecyclePhase() throws Exception { diff --git a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index d157ca33db..51859d80db 100644 --- a/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-core/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -20,28 +20,22 @@ package org.apache.maven.project; */ import java.io.File; -import java.io.FileNotFoundException; import java.util.Iterator; -import java.util.List; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ResolutionGroup; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.artifact.MavenMetadataSource; public class ProjectClasspathTest extends AbstractMavenProjectTestCase { - private static final String dir = "projects/scope/"; + static final String dir = "projects/scope/"; public void setUp() throws Exception { - super.setUp(); - projectBuilder = lookup( MavenProjectBuilder.class, "default" ); + //super.setUp(); + projectBuilder = lookup( MavenProjectBuilder.class, "classpath" ); } - + @Override protected String getCustomConfigurationName() { @@ -141,51 +135,4 @@ public class ProjectClasspathTest return null; } - public static class TestMavenProjectBuilder - extends DefaultMavenProjectBuilder - { - - @Override - public MavenProject buildFromRepository( Artifact artifact, ProjectBuilderConfiguration configuration ) - throws ProjectBuildingException - { - if ( "maven-test".equals( artifact.getGroupId() ) ) - { - String scope = artifact.getArtifactId().substring( "scope-".length() ); - try - { - artifact.setFile( getFileForClasspathResource( dir + "transitive-" + scope + "-dep.xml" ) ); - } - catch ( FileNotFoundException e ) - { - throw new IllegalStateException( "Missing test POM for " + artifact ); - } - } - if ( artifact.getFile() == null ) - { - return new MavenProject(); - } - return build( artifact.getFile(), configuration ); - } - } - - public static class MetadataSource - extends MavenMetadataSource - { - - @Override - public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, - List remoteRepositories ) - throws ArtifactMetadataRetrievalException - { - ResolutionGroup rg = super.retrieve( artifact, localRepository, remoteRepositories ); - for ( Artifact a : rg.getArtifacts() ) - { - a.setResolved( true ); - } - return rg; - } - - } - } diff --git a/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java b/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java index f7b1d16d96..9c839095d3 100644 --- a/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java +++ b/maven-core/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java @@ -1,11 +1,15 @@ package org.apache.maven.project; +import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.repository.LegacyRepositorySystem; import org.apache.maven.repository.RepositorySystem; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; -@Component(role = RepositorySystem.class, hint = "test") +@Component(role = RepositorySystem.class, hint = "classpath") public class TestMavenRepositorySystem extends LegacyRepositorySystem { + @Requirement(hint="classpath") + private ArtifactResolver artifactResolver; } diff --git a/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java deleted file mode 100644 index efe5d19adf..0000000000 --- a/maven-core/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apache.maven.project; - -/* - * 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.codehaus.plexus.component.annotations.Component; - -@Component(role=MavenProjectBuilder.class,hint="test") -public class TestProjectBuilder - extends DefaultMavenProjectBuilder -{ -} diff --git a/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml b/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml deleted file mode 100644 index 24e4ab7aaf..0000000000 --- a/maven-core/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml +++ /dev/null @@ -1,98 +0,0 @@ - - - - - org.apache.maven.project.MavenProjectBuilder - default - org.apache.maven.project.ProjectClasspathTest$TestMavenProjectBuilder - false - - - org.codehaus.plexus.logging.Logger - default - logger - - - org.apache.maven.project.validation.ModelValidator - default - validator - - - org.apache.maven.lifecycle.LifecycleExecutor - default - lifecycle - - - org.apache.maven.repository.RepositorySystem - default - repositorySystem - - - java.util.List - listeners - - - org.apache.maven.model.interpolator.Interpolator - default - interpolator - - - org.apache.maven.model.normalization.Normalizer - default - normalizer - - - org.apache.maven.model.lifecycle.LifecycleBindingsInjector - default - lifecycleBindingsInjector - - - org.apache.maven.artifact.resolver.ResolutionErrorHandler - default - resolutionErrorHandler - - - org.apache.maven.project.MavenProjectCache - default - projectCache - - - org.apache.maven.model.plugin.PluginConfigurationExpander - default - pluginConfigurationExpander - - - - - org.apache.maven.artifact.metadata.ArtifactMetadataSource - default - org.apache.maven.project.ProjectClasspathTest$MetadataSource - - - org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager - default - repositoryMetadataManager - - - org.apache.maven.repository.RepositorySystem - default - repositorySystem - - - org.apache.maven.project.MavenProjectBuilder - default - projectBuilder - - - org.codehaus.plexus.logging.Logger - default - logger - - - - - org.apache.maven.lifecycle.LifecycleExecutor - org.apache.maven.project.EmptyLifecycleExecutor - - -