mirror of https://github.com/apache/maven.git
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:
parent
118a53927d
commit
24c6328ad3
|
@ -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.ArtifactHandlerNotFoundException;
|
||||
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.MavenSession;
|
||||
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.PluginManager;
|
||||
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.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.injection.ModelDefaultsInjector;
|
||||
import org.apache.maven.settings.Settings;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -307,7 +301,7 @@ public class DefaultLifecycleExecutor
|
|||
throw new LifecycleExecutionException(
|
||||
"Required phase '" + mojoDescriptor.getPhase() + "' not found" );
|
||||
}
|
||||
phase.getGoals().add( mojoDescriptor.getId() );
|
||||
phase.getGoals().add( mojoDescriptor.getFullGoalName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ public class DefaultPluginManager
|
|||
{
|
||||
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
|
||||
|
||||
mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor );
|
||||
mojoDescriptors.put( mojoDescriptor.getFullGoalName(), mojoDescriptor );
|
||||
}
|
||||
|
||||
pluginDescriptors.put( key, pluginDescriptor );
|
||||
|
@ -353,7 +353,7 @@ public class DefaultPluginManager
|
|||
|
||||
Mojo plugin = null;
|
||||
|
||||
String goalName = mojoDescriptor.getId();
|
||||
String goalName = mojoDescriptor.getFullGoalName();
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -364,8 +364,9 @@ public class DefaultPluginManager
|
|||
String goalId = mojoDescriptor.getGoal();
|
||||
|
||||
// TODO: can probable refactor these a little when only the new plugin technique is in place
|
||||
Xpp3Dom dom = session.getProject().getGoalConfiguration(
|
||||
PluginDescriptor.getPluginArtifactIdFromGoal( goalName ), goalId );
|
||||
PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
|
||||
Xpp3Dom dom = session.getProject().getGoalConfiguration( pluginDescriptor.getGroupId(),
|
||||
pluginDescriptor.getArtifactId(), goalId );
|
||||
|
||||
PlexusConfiguration pomConfiguration;
|
||||
if ( dom == null )
|
||||
|
@ -471,7 +472,7 @@ public class DefaultPluginManager
|
|||
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() );
|
||||
}
|
||||
|
@ -724,7 +725,7 @@ public class DefaultPluginManager
|
|||
|
||||
message.append( "The '" + parameter.getName() );
|
||||
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( " The retrieval expression was: " ).append( expression );
|
||||
|
||||
|
|
|
@ -2004,12 +2004,15 @@
|
|||
if ( goalMap == null )
|
||||
{
|
||||
goalMap = new HashMap();
|
||||
if ( goals != null )
|
||||
{
|
||||
for ( Iterator i = goals.iterator(); i.hasNext(); )
|
||||
{
|
||||
Goal g = (Goal) i.next();
|
||||
goalMap.put( g.getId(), g );
|
||||
}
|
||||
}
|
||||
}
|
||||
return goalMap;
|
||||
}
|
||||
]]></code>
|
||||
|
|
|
@ -46,8 +46,6 @@ public class MojoDescriptor
|
|||
|
||||
private static final String DEFAULT_LANGUAGE = "java";
|
||||
|
||||
private String id;
|
||||
|
||||
private List parameters;
|
||||
|
||||
private Map parameterMap;
|
||||
|
@ -74,6 +72,8 @@ public class MojoDescriptor
|
|||
|
||||
private PlexusConfiguration mojoConfiguration;
|
||||
|
||||
private PluginDescriptor pluginDescriptor;
|
||||
|
||||
public MojoDescriptor()
|
||||
{
|
||||
setInstantiationStrategy( DEFAULT_INSTANTIATION_STRATEGY );
|
||||
|
@ -94,16 +94,6 @@ public class MojoDescriptor
|
|||
setComponentFactory( language );
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDeprecated()
|
||||
{
|
||||
return deprecated;
|
||||
|
@ -257,7 +247,12 @@ public class MojoDescriptor
|
|||
|
||||
public String getRoleHint()
|
||||
{
|
||||
return getId() + ":" + getGoal();
|
||||
return getFullGoalName();
|
||||
}
|
||||
|
||||
public String getFullGoalName()
|
||||
{
|
||||
return getPluginDescriptor().getGoalPrefix() + ":" + getGoal();
|
||||
}
|
||||
|
||||
public String getComponentType()
|
||||
|
@ -265,4 +260,13 @@ public class MojoDescriptor
|
|||
return MAVEN_PLUGIN;
|
||||
}
|
||||
|
||||
public PluginDescriptor getPluginDescriptor()
|
||||
{
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
public void setPluginDescriptor( PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
this.pluginDescriptor = pluginDescriptor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ public class PluginDescriptor
|
|||
|
||||
private boolean isolatedRealm;
|
||||
|
||||
private String goalPrefix;
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -134,7 +136,7 @@ public class PluginDescriptor
|
|||
*
|
||||
* @todo remove - harcoding. What about clashes?
|
||||
*/
|
||||
public static String getPluginIdFromArtifactId( String artifactId )
|
||||
public static String getGoalPrefixFromArtifactId( String artifactId )
|
||||
{
|
||||
int firstHyphen = artifactId.indexOf( "-" );
|
||||
|
||||
|
@ -161,4 +163,14 @@ public class PluginDescriptor
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getGoalPrefix()
|
||||
{
|
||||
return goalPrefix;
|
||||
}
|
||||
|
||||
public void setGoalPrefix( String goalPrefix )
|
||||
{
|
||||
this.goalPrefix = goalPrefix;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,18 +25,9 @@ public class PluginDescriptorBuilder
|
|||
|
||||
PluginDescriptor pluginDescriptor = new PluginDescriptor();
|
||||
|
||||
String id = c.getChild( "id" ).getValue();
|
||||
if ( id != null )
|
||||
{
|
||||
// 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() );
|
||||
}
|
||||
pluginDescriptor.setGoalPrefix( c.getChild( "goalPrefix" ).getValue() );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Components
|
||||
|
@ -50,7 +41,7 @@ public class PluginDescriptorBuilder
|
|||
{
|
||||
PlexusConfiguration component = mojoConfigurations[i];
|
||||
|
||||
mojos.add( buildComponentDescriptor( component ) );
|
||||
mojos.add( buildComponentDescriptor( component, pluginDescriptor ) );
|
||||
}
|
||||
|
||||
pluginDescriptor.setMojos( mojos );
|
||||
|
@ -85,12 +76,11 @@ public class PluginDescriptorBuilder
|
|||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c )
|
||||
public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDescriptor pluginDescriptor )
|
||||
throws PlexusConfigurationException
|
||||
{
|
||||
MojoDescriptor mojo = new MojoDescriptor();
|
||||
|
||||
mojo.setId( c.getChild( "id" ).getValue() );
|
||||
mojo.setPluginDescriptor( pluginDescriptor );
|
||||
|
||||
mojo.setGoal( c.getChild( "goal" ).getValue() );
|
||||
|
||||
|
|
|
@ -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");
|
||||
* 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.
|
||||
*/
|
||||
|
||||
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
|
||||
extends AbstractStringValuedBodyTag
|
||||
public class PluginToolsException
|
||||
extends Exception
|
||||
{
|
||||
|
||||
protected void setValue( String value ) throws MarmaladeExecutionException
|
||||
public PluginToolsException( String message, Throwable throwable )
|
||||
{
|
||||
MetadataTag metadataTag = (MetadataTag) requireParent( MetadataTag.class );
|
||||
metadataTag.setId( value );
|
||||
super( message, throwable );
|
||||
}
|
||||
|
||||
public PluginToolsException( String message )
|
||||
{
|
||||
super( message );
|
||||
}
|
||||
}
|
|
@ -1,6 +1,8 @@
|
|||
package org.apache.maven.tools.plugin.extractor;
|
||||
|
||||
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.util.DirectoryScanner;
|
||||
|
||||
|
@ -19,19 +21,19 @@ public abstract class AbstractScriptedMojoDescriptorExtractor
|
|||
extends AbstractLogEnabled
|
||||
implements MojoDescriptorExtractor
|
||||
{
|
||||
public Set execute( MavenProject project )
|
||||
throws Exception
|
||||
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException
|
||||
{
|
||||
Map scriptFilesKeyedByBasedir = gatherScriptSourcesByBasedir( project.getScriptSourceRoots(),
|
||||
getScriptFileExtension() );
|
||||
|
||||
Set mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir );
|
||||
Set mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir, pluginDescriptor );
|
||||
|
||||
return mojoDescriptors;
|
||||
}
|
||||
|
||||
protected abstract Set extractMojoDescriptors( Map scriptFilesKeyedByBasedir )
|
||||
throws Exception;
|
||||
protected abstract Set extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException;
|
||||
|
||||
protected abstract String getScriptFileExtension();
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.apache.maven.tools.plugin.extractor;
|
||||
|
||||
import org.apache.maven.tools.plugin.PluginToolsException;
|
||||
|
||||
/*
|
||||
* Copyright 2001-2004 The Apache Software Foundation.
|
||||
*
|
||||
|
@ -22,22 +24,13 @@ package org.apache.maven.tools.plugin.extractor;
|
|||
* jdcasey Exp $
|
||||
*/
|
||||
public class InvalidParameterException
|
||||
extends Exception
|
||||
extends PluginToolsException
|
||||
{
|
||||
public InvalidParameterException()
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidParameterException( String element, int i )
|
||||
{
|
||||
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 )
|
||||
{
|
||||
super( message, cause );
|
||||
|
|
|
@ -17,6 +17,8 @@ package org.apache.maven.tools.plugin.extractor;
|
|||
*/
|
||||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.tools.plugin.PluginToolsException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -25,10 +27,8 @@ import java.util.Set;
|
|||
*/
|
||||
public interface MojoDescriptorExtractor
|
||||
{
|
||||
|
||||
String ROLE = MojoDescriptorExtractor.class.getName();
|
||||
|
||||
Set execute( MavenProject project )
|
||||
throws Exception;
|
||||
|
||||
Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException;
|
||||
}
|
|
@ -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.JSourceWriter;
|
||||
import org.codehaus.modello.generator.java.javasource.JType;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -42,7 +44,8 @@ import java.util.Set;
|
|||
public class BeanGenerator
|
||||
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(); )
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
@ -95,7 +99,7 @@ public class BeanGenerator
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
||||
FileWriter writer = new FileWriter( destination );
|
||||
FileWriter writer = null;
|
||||
try
|
||||
{
|
||||
writer = new FileWriter( destination );
|
||||
|
||||
JSourceWriter sourceWriter = new JSourceWriter( writer );
|
||||
|
||||
jClass.print( sourceWriter );
|
||||
|
||||
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() );
|
||||
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -20,13 +16,17 @@ import java.util.Set;
|
|||
* 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>
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Generator
|
||||
{
|
||||
|
||||
void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project ) throws Exception;
|
||||
|
||||
void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
|
||||
throws IOException;
|
||||
}
|
|
@ -18,14 +18,17 @@ package org.apache.maven.tools.plugin.generator;
|
|||
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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.xml.PrettyPrintXMLWriter;
|
||||
import org.codehaus.plexus.util.xml.XMLWriter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -42,8 +45,9 @@ import java.util.Set;
|
|||
public class PluginDescriptorGenerator
|
||||
implements Generator
|
||||
{
|
||||
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project )
|
||||
throws Exception
|
||||
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project,
|
||||
String goalPrefix )
|
||||
throws IOException
|
||||
{
|
||||
File f = new File( destinationDirectory, "plugin.xml" );
|
||||
|
||||
|
@ -52,7 +56,10 @@ public class PluginDescriptorGenerator
|
|||
f.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
FileWriter writer = new FileWriter( f );
|
||||
FileWriter writer = null;
|
||||
try
|
||||
{
|
||||
writer = new FileWriter( f );
|
||||
|
||||
XMLWriter w = new PrettyPrintXMLWriter( writer );
|
||||
|
||||
|
@ -62,6 +69,8 @@ public class PluginDescriptorGenerator
|
|||
|
||||
element( w, "artifactId", project.getArtifactId() );
|
||||
|
||||
element( w, "goalPrefix", goalPrefix );
|
||||
|
||||
element( w, "isolatedRealm", "true" );
|
||||
|
||||
w.startElement( "mojos" );
|
||||
|
@ -79,12 +88,14 @@ public class PluginDescriptorGenerator
|
|||
w.endElement();
|
||||
|
||||
writer.flush();
|
||||
|
||||
writer.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( writer );
|
||||
}
|
||||
}
|
||||
|
||||
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
|
||||
throws Exception
|
||||
{
|
||||
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.writeText( mojoDescriptor.getGoal() );
|
||||
|
@ -200,8 +205,8 @@ public class PluginDescriptorGenerator
|
|||
|
||||
String expression = parameter.getExpression();
|
||||
|
||||
if ( StringUtils.isNotEmpty( expression )
|
||||
&& ( expression.startsWith( "${component." ) || expression.startsWith( "#component." ) ) )
|
||||
if ( StringUtils.isNotEmpty( expression ) &&
|
||||
( expression.startsWith( "${component." ) || expression.startsWith( "#component." ) ) )
|
||||
{
|
||||
// treat it as a component...a requirement, in other words.
|
||||
|
||||
|
@ -267,7 +272,7 @@ public class PluginDescriptorGenerator
|
|||
|
||||
w.startElement( parameter.getName() );
|
||||
|
||||
String type = convertType( parameter.getType() );
|
||||
String type = parameter.getType();
|
||||
if ( type != null )
|
||||
{
|
||||
w.addAttribute( "implementation", type );
|
||||
|
@ -323,35 +328,6 @@ public class PluginDescriptorGenerator
|
|||
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 )
|
||||
{
|
||||
w.startElement( name );
|
||||
|
|
|
@ -20,11 +20,13 @@ import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
|||
import org.apache.maven.plugin.descriptor.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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.XMLWriter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -38,8 +40,8 @@ import java.util.Set;
|
|||
public class PluginXdocGenerator
|
||||
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(); )
|
||||
{
|
||||
|
@ -49,12 +51,27 @@ public class PluginXdocGenerator
|
|||
}
|
||||
|
||||
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 );
|
||||
|
||||
w.startElement( "document" );
|
||||
|
@ -67,7 +84,7 @@ public class PluginXdocGenerator
|
|||
|
||||
w.startElement( "title" );
|
||||
|
||||
w.writeText( "Documentation for the " + mojoDescriptor.getId() + " plugin." );
|
||||
w.writeText( "Documentation for the " + id + " plugin." );
|
||||
|
||||
w.endElement();
|
||||
|
||||
|
@ -91,7 +108,7 @@ public class PluginXdocGenerator
|
|||
|
||||
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();
|
||||
|
||||
|
@ -133,14 +150,9 @@ public class PluginXdocGenerator
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
w.endElement();
|
||||
|
||||
writer.flush();
|
||||
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w )
|
||||
throws Exception
|
||||
{
|
||||
w.startElement( "p" );
|
||||
|
||||
|
|
|
@ -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.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.tools.plugin.generator.Generator;
|
||||
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.xml.PrettyPrintXMLWriter;
|
||||
import org.codehaus.plexus.util.xml.XMLWriter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -48,26 +49,56 @@ public class JellyHarnessGenerator
|
|||
return pluginDescriptor.getImplementation() + "Bean";
|
||||
}
|
||||
|
||||
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project )
|
||||
throws Exception
|
||||
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
|
||||
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.addAttribute( "xmlns:j", "jelly:core" );
|
||||
|
||||
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.addAttribute( "uri", pluginId );
|
||||
w.addAttribute( "uri", goalPrefix );
|
||||
|
||||
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
|
||||
{
|
||||
|
@ -100,23 +131,10 @@ public class JellyHarnessGenerator
|
|||
// ----------------------------------------------------------------------
|
||||
|
||||
w.endElement();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
writer.flush();
|
||||
|
||||
writer.close();
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// project.xml
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
writer = new FileWriter( new File( destinationDirectory, "project.xml" ) );
|
||||
|
||||
w = new PrettyPrintXMLWriter( writer );
|
||||
|
||||
private void writeProjectFile( PrettyPrintXMLWriter w, MavenProject project )
|
||||
{
|
||||
w.startElement( "project" );
|
||||
|
||||
w.startElement( "dependencies" );
|
||||
|
@ -126,18 +144,10 @@ public class JellyHarnessGenerator
|
|||
w.endElement();
|
||||
|
||||
w.endElement();
|
||||
|
||||
writer.flush();
|
||||
|
||||
writer.close();
|
||||
|
||||
}
|
||||
|
||||
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
|
||||
throws Exception
|
||||
{
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
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();
|
||||
|
||||
|
@ -216,18 +226,16 @@ public class JellyHarnessGenerator
|
|||
|
||||
private void writeGoals( MojoDescriptor mojoDescriptor, XMLWriter w )
|
||||
{
|
||||
String id = mojoDescriptor.getId();
|
||||
|
||||
w.startElement( "goal" );
|
||||
|
||||
w.addAttribute( "name", id + ":" + mojoDescriptor.getGoal() );
|
||||
w.addAttribute( "name", mojoDescriptor.getFullGoalName() );
|
||||
|
||||
if ( mojoDescriptor.getDescription() != null )
|
||||
{
|
||||
w.addAttribute( "description", mojoDescriptor.getDescription() );
|
||||
}
|
||||
|
||||
w.startElement( id + ":" + mojoDescriptor.getGoal() + "Bean" );
|
||||
w.startElement( mojoDescriptor.getFullGoalName() + "Bean" );
|
||||
|
||||
List goalParameters = mojoDescriptor.getParameters();
|
||||
|
||||
|
@ -245,11 +253,6 @@ public class JellyHarnessGenerator
|
|||
expression.substring( projectIndex + 7 );
|
||||
}
|
||||
|
||||
if ( expression.startsWith( "#" ) )
|
||||
{
|
||||
expression = "${" + expression.substring( 1 ) + "}";
|
||||
}
|
||||
|
||||
w.addAttribute( p.getName(), expression );
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@ package org.apache.maven.tools.plugin.scanner;
|
|||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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.Iterator;
|
||||
|
@ -42,8 +45,8 @@ public class DefaultMojoScanner
|
|||
{
|
||||
}
|
||||
|
||||
public Set execute( MavenProject project )
|
||||
throws Exception
|
||||
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException
|
||||
{
|
||||
Set descriptors = new HashSet();
|
||||
|
||||
|
@ -57,7 +60,7 @@ public class DefaultMojoScanner
|
|||
|
||||
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() +
|
||||
" mojo descriptors." );
|
||||
|
|
|
@ -17,6 +17,9 @@ package org.apache.maven.tools.plugin.scanner;
|
|||
*/
|
||||
|
||||
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;
|
||||
|
||||
|
@ -25,9 +28,9 @@ import java.util.Set;
|
|||
*/
|
||||
public interface MojoScanner
|
||||
{
|
||||
|
||||
String ROLE = MojoScanner.class.getName();
|
||||
|
||||
Set execute( MavenProject project ) throws Exception;
|
||||
Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException;
|
||||
|
||||
}
|
|
@ -60,7 +60,6 @@ public final class PluginUtils
|
|||
}
|
||||
|
||||
public static void writeDependencies( XMLWriter w, MavenProject project )
|
||||
throws Exception
|
||||
{
|
||||
|
||||
w.startElement( "dependencies" );
|
||||
|
|
|
@ -52,15 +52,10 @@ public abstract class AbstractGeneratorTestCase
|
|||
{
|
||||
setupGenerator();
|
||||
|
||||
String sourceDirectory = new File( basedir, "src/test/resources/source" ).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.setGoal( "testGoal" );
|
||||
mojoDescriptor.setId( "test" );
|
||||
mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" );
|
||||
mojoDescriptor.setRequiresDependencyResolution( "compile" );
|
||||
|
||||
|
@ -68,10 +63,10 @@ public abstract class AbstractGeneratorTestCase
|
|||
|
||||
Parameter param = new Parameter();
|
||||
param.setDefaultValue( "value" );
|
||||
param.setExpression( "#project.build.directory" );
|
||||
param.setExpression( "${project.build.directory}" );
|
||||
param.setName( "dir" );
|
||||
param.setRequired( true );
|
||||
param.setType( "String" );
|
||||
param.setType( "java.lang.String" );
|
||||
param.setDescription( "Test parameter description" );
|
||||
|
||||
params.add( param );
|
||||
|
@ -93,7 +88,7 @@ public abstract class AbstractGeneratorTestCase
|
|||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
generator.execute( destinationDirectory, descriptors, project );
|
||||
generator.execute( destinationDirectory, descriptors, project, "test" );
|
||||
|
||||
validate();
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class PluginDescriptorGeneratorTest
|
|||
|
||||
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() );
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class PluginDescriptorGeneratorTest
|
|||
private void checkParameter( Parameter parameter )
|
||||
{
|
||||
assertEquals( "dir", parameter.getName() );
|
||||
assertEquals( "String", parameter.getType() );
|
||||
assertEquals( String.class.getName(), parameter.getType() );
|
||||
assertTrue( parameter.isRequired() );
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import junit.framework.TestCase;
|
|||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -18,7 +19,8 @@ public class DefaultMojoScannerTest
|
|||
extends TestCase
|
||||
{
|
||||
|
||||
public void testShouldFindOneDescriptorFromTestExtractor() throws Exception
|
||||
public void testShouldFindOneDescriptorFromTestExtractor()
|
||||
throws Exception
|
||||
{
|
||||
Map extractors = Collections.singletonMap( "test", new TestExtractor() );
|
||||
|
||||
|
@ -33,12 +35,14 @@ public class DefaultMojoScannerTest
|
|||
MavenProject project = new MavenProject( model );
|
||||
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() );
|
||||
|
||||
MojoDescriptor desc = (MojoDescriptor) descriptors.iterator().next();
|
||||
assertEquals( "testPluginId", desc.getId() );
|
||||
assertEquals( pluginDescriptor, desc.getPluginDescriptor() );
|
||||
assertEquals( "testGoal", desc.getGoal() );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.apache.maven.tools.plugin.scanner;
|
||||
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
||||
|
||||
|
@ -14,11 +15,10 @@ public class TestExtractor
|
|||
implements MojoDescriptorExtractor
|
||||
{
|
||||
|
||||
public Set execute( MavenProject project )
|
||||
throws Exception
|
||||
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
MojoDescriptor desc = new MojoDescriptor();
|
||||
desc.setId( "testPluginId" );
|
||||
desc.setPluginDescriptor( pluginDescriptor );
|
||||
desc.setGoal( "testGoal" );
|
||||
|
||||
return Collections.singleton( desc );
|
||||
|
|
|
@ -24,7 +24,7 @@ public class PluginUtilsTest
|
|||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
String pluginId = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
|
||||
|
||||
assertEquals( "artifactId", pluginId );
|
||||
}
|
||||
|
|
|
@ -16,30 +16,30 @@ package org.apache.maven.tools.plugin.extractor.java;
|
|||
* 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.Parameter;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.tools.plugin.extractor.InvalidParameterException;
|
||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
||||
import org.apache.maven.tools.plugin.PluginToolsException;
|
||||
import org.codehaus.modello.StringUtils;
|
||||
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.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* @todo add example usage tag that can be shown in the doco
|
||||
|
@ -112,9 +112,10 @@ public class JavaMojoDescriptorExtractor
|
|||
// Mojo descriptor creation from @tags
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private MojoDescriptor createMojoDescriptor( JavaSource javaSource, MavenProject project )
|
||||
private MojoDescriptor createMojoDescriptor( JavaSource javaSource, PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
MojoDescriptor mojoDescriptor = new MojoDescriptor();
|
||||
mojoDescriptor.setPluginDescriptor( pluginDescriptor );
|
||||
|
||||
JavaClass javaClass = getJavaClass( javaSource );
|
||||
|
||||
|
@ -124,10 +125,6 @@ public class JavaMojoDescriptorExtractor
|
|||
|
||||
DocletTag tag;
|
||||
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
mojoDescriptor.setId( pluginId );
|
||||
|
||||
tag = findInClassHierarchy( javaClass, MAVEN_PLUGIN_DESCRIPTION );
|
||||
|
||||
if ( tag != null )
|
||||
|
@ -318,8 +315,8 @@ public class JavaMojoDescriptorExtractor
|
|||
return javaSource.getClasses()[0];
|
||||
}
|
||||
|
||||
public Set execute( MavenProject project )
|
||||
throws Exception
|
||||
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
throws InvalidParameterException
|
||||
{
|
||||
JavaDocBuilder builder = new JavaDocBuilder();
|
||||
|
||||
|
@ -346,7 +343,7 @@ public class JavaMojoDescriptorExtractor
|
|||
|
||||
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
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.maven.tools.plugin.extractor.java;
|
|||
import junit.framework.TestCase;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
@ -49,7 +50,9 @@ public class JavaMojoDescriptorExtractorTest
|
|||
project.setFile( new File( dir, "pom.xml" ) );
|
||||
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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -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.PluginDescriptor;
|
||||
import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives;
|
||||
import org.apache.maven.script.marmalade.tags.MojoTag;
|
||||
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.MarmaladeLaunchException;
|
||||
import org.codehaus.marmalade.model.MarmaladeScript;
|
||||
import org.codehaus.marmalade.model.MarmaladeTag;
|
||||
import org.codehaus.marmalade.runtime.DefaultContext;
|
||||
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
|
||||
import org.codehaus.marmalade.runtime.MarmaladeExecutionException;
|
||||
import org.codehaus.plexus.component.factory.marmalade.PlexusIntegratedLog;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -47,8 +52,8 @@ public class MarmaladeMojoDescriptorExtractor
|
|||
return ".mmld";
|
||||
}
|
||||
|
||||
protected Set extractMojoDescriptors( Map sourceFilesKeyedByBasedir )
|
||||
throws Exception
|
||||
protected Set extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
|
||||
throws PluginToolsException
|
||||
{
|
||||
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
|
||||
try
|
||||
|
@ -88,6 +93,7 @@ public class MarmaladeMojoDescriptorExtractor
|
|||
{
|
||||
Map contextMap = new TreeMap();
|
||||
contextMap.put( MarmaladeMojoExecutionDirectives.SCRIPT_BASEPATH_INVAR, basedir );
|
||||
contextMap.put( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, pluginDescriptor );
|
||||
|
||||
MarmaladeExecutionContext context = new DefaultContext( contextMap );
|
||||
|
||||
|
@ -110,6 +116,18 @@ public class MarmaladeMojoDescriptorExtractor
|
|||
|
||||
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
|
||||
{
|
||||
Thread.currentThread().setContextClassLoader( oldCl );
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.extractor.marmalade;
|
|||
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
||||
import org.codehaus.plexus.PlexusTestCase;
|
||||
|
@ -51,13 +52,15 @@ public class MarmaladeMojoDescriptorExtractorTest
|
|||
MarmaladeMojoDescriptorExtractor extractor = (MarmaladeMojoDescriptorExtractor) lookup(
|
||||
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() );
|
||||
|
||||
MojoDescriptor descriptor = (MojoDescriptor) descriptors.iterator().next();
|
||||
assertEquals( pluginDescriptor, descriptor.getPluginDescriptor() );
|
||||
assertEquals( "marmalade", descriptor.getLanguage() );
|
||||
assertEquals( "testId", descriptor.getId() );
|
||||
assertEquals( "testGoal", descriptor.getGoal() );
|
||||
assertEquals( 1, descriptor.getParameters().size() );
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
<mojo xmlns="marmalade:mojo">
|
||||
<metadata>
|
||||
<id>testId</id>
|
||||
<goal>testGoal</goal>
|
||||
<description>This is a test mojo</description>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>testParam</name>
|
||||
<default>TestValue</default>
|
||||
<expression>#pom.file</expression>
|
||||
<expression>${pom.file}</expression>
|
||||
<required>true</required>
|
||||
<description>This is a test parameter</description>
|
||||
</parameter>
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.pluggy;
|
|||
|
||||
import org.apache.maven.model.Model;
|
||||
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.tools.plugin.extractor.java.JavaMojoDescriptorExtractor;
|
||||
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.FileReader;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class Main
|
|||
{
|
||||
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 );
|
||||
}
|
||||
|
@ -59,12 +59,8 @@ public class Main
|
|||
|
||||
String pom = args[3];
|
||||
|
||||
String localRepo = args[4];
|
||||
|
||||
// Massage the local-repo path into an ArtifactRepository.
|
||||
File repoPath = new File( localRepo );
|
||||
|
||||
URL repoUrl = repoPath.toURL();
|
||||
|
||||
MavenXpp3Reader modelReader = new MavenXpp3Reader();
|
||||
FileReader reader = new FileReader( pom );
|
||||
|
@ -90,7 +86,10 @@ public class Main
|
|||
MojoScanner scanner = new DefaultMojoScanner(
|
||||
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.
|
||||
Generator generator = null;
|
||||
|
@ -114,6 +113,6 @@ public class Main
|
|||
|
||||
// Use the generator to process the discovered descriptors and produce
|
||||
// something with them.
|
||||
generator.execute( outputDirectory, descriptors, project );
|
||||
generator.execute( outputDirectory, descriptors, project, pluginDescriptor.getGoalPrefix() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,13 @@ package org.apache.maven.plugin.plugin;
|
|||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
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.PluginToolsException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -42,24 +46,45 @@ public abstract class AbstractGeneratorMojo
|
|||
*/
|
||||
protected MojoScanner mojoScanner;
|
||||
|
||||
/**
|
||||
* The goal prefix that will appear before the ":".
|
||||
*/
|
||||
protected String goalPrefix;
|
||||
|
||||
protected abstract String getOutputDirectory();
|
||||
|
||||
protected abstract void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project )
|
||||
throws Exception;
|
||||
protected abstract Generator createGenerator();
|
||||
|
||||
public void execute()
|
||||
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
|
||||
{
|
||||
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 generating plugin descriptor", e );
|
||||
throw new MojoExecutionException( "Error writing plugin descriptor", e );
|
||||
}
|
||||
catch ( PluginToolsException e )
|
||||
{
|
||||
throw new MojoExecutionException( "Error creatin plugin descriptor", e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.maven.plugin.plugin;
|
|||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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;
|
||||
|
||||
|
@ -25,7 +27,6 @@ import java.util.Set;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal bean
|
||||
* @description Goal for generating a plugin descriptor.
|
||||
*/
|
||||
public class BeanGeneratorMojo
|
||||
extends AbstractGeneratorMojo
|
||||
|
@ -41,11 +42,8 @@ public class BeanGeneratorMojo
|
|||
return outputDirectory;
|
||||
}
|
||||
|
||||
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project )
|
||||
throws Exception
|
||||
protected Generator createGenerator()
|
||||
{
|
||||
BeanGenerator generator = new BeanGenerator();
|
||||
|
||||
generator.execute( outputDirectory, mavenMojoDescriptors, project );
|
||||
return new BeanGenerator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.maven.plugin.plugin;
|
|||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
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;
|
||||
|
||||
|
@ -30,7 +32,6 @@ import java.util.Set;
|
|||
* @version $Id$
|
||||
* @goal descriptor
|
||||
* @phase process-classes
|
||||
* @description Goal for generating a plugin descriptor.
|
||||
*/
|
||||
public class DescriptorGeneratorMojo
|
||||
extends AbstractGeneratorMojo
|
||||
|
@ -46,12 +47,8 @@ public class DescriptorGeneratorMojo
|
|||
return outputDirectory;
|
||||
}
|
||||
|
||||
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project )
|
||||
throws Exception
|
||||
protected Generator createGenerator()
|
||||
{
|
||||
PluginDescriptorGenerator generator = new PluginDescriptorGenerator();
|
||||
|
||||
generator.execute( outputDirectory, mavenMojoDescriptors, project );
|
||||
|
||||
return new PluginDescriptorGenerator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package org.apache.maven.plugin.plugin;
|
|||
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.tools.plugin.generator.jelly.JellyHarnessGenerator;
|
||||
import org.apache.maven.tools.plugin.generator.Generator;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -25,7 +26,6 @@ import java.util.Set;
|
|||
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
* @version $Id$
|
||||
* @goal jelly
|
||||
* @description Goal for generating a plugin descriptor.
|
||||
*/
|
||||
public class JellyGeneratorMojo
|
||||
extends AbstractGeneratorMojo
|
||||
|
@ -41,11 +41,8 @@ public class JellyGeneratorMojo
|
|||
return outputDirectory;
|
||||
}
|
||||
|
||||
protected void generate( String outputDirectory, Set mavenMojoDescriptors, MavenProject project )
|
||||
throws Exception
|
||||
protected Generator createGenerator()
|
||||
{
|
||||
JellyHarnessGenerator generator = new JellyHarnessGenerator();
|
||||
|
||||
generator.execute( outputDirectory, mavenMojoDescriptors, project );
|
||||
return new JellyHarnessGenerator();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -704,7 +704,7 @@ public class MavenProject
|
|||
return distMgmtArtifactRepository;
|
||||
}
|
||||
|
||||
public Xpp3Dom getGoalConfiguration( String pluginId, String goalName )
|
||||
public Xpp3Dom getGoalConfiguration( String pluginGroupId, String pluginArtifactId, String goalId )
|
||||
{
|
||||
Xpp3Dom dom = null;
|
||||
|
||||
|
@ -720,17 +720,14 @@ public class MavenProject
|
|||
{
|
||||
Plugin plugin = (Plugin) iterator.next();
|
||||
|
||||
// TODO: groupID not handled
|
||||
if ( pluginId.equals( plugin.getArtifactId() ) )
|
||||
if ( pluginGroupId.equals( plugin.getGroupId() ) && pluginArtifactId.equals( plugin.getArtifactId() ) )
|
||||
{
|
||||
dom = (Xpp3Dom) plugin.getConfiguration();
|
||||
|
||||
if ( goalName != null )
|
||||
if ( goalId != null )
|
||||
{
|
||||
for ( Iterator j = plugin.getGoals().iterator(); j.hasNext(); )
|
||||
{
|
||||
Goal goal = (Goal) j.next();
|
||||
if ( goal.getId().equals( goalName ) )
|
||||
Goal goal = (Goal) plugin.getGoalsAsMap().get( goalId );
|
||||
if ( goal != null )
|
||||
{
|
||||
Xpp3Dom goalConfiguration = (Xpp3Dom) goal.getConfiguration();
|
||||
if ( goalConfiguration != null )
|
||||
|
@ -738,8 +735,6 @@ public class MavenProject
|
|||
Xpp3Dom newDom = new Xpp3Dom( goalConfiguration );
|
||||
dom = Xpp3Dom.mergeXpp3Dom( newDom, dom );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -30,6 +30,8 @@ public final class MarmaladeMojoExecutionDirectives
|
|||
|
||||
public static final String RESPONSE_INVAR = "response";
|
||||
|
||||
public static final String PLUGIN_DESCRIPTOR = "pluginDescriptor";
|
||||
|
||||
private MarmaladeMojoExecutionDirectives()
|
||||
{
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package org.apache.maven.script.marmalade.tags;
|
|||
*/
|
||||
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.script.marmalade.MarmaladeMojoExecutionDirectives;
|
||||
import org.codehaus.marmalade.model.AbstractMarmaladeTag;
|
||||
import org.codehaus.marmalade.runtime.MarmaladeExecutionContext;
|
||||
|
@ -34,9 +35,6 @@ public class MetadataTag
|
|||
extends AbstractMarmaladeTag
|
||||
implements DescriptionParent
|
||||
{
|
||||
|
||||
private String id;
|
||||
|
||||
private String goal;
|
||||
|
||||
private String requiresDependencyResolution = null;
|
||||
|
@ -76,10 +74,8 @@ public class MetadataTag
|
|||
descriptor.setComponentComposer( "map-oriented" );
|
||||
descriptor.setComponentConfigurator( "map-oriented" );
|
||||
|
||||
if ( notEmpty( id ) )
|
||||
{
|
||||
descriptor.setId( id );
|
||||
}
|
||||
descriptor.setPluginDescriptor(
|
||||
(PluginDescriptor) context.getVariable( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, null ) );
|
||||
|
||||
if ( notEmpty( goal ) )
|
||||
{
|
||||
|
@ -130,11 +126,6 @@ public class MetadataTag
|
|||
return test != null && test.trim().length() > 0;
|
||||
}
|
||||
|
||||
public void setId( String id )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setLifecyclePhase( String lifecyclePhase )
|
||||
{
|
||||
this.lifecyclePhase = lifecyclePhase;
|
||||
|
|
|
@ -31,7 +31,6 @@ public class MojoDefinitionTagLibrary
|
|||
registerTag( "execute", ExecuteTag.class );
|
||||
registerTag( "executionStrategy", ExecutionStrategyTag.class );
|
||||
registerTag( "goal", GoalTag.class );
|
||||
registerTag( "id", IdTag.class );
|
||||
registerTag( "instantiationStrategy", InstantiationStrategyTag.class );
|
||||
registerTag( "lifecyclePhase", LifecyclePhaseTag.class );
|
||||
registerTag( "metadata", MetadataTag.class );
|
||||
|
|
Loading…
Reference in New Issue