start to clean up the plugin vs. goal name handling so the hardcoding can be reduced, and eventually removed

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168040 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-04 01:20:49 +00:00
parent 650f14e2bb
commit b5670bdcaa
7 changed files with 83 additions and 78 deletions

View File

@ -23,7 +23,6 @@
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Goal;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.monitor.event.EventDispatcher;
@ -40,18 +39,18 @@
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Collections;
/**
* @todo there is some duplication between this and the plugin manager
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: DefaultLifecycleExecutor.java,v 1.16 2005/03/04 09:04:25
* jdcasey Exp $
* @todo there is some duplication between this and the plugin manager
*/
public class DefaultLifecycleExecutor
extends AbstractLogEnabled
@ -135,7 +134,7 @@ private void processGoals( MavenSession session, List tasks )
{
if ( artifactHandler.packageGoal() != null )
{
verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap );
configureMojo( artifactHandler.packageGoal(), session, phaseMap );
}
if ( artifactHandler.additionalPlugin() != null )
@ -149,7 +148,7 @@ private void processGoals( MavenSession session, List tasks )
}
}
processPluginConfiguration( session.getProject(), session, phaseMap );
processPluginConfiguration( project, session, phaseMap );
for ( Iterator i = tasks.iterator(); i.hasNext(); )
{
@ -177,6 +176,9 @@ private void processGoals( MavenSession session, List tasks )
private void injectHandlerPluginConfiguration( MavenProject project, String groupId, String artifactId )
{
// TODO: use the model injector, or just lookup the versions from the project?
// They need to be injected, but we should track the required plugins first, then just sweep through.
// TODO: this is a bit of a hack to get the version from plugin management - please fix
Plugin plugin = findPlugin( project.getPlugins(), groupId, artifactId );
@ -210,9 +212,10 @@ private void injectHandlerPluginConfiguration( MavenProject project, String grou
if ( plugin.getVersion() == null )
{
// TODO: this has probably supplanted the default in the plugin manager
plugin.setVersion( "1.0-SNAPSHOT" );
plugin.setVersion( PluginDescriptor.getDefaultPluginVersion() );
}
}
}
private static Plugin findPlugin( List plugins, String groupId, String artifactId )
@ -272,38 +275,19 @@ private void processPluginPhases( Plugin plugin, MavenSession session, Map phase
// mojos the user has specified and ignore the rest.
// ----------------------------------------------------------------------
if ( plugin.getGoals().size() > 0 )
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
{
String pluginId = pluginDescriptor.getArtifactId();
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
// TODO: Right now this maven-foo-plugin so this is a hack right now.
pluginId = PluginDescriptor.getPluginIdFromArtifactId( pluginId );
for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); )
// TODO: remove later
if ( mojoDescriptor.getGoal() == null )
{
Goal goal = (Goal) i.next();
String mojoId = pluginId + ":" + goal.getId();
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( mojoId );
if ( mojoDescriptor == null )
{
throw new LifecycleExecutionException( "A goal '" + mojoId +
"' was declared in pom.xml, but does not exist" );
}
configureMojo( mojoDescriptor, phaseMap, session.getSettings() );
throw new LifecycleExecutionException( "The plugin " + artifactId + " was built with an older version of Maven" );
}
}
else
{
for ( Iterator j = pluginDescriptor.getMojos().iterator(); j.hasNext(); )
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
configureMojo( mojoDescriptor, phaseMap, session.getSettings() );
if ( plugin.getGoals().isEmpty() || plugin.getGoalsAsMap().containsKey( mojoDescriptor.getGoal() ) )
{
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
}
}
@ -315,7 +299,7 @@ private void processPluginPhases( Plugin plugin, MavenSession session, Map phase
*
* @param mojoDescriptor
*/
private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings )
private void configureMojoPhaseBinding( MojoDescriptor mojoDescriptor, Map phaseMap, Settings settings )
throws LifecycleExecutionException
{
if ( settings.getActiveProfile().isOffline() && mojoDescriptor.requiresOnline() )
@ -331,7 +315,8 @@ private void configureMojo( MojoDescriptor mojoDescriptor, Map phaseMap, Setting
if ( phase == null )
{
throw new LifecycleExecutionException( "Required phase '" + mojoDescriptor.getPhase() + "' not found" );
throw new LifecycleExecutionException(
"Required phase '" + mojoDescriptor.getPhase() + "' not found" );
}
phase.getGoals().add( mojoDescriptor.getId() );
}
@ -359,18 +344,18 @@ private void processGoalChain( String task, MavenSession session, Map phaseMap )
{
String goal = (String) k.next();
verifyMojoPhase( goal, session, phaseMap );
configureMojo( goal, session, phaseMap );
}
}
}
}
else
{
verifyMojoPhase( task, session, phaseMap );
configureMojo( task, session, phaseMap );
}
}
private void verifyMojoPhase( String task, MavenSession session, Map phaseMap )
private void configureMojo( String task, MavenSession session, Map phaseMap )
throws LifecycleExecutionException, ArtifactResolutionException
{
MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( task );
@ -379,20 +364,13 @@ private void verifyMojoPhase( String task, MavenSession session, Map phaseMap )
{
String groupId = PluginDescriptor.getDefaultPluginGroupId();
String pluginId = task;
if ( pluginId.indexOf( ":" ) > 0 )
{
pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) );
}
String artifactId = PluginDescriptor.getDefaultPluginArtifactId( pluginId );
String artifactId = PluginDescriptor.getPluginArtifactIdFromGoal( task );
injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId );
try
{
pluginManager.verifyPluginForGoal( task, session );
pluginManager.verifyPlugin( groupId, artifactId, session );
}
catch ( PluginManagerException e )
{
@ -407,7 +385,7 @@ private void verifyMojoPhase( String task, MavenSession session, Map phaseMap )
}
}
configureMojo( mojoDescriptor, phaseMap, session.getSettings() );
configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
private void executePhase( String phase, MavenSession session, Map phaseMap )
@ -466,15 +444,6 @@ protected void executeMojo( String id, MavenSession session )
throws MojoExecutionException, PluginNotFoundException, PluginManagerException, ArtifactResolutionException,
LifecycleExecutionException
{
// ----------------------------------------------------------------------
// We have something of the form <pluginId>:<mojoId>, so this might be
// something like:
//
// clean:clean
// idea:idea
// archetype:create
// ----------------------------------------------------------------------
Logger logger = getLogger();
logger.debug( "Resolving artifacts from:" );
logger.debug( "\t{localRepository: " + session.getLocalRepository() + "}" );

View File

@ -97,15 +97,6 @@ public DefaultPluginManager()
pluginDescriptorBuilder = new PluginDescriptorBuilder();
}
// ----------------------------------------------------------------------
// Goal descriptors
// ----------------------------------------------------------------------
public Map getMojoDescriptors()
{
return mojoDescriptors;
}
/**
* Mojo descriptors are looked up using their id which is of the form
* <pluginId>: <mojoId>. So this might be archetype:create for example which
@ -190,7 +181,7 @@ public boolean isPluginInstalled( String groupId, String artifactId )
public void verifyPluginForGoal( String goalName, MavenSession session )
throws ArtifactResolutionException, PluginManagerException
{
String pluginId = PluginDescriptor.getPluginIdFromGoal( goalName );
String pluginId = PluginDescriptor.getPluginArtifactIdFromGoal( goalName );
verifyPlugin( PluginDescriptor.getDefaultPluginGroupId(), pluginId, session );
}
@ -378,17 +369,10 @@ public void executeMojo( MavenSession session, MojoDescriptor mojoDescriptor )
// TODO: remove
boolean newMojoTechnique = checkMojoTechnique( plugin.getClass() );
String goalId = null;
// TODO: much less of this magic is needed - make the mojoDescriptor just store the first and second part
int index = goalName.indexOf( ':' );
if ( index >= 0 )
{
goalId = goalName.substring( index + 1 );
}
String goalId = PluginDescriptor.getGoalIdFromFullGoal( goalName );
// TODO: can probable refactor these a little when only the new plugin technique is in place
Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor.getPluginIdFromGoal( goalName ),
Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor.getPluginArtifactIdFromGoal( goalName ),
goalId );
PlexusConfiguration pomConfiguration;

View File

@ -1993,6 +1993,28 @@
</association>
</field>
</fields>
<codeSegments>
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
private Map goalMap = null;
public Map getGoalsAsMap()
{
if ( goalMap == null )
{
goalMap = new HashMap();
for ( Iterator i = goals.iterator(); i.hasNext(); )
{
Goal g = (Goal) i.next();
goalMap.put( g.getId(), g );
}
}
return goalMap;
}
]]></code>
</codeSegment>
</codeSegments>
</class>
<class>
<name>Goal</name>

View File

@ -18,7 +18,10 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<!--
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
-->
<artifactId>maven-modello-plugin</artifactId>
<version>1.0-alpha-2-SNAPSHOT</version>
<configuration>

View File

@ -101,7 +101,7 @@ public String getId()
/**
* @todo remove - harcoding.
*/
public static String getPluginIdFromGoal( String goalName )
public static String getPluginArtifactIdFromGoal( String goalName )
{
String pluginId = goalName;
@ -142,4 +142,23 @@ public static String getPluginIdFromArtifactId( String artifactId )
return artifactId.substring( firstHyphen + 1, lastHyphen );
}
/**
* @todo remove - harcoding. What about clashes?
*/
public static String getDefaultPluginVersion()
{
return "1.0-SNAPSHOT";
}
public static String getGoalIdFromFullGoal( String goalName )
{
// TODO: much less of this magic is needed - make the mojoDescriptor just store the first and second part
int index = goalName.indexOf( ':' );
if ( index >= 0 )
{
return goalName.substring( index + 1 );
}
return null;
}
}

View File

@ -93,6 +93,8 @@ public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c )
mojo.setId( c.getChild( "id" ).getValue() );
mojo.setGoal( c.getChild( "goal" ).getValue() );
mojo.setImplementation( c.getChild( "implementation" ).getValue() );
PlexusConfiguration langConfig = c.getChild( "language" );

View File

@ -98,6 +98,12 @@ protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter
w.endElement();
w.startElement( "goal" );
w.writeText( mojoDescriptor.getGoal() );
w.endElement();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------