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


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-17 08:33:41 +00:00
parent f4fb75176a
commit fb065d7858
3 changed files with 88 additions and 54 deletions

View File

@ -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;
}
}
}

View File

@ -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>

View File

@ -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" );
}
}
}