[MNG-2222] dependency to dependency without source code fails

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@928058 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-03-26 21:03:19 +00:00
parent 10f90c7b3d
commit bd1f3b58e5
3 changed files with 84 additions and 40 deletions

View File

@ -10,8 +10,6 @@ import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.execution.BuildSuccess;
import org.apache.maven.execution.MavenExecutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.LocalArtifactRepository;
@ -22,7 +20,6 @@ import org.apache.maven.repository.LocalArtifactRepository;
* @author Jason van Zyl
*/
//TODO: need phase information here to determine whether to hand back the classes/ or archive.
public class ReactorArtifactRepository
extends LocalArtifactRepository
{
@ -30,14 +27,11 @@ public class ReactorArtifactRepository
private Map<String, List<String>> availableVersions;
private MavenExecutionResult executionResult;
private final int hashCode;
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects, MavenSession session )
{
this.reactorProjects = reactorProjects;
this.executionResult = ( session != null ) ? session.getResult() : null;
hashCode = ( reactorProjects != null ) ? reactorProjects.keySet().hashCode() : 0;
availableVersions = new HashMap<String, List<String>>( reactorProjects.size() * 2 );
@ -84,22 +78,26 @@ public class ReactorArtifactRepository
resolve( artifact, projectArtifact.getFile() );
}
else if ( isProjectOutputValid( project ) )
else
{
File classesDir;
Collection<String> lifecyclePhases = project.getLifecyclePhases();
if ( !lifecyclePhases.contains( "package" ) )
{
if ( isTestArtifact( artifact ) )
{
classesDir = new File( project.getBuild().getTestOutputDirectory() );
if ( lifecyclePhases.contains( "test-compile" ) )
{
resolve( artifact, new File( project.getBuild().getTestOutputDirectory() ) );
}
}
else
{
classesDir = new File( project.getBuild().getOutputDirectory() );
}
if ( classesDir.isDirectory() )
if ( lifecyclePhases.contains( "compile" ) )
{
resolve( artifact, classesDir );
resolve( artifact, new File( project.getBuild().getOutputDirectory() ) );
}
}
}
}
}
@ -219,18 +217,6 @@ public class ReactorArtifactRepository
return buffer.toString();
}
/**
* Determines whether the output directories of the specified project have valid contents and can be used for
* artifact resolution.
*
* @param project The project to check, must not be {@code null}.
* @return {@code true} if the output directories are valid, {@code false} otherwise.
*/
private boolean isProjectOutputValid( MavenProject project )
{
return executionResult != null && executionResult.getBuildSummary( project ) instanceof BuildSuccess;
}
/**
* Determines whether the specified artifact refers to test classes.
*

View File

@ -319,10 +319,7 @@ public class DefaultLifecycleExecutor
DependencyContext dependencyContext =
new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
{
execute( session, mojoExecution, projectIndex, dependencyContext );
}
execute( session, executionPlan.getExecutions(), projectIndex, dependencyContext );
long buildEndTime = System.currentTimeMillis();
@ -525,6 +522,39 @@ public class DefaultLifecycleExecutor
}
}
private void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex,
DependencyContext dependencyContext )
throws LifecycleExecutionException
{
MavenProject project = session.getCurrentProject();
String lastLifecyclePhase = null;
for ( MojoExecution mojoExecution : mojoExecutions )
{
execute( session, mojoExecution, projectIndex, dependencyContext );
String lifecyclePhase = mojoExecution.getLifecyclePhase();
if ( lifecyclePhase != null )
{
if ( lastLifecyclePhase == null )
{
lastLifecyclePhase = lifecyclePhase;
}
else if ( !lifecyclePhase.equals( lastLifecyclePhase ) )
{
project.addLifecyclePhase( lastLifecyclePhase );
lastLifecyclePhase = lifecyclePhase;
}
}
}
if ( lastLifecyclePhase != null )
{
project.addLifecyclePhase( lastLifecyclePhase );
}
}
private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
DependencyContext dependencyContext )
throws LifecycleExecutionException
@ -680,10 +710,7 @@ public class DefaultLifecycleExecutor
session.getProjects().set( index, executedProject );
projectIndex.projects.put( fork.getKey(), executedProject );
for ( MojoExecution forkedExecution : fork.getValue() )
{
execute( session, forkedExecution, projectIndex, dependencyContext );
}
execute( session, fork.getValue(), projectIndex, dependencyContext );
}
finally
{

View File

@ -175,7 +175,7 @@ public class MavenProject
private ArtifactFilter extensionArtifactFilter;
//
private Set<String> lifecyclePhases;
public MavenProject()
{
@ -1947,6 +1947,8 @@ public class MavenProject
{
setManagedVersionMap( new HashMap<String, Artifact>( project.getManagedVersionMap() ) );
}
lifecyclePhases = null;
}
private void addArtifactPath( Artifact artifact, List<String> classpath )
@ -2081,4 +2083,33 @@ public class MavenProject
this.artifactMap = null;
}
/**
* Gets the set of lifecycle phases this project has successfully completed.
*
* @return The (unmodifiable) set of lifecycle phases this project has successfully completed, can be empty but
* never {@code null}.
*/
public Set<String> getLifecyclePhases()
{
return ( lifecyclePhases != null ) ? Collections.unmodifiableSet( lifecyclePhases )
: Collections.<String> emptySet();
}
/**
* Adds the specified lifecycle phase to the phases this project has successfully completed.
* <strong>Warning:</strong> This is an internal utility method that is only public for technical reasons, it is not
* part of the public API. In particular, this method can be changed or deleted without prior notice and must not be
* used by plugins.
*
* @param lifecyclePhase The lifecycle phase to add, must not be {@code null}.
*/
public void addLifecyclePhase( String lifecyclePhase )
{
if ( lifecyclePhases == null )
{
lifecyclePhases = new LinkedHashSet<String>();
}
lifecyclePhases.add( lifecyclePhase );
}
}