Author: bentmann
Date: Fri Mar 26 21:03:19 2010
New Revision: 928058
URL: http://svn.apache.org/viewvc?rev=928058&view=rev
Log:
[MNG-2222] dependency to dependency without source code fails
Modified:
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorArtifactRepository.java
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Modified:
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorArtifactRepository.java
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorArtifactRepository.java?rev=928058&r1=928057&r2=928058&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorArtifactRepository.java
(original)
+++
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/ReactorArtifactRepository.java
Fri Mar 26 21:03:19 2010
@@ -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.Local
* @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;
-
- if ( isTestArtifact( artifact ) )
- {
- classesDir = new File(
project.getBuild().getTestOutputDirectory() );
- }
- else
- {
- classesDir = new File(
project.getBuild().getOutputDirectory() );
- }
+ Collection<String> lifecyclePhases =
project.getLifecyclePhases();
- if ( classesDir.isDirectory() )
+ if ( !lifecyclePhases.contains( "package" ) )
{
- resolve( artifact, classesDir );
+ if ( isTestArtifact( artifact ) )
+ {
+ if ( lifecyclePhases.contains( "test-compile" ) )
+ {
+ resolve( artifact, new File(
project.getBuild().getTestOutputDirectory() ) );
+ }
+ }
+ else
+ {
+ if ( lifecyclePhases.contains( "compile" ) )
+ {
+ resolve( artifact, new File(
project.getBuild().getOutputDirectory() ) );
+ }
+ }
}
}
}
@@ -220,18 +218,6 @@ public class ReactorArtifactRepository
}
/**
- * 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.
*
* @param artifact The artifact to check, must not be {...@code null}.
Modified:
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=928058&r1=928057&r2=928058&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
(original)
+++
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Fri Mar 26 21:03:19 2010
@@ -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
{
Modified:
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
URL:
http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java?rev=928058&r1=928057&r2=928058&view=diff
==============================================================================
---
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
(original)
+++
maven/maven-3/trunk/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Fri Mar 26 21:03:19 2010
@@ -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 );
+ }
+
}