Author: brett
Date: Fri Jun 17 01:33:41 2005
New Revision: 191111
URL: http://svn.apache.org/viewcvs?rev=191111&view=rev
Log:
PR: MNG-257
- hook up the source:jar goal to packaging, but only execute for non-SNAPSHOT
builds
- allow comma-delimited list of goals in phase definitions
- only register necessary phases for the goals given
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
maven/components/trunk/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=191111&r1=191110&r2=191111&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
(original)
+++
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Fri Jun 17 01:33:41 2005
@@ -115,45 +115,68 @@
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;
- }
+ Map mappings;
+ try
+ {
+ 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();
+ for ( Iterator i = phases.iterator(); i.hasNext(); )
+ {
+ String phase = (String) i.next();
- String task = (String) mappings.get( phase );
+ String phaseTasks = (String) mappings.get( phase );
- MojoDescriptor mojoDescriptor = configureMojo( task, session,
phaseMap );
+ if ( phaseTasks != null )
+ {
+ for ( StringTokenizer tok = new StringTokenizer(
phaseTasks, "," ); tok.hasMoreTokens(); )
+ {
+ String task = tok.nextToken().trim();
- addToPhaseMap( phaseMap, phase, mojoDescriptor );
+ MojoDescriptor mojoDescriptor = configureMojo( task,
session, phaseMap );
- List matchingGoalInstances = findMatchingGoalInstances(
mojoDescriptor, project );
+ addToPhaseMap( phaseMap, phase, mojoDescriptor );
- for ( Iterator instanceIterator =
matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
- {
- GoalInstance goalInstance = (GoalInstance)
instanceIterator.next();
+ List matchingGoalInstances =
findMatchingGoalInstances( mojoDescriptor, project );
+
+ for ( Iterator instanceIterator =
matchingGoalInstances.iterator(); instanceIterator.hasNext(); )
+ {
+ GoalInstance goalInstance = (GoalInstance)
instanceIterator.next();
+
+ addToGoalInstanceMap( goalInstanceMap,
goalInstance );
+ }
+ }
+ }
- addToGoalInstanceMap( goalInstanceMap, goalInstance );
+ if ( phase.equals( maxPhase ) )
+ {
+ break;
+ }
}
}
Modified:
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml?rev=191111&r1=191110&r2=191111&view=diff
==============================================================================
---
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
(original)
+++
maven/components/trunk/maven-core/src/main/resources/META-INF/plexus/components.xml
Fri Jun 17 01:33:41 2005
@@ -110,7 +110,7 @@
<process-test-resources>resources:testResources</process-test-resources>
<test-compile>compiler:testCompile</test-compile>
<test>surefire:test</test>
- <package>jar:jar</package>
+ <package>jar:jar,source:jar</package>
<install>install:install</install>
<deploy>deploy:deploy</deploy>
</defaultPhases>
@@ -119,9 +119,7 @@
</component>
<!-- TODO: issues with the lifecycle:
- - must manually configure plugins that are not in here for a given
packaging, unless that packaging could be mapped to a plugin from the repo
- manually configured lifecycles will not pick up any later additions to
the defaults where they are intended to extend defaults (have configuration
<includeDefaults/> ?)
- - should we be registering goals, or just plugins and letting them bind
phases? Is it better to remove the plugin phase binding perhaps?
-->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
@@ -149,7 +147,7 @@
<process-test-resources>resources:testResources</process-test-resources>
<test-compile>compiler:testCompile</test-compile>
<test>surefire:test</test>
- <package>jar:jar</package>
+ <package>jar:jar,source:jar</package>
<install>install:install</install>
<deploy>deploy:deploy</deploy>
</phases>
@@ -178,7 +176,6 @@
</configuration>
</component>
- <!-- TODO: move to the ejb plugin? -->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>ejb</role-hint>
@@ -191,7 +188,7 @@
<process-test-resources>resources:testResources</process-test-resources>
<test-compile>compiler:testCompile</test-compile>
<test>surefire:test</test>
- <package>ejb:ejb</package>
+ <package>ejb:ejb,source:jar</package>
<install>install:install</install>
<deploy>deploy:deploy</deploy>
</phases>
@@ -199,7 +196,6 @@
</configuration>
</component>
- <!-- TODO: move to the war plugin? -->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>war</role-hint>
@@ -220,7 +216,7 @@
</configuration>
</component>
- <!-- TODO: move to the plexus plugin? -->
+ <!-- TODO: move to the plexus plugin -->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>plexus-application</role-hint>
@@ -241,7 +237,7 @@
</configuration>
</component>
- <!-- TODO: move to the plexus plugin? -->
+ <!-- TODO: move to the plexus plugin -->
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>plexus-service</role-hint>
Modified:
maven/components/trunk/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java?rev=191111&r1=191110&r2=191111&view=diff
==============================================================================
---
maven/components/trunk/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
(original)
+++
maven/components/trunk/maven-plugins/maven-source-plugin/src/main/java/org/apache/maven/plugin/source/JarSourceMojo.java
Fri Jun 17 01:33:41 2005
@@ -35,6 +35,13 @@
extends AbstractMojo
{
/**
+ * @parameter expression="${project.version}"
+ * @readonly
+ * @required
+ */
+ private String version;
+
+ /**
* @parameter expression="${project.build.finalName}"
* @required
*/
@@ -47,7 +54,7 @@
private List compileSourceRoots;
/**
- * @parameter expression="${project.build.output}"
+ * @parameter expression="${project.build.outputDirectory}"
* @required
*/
private File outputDirectory;
@@ -55,27 +62,35 @@
public void execute()
throws MojoExecutionException
{
- // TODO: use a component lookup?
- JarArchiver archiver = new JarArchiver();
-
- SourceBundler sourceBundler = new SourceBundler();
+ // TODO: this should be via a release profile instead
+ if ( version.indexOf( "SNAPSHOT" ) < 0 )
+ {
+ // TODO: use a component lookup?
+ JarArchiver archiver = new JarArchiver();
- File outputFile = new File( outputDirectory, finalName +
"-sources.jar" );
+ SourceBundler sourceBundler = new SourceBundler();
- File[] sourceDirectories = new File[compileSourceRoots.size()];
- int count = 0;
- for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); count++
)
- {
- sourceDirectories[count] = new File( (String) i.next() );
- }
+ File outputFile = new File( outputDirectory, finalName +
"-sources.jar" );
- try
- {
- sourceBundler.makeSourceBundle( outputFile, sourceDirectories,
archiver );
+ 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 );
+ }
}
- catch ( Exception e )
+ else
{
- throw new MojoExecutionException( "Error building source JAR", e );
+ getLog().info( "Not producing source bundle for a SNAPSHOT build"
);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]