declare the desired "prefix" inside the plugin descriptor instead of pulling apart the artifact ID (though that is how the default is created).

Currently, the reverse is not handled in anyway, so a non-default prefix may not work, but this makes the code easier to isolate.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-04 08:17:39 +00:00
parent 118a53927d
commit 24c6328ad3
37 changed files with 360 additions and 330 deletions

View File

@ -20,13 +20,9 @@ import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException; import org.apache.maven.artifact.handler.manager.ArtifactHandlerNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenExecutionResponse; import org.apache.maven.execution.MavenExecutionResponse;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin; import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginManagement;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.monitor.event.MavenEvents;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.PluginManager; import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.PluginManagerException; import org.apache.maven.plugin.PluginManagerException;
@ -34,11 +30,9 @@ import org.apache.maven.plugin.PluginNotFoundException;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.injection.ModelDefaultsInjector; import org.apache.maven.project.injection.ModelDefaultsInjector;
import org.apache.maven.settings.Settings; import org.apache.maven.settings.Settings;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -307,7 +301,7 @@ public class DefaultLifecycleExecutor
throw new LifecycleExecutionException( throw new LifecycleExecutionException(
"Required phase '" + mojoDescriptor.getPhase() + "' not found" ); "Required phase '" + mojoDescriptor.getPhase() + "' not found" );
} }
phase.getGoals().add( mojoDescriptor.getId() ); phase.getGoals().add( mojoDescriptor.getFullGoalName() );
} }
} }
} }

View File

@ -135,7 +135,7 @@ public class DefaultPluginManager
{ {
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next(); MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor ); mojoDescriptors.put( mojoDescriptor.getFullGoalName(), mojoDescriptor );
} }
pluginDescriptors.put( key, pluginDescriptor ); pluginDescriptors.put( key, pluginDescriptor );
@ -353,7 +353,7 @@ public class DefaultPluginManager
Mojo plugin = null; Mojo plugin = null;
String goalName = mojoDescriptor.getId(); String goalName = mojoDescriptor.getFullGoalName();
try try
{ {
@ -364,8 +364,9 @@ public class DefaultPluginManager
String goalId = mojoDescriptor.getGoal(); String goalId = mojoDescriptor.getGoal();
// TODO: can probable refactor these a little when only the new plugin technique is in place // TODO: can probable refactor these a little when only the new plugin technique is in place
Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
PluginDescriptor.getPluginArtifactIdFromGoal( goalName ), goalId ); Xpp3Dom dom = session.getProject().getGoalConfiguration( pluginDescriptor.getGroupId(),
pluginDescriptor.getArtifactId(), goalId );
PlexusConfiguration pomConfiguration; PlexusConfiguration pomConfiguration;
if ( dom == null ) if ( dom == null )
@ -471,7 +472,7 @@ public class DefaultPluginManager
errorMessage.append( " (with alias: " ).append( lookupKey ).append( ")" ); errorMessage.append( " (with alias: " ).append( lookupKey ).append( ")" );
} }
errorMessage.append( " in goal: " ).append( goal.getId() ); errorMessage.append( " in goal: " ).append( goal.getFullGoalName() );
throw new PluginConfigurationException( errorMessage.toString() ); throw new PluginConfigurationException( errorMessage.toString() );
} }
@ -724,7 +725,7 @@ public class DefaultPluginManager
message.append( "The '" + parameter.getName() ); message.append( "The '" + parameter.getName() );
message.append( "' parameter is required for the execution of the " ); message.append( "' parameter is required for the execution of the " );
message.append( mojo.getId() ); message.append( mojo.getFullGoalName() );
message.append( " mojo and cannot be null." ); message.append( " mojo and cannot be null." );
message.append( " The retrieval expression was: " ).append( expression ); message.append( " The retrieval expression was: " ).append( expression );

View File

@ -2004,10 +2004,13 @@
if ( goalMap == null ) if ( goalMap == null )
{ {
goalMap = new HashMap(); goalMap = new HashMap();
for ( Iterator i = goals.iterator(); i.hasNext(); ) if ( goals != null )
{ {
Goal g = (Goal) i.next(); for ( Iterator i = goals.iterator(); i.hasNext(); )
goalMap.put( g.getId(), g ); {
Goal g = (Goal) i.next();
goalMap.put( g.getId(), g );
}
} }
} }
return goalMap; return goalMap;

View File

@ -46,8 +46,6 @@ public class MojoDescriptor
private static final String DEFAULT_LANGUAGE = "java"; private static final String DEFAULT_LANGUAGE = "java";
private String id;
private List parameters; private List parameters;
private Map parameterMap; private Map parameterMap;
@ -74,6 +72,8 @@ public class MojoDescriptor
private PlexusConfiguration mojoConfiguration; private PlexusConfiguration mojoConfiguration;
private PluginDescriptor pluginDescriptor;
public MojoDescriptor() public MojoDescriptor()
{ {
setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY ); setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY );
@ -94,16 +94,6 @@ public class MojoDescriptor
setComponentFactory( language ); setComponentFactory( language );
} }
public String getId()
{
return id;
}
public void setId( String id )
{
this.id = id;
}
public String getDeprecated() public String getDeprecated()
{ {
return deprecated; return deprecated;
@ -257,7 +247,12 @@ public class MojoDescriptor
public String getRoleHint() public String getRoleHint()
{ {
return getId() + ":" + getGoal(); return getFullGoalName();
}
public String getFullGoalName()
{
return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
} }
public String getComponentType() public String getComponentType()
@ -265,4 +260,13 @@ public class MojoDescriptor
return MAVEN_PLUGIN; return MAVEN_PLUGIN;
} }
public PluginDescriptor getPluginDescriptor()
{
return pluginDescriptor;
}
public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
{
this.pluginDescriptor = pluginDescriptor;
}
} }

View File

@ -35,6 +35,8 @@ public class PluginDescriptor
private boolean isolatedRealm; private boolean isolatedRealm;
private String goalPrefix;
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -134,7 +136,7 @@ public class PluginDescriptor
* *
* @todo remove - harcoding. What about clashes? * @todo remove - harcoding. What about clashes?
*/ */
public static String getPluginIdFromArtifactId( String artifactId ) public static String getGoalPrefixFromArtifactId( String artifactId )
{ {
int firstHyphen = artifactId.indexOf( "-" ); int firstHyphen = artifactId.indexOf( "-" );
@ -161,4 +163,14 @@ public class PluginDescriptor
} }
return null; return null;
} }
public String getGoalPrefix()
{
return goalPrefix;
}
public void setGoalPrefix( String goalPrefix )
{
this.goalPrefix = goalPrefix;
}
} }

