diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
index 98dd6d497b..436a5bf4ae 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
@@ -115,45 +115,68 @@ public class DefaultLifecycleExecutor
Map phaseMap = new HashMap();
Map goalInstanceMap = new HashMap();
+ String maxPhase = null;
+
for ( Iterator i = phases.iterator(); i.hasNext(); )
{
String p = (String) i.next();
// Make a copy of the phase as we will modify it
phaseMap.put( p, new ArrayList() );
+
+ if ( tasks.contains( p ) )
+ {
+ maxPhase = p;
+ }
}
MavenProject project = session.getProject();
- Map mappings;
- try
+ if ( maxPhase != null )
{
- LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, project.getPackaging() );
- mappings = m.getPhases();
- }
- catch ( ComponentLookupException e )
- {
- getLogger().error( "No lifecycle mapping for type '" + project.getPackaging() + "': using defaults" );
- mappings = defaultPhases;
- }
-
- for ( Iterator i = mappings.keySet().iterator(); i.hasNext(); )
- {
- String phase = (String) i.next();
-
- String task = (String) mappings.get( phase );
-
- MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
-
- addToPhaseMap( phaseMap, phase, mojoDescriptor );
-
- List matchingGoalInstances = findMatchingGoalInstances( mojoDescriptor, project );
-
- for ( Iterator instanceIterator = matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
+ Map mappings;
+ try
{
- GoalInstance goalInstance = (GoalInstance) instanceIterator.next();
+ LifecycleMapping m = (LifecycleMapping) session.lookup( LifecycleMapping.ROLE, project.getPackaging() );
+ mappings = m.getPhases();
+ }
+ catch ( ComponentLookupException e )
+ {
+ getLogger().error( "No lifecycle mapping for type '" + project.getPackaging() + "': using defaults" );
+ mappings = defaultPhases;
+ }
- addToGoalInstanceMap( goalInstanceMap, goalInstance );
+ for ( Iterator i = phases.iterator(); i.hasNext(); )
+ {
+ String phase = (String) i.next();
+
+ String phaseTasks = (String) mappings.get( phase );
+
+ if ( phaseTasks != null )
+ {
+ for ( StringTokenizer tok = new StringTokenizer( phaseTasks, "," ); tok.hasMoreTokens(); )
+ {
+ String task = tok.nextToken().trim();
+
+ MojoDescriptor mojoDescriptor = configureMojo( task, session, phaseMap );
+
+ addToPhaseMap( phaseMap, phase, mojoDescriptor );
+
+ List matchingGoalInstances = findMatchingGoalInstances( mojoDescriptor, project );
+
+ for ( Iterator instanceIterator = matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
+ {
+ GoalInstance goalInstance = (GoalInstance) instanceIterator.next();
+
+ addToGoalInstanceMap( goalInstanceMap, goalInstance );
+ }
+ }
+ }
+
+ if ( phase.equals( maxPhase ) )
+ {
+ break;
+ }
}
}
diff --git a/maven-core/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/main/resources/META-INF/plexus/components.xml
index 87a4d0471e..2681e3d666 100644
--- a/maven-core/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-core/src/main/resources/META-INF/plexus/components.xml
@@ -110,7 +110,7 @@
resources:testResources
compiler:testCompile
surefire:test
- jar:jar
+ jar:jar,source:jar
install:install
deploy:deploy
@@ -119,9 +119,7 @@
org.apache.maven.lifecycle.mapping.LifecycleMapping
@@ -149,7 +147,7 @@
resources:testResources
compiler:testCompile
surefire:test
- jar:jar
+ jar:jar,source:jar
install:install
deploy:deploy
@@ -178,7 +176,6 @@
-
org.apache.maven.lifecycle.mapping.LifecycleMapping
ejb
@@ -191,7 +188,7 @@
resources:testResources
compiler:testCompile
surefire:test
- ejb:ejb
+ ejb:ejb,source:jar
install:install
deploy:deploy
@@ -199,7 +196,6 @@
-
org.apache.maven.lifecycle.mapping.LifecycleMapping
war
@@ -220,7 +216,7 @@
-
+
org.apache.maven.lifecycle.mapping.LifecycleMapping
plexus-application
@@ -241,7 +237,7 @@
-
+
org.apache.maven.lifecycle.mapping.LifecycleMapping
plexus-service
diff --git a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
index dcc874b4c0..801f70962c 100644
--- a/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
+++ b/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
@@ -34,6 +34,13 @@ import java.util.List;
public class JarSourceMojo
extends AbstractMojo
{
+ /**
+ * @parameter expression="${project.version}"
+ * @readonly
+ * @required
+ */
+ private String version;
+
/**
* @parameter expression="${project.build.finalName}"
* @required
@@ -47,7 +54,7 @@ public class JarSourceMojo
private List compileSourceRoots;
/**
- * @parameter expression="${project.build.output}"
+ * @parameter expression="${project.build.outputDirectory}"
* @required
*/
private File outputDirectory;
@@ -55,27 +62,35 @@ public class JarSourceMojo
public void execute()
throws MojoExecutionException
{
- // TODO: use a component lookup?
- JarArchiver archiver = new JarArchiver();
-
- SourceBundler sourceBundler = new SourceBundler();
-
- File outputFile = new File( outputDirectory, finalName + "-sources.jar" );
-
- File[] sourceDirectories = new File[compileSourceRoots.size()];
- int count = 0;
- for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); count++ )
+ // TODO: this should be via a release profile instead
+ if ( version.indexOf( "SNAPSHOT" ) < 0 )
{
- sourceDirectories[count] = new File( (String) i.next() );
+ // TODO: use a component lookup?
+ JarArchiver archiver = new JarArchiver();
+
+ SourceBundler sourceBundler = new SourceBundler();
+
+ File outputFile = new File( outputDirectory, finalName + "-sources.jar" );
+
+ File[] sourceDirectories = new File[compileSourceRoots.size()];
+ int count = 0;
+ for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); count++ )
+ {
+ sourceDirectories[count] = new File( (String) i.next() );
+ }
+
+ try
+ {
+ sourceBundler.makeSourceBundle( outputFile, sourceDirectories, archiver );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Error building source JAR", e );
+ }
}
-
- try
+ else
{
- sourceBundler.makeSourceBundle( outputFile, sourceDirectories, archiver );
- }
- catch ( Exception e )
- {
- throw new MojoExecutionException( "Error building source JAR", e );
+ getLog().info( "Not producing source bundle for a SNAPSHOT build" );
}
}
}