You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/05/04 03:20:49 UTC
svn commit: r168040 -
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle
/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin
/maven/components/trunk/maven-model
/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor
/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator
Author: brett
Date: Tue May 3 18:20:49 2005
New Revision: 168040
URL: http://svn.apache.org/viewcvs?rev=168040&view=rev
Log:
start to clean up the plugin vs. goal name handling so the hardcoding can be reduced, and eventually removed
Modified:
maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
maven/components/trunk/maven-model/maven.mdo
maven/components/trunk/maven-model/pom.xml
maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.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=168040&r1=168039&r2=168040&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 Tue May 3 18:20:49 2005
@@ -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 @@
{
if ( artifactHandler.packageGoal() != null )
{
- verifyMojoPhase( artifactHandler.packageGoal(), session, phaseMap );
+ configureMojo( artifactHandler.packageGoal(), session, phaseMap );
}
if ( artifactHandler.additionalPlugin() != null )
@@ -149,7 +148,7 @@
}
}
- processPluginConfiguration( session.getProject(), session, phaseMap );
+ processPluginConfiguration( project, session, phaseMap );
for ( Iterator i = tasks.iterator(); i.hasNext(); )
{
@@ -177,6 +176,9 @@
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 @@
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 @@
// 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();
-
- // TODO: Right now this maven-foo-plugin so this is a hack right now.
+ MojoDescriptor mojoDescriptor = (MojoDescriptor) j.next();
- 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 @@
*
* @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 @@
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 @@
{
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 @@
{
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 @@
}
}
- configureMojo( mojoDescriptor, phaseMap, session.getSettings() );
+ configureMojoPhaseBinding( mojoDescriptor, phaseMap, session.getSettings() );
}
private void executePhase( String phase, MavenSession session, Map phaseMap )
@@ -466,15 +444,6 @@
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() + "}" );
Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Tue May 3 18:20:49 2005
@@ -97,15 +97,6 @@
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 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 @@
// 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;
Modified: maven/components/trunk/maven-model/maven.mdo
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-model/maven.mdo?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-model/maven.mdo (original)
+++ maven/components/trunk/maven-model/maven.mdo Tue May 3 18:20:49 2005
@@ -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>
Modified: maven/components/trunk/maven-model/pom.xml
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-model/pom.xml?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-model/pom.xml (original)
+++ maven/components/trunk/maven-model/pom.xml Tue May 3 18:20:49 2005
@@ -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>
Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java Tue May 3 18:20:49 2005
@@ -101,7 +101,7 @@
/**
* @todo remove - harcoding.
*/
- public static String getPluginIdFromGoal( String goalName )
+ public static String getPluginArtifactIdFromGoal( String goalName )
{
String pluginId = goalName;
@@ -141,5 +141,24 @@
int lastHyphen = artifactId.lastIndexOf( "-" );
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;
}
}
Modified: maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java (original)
+++ maven/components/trunk/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java Tue May 3 18:20:49 2005
@@ -93,6 +93,8 @@
mojo.setId( c.getChild( "id" ).getValue() );
+ mojo.setGoal( c.getChild( "goal" ).getValue() );
+
mojo.setImplementation( c.getChild( "implementation" ).getValue() );
PlexusConfiguration langConfig = c.getChild( "language" );
Modified: maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java?rev=168040&r1=168039&r2=168040&view=diff
==============================================================================
--- maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java (original)
+++ maven/components/trunk/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java Tue May 3 18:20:49 2005
@@ -98,6 +98,12 @@
w.endElement();
+ w.startElement( "goal" );
+
+ w.writeText( mojoDescriptor.getGoal() );
+
+ w.endElement();
+
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org