View File

@ -25,18 +25,9 @@ public class PluginDescriptorBuilder
PluginDescriptor pluginDescriptor = new PluginDescriptor(); PluginDescriptor pluginDescriptor = new PluginDescriptor();
String id = c.getChild( "id" ).getValue(); pluginDescriptor.setGroupId( c.getChild( "groupId" ).getValue() );
if ( id != null ) pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() );
{ pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).getValue() );
// TODO: remove. This is old style mojos (alpha-1)
pluginDescriptor.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
pluginDescriptor.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId( id ) );
}
else
{
pluginDescriptor.setGroupId( c.getChild( "groupId" ).getValue() );
pluginDescriptor.setArtifactId( c.getChild( "artifactId" ).getValue() );
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Components // Components
@ -50,7 +41,7 @@ public class PluginDescriptorBuilder
{ {
PlexusConfiguration component = mojoConfigurations[i]; PlexusConfiguration component = mojoConfigurations[i];
mojos.add( buildComponentDescriptor( component ) ); mojos.add( buildComponentDescriptor( component, pluginDescriptor ) );
} }
pluginDescriptor.setMojos( mojos ); pluginDescriptor.setMojos( mojos );
@ -85,12 +76,11 @@ public class PluginDescriptorBuilder
return pluginDescriptor; return pluginDescriptor;
} }
public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c ) public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDescriptor pluginDescriptor )
throws PlexusConfigurationException throws PlexusConfigurationException
{ {
MojoDescriptor mojo = new MojoDescriptor(); MojoDescriptor mojo = new MojoDescriptor();
mojo.setPluginDescriptor( pluginDescriptor );
mojo.setId( c.getChild( "id" ).getValue() );
mojo.setGoal( c.getChild( "goal" ).getValue() ); mojo.setGoal( c.getChild( "goal" ).getValue() );

View File

@ -1,7 +1,7 @@
package org.apache.maven.script.marmalade.tags; package org.apache.maven.tools.plugin;
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,19 +16,22 @@ package org.apache.maven.script.marmalade.tags;
* limitations under the License. * limitations under the License.
*/ */
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
/** /**
* @author jdcasey Created on Feb 8, 2005 * Error during the plugin tools.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id$
*/ */
public class IdTag public class PluginToolsException
extends AbstractStringValuedBodyTag extends Exception
{ {
public PluginToolsException( String message, Throwable throwable )
protected void setValue( String value ) throws MarmaladeExecutionException
{ {
MetadataTag metadataTag = (MetadataTag) requireParent( MetadataTag.class ); super( message, throwable );
metadataTag.setId( value );
} }
} public PluginToolsException( String message )
{
super( message );
}
}

View File

@ -1,6 +1,8 @@
package org.apache.maven.tools.plugin.extractor; package org.apache.maven.tools.plugin.extractor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsException;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.DirectoryScanner;
@ -19,19 +21,19 @@ public abstract class AbstractScriptedMojoDescriptorExtractor
extends AbstractLogEnabled extends AbstractLogEnabled
implements MojoDescriptorExtractor implements MojoDescriptorExtractor
{ {
public Set execute( MavenProject project ) public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws Exception throws PluginToolsException
{ {
Map scriptFilesKeyedByBasedir = gatherScriptSourcesByBasedir( project.getScriptSourceRoots(), Map scriptFilesKeyedByBasedir = gatherScriptSourcesByBasedir( project.getScriptSourceRoots(),
getScriptFileExtension() ); getScriptFileExtension() );
Set mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir ); Set mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir, pluginDescriptor );
return mojoDescriptors; return mojoDescriptors;
} }
protected abstract Set extractMojoDescriptors( Map scriptFilesKeyedByBasedir ) protected abstract Set extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
throws Exception; throws PluginToolsException;
protected abstract String getScriptFileExtension(); protected abstract String getScriptFileExtension();

View File

@ -1,5 +1,7 @@
package org.apache.maven.tools.plugin.extractor; package org.apache.maven.tools.plugin.extractor;
import org.apache.maven.tools.plugin.PluginToolsException;
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2004 The Apache Software Foundation.
* *
@ -22,22 +24,13 @@ package org.apache.maven.tools.plugin.extractor;
* jdcasey Exp $ * jdcasey Exp $
*/ */
public class InvalidParameterException public class InvalidParameterException
extends Exception extends PluginToolsException
{ {
public InvalidParameterException()
{
}
public InvalidParameterException( String element, int i ) public InvalidParameterException( String element, int i )
{ {
super( "The " + element + " element in parameter # " + i + " is invalid. It cannot be null." ); super( "The " + element + " element in parameter # " + i + " is invalid. It cannot be null." );
} }
public InvalidParameterException( Throwable cause )
{
super( cause );
}
public InvalidParameterException( String message, Throwable cause ) public InvalidParameterException( String message, Throwable cause )
{ {
super( message, cause ); super( message, cause );

View File

@ -17,6 +17,8 @@ package org.apache.maven.tools.plugin.extractor;
*/ */
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.PluginToolsException;
import java.util.Set; import java.util.Set;
@ -25,10 +27,8 @@ import java.util.Set;
*/ */
public interface MojoDescriptorExtractor public interface MojoDescriptorExtractor
{ {
String ROLE = MojoDescriptorExtractor.class.getName(); String ROLE = MojoDescriptorExtractor.class.getName();
Set execute( MavenProject project ) Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws Exception; throws PluginToolsException;
} }

View File

@ -25,9 +25,11 @@ import org.codehaus.modello.generator.java.javasource.JMethod;
import org.codehaus.modello.generator.java.javasource.JParameter; import org.codehaus.modello.generator.java.javasource.JParameter;
import org.codehaus.modello.generator.java.javasource.JSourceWriter; import org.codehaus.modello.generator.java.javasource.JSourceWriter;
import org.codehaus.modello.generator.java.javasource.JType; import org.codehaus.modello.generator.java.javasource.JType;
import org.codehaus.plexus.util.IOUtil;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -42,7 +44,8 @@ import java.util.Set;
public class BeanGenerator public class BeanGenerator
implements Generator implements Generator
{ {
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) throws Exception public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
throws IOException
{ {
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); ) for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
{ {
@ -51,7 +54,8 @@ public class BeanGenerator
} }
} }
protected void processPluginDescriptor( MojoDescriptor descriptor, String destinationDirectory ) throws Exception protected void processPluginDescriptor( MojoDescriptor descriptor, String destinationDirectory )
throws IOException
{ {
String implementation = descriptor.getImplementation(); String implementation = descriptor.getImplementation();
@ -95,7 +99,7 @@ public class BeanGenerator
{ {
Parameter parameter = (Parameter) parameters.get( i ); Parameter parameter = (Parameter) parameters.get( i );
jClass.addMethod( createSetter( parameter, jClass ) ); jClass.addMethod( createSetter( parameter ) );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -111,18 +115,24 @@ public class BeanGenerator
destination.getParentFile().mkdirs(); destination.getParentFile().mkdirs();
} }
FileWriter writer = new FileWriter( destination ); FileWriter writer = null;
try
{
writer = new FileWriter( destination );
JSourceWriter sourceWriter = new JSourceWriter( writer ); JSourceWriter sourceWriter = new JSourceWriter( writer );
jClass.print( sourceWriter ); jClass.print( sourceWriter );
writer.flush(); writer.flush();
}
writer.close(); finally
{
IOUtil.close( writer );
}
} }
private JMethod createSetter( Parameter parameter, JClass jClass ) private JMethod createSetter( Parameter parameter )
{ {
String propertyName = capitalise( parameter.getName() ); String propertyName = capitalise( parameter.getName() );

View File

@ -1,11 +1,7 @@
package org.apache.maven.tools.plugin.generator; package org.apache.maven.tools.plugin.generator;
import org.apache.maven.project.MavenProject;
import java.util.Set;
/* /*
* Copyright 2001-2004 The Apache Software Foundation. * Copyright 2001-2005 The Apache Software Foundation.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -20,13 +16,17 @@ import java.util.Set;
* limitations under the License. * limitations under the License.
*/ */
import org.apache.maven.project.MavenProject;
import java.util.Set;
import java.io.IOException;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id$ * @version $Id$
*/ */
public interface Generator public interface Generator
{ {
void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) throws Exception; throws IOException;
} }

View File

@ -18,14 +18,17 @@ package org.apache.maven.tools.plugin.generator;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.util.PluginUtils; import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -42,8 +45,9 @@ import java.util.Set;
public class PluginDescriptorGenerator public class PluginDescriptorGenerator
implements Generator implements Generator
{ {
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project ) public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project,
throws Exception String goalPrefix )
throws IOException
{ {
File f = new File( destinationDirectory, "plugin.xml" ); File f = new File( destinationDirectory, "plugin.xml" );
@ -52,39 +56,46 @@ public class PluginDescriptorGenerator
f.getParentFile().mkdirs(); f.getParentFile().mkdirs();
} }
FileWriter writer = new FileWriter( f ); FileWriter writer = null;
try
XMLWriter w = new PrettyPrintXMLWriter( writer );
w.startElement( "plugin" );
element( w, "groupId", project.getGroupId() );
element( w, "artifactId", project.getArtifactId() );
element( w, "isolatedRealm", "true" );
w.startElement( "mojos" );
for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); )
{ {
MojoDescriptor descriptor = (MojoDescriptor) it.next(); writer = new FileWriter( f );
processPluginDescriptor( descriptor, w, project );
XMLWriter w = new PrettyPrintXMLWriter( writer );
w.startElement( "plugin" );
element( w, "groupId", project.getGroupId() );
element( w, "artifactId", project.getArtifactId() );
element( w, "goalPrefix", goalPrefix );
element( w, "isolatedRealm", "true" );
w.startElement( "mojos" );
for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
processPluginDescriptor( descriptor, w, project );
}
w.endElement();
PluginUtils.writeDependencies( w, project );
w.endElement();
writer.flush();
}
finally
{
IOUtil.close( writer );
} }
w.endElement();
PluginUtils.writeDependencies( w, project );
w.endElement();
writer.flush();
writer.close();
} }
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project ) protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
throws Exception
{ {
w.startElement( "mojo" ); w.startElement( "mojo" );
@ -92,12 +103,6 @@ public class PluginDescriptorGenerator
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
w.startElement( "id" );
w.writeText( mojoDescriptor.getId() + ":" + mojoDescriptor.getGoal() );
w.endElement();
w.startElement( "goal" ); w.startElement( "goal" );
w.writeText( mojoDescriptor.getGoal() ); w.writeText( mojoDescriptor.getGoal() );
@ -200,8 +205,8 @@ public class PluginDescriptorGenerator
String expression = parameter.getExpression(); String expression = parameter.getExpression();
if ( StringUtils.isNotEmpty( expression ) if ( StringUtils.isNotEmpty( expression ) &&
&& ( expression.startsWith( "${component." ) || expression.startsWith( "#component." ) ) ) ( expression.startsWith( "${component." ) || expression.startsWith( "#component." ) ) )
{ {
// treat it as a component...a requirement, in other words. // treat it as a component...a requirement, in other words.
@ -267,7 +272,7 @@ public class PluginDescriptorGenerator
w.startElement( parameter.getName() ); w.startElement( parameter.getName() );
String type = convertType( parameter.getType() ); String type = parameter.getType();
if ( type != null ) if ( type != null )
{ {
w.addAttribute( "implementation", type ); w.addAttribute( "implementation", type );
@ -323,35 +328,6 @@ public class PluginDescriptorGenerator
w.endElement(); w.endElement();
} }
/**
* @param type
* @return
* @deprecated - should force proper class specification
*/
private static String convertType( String type )
{
if ( "String".equals( type ) )
{
return "java.lang.String";
}
else if ( "File".equals( type ) )
{
return "java.io.File";
}
else if ( "List".equals( type ) )
{
return "java.util.List";
}
else if ( "".equals( type ) )
{
return null;
}
else
{
return type;
}
}
public void element( XMLWriter w, String name, String value ) public void element( XMLWriter w, String name, String value )
{ {
w.startElement( name ); w.startElement( name );

View File

@ -20,11 +20,13 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -38,8 +40,8 @@ import java.util.Set;
public class PluginXdocGenerator public class PluginXdocGenerator
implements Generator implements Generator
{ {
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
throws Exception throws IOException
{ {
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); ) for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
{ {
@ -49,12 +51,27 @@ public class PluginXdocGenerator
} }
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, String destinationDirectory ) protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, String destinationDirectory )
throws Exception throws IOException
{ {
String id = mojoDescriptor.getId(); String id = mojoDescriptor.getGoal();
FileWriter writer = new FileWriter( new File( destinationDirectory, id + "-plugin.xml" ) ); FileWriter writer = null;
try
{
writer = new FileWriter( new File( destinationDirectory, id + "-plugin.xml" ) );
writeBody( writer, id, mojoDescriptor );
writer.flush();
}
finally
{
IOUtil.close( writer );
}
}
private void writeBody( FileWriter writer, String id, MojoDescriptor mojoDescriptor )
{
XMLWriter w = new PrettyPrintXMLWriter( writer ); XMLWriter w = new PrettyPrintXMLWriter( writer );
w.startElement( "document" ); w.startElement( "document" );
@ -67,7 +84,7 @@ public class PluginXdocGenerator
w.startElement( "title" ); w.startElement( "title" );
w.writeText( "Documentation for the " + mojoDescriptor.getId() + " plugin." ); w.writeText( "Documentation for the " + id + " plugin." );
w.endElement(); w.endElement();
@ -91,7 +108,7 @@ public class PluginXdocGenerator
w.startElement( "p" ); w.startElement( "p" );
w.writeText( "The goals for the " + mojoDescriptor.getId() + " are as follows:" ); w.writeText( "The goals for the " + id + " are as follows:" );
w.endElement(); w.endElement();
@ -133,14 +150,9 @@ public class PluginXdocGenerator
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
w.endElement(); w.endElement();
writer.flush();
writer.close();
} }
private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w ) private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w )
throws Exception
{ {
w.startElement( "p" ); w.startElement( "p" );

View File

@ -18,16 +18,17 @@ package org.apache.maven.tools.plugin.generator.jelly;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.Generator; import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.util.PluginUtils; import org.apache.maven.tools.plugin.util.PluginUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -48,26 +49,56 @@ public class JellyHarnessGenerator
return pluginDescriptor.getImplementation() + "Bean"; return pluginDescriptor.getImplementation() + "Bean";
} }
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
throws Exception throws IOException
{ {
FileWriter writer = new FileWriter( new File( destinationDirectory, "plugin.jelly" ) ); FileWriter writer = null;
PrettyPrintXMLWriter w;
try
{
writer = new FileWriter( new File( destinationDirectory, "plugin.jelly" ) );
PrettyPrintXMLWriter w = new PrettyPrintXMLWriter( writer ); w = new PrettyPrintXMLWriter( writer );
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() ); writePluginFile( w, goalPrefix, mojoDescriptors, project );
writer.flush();
}
finally
{
IOUtil.close( writer );
}
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// // project.xml
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
writer = null;
try
{
writer = new FileWriter( new File( destinationDirectory, "project.xml" ) );
w = new PrettyPrintXMLWriter( writer );
writeProjectFile( w, project );
writer.flush();
}
finally
{
IOUtil.close( writer );
}
}
private void writePluginFile( PrettyPrintXMLWriter w, String goalPrefix, Set mojoDescriptors, MavenProject project )
{
w.startElement( "project" ); w.startElement( "project" );
w.addAttribute( "xmlns:j", "jelly:core" ); w.addAttribute( "xmlns:j", "jelly:core" );
w.addAttribute( "xmlns:d", "jelly:define" ); w.addAttribute( "xmlns:d", "jelly:define" );
w.addAttribute( "xmlns:" + pluginId, pluginId ); w.addAttribute( "xmlns:" + goalPrefix, goalPrefix );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// //
@ -75,7 +106,7 @@ public class JellyHarnessGenerator
w.startElement( "d:taglib" ); w.startElement( "d:taglib" );
w.addAttribute( "uri", pluginId ); w.addAttribute( "uri", goalPrefix );
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); ) for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
{ {
@ -100,23 +131,10 @@ public class JellyHarnessGenerator
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
w.endElement(); w.endElement();
}
// ---------------------------------------------------------------------- private void writeProjectFile( PrettyPrintXMLWriter w, MavenProject project )
// {
// ----------------------------------------------------------------------
writer.flush();
writer.close();
// ----------------------------------------------------------------------
// project.xml
// ----------------------------------------------------------------------
writer = new FileWriter( new File( destinationDirectory, "project.xml" ) );
w = new PrettyPrintXMLWriter( writer );
w.startElement( "project" ); w.startElement( "project" );
w.startElement( "dependencies" ); w.startElement( "dependencies" );
@ -126,18 +144,10 @@ public class JellyHarnessGenerator
w.endElement(); w.endElement();
w.endElement(); w.endElement();
writer.flush();
writer.close();
} }
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project ) protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
throws Exception
{ {
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
String goalName = mojoDescriptor.getGoal(); String goalName = mojoDescriptor.getGoal();
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -187,7 +197,7 @@ public class JellyHarnessGenerator
// //
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
w.startElement( pluginId + ":" + goalName + "Bean" ); w.startElement( mojoDescriptor.getFullGoalName() + "Bean" );
List parameters = mojoDescriptor.getParameters(); List parameters = mojoDescriptor.getParameters();
@ -196,12 +206,12 @@ public class JellyHarnessGenerator
Parameter parameter = (Parameter) parameters.get( i ); Parameter parameter = (Parameter) parameters.get( i );
String paramName = parameter.getAlias(); String paramName = parameter.getAlias();
if( StringUtils.isEmpty( paramName ) ) if ( StringUtils.isEmpty( paramName ) )
{ {
paramName = parameter.getName(); paramName = parameter.getName();
} }
w.addAttribute( paramName, "${" + paramName + "}" ); w.addAttribute( paramName, "${" + paramName + "}" );
} }
@ -216,18 +226,16 @@ public class JellyHarnessGenerator
private void writeGoals( MojoDescriptor mojoDescriptor, XMLWriter w ) private void writeGoals( MojoDescriptor mojoDescriptor, XMLWriter w )
{ {
String id = mojoDescriptor.getId();
w.startElement( "goal" ); w.startElement( "goal" );
w.addAttribute( "name", id + ":" + mojoDescriptor.getGoal() ); w.addAttribute( "name", mojoDescriptor.getFullGoalName() );
if ( mojoDescriptor.getDescription() != null ) if ( mojoDescriptor.getDescription() != null )
{ {
w.addAttribute( "description", mojoDescriptor.getDescription() ); w.addAttribute( "description", mojoDescriptor.getDescription() );
} }
w.startElement( id + ":" + mojoDescriptor.getGoal() + "Bean" ); w.startElement( mojoDescriptor.getFullGoalName() + "Bean" );
List goalParameters = mojoDescriptor.getParameters(); List goalParameters = mojoDescriptor.getParameters();
@ -245,11 +253,6 @@ public class JellyHarnessGenerator
expression.substring( projectIndex + 7 ); expression.substring( projectIndex + 7 );
} }
if ( expression.startsWith( "#" ) )
{
expression = "${" + expression.substring( 1 ) + "}";
}
w.addAttribute( p.getName(), expression ); w.addAttribute( p.getName(), expression );
} }

View File

@ -18,6 +18,9 @@ package org.apache.maven.tools.plugin.scanner;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.apache.maven.tools.plugin.extractor.InvalidParameterException;
import org.apache.maven.tools.plugin.PluginToolsException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -42,8 +45,8 @@ public class DefaultMojoScanner
{ {
} }
public Set execute( MavenProject project ) public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws Exception throws PluginToolsException
{ {
Set descriptors = new HashSet(); Set descriptors = new HashSet();
@ -57,7 +60,7 @@ public class DefaultMojoScanner
System.out.println( "Applying extractor for language: " + language ); System.out.println( "Applying extractor for language: " + language );
Set extractorDescriptors = extractor.execute( project ); Set extractorDescriptors = extractor.execute( project, pluginDescriptor );
System.out.println( "Extractor for language: " + language + " found " + extractorDescriptors.size() + System.out.println( "Extractor for language: " + language + " found " + extractorDescriptors.size() +
" mojo descriptors." ); " mojo descriptors." );

View File

@ -17,6 +17,9 @@ package org.apache.maven.tools.plugin.scanner;
*/ */
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.tools.plugin.extractor.InvalidParameterException;
import org.apache.maven.tools.plugin.PluginToolsException;
import java.util.Set; import java.util.Set;
@ -25,9 +28,9 @@ import java.util.Set;
*/ */
public interface MojoScanner public interface MojoScanner
{ {
String ROLE = MojoScanner.class.getName(); String ROLE = MojoScanner.class.getName();
Set execute( MavenProject project ) throws Exception; Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws PluginToolsException;
} }

View File

@ -60,7 +60,6 @@ public final class PluginUtils
} }
public static void writeDependencies( XMLWriter w, MavenProject project ) public static void writeDependencies( XMLWriter w, MavenProject project )
throws Exception
{ {
w.startElement( "dependencies" ); w.startElement( "dependencies" );

View File

@ -52,15 +52,10 @@ public abstract class AbstractGeneratorTestCase
{ {
setupGenerator(); setupGenerator();
String sourceDirectory = new File( basedir, "src/test/resources/source" ).getPath();
String destinationDirectory = new File( basedir, "target" ).getPath(); String destinationDirectory = new File( basedir, "target" ).getPath();
String pom = new File( basedir, "src/test/resources/source/pom.xml" ).getPath();
MojoDescriptor mojoDescriptor = new MojoDescriptor(); MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setGoal( "testGoal" ); mojoDescriptor.setGoal( "testGoal" );
mojoDescriptor.setId( "test" );
mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" ); mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" );
mojoDescriptor.setRequiresDependencyResolution( "compile" ); mojoDescriptor.setRequiresDependencyResolution( "compile" );
@ -68,10 +63,10 @@ public abstract class AbstractGeneratorTestCase
Parameter param = new Parameter(); Parameter param = new Parameter();
param.setDefaultValue( "value" ); param.setDefaultValue( "value" );
param.setExpression( "#project.build.directory" ); param.setExpression( "${project.build.directory}" );
param.setName( "dir" ); param.setName( "dir" );
param.setRequired( true ); param.setRequired( true );
param.setType( "String" ); param.setType( "java.lang.String" );
param.setDescription( "Test parameter description" ); param.setDescription( "Test parameter description" );
params.add( param ); params.add( param );
@ -93,7 +88,7 @@ public abstract class AbstractGeneratorTestCase
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model );
generator.execute( destinationDirectory, descriptors, project ); generator.execute( destinationDirectory, descriptors, project, "test" );
validate(); validate();
} }

View File

@ -91,7 +91,7 @@ public class PluginDescriptorGeneratorTest
private void checkMojo( MojoDescriptor mojoDescriptor ) private void checkMojo( MojoDescriptor mojoDescriptor )
{ {
assertEquals( "test:testGoal", mojoDescriptor.getId() ); assertEquals( "test:testGoal", mojoDescriptor.getFullGoalName() );
assertEquals( "org.apache.maven.tools.plugin.generator.TestMojo", mojoDescriptor.getImplementation() ); assertEquals( "org.apache.maven.tools.plugin.generator.TestMojo", mojoDescriptor.getImplementation() );
@ -107,7 +107,7 @@ public class PluginDescriptorGeneratorTest
private void checkParameter( Parameter parameter ) private void checkParameter( Parameter parameter )
{ {
assertEquals( "dir", parameter.getName() ); assertEquals( "dir", parameter.getName() );
assertEquals( "String", parameter.getType() ); assertEquals( String.class.getName(), parameter.getType() );
assertTrue( parameter.isRequired() ); assertTrue( parameter.isRequired() );
} }

View File

@ -4,6 +4,7 @@ import junit.framework.TestCase;
import org.apache.maven.model.Build; import org.apache.maven.model.Build;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.io.File; import java.io.File;
@ -18,7 +19,8 @@ public class DefaultMojoScannerTest
extends TestCase extends TestCase
{ {
public void testShouldFindOneDescriptorFromTestExtractor() throws Exception public void testShouldFindOneDescriptorFromTestExtractor()
throws Exception
{ {
Map extractors = Collections.singletonMap( "test", new TestExtractor() ); Map extractors = Collections.singletonMap( "test", new TestExtractor() );
@ -33,12 +35,14 @@ public class DefaultMojoScannerTest
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model );
project.setFile( new File( "." ) ); project.setFile( new File( "." ) );
Set descriptors = scanner.execute( project ); PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "testId" );
Set descriptors = scanner.execute( project, pluginDescriptor );
assertEquals( 1, descriptors.size() ); assertEquals( 1, descriptors.size() );
MojoDescriptor desc = (MojoDescriptor) descriptors.iterator().next(); MojoDescriptor desc = (MojoDescriptor) descriptors.iterator().next();
assertEquals( "testPluginId", desc.getId() ); assertEquals( pluginDescriptor, desc.getPluginDescriptor() );
assertEquals( "testGoal", desc.getGoal() ); assertEquals( "testGoal", desc.getGoal() );
} }

View File

@ -1,6 +1,7 @@
package org.apache.maven.tools.plugin.scanner; package org.apache.maven.tools.plugin.scanner;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
@ -14,11 +15,10 @@ public class TestExtractor
implements MojoDescriptorExtractor implements MojoDescriptorExtractor
{ {
public Set execute( MavenProject project ) public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws Exception
{ {
MojoDescriptor desc = new MojoDescriptor(); MojoDescriptor desc = new MojoDescriptor();
desc.setId( "testPluginId" ); desc.setPluginDescriptor( pluginDescriptor );
desc.setGoal( "testGoal" ); desc.setGoal( "testGoal" );
return Collections.singleton( desc ); return Collections.singleton( desc );

View File

@ -24,7 +24,7 @@ public class PluginUtilsTest
MavenProject project = new MavenProject( model ); MavenProject project = new MavenProject( model );
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() ); String pluginId = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
assertEquals( "artifactId", pluginId ); assertEquals( "artifactId", pluginId );
} }

View File

@ -16,30 +16,30 @@ package org.apache.maven.tools.plugin.extractor.java;
* limitations under the License. * limitations under the License.
*/ */
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaSource;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter; import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.InvalidParameterException; import org.apache.maven.tools.plugin.extractor.InvalidParameterException;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.apache.maven.tools.plugin.PluginToolsException;
import org.codehaus.modello.StringUtils; import org.codehaus.modello.StringUtils;
import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.logging.AbstractLogEnabled;
import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import com.thoughtworks.qdox.model.JavaSource;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.Map.Entry;
/** /**
* @todo add example usage tag that can be shown in the doco * @todo add example usage tag that can be shown in the doco
@ -112,9 +112,10 @@ public class JavaMojoDescriptorExtractor
// Mojo descriptor creation from @tags // Mojo descriptor creation from @tags
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
private MojoDescriptor createMojoDescriptor( JavaSource javaSource, MavenProject project ) private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescriptor pluginDescriptor )
{ {
MojoDescriptor mojoDescriptor = new MojoDescriptor(); MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
JavaClass javaClass = getJavaClass( javaSource ); JavaClass javaClass = getJavaClass( javaSource );
@ -124,10 +125,6 @@ public class JavaMojoDescriptorExtractor
DocletTag tag; DocletTag tag;
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
mojoDescriptor.setId( pluginId );
tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_DESCRIPTION ); tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_DESCRIPTION );
if ( tag != null ) if ( tag != null )
@ -318,8 +315,8 @@ public class JavaMojoDescriptorExtractor
return javaSource.getClasses()[0]; return javaSource.getClasses()[0];
} }
public Set execute( MavenProject project ) public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws Exception throws InvalidParameterException
{ {
JavaDocBuilder builder = new JavaDocBuilder(); JavaDocBuilder builder = new JavaDocBuilder();
@ -346,7 +343,7 @@ public class JavaMojoDescriptorExtractor
if ( tag != null ) if ( tag != null )
{ {
MojoDescriptor mojoDescriptor = createMojoDescriptor( javaSources[i], project ); MojoDescriptor mojoDescriptor = createMojoDescriptor( javaSources[i], pluginDescriptor );
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// Validate the descriptor as best we can before allowing it // Validate the descriptor as best we can before allowing it

View File

@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.extractor.java;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
@ -49,7 +50,9 @@ public class JavaMojoDescriptorExtractorTest
project.setFile( new File( dir, "pom.xml" ) ); project.setFile( new File( dir, "pom.xml" ) );
project.addCompileSourceRoot( new File( dir, "source" ).getPath() ); project.addCompileSourceRoot( new File( dir, "source" ).getPath() );
Set results = extractor.execute( project ); PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "test" );
Set results = extractor.execute( project, pluginDescriptor );
assertEquals( 2, results.size() ); assertEquals( 2, results.size() );
} }

View File

@ -17,18 +17,23 @@ package org.apache.maven.tools.plugin.extractor.marmalade;
*/ */
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives; import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives;
import org.apache.maven.script.marmalade.tags.MojoTag; import org.apache.maven.script.marmalade.tags.MojoTag;
import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
import org.apache.maven.tools.plugin.PluginToolsException;
import org.codehaus.marmalade.launch.MarmaladeLauncher; import org.codehaus.marmalade.launch.MarmaladeLauncher;
import org.codehaus.marmalade.launch.MarmaladeLaunchException;
import org.codehaus.marmalade.model.MarmaladeScript; import org.codehaus.marmalade.model.MarmaladeScript;
import org.codehaus.marmalade.model.MarmaladeTag; import org.codehaus.marmalade.model.MarmaladeTag;
import org.codehaus.marmalade.runtime.DefaultContext; import org.codehaus.marmalade.runtime.DefaultContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext; import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
import org.codehaus.plexus.component.factory.marmalade.PlexusIntegratedLog; import org.codehaus.plexus.component.factory.marmalade.PlexusIntegratedLog;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -47,8 +52,8 @@ public class MarmaladeMojoDescriptorExtractor
return ".mmld"; return ".mmld";
} }
protected Set extractMojoDescriptors( Map sourceFilesKeyedByBasedir ) protected Set extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
throws Exception throws PluginToolsException
{ {
ClassLoader oldCl = Thread.currentThread().getContextClassLoader(); ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
try try
@ -88,6 +93,7 @@ public class MarmaladeMojoDescriptorExtractor
{ {
Map contextMap = new TreeMap(); Map contextMap = new TreeMap();
contextMap.put( MarmaladeMojoExecutionDirectives.SCRIPT_BASEPATH_INVAR, basedir ); contextMap.put( MarmaladeMojoExecutionDirectives.SCRIPT_BASEPATH_INVAR, basedir );
contextMap.put( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, pluginDescriptor );
MarmaladeExecutionContext context = new DefaultContext( contextMap ); MarmaladeExecutionContext context = new DefaultContext( contextMap );
@ -110,6 +116,18 @@ public class MarmaladeMojoDescriptorExtractor
return descriptors; return descriptors;
} }
catch ( IOException e )
{
throw new PluginToolsException( "Error reading Marmalade for extracting mojo descriptor", e );
}
catch ( MarmaladeExecutionException e )
{
throw new PluginToolsException( "Error executing Marmalade for extracting mojo descriptor", e );
}
catch ( MarmaladeLaunchException e )
{
throw new PluginToolsException( "Error executing Marmalade for extracting mojo descriptor", e );
}
finally finally
{ {
Thread.currentThread().setContextClassLoader( oldCl ); Thread.currentThread().setContextClassLoader( oldCl );

View File

@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.extractor.marmalade;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -45,19 +46,21 @@ public class MarmaladeMojoDescriptorExtractorTest
project.setFile( new File( basedir, "pom.xml" ) ); project.setFile( new File( basedir, "pom.xml" ) );
System.out.println("Basedir: " + basedir); System.out.println( "Basedir: " + basedir );
project.addScriptSourceRoot( basedir.getPath() ); project.addScriptSourceRoot( basedir.getPath() );
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup( MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup(
MojoDescriptorExtractor.ROLE, "marmalade" ); MojoDescriptorExtractor.ROLE, "marmalade" );
Set descriptors = extractor.execute( project ); PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "test" );
Set descriptors = extractor.execute( project, pluginDescriptor );
assertEquals( 1, descriptors.size() ); assertEquals( 1, descriptors.size() );
MojoDescriptor descriptor = (MojoDescriptor) descriptors.iterator().next(); MojoDescriptor descriptor = (MojoDescriptor) descriptors.iterator().next();
assertEquals( pluginDescriptor, descriptor.getPluginDescriptor() );
assertEquals( "marmalade", descriptor.getLanguage() ); assertEquals( "marmalade", descriptor.getLanguage() );
assertEquals( "testId", descriptor.getId() );
assertEquals( "testGoal", descriptor.getGoal() ); assertEquals( "testGoal", descriptor.getGoal() );
assertEquals( 1, descriptor.getParameters().size() ); assertEquals( 1, descriptor.getParameters().size() );
} }

View File

@ -2,14 +2,13 @@
<mojo xmlns="marmalade:mojo"> <mojo xmlns="marmalade:mojo">
<metadata> <metadata>
<id>testId</id>
<goal>testGoal</goal> <goal>testGoal</goal>
<description>This is a test mojo</description> <description>This is a test mojo</description>
<parameters> <parameters>
<parameter> <parameter>
<name>testParam</name> <name>testParam</name>
<default>TestValue</default> <default>TestValue</default>
<expression>#pom.file</expression> <expression>${pom.file}</expression>
<required>true</required> <required>true</required>
<description>This is a test parameter</description> <description>This is a test parameter</description>
</parameter> </parameter>
@ -18,4 +17,4 @@
<execute> <execute>
<set xmlns="marmalade:core" var="testVar" extern="true">testVal</set> <set xmlns="marmalade:core" var="testVar" extern="true">testVal</set>
</execute> </execute>
</mojo> </mojo>

View File

@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.pluggy;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.java.JavaMojoDescriptorExtractor; import org.apache.maven.tools.plugin.extractor.java.JavaMojoDescriptorExtractor;
import org.apache.maven.tools.plugin.generator.BeanGenerator; import org.apache.maven.tools.plugin.generator.BeanGenerator;
@ -30,7 +31,6 @@ import org.apache.maven.tools.plugin.scanner.MojoScanner;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
@ -45,7 +45,7 @@ public class Main
{ {
if ( args.length != 5 ) if ( args.length != 5 )
{ {
System.err.println( "Usage: pluggy <mode> <source directory> <output directory> <pom> <local-repo>" ); System.err.println( "Usage: pluggy <mode> <source directory> <output directory> <pom>" );
System.exit( 1 ); System.exit( 1 );
} }
@ -59,12 +59,8 @@ public class Main
String pom = args[3]; String pom = args[3];
String localRepo = args[4];
// Massage the local-repo path into an ArtifactRepository. // Massage the local-repo path into an ArtifactRepository.
File repoPath = new File( localRepo );
URL repoUrl = repoPath.toURL();
MavenXpp3Reader modelReader = new MavenXpp3Reader(); MavenXpp3Reader modelReader = new MavenXpp3Reader();
FileReader reader = new FileReader( pom ); FileReader reader = new FileReader( pom );
@ -90,7 +86,10 @@ public class Main
MojoScanner scanner = new DefaultMojoScanner( MojoScanner scanner = new DefaultMojoScanner(
Collections.singletonMap( "java", new JavaMojoDescriptorExtractor() ) ); Collections.singletonMap( "java", new JavaMojoDescriptorExtractor() ) );
Set descriptors = scanner.execute( project ); PluginDescriptor pluginDescriptor = new PluginDescriptor();
// TODO: should read this from the pom...
pluginDescriptor.setGoalPrefix( PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ) );
Set descriptors = scanner.execute( project, pluginDescriptor );
// Create the generator. // Create the generator.
Generator generator = null; Generator generator = null;
@ -114,6 +113,6 @@ public class Main
// Use the generator to process the discovered descriptors and produce // Use the generator to process the discovered descriptors and produce
// something with them. // something with them.
generator.execute( outputDirectory, descriptors, project ); generator.execute( outputDirectory, descriptors, project, pluginDescriptor.getGoalPrefix() );
} }
} }

View File

@ -18,9 +18,13 @@ package org.apache.maven.plugin.plugin;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.scanner.MojoScanner; import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.PluginToolsException;
import java.io.IOException;
import java.util.Set; import java.util.Set;
/** /**
@ -41,25 +45,46 @@ public abstract class AbstractGeneratorMojo
* @required * @required
*/ */
protected MojoScanner mojoScanner; protected MojoScanner mojoScanner;
/**
* The goal prefix that will appear before the ":".
*/
protected String goalPrefix;
protected abstract String getOutputDirectory(); protected abstract String getOutputDirectory();
protected abstract void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project ) protected abstract Generator createGenerator();
throws Exception;
public void execute() public void execute()
throws MojoExecutionException throws MojoExecutionException
{ {
String defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
if ( goalPrefix == null )
{
goalPrefix = defaultGoalPrefix;
}
else
{
getLog().warn( "Goal prefix is: " + goalPrefix + "; Maven currently expects it to be " + defaultGoalPrefix );
}
// TODO: could use this more, eg in the writing of the plugin descriptor!
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( goalPrefix );
try try
{ {
Set mavenMojoDescriptors = mojoScanner.execute( project ); Set mavenMojoDescriptors = mojoScanner.execute( project, pluginDescriptor );
generate( getOutputDirectory(), mavenMojoDescriptors, project ); createGenerator().execute( getOutputDirectory(), mavenMojoDescriptors, project, goalPrefix );
} }
catch ( Exception e ) catch ( IOException e )
{ {
// TODO: improve error handling throw new MojoExecutionException( "Error writing plugin descriptor", e );
throw new MojoExecutionException( "Error generating plugin descriptor", e ); }
catch ( PluginToolsException e )
{
throw new MojoExecutionException( "Error creatin plugin descriptor", e );
} }
} }
} }

View File

@ -18,6 +18,8 @@ package org.apache.maven.plugin.plugin;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.BeanGenerator; import org.apache.maven.tools.plugin.generator.BeanGenerator;
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
import org.apache.maven.tools.plugin.generator.Generator;
import java.util.Set; import java.util.Set;
@ -25,7 +27,6 @@ import java.util.Set;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal bean * @goal bean
* @description Goal for generating a plugin descriptor.
*/ */
public class BeanGeneratorMojo public class BeanGeneratorMojo
extends AbstractGeneratorMojo extends AbstractGeneratorMojo
@ -41,11 +42,8 @@ public class BeanGeneratorMojo
return outputDirectory; return outputDirectory;
} }
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project ) protected Generator createGenerator()
throws Exception
{ {
BeanGenerator generator = new BeanGenerator(); return new BeanGenerator();
generator.execute( outputDirectory, mavenMojoDescriptors, project );
} }
} }

View File

@ -18,6 +18,8 @@ package org.apache.maven.plugin.plugin;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator; import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import java.util.Set; import java.util.Set;
@ -30,7 +32,6 @@ import java.util.Set;
* @version $Id$ * @version $Id$
* @goal descriptor * @goal descriptor
* @phase process-classes * @phase process-classes
* @description Goal for generating a plugin descriptor.
*/ */
public class DescriptorGeneratorMojo public class DescriptorGeneratorMojo
extends AbstractGeneratorMojo extends AbstractGeneratorMojo
@ -46,12 +47,8 @@ public class DescriptorGeneratorMojo
return outputDirectory; return outputDirectory;
} }
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project ) protected Generator createGenerator()
throws Exception
{ {
PluginDescriptorGenerator generator = new PluginDescriptorGenerator(); return new PluginDescriptorGenerator();
generator.execute( outputDirectory, mavenMojoDescriptors, project );
} }
} }

