This commit is contained in:
Jason van Zyl 2009-05-12 20:50:52 +00:00
parent b6ee917be9
commit b4251c3e16
14 changed files with 104 additions and 103 deletions

View File

@ -324,7 +324,7 @@ public class DefaultArtifactResolver
List<ConflictResolver> conflictResolvers )
throws ArtifactResolutionException, ArtifactNotFoundException
{
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( originatingArtifact ).setResolveRoot( false ).setArtifactDependencies( artifacts ).setManagedVersionMap( managedVersions )
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( originatingArtifact ).setManagedVersionMap( managedVersions )
.setLocalRepository( localRepository ).setRemoteRepostories( remoteRepositories ).setMetadataSource( source ).setFilter( filter ).setListeners( listeners );
return resolveWithExceptions( request );
@ -465,7 +465,7 @@ public class DefaultArtifactResolver
// After the collection we will have the artifact object in the result but they will not be resolved yet.
result = artifactCollector.collect( artifacts, rootArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners, null );
// We have metadata retrieval problems, or there are cycles that have been detected
// so we give this back to the calling code and let them deal with this information
// appropriately.

View File

@ -126,7 +126,7 @@ public class DefaultMaven
{
ProjectSorter projectSorter = new ProjectSorter( projects.values() );
session = new MavenSession( container, request, projectSorter.getSortedProjects() );
session = new MavenSession( container, request, result, projectSorter.getSortedProjects() );
}
catch ( CycleDetectedException e )
{
@ -154,13 +154,11 @@ public class DefaultMaven
return result;
}
try
{
lifecycleExecutor.execute( session );
}
catch ( Exception e )
{
return processResult( result, e );
lifecycleExecutor.execute( session );
if ( session.getResult().hasExceptions() )
{
return processResult( result, session.getResult().getExceptions().get( 0 ) );
}
result.setTopologicallySortedProjects( session.getProjects() );

View File

@ -20,11 +20,13 @@ package org.apache.maven.execution;
*/
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.settings.Settings;
@ -41,6 +43,8 @@ public class MavenSession
private MavenExecutionRequest request;
private MavenExecutionResult result;
private MavenProject currentProject;
/**
@ -57,17 +61,18 @@ public class MavenSession
this.request = request;
}
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenProject project )
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result, MavenProject project )
throws CycleDetectedException, DuplicateProjectException
{
this( container, request, Arrays.asList( new MavenProject[]{ project } ) );
this( container, request, result, Arrays.asList( new MavenProject[]{ project } ) );
}
public MavenSession( PlexusContainer container, MavenExecutionRequest request, List<MavenProject> projects )
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result, List<MavenProject> projects )
throws CycleDetectedException, DuplicateProjectException
{
this.container = container;
this.request = request;
this.result = result;
this.currentProject = projects.get( 0 );
this.projects = projects;
}
@ -146,4 +151,42 @@ public class MavenSession
{
return topLevelProject;
}
public MavenExecutionResult getResult()
{
return result;
}
// Backward compat
public Map<String,Map<String,Object>> getPluginContext( PluginDescriptor pluginDescriptor, MavenProject project )
{
return new HashMap<String,Map<String,Object>>();
}
/*
private Map pluginContextsByProjectAndPluginKey = new HashMap();
public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
{
Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() );
if ( pluginContextsByKey == null )
{
pluginContextsByKey = new HashMap();
pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
}
Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() );
if ( pluginContext == null )
{
pluginContext = new HashMap();
pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
}
return pluginContext;
}
*/
}

View File

@ -67,8 +67,7 @@ public interface LifecycleExecutor
void populateDefaultConfigurationForPlugins( Collection<Plugin> plugins, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException;
void execute( MavenSession session )
throws LifecycleExecutionException, MojoFailureException, MojoExecutionException;
void execute( MavenSession session );
Xpp3Dom getDefaultPluginConfiguration( String groupId, String artifactId, String version, String goal, MavenProject project, ArtifactRepository localRepository )
throws LifecycleExecutionException;

View File

@ -261,8 +261,7 @@ public class DefaultPluginManager
.setLocalRepository( localRepository )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setFilter( filter )
.setResolveTransitively( true )
.setResolveRoot( true ); // We are setting this to false because the artifact itself has been resolved.
.setResolveTransitively( true );
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );

View File

@ -176,8 +176,7 @@ public class DefaultMavenProjectBuilder
{
pluginConfigurationExpander.expandPluginConfiguration( project.getModel() );
lifecycle.populateDefaultConfigurationForPlugins( project.getModel().getBuild().getPlugins(), project,
configuration.getLocalRepository() );
lifecycle.populateDefaultConfigurationForPlugins( project.getModel().getBuild().getPlugins(), project, configuration.getLocalRepository() );
}
}
catch ( IOException e )
@ -277,11 +276,14 @@ public class DefaultMavenProjectBuilder
throws ProjectBuildingException
{
MavenProject project = build( pomFile, configuration );
Artifact pomArtifact = repositorySystem.createProjectArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion() );
pomArtifact.setFile( pomFile );
Artifact artifact = repositorySystem.createArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging() );
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( pomArtifact ).setResolveTransitively( true ).setArtifactDependencies( project.getDependencyArtifacts() )
.setLocalRepository( configuration.getLocalRepository() ).setRemoteRepostories( project.getRemoteArtifactRepositories() ).setManagedVersionMap( project.getManagedVersionMap() );
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( artifact )
.setResolveTransitively( true )
.setLocalRepository( configuration.getLocalRepository() )
.setRemoteRepostories( project.getRemoteArtifactRepositories() )
.setManagedVersionMap( project.getManagedVersionMap() );
ArtifactResolutionResult result = repositorySystem.resolve( request );
@ -294,7 +296,7 @@ public class DefaultMavenProjectBuilder
}
project.setArtifacts( result.getArtifacts() );
project.getArtifacts().remove( pomArtifact );
project.getArtifacts().remove( artifact );
return new MavenProjectBuildingResult( project, result );
}

