o make the project dependencies resolver set the project artifacts

o Allow the artifact exlusions to be altered by injecting delegates with knowledge of client systems (m2eclipse)
  Submitted by: Igor Fedorenko



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@780176 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-05-30 05:05:00 +00:00
parent 4d45d00881
commit 1e2b77c10f
10 changed files with 94 additions and 9 deletions

View File

@ -19,12 +19,18 @@ package org.apache.maven;
* under the License.
*/
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
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;
/**
* @author Jason van Zyl
@ -38,6 +44,9 @@ public class DefaultArtifactFilterManager
private static final Set<String> DEFAULT_EXCLUSIONS;
@Requirement
private PlexusContainer plexus;
static
{
Set<String> artifacts = new HashSet<String>();
@ -96,7 +105,14 @@ public class DefaultArtifactFilterManager
*/
public ArtifactFilter getArtifactFilter()
{
return new ExclusionSetFilter( excludedArtifacts );
Set<String> excludes = new LinkedHashSet<String>( excludedArtifacts );
for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
{
delegate.addExcludes( excludes );
}
return new ExclusionSetFilter( excludes );
}
/**
@ -106,7 +122,26 @@ public class DefaultArtifactFilterManager
*/
public ArtifactFilter getCoreArtifactFilter()
{
return new ExclusionSetFilter( DEFAULT_EXCLUSIONS );
Set<String> excludes = new LinkedHashSet<String>( DEFAULT_EXCLUSIONS );
for ( ArtifactFilterManagerDelegate delegate : getDelegates() )
{
delegate.addCoreExcludes( excludes );
}
return new ExclusionSetFilter( excludes );
}
private List<ArtifactFilterManagerDelegate> getDelegates()
{
try
{
return plexus.lookupList( ArtifactFilterManagerDelegate.class );
}
catch ( ComponentLookupException e )
{
return new ArrayList<ArtifactFilterManagerDelegate>();
}
}
/* (non-Javadoc)

View File

@ -74,6 +74,7 @@ public class DefaultProjectDependenciesResolver
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
project.setArtifacts( result.getArtifacts() );
return result.getArtifacts();
}
}

View File

@ -45,6 +45,9 @@ public class ReactorArtifactRepository
}
else
{
//TODO Need to look for attached artifacts
//TODO Need to look for plugins
File artifactFile = project.getArtifact().getFile();
if ( artifactFile != null && artifactFile.exists() )

View File

@ -164,8 +164,7 @@ public class DefaultLifecycleExecutor
// mojoDescriptor.isDependencyResolutionRequired() is actually the scope of the dependency resolution required, not a boolean ... yah.
try
{
Set<Artifact> projectDependencies = projectDependenciesResolver.resolve( currentProject, executionPlan.getRequiredResolutionScope(), session.getLocalRepository(), currentProject.getRemoteArtifactRepositories() );
currentProject.setArtifacts( projectDependencies );
projectDependenciesResolver.resolve( currentProject, executionPlan.getRequiredResolutionScope(), session.getLocalRepository(), currentProject.getRemoteArtifactRepositories() );
}
catch ( ArtifactNotFoundException e )
{

View File

@ -333,7 +333,7 @@ public class DefaultPluginManager
}
catch ( PluginManagerException e )
{
throw new PluginExecutionException( mojoExecution, project, e.getMessage() );
throw new PluginExecutionException( mojoExecution, project, e );
}
finally
{

View File

@ -15,7 +15,7 @@ public class PluginExecutionException
this.mojoExecution = mojoExecution;
}
public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, MojoExecutionException cause )
public PluginExecutionException( MojoExecution mojoExecution, MavenProject project, Exception cause )
{
super( mojoExecution.getMojoDescriptor(), project, "Mojo execution failed.", cause );
this.mojoExecution = mojoExecution;

View File

@ -250,7 +250,6 @@ public class PluginParameterExpressionEvaluator
}
catch ( Exception e )
{
e.printStackTrace();
throw new ExpressionEvaluationException( "Error evaluating plugin parameter expression: " + expression, e );
}
}

View File

@ -99,13 +99,20 @@ public abstract class AbstractCoreMavenComponentTestCase
// a Maven subclass because we don't want to couple maven to the project builder which we need to
// separate.
protected MavenSession createMavenSession( File pom )
throws Exception
{
return createMavenSession( pom, new Properties() );
}
protected MavenSession createMavenSession( File pom, Properties executionProperties )
throws Exception
{
MavenExecutionRequest request = createMavenExecutionRequest( pom );
ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest()
.setLocalRepository( request.getLocalRepository() )
.setRemoteRepositories( request.getRemoteRepositories() );
.setRemoteRepositories( request.getRemoteRepositories() )
.setExecutionProperties( executionProperties );
MavenProject project = null;

View File

@ -1,9 +1,12 @@
package org.apache.maven;
import java.io.File;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Exclusion;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.annotations.Requirement;
@ -63,4 +66,25 @@ public class ProjectDependenciesResolverTest
Set<Artifact> artifactDependencies = resolver.resolve( project, Artifact.SCOPE_COMPILE, getLocalRepository(), getRemoteRepositories() );
assertEquals( 1, artifactDependencies.size() );
}
/*
public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
throws Exception
{
File pom = getProject( "it0063" );
Properties eps = new Properties();
eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() );
MavenSession session = createMavenSession( pom, eps );
MavenProject project = session.getCurrentProject();
resolver.resolve( project, Artifact.SCOPE_COMPILE, getLocalRepository(), getRemoteRepositories() );
// Here we will actually not have any artifacts because the ProjectDependenciesResolver is not involved here. So
// right now it's not valid to ask for artifacts unless plugins require the artifacts.
List<String> elements = project.getCompileClasspathElements();
}
*/
}

View File

@ -1,6 +1,11 @@
package org.apache.maven.project;
import java.io.File;
import java.util.List;
import java.util.Properties;
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.execution.MavenSession;
public class ProjectBuilderTest
extends AbstractCoreMavenComponentTestCase
@ -10,8 +15,20 @@ public class ProjectBuilderTest
return "src/test/projects/project-builder";
}
public void testProjectBuilderWhereOutputDirectoryIsOverridden()
public void testSystemScopeDependencyIsPresentInTheCompileClasspathElements()
throws Exception
{
File pom = getProject( "it0063" );
Properties eps = new Properties();
eps.setProperty( "jre.home", new File( pom.getParentFile(), "jdk/jre" ).getPath() );
MavenSession session = createMavenSession( pom, eps );
MavenProject project = session.getCurrentProject();
// Here we will actually not have any artifacts because the ProjectDependenciesResolver is not involved here. So
// right now it's not valid to ask for artifacts unless plugins require the artifacts.
List<String> elements = project.getCompileClasspathElements();
}
}