View File

@ -18,6 +18,7 @@ package org.apache.maven.plugin.plugin;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.generator.jelly.JellyHarnessGenerator; import org.apache.maven.tools.plugin.generator.jelly.JellyHarnessGenerator;
import org.apache.maven.tools.plugin.generator.Generator;
import java.util.Set; import java.util.Set;
@ -25,7 +26,6 @@ import java.util.Set;
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$ * @version $Id$
* @goal jelly * @goal jelly
* @description Goal for generating a plugin descriptor.
*/ */
public class JellyGeneratorMojo public class JellyGeneratorMojo
extends AbstractGeneratorMojo extends AbstractGeneratorMojo
@ -41,11 +41,8 @@ public class JellyGeneratorMojo
return outputDirectory; return outputDirectory;
} }
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project ) protected Generator createGenerator()
throws Exception
{ {
JellyHarnessGenerator generator = new JellyHarnessGenerator(); return new JellyHarnessGenerator();
generator.execute( outputDirectory, mavenMojoDescriptors, project );
} }
} }

View File

@ -704,7 +704,7 @@ public class MavenProject
return distMgmtArtifactRepository; return distMgmtArtifactRepository;
} }
public Xpp3Dom getGoalConfiguration( String pluginId, String goalName ) public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String goalId )
{ {
Xpp3Dom dom = null; Xpp3Dom dom = null;
@ -720,25 +720,20 @@ public class MavenProject
{ {
Plugin plugin = (Plugin) iterator.next(); Plugin plugin = (Plugin) iterator.next();
// TODO: groupID not handled if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
if ( pluginId.equals( plugin.getArtifactId() ) )
{ {
dom = (Xpp3Dom) plugin.getConfiguration(); dom = (Xpp3Dom) plugin.getConfiguration();
if ( goalName != null ) if ( goalId != null )
{ {
for ( Iterator j = plugin.getGoals().iterator(); j.hasNext(); ) Goal goal = (Goal) plugin.getGoalsAsMap().get( goalId );
if ( goal != null )
{ {
Goal goal = (Goal) j.next(); Xpp3Dom goalConfiguration = (Xpp3Dom) goal.getConfiguration();
if ( goal.getId().equals( goalName ) ) if ( goalConfiguration != null )
{ {
Xpp3Dom goalConfiguration = (Xpp3Dom) goal.getConfiguration(); Xpp3Dom newDom = new Xpp3Dom( goalConfiguration );
if ( goalConfiguration != null ) dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
{
Xpp3Dom newDom = new Xpp3Dom( goalConfiguration );
dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
}
break;
} }
} }
} }

View File

@ -30,6 +30,8 @@ public final class MarmaladeMojoExecutionDirectives
public static final String RESPONSE_INVAR = "response"; public static final String RESPONSE_INVAR = "response";
public static final String PLUGIN_DESCRIPTOR = "pluginDescriptor";
private MarmaladeMojoExecutionDirectives() private MarmaladeMojoExecutionDirectives()
{ {
} }

View File

@ -17,6 +17,7 @@ package org.apache.maven.script.marmalade.tags;
*/ */
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives; import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives;
import org.codehaus.marmalade.model.AbstractMarmaladeTag; import org.codehaus.marmalade.model.AbstractMarmaladeTag;
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext; import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
@ -34,9 +35,6 @@ public class MetadataTag
extends AbstractMarmaladeTag extends AbstractMarmaladeTag
implements DescriptionParent implements DescriptionParent
{ {
private String id;
private String goal; private String goal;
private String requiresDependencyResolution = null; private String requiresDependencyResolution = null;
@ -76,10 +74,8 @@ public class MetadataTag
descriptor.setComponentComposer( "map-oriented" ); descriptor.setComponentComposer( "map-oriented" );
descriptor.setComponentConfigurator( "map-oriented" ); descriptor.setComponentConfigurator( "map-oriented" );
if ( notEmpty( id ) ) descriptor.setPluginDescriptor(
{ (PluginDescriptor) context.getVariable( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, null ) );
descriptor.setId( id );
}
if ( notEmpty( goal ) ) if ( notEmpty( goal ) )
{ {
@ -130,11 +126,6 @@ public class MetadataTag
return test != null && test.trim().length() > 0; return test != null && test.trim().length() > 0;
} }
public void setId( String id )
{
this.id = id;
}
public void setLifecyclePhase( String lifecyclePhase ) public void setLifecyclePhase( String lifecyclePhase )
{ {
this.lifecyclePhase = lifecyclePhase; this.lifecyclePhase = lifecyclePhase;

View File

@ -31,7 +31,6 @@ public class MojoDefinitionTagLibrary
registerTag( "execute", ExecuteTag.class ); registerTag( "execute", ExecuteTag.class );
registerTag( "executionStrategy", ExecutionStrategyTag.class ); registerTag( "executionStrategy", ExecutionStrategyTag.class );
registerTag( "goal", GoalTag.class ); registerTag( "goal", GoalTag.class );
registerTag( "id", IdTag.class );
registerTag( "instantiationStrategy", InstantiationStrategyTag.class ); registerTag( "instantiationStrategy", InstantiationStrategyTag.class );
registerTag( "lifecyclePhase", LifecyclePhaseTag.class ); registerTag( "lifecyclePhase", LifecyclePhaseTag.class );
registerTag( "metadata", MetadataTag.class ); registerTag( "metadata", MetadataTag.class );