mirror of https://github.com/apache/maven.git
o injecting the metadata sources results in having to do some trickery to break the circular dependency between the components, this
is visible now in the metadata source which shows we need to do some work there as circular deps are pretty sure sign of poor design o the ProjectClasspathTest has little stub components so I'm not even sure if it's a decent test but it requires a bunch of custom implementations as i tried to get rid of the hand written descriptor and have only annotated tests implementations but somewhere an incorrect implementations is being injected. I'll work on breaking the circular dependency and we need a nicer way to inject test implementations, the way the Module works in Guice is the way to go. We'll bridge the gap until we can switch over to Guice. git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@776529 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
03aef5b15b
commit
9be598d351
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public class DefaultArtifactResolver
|
|||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
@Requirement
|
||||
private PlexusContainer container;
|
||||
private ArtifactMetadataSource source;
|
||||
|
||||
public void resolve( Artifact artifact, List<ArtifactRepository> 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<ArtifactRepository> remoteRepositories = request.getRemoteRepostories();
|
||||
ArtifactMetadataSource source = request.getMetadataSource();
|
||||
List<ResolutionListener> 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<ResolutionListener>();
|
||||
|
|
|
@ -97,6 +97,15 @@
|
|||
</models>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/ProjectClasspathTest.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MojoExecution> 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
|
||||
{
|
||||
|
|
|
@ -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<ArtifactRepository> remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
ResolutionGroup rg = super.retrieve( artifact, localRepository, remoteRepositories );
|
||||
for ( Artifact a : rg.getArtifacts() )
|
||||
{
|
||||
a.setResolved( true );
|
||||
}
|
||||
return rg;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plexus>
|
||||
<components>
|
||||
<component>
|
||||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.project.ProjectClasspathTest$TestMavenProjectBuilder</implementation>
|
||||
<isolated-realm>false</isolated-realm>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.codehaus.plexus.logging.Logger</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>logger</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.validation.ModelValidator</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>validator</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>lifecycle</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.repository.RepositorySystem</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>repositorySystem</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>java.util.List</role>
|
||||
<field-name>listeners</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.model.interpolator.Interpolator</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>interpolator</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.model.normalization.Normalizer</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>normalizer</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.model.lifecycle.LifecycleBindingsInjector</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>lifecycleBindingsInjector</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.resolver.ResolutionErrorHandler</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>resolutionErrorHandler</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.MavenProjectCache</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>projectCache</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.model.plugin.PluginConfigurationExpander</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>pluginConfigurationExpander</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.apache.maven.artifact.metadata.ArtifactMetadataSource</role>
|
||||
<role-hint>default</role-hint>
|
||||
<implementation>org.apache.maven.project.ProjectClasspathTest$MetadataSource</implementation>
|
||||
<requirements>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>repositoryMetadataManager</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.repository.RepositorySystem</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>repositorySystem</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.project.MavenProjectBuilder</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>projectBuilder</field-name>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.codehaus.plexus.logging.Logger</role>
|
||||
<role-hint>default</role-hint>
|
||||
<field-name>logger</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
</component>
|
||||
<component>
|
||||
<role>org.apache.maven.lifecycle.LifecycleExecutor</role>
|
||||
<implementation>org.apache.maven.project.EmptyLifecycleExecutor</implementation>
|
||||
</component>
|
||||
</components>
|
||||
</plexus>
|
Loading…
Reference in New Issue