mirror of https://github.com/apache/maven.git
[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:
parent
10f90c7b3d
commit
bd1f3b58e5
|
@ -10,8 +10,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.ArtifactUtils;
|
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.execution.MavenSession;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.repository.LocalArtifactRepository;
|
import org.apache.maven.repository.LocalArtifactRepository;
|
||||||
|
@ -22,7 +20,6 @@ import org.apache.maven.repository.LocalArtifactRepository;
|
||||||
* @author Jason van Zyl
|
* @author Jason van Zyl
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//TODO: need phase information here to determine whether to hand back the classes/ or archive.
|
|
||||||
public class ReactorArtifactRepository
|
public class ReactorArtifactRepository
|
||||||
extends LocalArtifactRepository
|
extends LocalArtifactRepository
|
||||||
{
|
{
|
||||||
|
@ -30,14 +27,11 @@ public class ReactorArtifactRepository
|
||||||
|
|
||||||
private Map<String, List<String>> availableVersions;
|
private Map<String, List<String>> availableVersions;
|
||||||
|
|
||||||
private MavenExecutionResult executionResult;
|
|
||||||
|
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects, MavenSession session )
|
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects, MavenSession session )
|
||||||
{
|
{
|
||||||
this.reactorProjects = reactorProjects;
|
this.reactorProjects = reactorProjects;
|
||||||
this.executionResult = ( session != null ) ? session.getResult() : null;
|
|
||||||
hashCode = ( reactorProjects != null ) ? reactorProjects.keySet().hashCode() : 0;
|
hashCode = ( reactorProjects != null ) ? reactorProjects.keySet().hashCode() : 0;
|
||||||
|
|
||||||
availableVersions = new HashMap<String, List<String>>( reactorProjects.size() * 2 );
|
availableVersions = new HashMap<String, List<String>>( reactorProjects.size() * 2 );
|
||||||
|
@ -84,22 +78,26 @@ public class ReactorArtifactRepository
|
||||||
|
|
||||||
resolve( artifact, projectArtifact.getFile() );
|
resolve( artifact, projectArtifact.getFile() );
|
||||||
}
|
}
|
||||||
else if ( isProjectOutputValid( project ) )
|
else
|
||||||
{
|
{
|
||||||
File classesDir;
|
Collection<String> lifecyclePhases = project.getLifecyclePhases();
|
||||||
|
|
||||||
if ( isTestArtifact( artifact ) )
|
if ( !lifecyclePhases.contains( "package" ) )
|
||||||
{
|
{
|
||||||
classesDir = new File( project.getBuild().getTestOutputDirectory() );
|
if ( isTestArtifact( artifact ) )
|
||||||
}
|
{
|
||||||
else
|
if ( lifecyclePhases.contains( "test-compile" ) )
|
||||||
{
|
{
|
||||||
classesDir = new File( project.getBuild().getOutputDirectory() );
|
resolve( artifact, new File( project.getBuild().getTestOutputDirectory() ) );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( classesDir.isDirectory() )
|
else
|
||||||
{
|
{
|
||||||
resolve( artifact, classesDir );
|
if ( lifecyclePhases.contains( "compile" ) )
|
||||||
|
{
|
||||||
|
resolve( artifact, new File( project.getBuild().getOutputDirectory() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,18 +217,6 @@ public class ReactorArtifactRepository
|
||||||
return buffer.toString();
|
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.
|
* Determines whether the specified artifact refers to test classes.
|
||||||
*
|
*
|
||||||
|
|
|
@ -319,10 +319,7 @@ public class DefaultLifecycleExecutor
|
||||||
DependencyContext dependencyContext =
|
DependencyContext dependencyContext =
|
||||||
new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );
|
new DependencyContext( executionPlan, projectBuild.taskSegment.aggregating );
|
||||||
|
|
||||||
for ( MojoExecution mojoExecution : executionPlan.getExecutions() )
|
execute( session, executionPlan.getExecutions(), projectIndex, dependencyContext );
|
||||||
{
|
|
||||||
execute( session, mojoExecution, projectIndex, dependencyContext );
|
|
||||||
}
|
|
||||||
|
|
||||||
long buildEndTime = System.currentTimeMillis();
|
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,
|
private void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
|
||||||
DependencyContext dependencyContext )
|
DependencyContext dependencyContext )
|
||||||
throws LifecycleExecutionException
|
throws LifecycleExecutionException
|
||||||
|
@ -680,10 +710,7 @@ public class DefaultLifecycleExecutor
|
||||||
session.getProjects().set( index, executedProject );
|
session.getProjects().set( index, executedProject );
|
||||||
projectIndex.projects.put( fork.getKey(), executedProject );
|
projectIndex.projects.put( fork.getKey(), executedProject );
|
||||||
|
|
||||||
for ( MojoExecution forkedExecution : fork.getValue() )
|
execute( session, fork.getValue(), projectIndex, dependencyContext );
|
||||||
{
|
|
||||||
execute( session, forkedExecution, projectIndex, dependencyContext );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class MavenProject
|
||||||
|
|
||||||
private ArtifactFilter extensionArtifactFilter;
|
private ArtifactFilter extensionArtifactFilter;
|
||||||
|
|
||||||
//
|
private Set<String> lifecyclePhases;
|
||||||
|
|
||||||
public MavenProject()
|
public MavenProject()
|
||||||
{
|
{
|
||||||
|
@ -1947,6 +1947,8 @@ public class MavenProject
|
||||||
{
|
{
|
||||||
setManagedVersionMap( new HashMap<String, Artifact>( project.getManagedVersionMap() ) );
|
setManagedVersionMap( new HashMap<String, Artifact>( project.getManagedVersionMap() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lifecyclePhases = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addArtifactPath( Artifact artifact, List<String> classpath )
|
private void addArtifactPath( Artifact artifact, List<String> classpath )
|
||||||
|
@ -2081,4 +2083,33 @@ public class MavenProject
|
||||||
this.artifactMap = null;
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue