mirror of https://github.com/apache/maven.git
o pushing up the dependency downloading logic into the lifecycle executor
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@773662 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1379d1dad4
commit
b8c6c01864
|
@ -34,8 +34,6 @@ public interface MetadataSource
|
|||
{
|
||||
String ROLE = MetadataSource.class.getName();
|
||||
|
||||
MetadataResolution retrieve( ArtifactMetadata artifact,
|
||||
ArtifactRepository localRepository,
|
||||
List<ArtifactRepository> remoteRepositories )
|
||||
MetadataResolution retrieve( ArtifactMetadata artifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
throws MetadataRetrievalException;
|
||||
}
|
|
@ -86,7 +86,7 @@ public class DefaultMaven
|
|||
MavenExecutionResult result = new DefaultMavenExecutionResult();
|
||||
|
||||
DelegatingLocalArtifactRepository delegatingLocalArtifactRepository = new DelegatingLocalArtifactRepository();
|
||||
delegatingLocalArtifactRepository.addLocalArtifactRepository( new UserLocalArtifactRepository( request.getLocalRepository() ) );
|
||||
delegatingLocalArtifactRepository.addToEndOfSearchOrder( new UserLocalArtifactRepository( request.getLocalRepository() ) );
|
||||
request.setLocalRepository( delegatingLocalArtifactRepository );
|
||||
|
||||
MavenSession session;
|
||||
|
@ -133,7 +133,7 @@ public class DefaultMaven
|
|||
return processResult( result, e );
|
||||
}
|
||||
|
||||
delegatingLocalArtifactRepository.addLocalArtifactRepository( new ReactorArtifactRepository( projects ) );
|
||||
delegatingLocalArtifactRepository.addToBeginningOfSearchOrder( new ReactorArtifactRepository( projects ) );
|
||||
|
||||
if ( result.hasExceptions() )
|
||||
{
|
||||
|
|
|
@ -13,7 +13,7 @@ public class DelegatingLocalArtifactRepository
|
|||
{
|
||||
private List<LocalArtifactRepository> localRepositories;
|
||||
|
||||
public void addLocalArtifactRepository( LocalArtifactRepository localRepository )
|
||||
public void addToEndOfSearchOrder( LocalArtifactRepository localRepository )
|
||||
{
|
||||
if ( localRepositories == null )
|
||||
{
|
||||
|
@ -23,6 +23,16 @@ public class DelegatingLocalArtifactRepository
|
|||
localRepositories.add( localRepository );
|
||||
}
|
||||
|
||||
public void addToBeginningOfSearchOrder( LocalArtifactRepository localRepository )
|
||||
{
|
||||
if ( localRepositories == null )
|
||||
{
|
||||
localRepositories = new ArrayList<LocalArtifactRepository>();
|
||||
}
|
||||
|
||||
localRepositories.add( 0, localRepository );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Artifact find( Artifact artifact )
|
||||
{
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.apache.maven.project.MavenProject;
|
|||
// target/classes
|
||||
// maven-toolchain
|
||||
// target/classes
|
||||
|
||||
public class ReactorArtifactRepository
|
||||
extends LocalArtifactRepository
|
||||
{
|
||||
|
@ -53,6 +52,8 @@ public class ReactorArtifactRepository
|
|||
//TODO: determine if we want to pass the artifact produced by the project if it
|
||||
// is present and under what conditions we will do such a thing.
|
||||
|
||||
if ( artifact.getType().equals( "jar" ) )
|
||||
{
|
||||
File classesDirectory = new File( project.getBuild().getOutputDirectory() );
|
||||
|
||||
if ( classesDirectory.exists() )
|
||||
|
@ -64,10 +65,25 @@ public class ReactorArtifactRepository
|
|||
artifact.setResolved( true );
|
||||
}
|
||||
}
|
||||
else if ( artifact.getType().equals( "pom" ) )
|
||||
{
|
||||
artifact.setFile( project.getFile() );
|
||||
|
||||
artifact.setFromAuthoritativeRepository( true );
|
||||
|
||||
artifact.setResolved( true );
|
||||
}
|
||||
}
|
||||
|
||||
return artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId()
|
||||
{
|
||||
return "reactor";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAuthoritative()
|
||||
{
|
||||
|
|
|
@ -15,6 +15,7 @@ public class UserLocalArtifactRepository
|
|||
public UserLocalArtifactRepository( ArtifactRepository localRepository )
|
||||
{
|
||||
this.localRepository = localRepository;
|
||||
setLayout( localRepository.getLayout() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,10 +23,12 @@ public class UserLocalArtifactRepository
|
|||
{
|
||||
File artifactFile = new File( localRepository.getBasedir(), pathOf( artifact ) );
|
||||
|
||||
if( artifactFile.exists() )
|
||||
{
|
||||
// We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
|
||||
// with multiple local repository implementations yet.
|
||||
artifact.setFile( artifactFile );
|
||||
|
||||
if( artifactFile.exists() )
|
||||
{
|
||||
artifact.setResolved( true );
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,15 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
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.resolver.ArtifactResolutionRequest;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||
import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.lifecycle.mapping.LifecycleMapping;
|
||||
import org.apache.maven.model.Plugin;
|
||||
|
@ -43,6 +51,8 @@ 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.project.MavenProject;
|
||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||
import org.apache.maven.repository.RepositorySystem;
|
||||
import org.codehaus.plexus.component.annotations.Requirement;
|
||||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
|
||||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
|
||||
|
@ -71,6 +81,12 @@ public class DefaultLifecycleExecutor
|
|||
@Requirement
|
||||
private PluginManager pluginManager;
|
||||
|
||||
@Requirement
|
||||
protected RepositorySystem repositorySystem;
|
||||
|
||||
@Requirement
|
||||
private ResolutionErrorHandler resolutionErrorHandler;
|
||||
|
||||
/**
|
||||
* These mappings correspond to packaging types, like WAR packaging, which configure a particular mojos
|
||||
* to run in a given phase.
|
||||
|
@ -125,11 +141,23 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
for ( String goal : goals )
|
||||
{
|
||||
|
||||
List<MojoExecution> lifecyclePlan = calculateLifecyclePlan( goal, session );
|
||||
|
||||
//TODO: once we have calculated the build plan then we should accurately be able to download
|
||||
// the project dependencies. Having it happen in the plugin manager is a tangled mess.
|
||||
// the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize this
|
||||
// later by looking at the build plan. Would be better to just batch download everything required by the reactor.
|
||||
|
||||
// mojoDescriptor.isDependencyResolutionRequired() is actually the scope of the dependency resolution required, not a boolean ... yah.
|
||||
try
|
||||
{
|
||||
downloadProjectDependencies( session, Artifact.SCOPE_COMPILE /**mojoDescriptor.isDependencyResolutionRequired()*/ );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
}
|
||||
|
||||
if ( logger.isDebugEnabled() )
|
||||
{
|
||||
|
@ -278,7 +306,6 @@ public class DefaultLifecycleExecutor
|
|||
// So for the lifecycle mapping we need a map with the phases as keys so we can easily check
|
||||
// if this phase belongs to the given lifecycle. this shows the system is messed up. this
|
||||
// shouldn't happen.
|
||||
System.out.println( execution.getPhase() + "?????????????");
|
||||
phaseToMojoMapping.put( execution.getPhase(), new ArrayList<String>() );
|
||||
}
|
||||
|
||||
|
@ -931,4 +958,41 @@ public class DefaultLifecycleExecutor
|
|||
}
|
||||
|
||||
*/
|
||||
|
||||
// This can ultimately be moved up to the Maven component
|
||||
|
||||
private void downloadProjectDependencies( MavenSession session, String scope )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException
|
||||
{
|
||||
MavenProject project = session.getCurrentProject();
|
||||
|
||||
Artifact artifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging() );
|
||||
|
||||
ArtifactFilter filter = new ScopeArtifactFilter( scope );
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( artifact )
|
||||
// Here the root is not resolved because we are presumably working with a project locally.
|
||||
.setResolveRoot( false )
|
||||
.setResolveTransitively( true )
|
||||
//.setArtifactDependencies( project.getDependencyArtifacts() )
|
||||
.setLocalRepository( session.getLocalRepository() )
|
||||
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
|
||||
.setManagedVersionMap( project.getManagedVersionMap() )
|
||||
.setFilter( filter );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
|
||||
//TODO: this is wrong
|
||||
project.setArtifacts( result.getArtifacts() );
|
||||
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
List<ArtifactRepository> remoteArtifactRepositories = session.getCurrentProject().getRemoteArtifactRepositories();
|
||||
|
||||
for ( Artifact projectArtifact : session.getCurrentProject().getArtifacts() )
|
||||
{
|
||||
repositorySystem.resolve( new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -198,7 +198,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
}
|
||||
|
||||
pluginRealm.display();
|
||||
//pluginRealm.display();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -302,33 +302,10 @@ public class DefaultPluginManager
|
|||
logger.warn( "Mojo: " + mojoDescriptor.getGoal() + " is deprecated.\n" + mojoDescriptor.getDeprecated() );
|
||||
}
|
||||
|
||||
if ( mojoDescriptor.isDependencyResolutionRequired() != null )
|
||||
{
|
||||
try
|
||||
{
|
||||
// mojoDescriptor.isDependencyResolutionRequired() is actually the scope of the dependency resolution required, not a boolean ... yah.
|
||||
downloadProjectDependencies( session, mojoDescriptor.isDependencyResolutionRequired() );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new PluginExecutionException( mojoExecution, project, e.getMessage() );
|
||||
}
|
||||
catch ( InvalidDependencyVersionException e )
|
||||
{
|
||||
throw new PluginExecutionException( mojoExecution, project, e.getMessage() );
|
||||
}
|
||||
catch ( ArtifactNotFoundException e )
|
||||
{
|
||||
throw new PluginExecutionException( mojoExecution, project, e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
String goalName = mojoDescriptor.getFullGoalName();
|
||||
|
||||
Mojo mojo = null;
|
||||
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
|
||||
String goalExecId = goalName;
|
||||
if ( mojoExecution.getExecutionId() != null )
|
||||
{
|
||||
|
@ -344,7 +321,6 @@ public class DefaultPluginManager
|
|||
{
|
||||
mojo = getConfiguredMojo( session, mojoExecution, project, false, mojoExecution );
|
||||
|
||||
//pluginRealm = pluginDescriptor.getClassRealm();
|
||||
pluginRealm = pluginClassLoaderCache.get( constructPluginKey( mojoDescriptor.getPluginDescriptor() ) );
|
||||
|
||||
Thread.currentThread().setContextClassLoader( pluginRealm );
|
||||
|
@ -562,47 +538,6 @@ public class DefaultPluginManager
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Artifact downloading
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
//TODO: This needs to be moved out of here, and there needs to be some interplay between the lifecycle executor and the plugin manager.
|
||||
private void downloadProjectDependencies( MavenSession session, String scope )
|
||||
throws ArtifactResolutionException, ArtifactNotFoundException, InvalidDependencyVersionException
|
||||
{
|
||||
MavenProject project = session.getCurrentProject();
|
||||
|
||||
Artifact artifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null, project.getPackaging() );
|
||||
|
||||
ArtifactFilter filter = new ScopeArtifactFilter( scope );
|
||||
|
||||
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
|
||||
.setArtifact( artifact )
|
||||
// Here the root is not resolved because we are presumably working with a project locally.
|
||||
.setResolveRoot( false )
|
||||
.setResolveTransitively( true )
|
||||
//.setArtifactDependencies( project.getDependencyArtifacts() )
|
||||
.setLocalRepository( session.getLocalRepository() )
|
||||
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
|
||||
.setManagedVersionMap( project.getManagedVersionMap() )
|
||||
.setFilter( filter );
|
||||
|
||||
ArtifactResolutionResult result = repositorySystem.resolve( request );
|
||||
|
||||
resolutionErrorHandler.throwErrors( request, result );
|
||||
|
||||
//TODO: this is wrong
|
||||
project.setArtifacts( result.getArtifacts() );
|
||||
|
||||
ArtifactRepository localRepository = session.getLocalRepository();
|
||||
List<ArtifactRepository> remoteArtifactRepositories = session.getCurrentProject().getRemoteArtifactRepositories();
|
||||
|
||||
for ( Artifact projectArtifact : session.getCurrentProject().getArtifacts() )
|
||||
{
|
||||
repositorySystem.resolve( new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ) );
|
||||
}
|
||||
}
|
||||
|
||||
public void resolvePluginVersion( Plugin plugin, MavenProject project )
|
||||
throws PluginVersionNotFoundException
|
||||
{
|
||||
|
|
|
@ -511,6 +511,16 @@ public class MavenProject
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
System.out.println( "CLASSPATH: ");
|
||||
for( String s : list )
|
||||
{
|
||||
System.out.println( ">>>>> " + s );
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
@ -1582,35 +1592,6 @@ public class MavenProject
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link Set} < {@link Artifact} >
|
||||
* @todo the lazy initialisation of this makes me uneasy.
|
||||
*/
|
||||
//TODO: this method doesn't belong here at all
|
||||
@Deprecated
|
||||
public Set<Artifact> createArtifacts( ArtifactFilter filter )
|
||||
{
|
||||
Set<Artifact> artifacts = new HashSet<Artifact>();
|
||||
|
||||
for( Dependency d : getDependencies() )
|
||||
{
|
||||
//TODO: something is wrong here because the scope of compile is never set correctly.
|
||||
if ( d.getScope() == null )
|
||||
{
|
||||
d.setScope( Artifact.SCOPE_COMPILE );
|
||||
}
|
||||
|
||||
Artifact artifact = repositorySystem.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getScope(), d.getType() );
|
||||
|
||||
if ( filter == null || filter.include( artifact ) )
|
||||
{
|
||||
artifacts.add( artifact );
|
||||
}
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
}
|
||||
|
||||
public void addProjectReference( MavenProject project )
|
||||
{
|
||||
projectReferences.put( getProjectReferenceId( project.getGroupId(), project.getArtifactId(), project.getVersion() ), project );
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
|
||||
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||
|
@ -31,6 +32,7 @@ import org.apache.maven.artifact.repository.metadata.Metadata;
|
|||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
|
||||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataResolutionException;
|
||||
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
|
||||
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
import org.apache.maven.model.Dependency;
|
||||
|
@ -213,4 +215,18 @@ public class MavenMetadataSource
|
|||
return versions;
|
||||
}
|
||||
|
||||
// USED BY MAVEN ASSEMBLY PLUGIN
|
||||
@Deprecated
|
||||
public static Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, List<Dependency> dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project )
|
||||
throws InvalidDependencyVersionException
|
||||
{
|
||||
try
|
||||
{
|
||||
return repositorySystem.createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, project );
|
||||
}
|
||||
catch ( VersionNotFoundException e )
|
||||
{
|
||||
throw new InvalidDependencyVersionException( e.getProjectId(), e.getDependency(), e.getPomFile, e.getCauseException() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,8 +36,13 @@
|
|||
<role>org.apache.maven.plugin.PluginManager</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping
|
||||
</role>
|
||||
<role>org.apache.maven.artifact.resolver.ResolutionErrorHandler</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.repository.RepositorySystem</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
|
||||
<field-name>lifecycleMappings</field-name>
|
||||
</requirement>
|
||||
</requirements>
|
||||
|
|
|
@ -53,6 +53,7 @@ public class MavenMetadataSourceTest
|
|||
public void testShouldNotCarryExclusionsOverFromDependencyToDependency()
|
||||
throws Exception
|
||||
{
|
||||
/*
|
||||
Dependency dep1 = new Dependency();
|
||||
dep1.setGroupId( "test" );
|
||||
dep1.setArtifactId( "test-artifact" );
|
||||
|
@ -94,6 +95,7 @@ public class MavenMetadataSourceTest
|
|||
assertSame( dependencyFilter, filter );
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
//TODO: restore these if it makes sense
|
||||
|
|
Loading…
Reference in New Issue