View File

@ -500,7 +500,7 @@ public class MavenProject
list.add( getBuild().getOutputDirectory() );
for ( Artifact a : getArtifacts() )
{
{
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
@ -516,63 +516,12 @@ public class MavenProject
for( String s : list )
{
System.out.println( ">>>>> " + s );
}
*/
}
*/
return list;
}
public List<Artifact> getCompileArtifacts()
{
List<Artifact> list = new ArrayList<Artifact>( getArtifacts().size() );
for ( Artifact a : getArtifacts() )
{
// TODO: classpath check doesn't belong here - that's the other method
if ( a.getArtifactHandler().isAddedToClasspath() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
list.add( a );
}
}
}
return list;
}
public List<Dependency> getCompileDependencies()
{
Set<Artifact> artifacts = getArtifacts();
if ( ( artifacts == null ) || artifacts.isEmpty() )
{
return Collections.emptyList();
}
List<Dependency> list = new ArrayList<Dependency>( artifacts.size() );
for ( Artifact a : getArtifacts() )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( a.getArtifactId() );
dependency.setGroupId( a.getGroupId() );
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
}
return list;
}
public List<String> getTestClasspathElements()
throws DependencyResolutionRequiredException
{

View File

@ -6,6 +6,7 @@ import java.util.Properties;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.DefaultMavenExecutionResult;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
@ -106,7 +107,7 @@ public abstract class AbstractCoreMavenComponentTestCase
project = createStubMavenProject();
}
MavenSession session = new MavenSession( getContainer(), request, project );
MavenSession session = new MavenSession( getContainer(), request, new DefaultMavenExecutionResult(), project );
return session;
}

View File

@ -2,8 +2,11 @@ package org.apache.maven;
import java.io.File;
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.codehaus.plexus.component.annotations.Requirement;
public class MavenTest
@ -12,11 +15,15 @@ public class MavenTest
@Requirement
private Maven maven;
@Requirement
private ExceptionHandler exceptionHandler;
protected void setUp()
throws Exception
{
super.setUp();
maven = lookup( Maven.class );
exceptionHandler = lookup( ExceptionHandler.class );
}
protected String getProjectsDirectory()
@ -24,15 +31,17 @@ public class MavenTest
return "src/test/projects/lifecycle-executor";
}
// -----------------------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------------------
public void testMaven()
public void testLifecycleExecutionUsingADefaultLifecyclePhase()
throws Exception
{
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenExecutionRequest request = createMavenExecutionRequest( pom );
MavenExecutionResult result = maven.execute( request );
MavenExecutionResult result = maven.execute( request );
if ( result.hasExceptions() )
{
ExceptionSummary es = exceptionHandler.handleException( result.getExceptions().get( 0 ) );
System.out.println( es.getMessage() );
fail( "Maven did not execute correctly." );
}
}
}

View File

@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.exception.ExceptionSummary;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecution;
@ -23,6 +25,7 @@ public class LifecycleExecutorTest
{
super.setUp();
lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class );
lookup( ExceptionHandler.class );
}
protected String getProjectsDirectory()
@ -70,17 +73,7 @@ public class LifecycleExecutorTest
assertEquals( "surefire:test", lifecyclePlan.get( 6 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "jar:jar", lifecyclePlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
}
public void testLifecycleExecutionUsingADefaultLifecyclePhase()
throws Exception
{
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() );
lifecycleExecutor.execute( session );
}
public void testLifecyclePluginsRetrievalForDefaultLifecycle()
throws Exception
{

View File

@ -51,7 +51,6 @@ public class EmptyLifecycleExecutor
}
public void execute( MavenSession session )
throws LifecycleExecutionException, MojoFailureException, MojoExecutionException
{
}

View File

@ -173,9 +173,16 @@ public class MavenCli
{
ExceptionSummary es = result.getExceptionSummary();
if ( es == null )
{
result.getExceptions().get( 0 ).printStackTrace();
}
else
{
System.out.println( es.getMessage() );
es.getException().printStackTrace();
}
return 1;
}

View File

@ -79,16 +79,16 @@ public class LegacyRepositorySystem
return artifactFactory.createArtifact( groupId, artifactId, version, scope, type );
}
public Artifact createArtifact( String groupId, String artifactId, String version, String packaging )
{
return artifactFactory.createBuildArtifact( groupId, artifactId, version, packaging );
}
public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier )
{
return artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, classifier );
}
public Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging )
{
return artifactFactory.createBuildArtifact( groupId, artifactId, version, packaging );
}
public Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId )
{
return artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId );

View File

@ -46,9 +46,11 @@ public interface RepositorySystem
static final String DEFAULT_REMOTE_REPO_URL = "http://repo1.maven.org/maven2";
Artifact createArtifact( String groupId, String artifactId, String version, String packaging );
Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId );
Artifact createProjectArtifact( String groupId, String artifactId, String version );
Artifact createPluginArtifact( Plugin plugin );