[MNG-3043] Allow 'mvn test' to work with test-jar dependencies in a reactor

o Revised to consider reactor state

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800294 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-08-03 10:54:22 +00:00
parent 381cb0b904
commit ce6a726a03
2 changed files with 40 additions and 24 deletions

View File

@ -165,7 +165,7 @@ public MavenExecutionResult execute( MavenExecutionRequest request )
// User Local Repository // User Local Repository
try try
{ {
delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( getProjectMap( session.getProjects() ) ) ); delegatingLocalArtifactRepository.setBuildReactor( new ReactorArtifactRepository( getProjectMap( session.getProjects() ), session ) );
} }
catch ( MavenExecutionException e ) catch ( MavenExecutionException e )
{ {

View File

@ -6,6 +6,9 @@
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.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.LocalArtifactRepository; import org.apache.maven.repository.LocalArtifactRepository;
@ -21,11 +24,14 @@ public class ReactorArtifactRepository
{ {
private Map<String, MavenProject> reactorProjects; private Map<String, MavenProject> reactorProjects;
private MavenExecutionResult executionResult;
private final int hashCode; private final int hashCode;
public ReactorArtifactRepository( Map<String, MavenProject> reactorProjects ) 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;
} }
@ -60,28 +66,26 @@ public Artifact find( Artifact artifact )
artifact.setResolved( true ); artifact.setResolved( true );
} }
// TODO: The code below supports MNG-3043 & MNG-2871 but in its current form causes MNG-4269. else if ( isProjectOutputValid( project ) )
// We need to consider the state of the reactor before handing out directories. {
// else File classesDir;
// {
// File classesDir; if ( isTestArtifact( artifact ) )
// {
// if ( isTestArtifact( artifact ) ) classesDir = new File( project.getBuild().getTestOutputDirectory() );
// { }
// classesDir = new File( project.getBuild().getTestOutputDirectory() ); else
// } {
// else classesDir = new File( project.getBuild().getOutputDirectory() );
// { }
// classesDir = new File( project.getBuild().getOutputDirectory() );
// } if ( classesDir.isDirectory() )
// {
// if ( classesDir.isDirectory() ) artifact.setFile( classesDir );
// {
// artifact.setFile( classesDir ); artifact.setResolved( true );
// }
// artifact.setResolved( true ); }
// }
// }
} }
} }
@ -180,6 +184,18 @@ private String getRepositoryConflictId( Artifact artifact )
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.
* *