Final pass on cleaning up the mojo api...collapsed MavenPluginDescriptor and PluginDescriptor in the same way as MavenMojoDescriptor/MojoDescriptor had been; eliminated the need for plugin.descriptor.Dependency and MavenPluginDependency (using ComponentDependencies instead); adjusted the MojoExtractors (name?) to return Lists instead of Sets; added duplicate checking to a new addMojo(MojoDescriptor) method on PluginDescriptor, so we catch it on all sides; changed the Generators to use execute(outputDirectory, pluginDescriptor) rather than the myriad pluginDescriptor-derived values; added an IT for checking that the build for a plugin will fail if multiple mojos are detected with the same goal; and, added a special case to PluginDescriptor.getGoalPrefixFromArtifactId() to handle maven-plugin-plugin. That should be about it. I'm not sure that I've gotten the IT for that failure test added to svn yet, so that may follow.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@168481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-05-06 00:32:08 +00:00
parent 404a07b391
commit 5877385df1
33 changed files with 407 additions and 494 deletions

View File

@ -119,10 +119,9 @@ public class DefaultPluginManager
private Set pluginsInProcess = new HashSet();
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor )
public void processPluginDescriptor( PluginDescriptor pluginDescriptor )
throws CycleDetectedException
{
PluginDescriptor pluginDescriptor = mavenPluginDescriptor.getPluginDescriptor();
String key = pluginDescriptor.getId();
if ( pluginsInProcess.contains( key ) )
@ -132,7 +131,7 @@ public class DefaultPluginManager
pluginsInProcess.add( key );
for ( Iterator it = mavenPluginDescriptor.getMavenMojoDescriptors().iterator(); it.hasNext(); )
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor mojoDescriptor = (MojoDescriptor) it.next();
@ -150,12 +149,12 @@ public class DefaultPluginManager
{
ComponentSetDescriptor componentSetDescriptor = event.getComponentSetDescriptor();
if ( !( componentSetDescriptor instanceof MavenPluginDescriptor ) )
if ( !( componentSetDescriptor instanceof PluginDescriptor ) )
{
return;
}
MavenPluginDescriptor pluginDescriptor = (MavenPluginDescriptor) componentSetDescriptor;
PluginDescriptor pluginDescriptor = (PluginDescriptor) componentSetDescriptor;
try
{

View File

@ -1,40 +0,0 @@
package org.apache.maven.plugin;
/* ====================================================================
* Copyright 2001-2004 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import org.apache.maven.plugin.descriptor.Dependency;
import org.codehaus.plexus.component.repository.ComponentDependency;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenPluginDependency
extends ComponentDependency
{
public MavenPluginDependency( Dependency dependency )
{
setGroupId( dependency.getGroupId() );
setArtifactId( dependency.getArtifactId() );
setType( dependency.getType() );
setVersion( dependency.getVersion() );
}
}

View File

@ -1,60 +0,0 @@
package org.apache.maven.plugin;
/* ====================================================================
* Copyright 2001-2004 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class MavenPluginDescriptor
extends ComponentSetDescriptor
{
private PluginDescriptor pluginDescriptor;
private List mojoDescriptors;
public MavenPluginDescriptor( PluginDescriptor pluginDescriptor )
{
this.pluginDescriptor = pluginDescriptor;
}
// ----------------------------------------------------------------------
// Accessors
// ----------------------------------------------------------------------
public PluginDescriptor getPluginDescriptor()
{
return pluginDescriptor;
}
public List getMavenMojoDescriptors()
{
return super.getComponents();
}
public boolean isIsolatedRealm()
{
return pluginDescriptor.isIsolatedRealm();
}
}

View File

@ -17,18 +17,12 @@ package org.apache.maven.plugin;
* ====================================================================
*/
import org.apache.maven.plugin.descriptor.Dependency;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.codehaus.plexus.component.discovery.AbstractComponentDiscoverer;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -53,60 +47,6 @@ public class MavenPluginDiscoverer
public ComponentSetDescriptor createComponentDescriptors( Reader componentDescriptorConfiguration, String source )
throws PlexusConfigurationException
{
PluginDescriptor pluginDescriptor;
try
{
pluginDescriptor = builder.build( componentDescriptorConfiguration );
}
catch ( PlexusConfigurationException e )
{
// If the plugin is not valid, we cannot continue as it may make the lifecycle ebhave differently than expected
throw new PlexusConfigurationException( "Cannot process plugin descriptor: " + source, e );
}
// ----------------------------------------------------------------------
// We take the plugin descriptor as it has been built by the maven-plugin-descriptor
// code. This descriptor is specific to maven-plugin-descriptor and we are now
// going to adapt it into a ComponentSetDescriptor that can be
// utlized by Plexus.
// ----------------------------------------------------------------------
ComponentSetDescriptor componentSet = new MavenPluginDescriptor( pluginDescriptor );
// TODO: no group
componentSet.setId( pluginDescriptor.getArtifactId() );
// ----------------------------------------------------------------------
// If the ComponentSet states any dependencies then we want to collect
// them and store them for later use.
// ----------------------------------------------------------------------
if ( pluginDescriptor.getDependencies() != null )
{
List dependencies = new ArrayList();
for ( Iterator it = pluginDescriptor.getDependencies().iterator(); it.hasNext(); )
{
dependencies.add( new MavenPluginDependency( (Dependency) it.next() ) );
}
componentSet.setDependencies( dependencies );
}
// ----------------------------------------------------------------------
// Process each of the component descriptors within the ComponentSet.
// ----------------------------------------------------------------------
List componentDescriptors = new ArrayList();
for ( Iterator iterator = pluginDescriptor.getMojos().iterator(); iterator.hasNext(); )
{
componentDescriptors.add( (MojoDescriptor) iterator.next() );
}
componentSet.setComponents( componentDescriptors );
return componentSet;
return builder.build( componentDescriptorConfiguration );
}
}

View File

@ -1,60 +0,0 @@
package org.apache.maven.plugin.descriptor;
/*
* LICENSE
*/
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public class Dependency
{
private String groupId;
private String artifactId;
private String type;
private String version;
public String getGroupId()
{
return groupId;
}
public void setGroupId( String groupId )
{
this.groupId = groupId;
}
public String getArtifactId()
{
return artifactId;
}
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
}
public String getType()
{
return type;
}
public void setType( String type )
{
this.type = type;
}
public String getVersion()
{
return version;
}
public void setVersion( String version )
{
this.version = version;
}
}

View File

@ -0,0 +1,28 @@
package org.apache.maven.plugin.descriptor;
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class DuplicateMojoDescriptorException
extends PluginConfigurationException
{
public DuplicateMojoDescriptorException( String goalPrefix, String goal, String existingImplementation, String newImplementation )
{
super( "Goal: " + goal + " already exists in the plugin descriptor for prefix: " + goalPrefix + "\nExisting implementation is: " + existingImplementation + "\nConflicting implementation is: " + newImplementation );
}
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.plugin.descriptor;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class PluginConfigurationException
extends PlexusConfigurationException
{
public PluginConfigurationException( String message, Throwable cause )
{
super( message, cause );
}
public PluginConfigurationException( String message )
{
super( message );
}
}

View File

@ -16,7 +16,9 @@ package org.apache.maven.plugin.descriptor;
* limitations under the License.
*/
import java.util.LinkedList;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import java.util.Iterator;
import java.util.List;
/**
@ -24,9 +26,8 @@ import java.util.List;
* @version $Id$
*/
public class PluginDescriptor
extends ComponentSetDescriptor
{
private List mojos;
private String groupId;
private String artifactId;
@ -43,12 +44,41 @@ public class PluginDescriptor
public List getMojos()
{
return mojos;
return getComponents();
}
public void setMojos( List mojos )
throws DuplicateMojoDescriptorException
{
this.mojos = new LinkedList( mojos );
for ( Iterator it = mojos.iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
addMojo( descriptor );
}
}
public void addMojo( MojoDescriptor mojoDescriptor )
throws DuplicateMojoDescriptorException
{
// this relies heavily on the equals() and hashCode() for ComponentDescriptor,
// which uses role:roleHint for identity...and roleHint == goalPrefix:goal.
// role does not vary for Mojos.
List mojos = getComponents();
if ( mojos != null && mojos.contains( mojoDescriptor ) )
{
int indexOf = mojos.indexOf( mojoDescriptor );
MojoDescriptor existing = (MojoDescriptor) mojos.get( indexOf );
throw new DuplicateMojoDescriptorException( getGoalPrefix(), mojoDescriptor.getGoal(), existing
.getImplementation(), mojoDescriptor.getImplementation() );
}
else
{
addComponentDescriptor( mojoDescriptor );
}
}
public String getGroupId()
@ -69,22 +99,14 @@ public class PluginDescriptor
public void setArtifactId( String artifactId )
{
this.artifactId = artifactId;
setId( artifactId );
}
// ----------------------------------------------------------------------
// Dependencies
// ----------------------------------------------------------------------
public List getDependencies()
{
return dependencies;
}
public void setDependencies( List dependencies )
{
this.dependencies = new LinkedList( dependencies );
}
public boolean isIsolatedRealm()
{
return isolatedRealm;
@ -136,9 +158,16 @@ public class PluginDescriptor
* @todo remove - harcoding. What about clashes?
*/
public static String getGoalPrefixFromArtifactId( String artifactId )
{
if ( "maven-plugin-plugin".equals( artifactId ) )
{
return "plugin";
}
else
{
return artifactId.replaceAll( "-?maven-?", "" ).replaceAll( "-?plugin-?", "" );
}
}
/**
* @todo remove - harcoding. What about clashes?

View File

@ -1,5 +1,6 @@
package org.apache.maven.plugin.descriptor;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
@ -35,16 +36,14 @@ public class PluginDescriptorBuilder
PlexusConfiguration[] mojoConfigurations = c.getChild( "mojos" ).getChildren( "mojo" );
List mojos = new ArrayList();
for ( int i = 0; i < mojoConfigurations.length; i++ )
{
PlexusConfiguration component = mojoConfigurations[i];
mojos.add( buildComponentDescriptor( component, pluginDescriptor ) );
}
MojoDescriptor mojoDescriptor = buildComponentDescriptor( component, pluginDescriptor );
pluginDescriptor.setMojos( mojos );
pluginDescriptor.addMojo( mojoDescriptor );
}
// ----------------------------------------------------------------------
// Dependencies
@ -58,7 +57,7 @@ public class PluginDescriptorBuilder
{
PlexusConfiguration d = dependencyConfigurations[i];
Dependency cd = new Dependency();
ComponentDependency cd = new ComponentDependency();
cd.setArtifactId( d.getChild( "artifactId" ).getValue() );

View File

@ -21,18 +21,18 @@ public abstract class AbstractScriptedMojoDescriptorExtractor
extends AbstractLogEnabled
implements MojoDescriptorExtractor
{
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws PluginToolsException
{
Map scriptFilesKeyedByBasedir = gatherScriptSourcesByBasedir( project.getScriptSourceRoots(),
getScriptFileExtension() );
Set mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir, pluginDescriptor );
List mojoDescriptors = extractMojoDescriptors( scriptFilesKeyedByBasedir, pluginDescriptor );
return mojoDescriptors;
}
protected abstract Set extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
protected abstract List extractMojoDescriptors( Map scriptFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
throws PluginToolsException;
protected abstract String getScriptFileExtension();

View File

@ -16,11 +16,11 @@ package org.apache.maven.tools.plugin.extractor;
* limitations under the License.
*/
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.PluginToolsException;
import java.util.Set;
import java.util.List;
/**
* @author jdcasey
@ -29,6 +29,6 @@ public interface MojoDescriptorExtractor
{
String ROLE = MojoDescriptorExtractor.class.getName();
Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
List execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws PluginToolsException;
}

View File

@ -18,7 +18,7 @@ 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.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.modello.generator.java.javasource.JClass;
import org.codehaus.modello.generator.java.javasource.JConstructor;
import org.codehaus.modello.generator.java.javasource.JMethod;
@ -32,7 +32,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* [JC] Is this class defunct now? I can't find o.a.m.plugin.BeanPluginAdapter in the codebase...
@ -44,10 +43,10 @@ import java.util.Set;
public class BeanGenerator
implements Generator
{
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
public void execute( String destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
processPluginDescriptor( descriptor, destinationDirectory );

View File

@ -16,9 +16,8 @@ package org.apache.maven.tools.plugin.generator;
* limitations under the License.
*/
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import java.util.Set;
import java.io.IOException;
/**
@ -27,6 +26,6 @@ import java.io.IOException;
*/
public interface Generator
{
void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
void execute( String destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException;
}

View File

@ -19,7 +19,6 @@ 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;
@ -35,7 +34,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @todo add example usage tag that can be shown in the doco
@ -45,8 +43,7 @@ import java.util.Set;
public class PluginDescriptorGenerator
implements Generator
{
public void execute( String destinationDirectory, Set mavenMojoDescriptors, MavenProject project,
String goalPrefix )
public void execute( String destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
File f = new File( destinationDirectory, "plugin.xml" );
@ -65,23 +62,23 @@ public class PluginDescriptorGenerator
w.startElement( "plugin" );
element( w, "groupId", project.getGroupId() );
element( w, "groupId", pluginDescriptor.getGroupId() );
element( w, "artifactId", project.getArtifactId() );
element( w, "artifactId", pluginDescriptor.getArtifactId() );
element( w, "goalPrefix", goalPrefix );
element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );
w.startElement( "mojos" );
for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); )
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
processPluginDescriptor( descriptor, w, project );
processMojoDescriptor( descriptor, w );
}
w.endElement();
PluginUtils.writeDependencies( w, project );
PluginUtils.writeDependencies( w, pluginDescriptor );
w.endElement();
@ -93,7 +90,7 @@ public class PluginDescriptorGenerator
}
}
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w )
{
w.startElement( "mojo" );
@ -221,7 +218,11 @@ public class PluginDescriptorGenerator
w.startElement( "parameters" );
Collection requirements = new ArrayList();
Map configuration = new HashMap( parameters.size() );
Map configuration = new HashMap();
if( parameters != null )
{
for ( int j = 0; j < parameters.size(); j++ )
{
Parameter parameter = (Parameter) parameters.get( j );
@ -272,6 +273,7 @@ public class PluginDescriptorGenerator
}
}
}
w.endElement();

View File

@ -18,9 +18,9 @@ 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.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
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;
@ -30,7 +30,6 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @todo add example usage tag that can be shown in the doco
@ -40,10 +39,10 @@ import java.util.Set;
public class PluginXdocGenerator
implements Generator
{
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
public void execute( String destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
for ( Iterator it = mojoDescriptors.iterator(); it.hasNext(); )
for ( Iterator it = pluginDescriptor.getMojos().iterator(); it.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) it.next();
processPluginDescriptor( descriptor, destinationDirectory );

View File

@ -18,6 +18,7 @@ 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;
@ -49,7 +50,7 @@ public class JellyHarnessGenerator
return pluginDescriptor.getImplementation() + "Bean";
}
public void execute( String destinationDirectory, Set mojoDescriptors, MavenProject project, String goalPrefix )
public void execute( String destinationDirectory, PluginDescriptor pluginDescriptor )
throws IOException
{
FileWriter writer = null;
@ -60,7 +61,7 @@ public class JellyHarnessGenerator
w = new PrettyPrintXMLWriter( writer );
writePluginFile( w, goalPrefix, mojoDescriptors, project );
writeProjectFile( w, pluginDescriptor );
writer.flush();
}
@ -80,7 +81,7 @@ public class JellyHarnessGenerator
w = new PrettyPrintXMLWriter( writer );
writeProjectFile( w, project );
writeProjectFile( w, pluginDescriptor );
writer.flush();
}
@ -133,13 +134,13 @@ public class JellyHarnessGenerator
w.endElement();
}
private void writeProjectFile( PrettyPrintXMLWriter w, MavenProject project )
private void writeProjectFile( PrettyPrintXMLWriter w, PluginDescriptor pluginDescriptor )
{
w.startElement( "project" );
w.startElement( "dependencies" );
PluginUtils.writeDependencies( w, project );
PluginUtils.writeDependencies( w, pluginDescriptor );
w.endElement();

View File

@ -16,21 +16,25 @@ package org.apache.maven.tools.plugin.scanner;
* limitations under the License.
*/
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.DuplicateMojoDescriptorException;
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.PluginToolsException;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author jdcasey
*/
public class DefaultMojoScanner
extends AbstractLogEnabled
implements MojoScanner
{
@ -39,18 +43,20 @@ public class DefaultMojoScanner
public DefaultMojoScanner( Map extractors )
{
this.mojoDescriptorExtractors = extractors;
this.enableLogging( new ConsoleLogger( Logger.LEVEL_INFO, "standalone-scanner-logger" ) );
}
public DefaultMojoScanner()
{
}
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
public void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor )
throws PluginToolsException
{
Set descriptors = new HashSet();
Logger logger = getLogger();
System.out.println( "Using " + mojoDescriptorExtractors.size() + " extractors." );
logger.debug( "Using " + mojoDescriptorExtractors.size() + " extractors." );
for ( Iterator it = mojoDescriptorExtractors.entrySet().iterator(); it.hasNext(); )
{
@ -58,17 +64,32 @@ public class DefaultMojoScanner
String language = (String) entry.getKey();
MojoDescriptorExtractor extractor = (MojoDescriptorExtractor) entry.getValue();
System.out.println( "Applying extractor for language: " + language );
logger.debug( "Applying extractor for language: " + language );
Set extractorDescriptors = extractor.execute( project, pluginDescriptor );
List extractorDescriptors = extractor.execute( project, pluginDescriptor );
System.out.println( "Extractor for language: " + language + " found " + extractorDescriptors.size() +
" mojo descriptors." );
logger.debug( "Extractor for language: " + language + " found " + extractorDescriptors.size()
+ " mojo descriptors." );
descriptors.addAll( extractorDescriptors );
for ( Iterator descriptorIt = extractorDescriptors.iterator(); descriptorIt.hasNext(); )
{
MojoDescriptor descriptor = (MojoDescriptor) descriptorIt.next();
logger.debug( "Adding mojo: " + descriptor + " to plugin descriptor." );
descriptor.setPluginDescriptor( pluginDescriptor );
try
{
pluginDescriptor.addMojo( descriptor );
}
catch ( DuplicateMojoDescriptorException e )
{
throw new PluginToolsException( "Duplicate goal specification detected.\nError was: "
+ e.getLocalizedMessage(), e );
}
}
}
return descriptors;
}
}

View File

@ -16,13 +16,10 @@ package org.apache.maven.tools.plugin.scanner;
* limitations under the License.
*/
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.project.MavenProject;
import org.apache.maven.tools.plugin.PluginToolsException;
import java.util.Set;
/**
* @author jdcasey
*/
@ -30,7 +27,7 @@ public interface MojoScanner
{
String ROLE = MojoScanner.class.getName();
Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
void populatePluginDescriptor( MavenProject project, PluginDescriptor pluginDescriptor )
throws PluginToolsException;
}

View File

@ -16,14 +16,16 @@ package org.apache.maven.tools.plugin.util;
* limitations under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/**
* @author jdcasey
@ -60,17 +62,15 @@ public final class PluginUtils
return scanner.getIncludedFiles();
}
public static void writeDependencies( XMLWriter w, MavenProject project )
public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
{
w.startElement( "dependencies" );
for ( Iterator it = project.getDependencies().iterator(); it.hasNext(); )
for ( Iterator it = pluginDescriptor.getDependencies().iterator(); it.hasNext(); )
{
Dependency dep = (Dependency) it.next();
ComponentDependency dep = (ComponentDependency) it.next();
if ( !Artifact.SCOPE_TEST.equals( dep.getScope() ) )
{
w.startElement( "dependency" );
PluginUtils.element( w, "groupId", dep.getGroupId() );
@ -83,11 +83,31 @@ public final class PluginUtils
w.endElement();
}
}
w.endElement();
}
public static List toComponentDependencies(List dependencies)
{
List componentDeps = new LinkedList();
for ( Iterator it = dependencies.iterator(); it.hasNext(); )
{
Dependency dependency = (Dependency) it.next();
ComponentDependency cd = new ComponentDependency();
cd.setArtifactId( dependency.getArtifactId() );
cd.setGroupId( dependency.getGroupId() );
cd.setVersion( dependency.getVersion() );
cd.setType( dependency.getType() );
componentDeps.add( cd );
}
return componentDeps;
}
private static void element( XMLWriter w, String name, String value )
{
w.startElement( name );

View File

@ -16,12 +16,10 @@ package org.apache.maven.tools.plugin.generator;
* limitations under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.repository.ComponentDependency;
import java.io.File;
import java.util.ArrayList;
@ -29,6 +27,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import junit.framework.TestCase;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: AbstractGeneratorTestCase.java,v 1.1 2005/02/20 16:25:21
@ -52,8 +52,6 @@ public abstract class AbstractGeneratorTestCase
{
setupGenerator();
String destinationDirectory = new File( basedir, "target" ).getPath();
MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setGoal( "testGoal" );
mojoDescriptor.setImplementation( "org.apache.maven.tools.plugin.generator.TestMojo" );
@ -75,22 +73,26 @@ public abstract class AbstractGeneratorTestCase
Set descriptors = Collections.singleton( mojoDescriptor );
Model model = new Model();
PluginDescriptor pluginDescriptor = new PluginDescriptor();
model.setArtifactId( "maven-unitTesting-plugin" );
pluginDescriptor.addMojo(mojoDescriptor);
Dependency dependency = new Dependency();
pluginDescriptor.setArtifactId( "maven-unitTesting-plugin" );
pluginDescriptor.setGoalPrefix( "test" );
ComponentDependency dependency = new ComponentDependency();
dependency.setGroupId( "testGroup" );
dependency.setArtifactId( "testArtifact" );
dependency.setVersion( "0.0.0" );
model.addDependency( dependency );
pluginDescriptor.setDependencies( Collections.singletonList( dependency ) );
MavenProject project = new MavenProject( model );
File tempFile = File.createTempFile( "testGenerator-outDir", ".marker.txt" ).getAbsoluteFile();
File destinationDirectory = tempFile.getParentFile();
generator.execute( destinationDirectory, descriptors, project, "test" );
generator.execute( destinationDirectory.getAbsolutePath(), pluginDescriptor );
validate();
validate(destinationDirectory);
}
// ----------------------------------------------------------------------
@ -122,7 +124,7 @@ public abstract class AbstractGeneratorTestCase
//
// ----------------------------------------------------------------------
protected void validate()
protected void validate(File destinationDirectory)
throws Exception
{
// empty

View File

@ -16,11 +16,11 @@ package org.apache.maven.tools.plugin.generator;
* limitations under the License.
*/
import org.apache.maven.plugin.descriptor.Dependency;
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.plugin.descriptor.PluginDescriptorBuilder;
import org.codehaus.plexus.component.repository.ComponentDependency;
import java.io.BufferedReader;
import java.io.File;
@ -39,17 +39,19 @@ import java.util.List;
public class PluginDescriptorGeneratorTest
extends AbstractGeneratorTestCase
{
protected void validate()
protected void validate(File destinationDirectory)
throws Exception
{
PluginDescriptorBuilder pdb = new PluginDescriptorBuilder();
File pluginDescriptorFile = new File( basedir, "target/plugin.xml" );
File pluginDescriptorFile = new File( destinationDirectory, "plugin.xml" );
String pd = readFile( pluginDescriptorFile );
PluginDescriptor pluginDescriptor = pdb.build( new StringReader( pd ) );
assertEquals( 1, pluginDescriptor.getMojos().size() );
MojoDescriptor mojoDescriptor = (MojoDescriptor) pluginDescriptor.getMojos().get( 0 );
checkMojo( mojoDescriptor );
@ -60,11 +62,11 @@ public class PluginDescriptorGeneratorTest
List dependencies = pluginDescriptor.getDependencies();
checkDependency( "testGroup", "testArtifact", "0.0.0", (Dependency) dependencies.get( 0 ) );
checkDependency( "testGroup", "testArtifact", "0.0.0", (ComponentDependency) dependencies.get( 0 ) );
assertEquals( 1, dependencies.size() );
Dependency dependency = (Dependency) dependencies.get( 0 );
ComponentDependency dependency = (ComponentDependency) dependencies.get( 0 );
assertEquals( "testGroup", dependency.getGroupId() );
assertEquals( "testArtifact", dependency.getArtifactId() );
assertEquals( "0.0.0", dependency.getVersion() );
@ -111,7 +113,7 @@ public class PluginDescriptorGeneratorTest
assertTrue( parameter.isRequired() );
}
private void checkDependency( String groupId, String artifactId, String version, Dependency dependency )
private void checkDependency( String groupId, String artifactId, String version, ComponentDependency dependency )
{
assertNotNull( dependency );

View File

@ -1,6 +1,5 @@
package org.apache.maven.tools.plugin.scanner;
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -9,8 +8,10 @@ import org.apache.maven.project.MavenProject;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
/**
* @author jdcasey
@ -37,7 +38,10 @@ public class DefaultMojoScannerTest
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "testId" );
Set descriptors = scanner.execute( project, pluginDescriptor );
scanner.populatePluginDescriptor( project, pluginDescriptor );
List descriptors = pluginDescriptor.getMojos();
assertEquals( 1, descriptors.size() );

View File

@ -6,7 +6,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
import java.util.Collections;
import java.util.Set;
import java.util.List;
/**
* @author jdcasey
@ -15,13 +15,13 @@ public class TestExtractor
implements MojoDescriptorExtractor
{
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
{
MojoDescriptor desc = new MojoDescriptor();
desc.setPluginDescriptor( pluginDescriptor );
desc.setGoal( "testGoal" );
return Collections.singleton( desc );
return Collections.singletonList( desc );
}
}

View File

@ -1,14 +1,14 @@
package org.apache.maven.tools.plugin.util;
import junit.framework.TestCase;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.xml.CompactXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.StringWriter;
import java.util.Collections;
import junit.framework.TestCase;
/**
* @author jdcasey
@ -24,26 +24,25 @@ public class PluginUtilsTest
assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-maven-plugin" ) );
assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId" ) );
assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-plugin" ) );
assertEquals( "plugin", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-plugin" ) );
}
public void testShouldWriteDependencies()
throws Exception
{
Dependency dependency = new Dependency();
ComponentDependency dependency = new ComponentDependency();
dependency.setArtifactId( "testArtifactId" );
dependency.setGroupId( "testGroupId" );
dependency.setType( "pom" );
dependency.setVersion( "0.0.0" );
Model model = new Model();
model.addDependency( dependency );
MavenProject project = new MavenProject( model );
PluginDescriptor descriptor = new PluginDescriptor();
descriptor.setDependencies( Collections.singletonList( dependency ) );
StringWriter sWriter = new StringWriter();
XMLWriter writer = new CompactXMLWriter( sWriter );
PluginUtils.writeDependencies( writer, project );
PluginUtils.writeDependencies( writer, descriptor );
String output = sWriter.toString();

View File

@ -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
@ -328,17 +328,13 @@ public class JavaMojoDescriptorExtractor
return javaSource.getClasses()[0];
}
public Set execute( MavenProject project, PluginDescriptor pluginDescriptor )
public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws InvalidParameterException
{
JavaDocBuilder builder = new JavaDocBuilder();
File basedir = project.getBasedir();
System.out.println( "Project basedir: " + basedir );
System.out.println( "Source directory for java mojo extraction: " + project.getCompileSourceRoots() );
for ( Iterator i = project.getCompileSourceRoots().iterator(); i.hasNext(); )
{
builder.addSourceTree( new File( (String) i.next() ) );
@ -346,7 +342,7 @@ public class JavaMojoDescriptorExtractor
JavaSource[] javaSources = builder.getSources();
Set descriptors = new HashSet();
List descriptors = new ArrayList();
for ( int i = 0; i < javaSources.length; i++ )
{
@ -365,10 +361,13 @@ public class JavaMojoDescriptorExtractor
List parameters = mojoDescriptor.getParameters();
if ( parameters != null )
{
for ( int j = 0; j < parameters.size(); j++ )
{
validateParameter( (Parameter) parameters.get( j ), j );
}
}
// Commented because it causes a VerifyError:
// java.lang.VerifyError:

View File

@ -23,7 +23,7 @@ import org.apache.maven.plugin.descriptor.PluginDescriptor;
import java.io.File;
import java.net.URL;
import java.util.Set;
import java.util.List;
/**
* @author jdcasey
@ -52,7 +52,7 @@ public class JavaMojoDescriptorExtractorTest
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "test" );
Set results = extractor.execute( project, pluginDescriptor );
List results = extractor.execute( project, pluginDescriptor );
assertEquals( 2, results.size() );
}

View File

@ -20,25 +20,22 @@ 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.apache.maven.tools.plugin.extractor.AbstractScriptedMojoDescriptorExtractor;
import org.codehaus.marmalade.launch.MarmaladeLaunchException;
import org.codehaus.marmalade.launch.MarmaladeLauncher;
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.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
/**
* @author jdcasey
@ -52,7 +49,7 @@ public class MarmaladeMojoDescriptorExtractor
return ".mmld";
}
protected Set extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
protected List extractMojoDescriptors( Map sourceFilesKeyedByBasedir, PluginDescriptor pluginDescriptor )
throws PluginToolsException
{
ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
@ -60,7 +57,7 @@ public class MarmaladeMojoDescriptorExtractor
{
Thread.currentThread().setContextClassLoader( MarmaladeMojoDescriptorExtractor.class.getClassLoader() );
Set descriptors = new HashSet();
List descriptors = new ArrayList();
for ( Iterator mapIterator = sourceFilesKeyedByBasedir.entrySet().iterator(); mapIterator.hasNext(); )
{
@ -73,6 +70,8 @@ public class MarmaladeMojoDescriptorExtractor
{
File scriptFile = (File) it.next();
try
{
MarmaladeLauncher launcher = new MarmaladeLauncher().withInputFile( scriptFile );
Logger logger = getLogger();
@ -91,15 +90,11 @@ public class MarmaladeMojoDescriptorExtractor
MarmaladeTag rootTag = script.getRoot();
if ( rootTag instanceof MojoTag )
{
Map contextMap = new TreeMap();
contextMap.put( MarmaladeMojoExecutionDirectives.SCRIPT_BASEPATH_INVAR, basedir );
contextMap.put( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, pluginDescriptor );
launcher.withVariable( MarmaladeMojoExecutionDirectives.SCRIPT_BASEPATH_INVAR, basedir );
launcher
.withVariable( MarmaladeMojoExecutionDirectives.PLUGIN_DESCRIPTOR, pluginDescriptor );
MarmaladeExecutionContext context = new DefaultContext( contextMap );
script.execute( context );
contextMap = context.getExternalizedVariables();
Map contextMap = launcher.run();
MojoDescriptor descriptor = (MojoDescriptor) contextMap
.get( MarmaladeMojoExecutionDirectives.METADATA_OUTVAR );
@ -108,26 +103,26 @@ public class MarmaladeMojoDescriptorExtractor
}
else
{
System.out.println( "This script is not a mojo. Its root tag is {element: "
+ rootTag.getTagInfo().getElement() + ", class: " + rootTag.getClass().getName() + "}" );
getLogger().debug(
"Found non-mojo marmalade script at: " + scriptFile
+ ".\nIts root tag is {element: "
+ rootTag.getTagInfo().getElement() + ", class: "
+ rootTag.getClass().getName() + "}" );
}
}
catch ( IOException e )
{
throw new PluginToolsException( "Error reading descriptor Marmalade mojo in: " + scriptFile, e );
}
catch ( MarmaladeLaunchException e )
{
throw new PluginToolsException( "Error extracting descriptor Marmalade mojo from: " + scriptFile, e );
}
}
}
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 );

View File

@ -25,7 +25,7 @@ import org.codehaus.plexus.PlexusTestCase;
import java.io.File;
import java.net.URL;
import java.util.Set;
import java.util.List;
/**
* @author jdcasey
@ -54,7 +54,7 @@ public class MarmaladeMojoDescriptorExtractorTest
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGoalPrefix( "test" );
Set descriptors = extractor.execute( project, pluginDescriptor );
List descriptors = extractor.execute( project, pluginDescriptor );
assertEquals( 1, descriptors.size() );

View File

@ -28,11 +28,11 @@ import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
import org.apache.maven.tools.plugin.generator.jelly.JellyHarnessGenerator;
import org.apache.maven.tools.plugin.scanner.DefaultMojoScanner;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.util.PluginUtils;
import java.io.File;
import java.io.FileReader;
import java.util.Collections;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -87,9 +87,17 @@ public class Main
Collections.singletonMap( "java", new JavaMojoDescriptorExtractor() ) );
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGroupId(project.getGroupId());
pluginDescriptor.setArtifactId(project.getArtifactId());
// TODO: should read this from the pom...
pluginDescriptor.setGoalPrefix( PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ) );
Set descriptors = scanner.execute( project, pluginDescriptor );
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getDependencies() ) );
scanner.populatePluginDescriptor( project, pluginDescriptor );
// Create the generator.
Generator generator = null;
@ -113,6 +121,6 @@ public class Main
// Use the generator to process the discovered descriptors and produce
// something with them.
generator.execute( outputDirectory, descriptors, project, pluginDescriptor.getGoalPrefix() );
generator.execute( outputDirectory, pluginDescriptor );
}
}

View File

@ -20,12 +20,12 @@ 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.PluginToolsException;
import org.apache.maven.tools.plugin.generator.Generator;
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.apache.maven.tools.plugin.PluginToolsException;
import org.apache.maven.tools.plugin.util.PluginUtils;
import java.io.IOException;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -70,13 +70,20 @@ public abstract class AbstractGeneratorMojo
// TODO: could use this more, eg in the writing of the plugin descriptor!
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGroupId( project.getGroupId() );
pluginDescriptor.setArtifactId( project.getArtifactId() );
pluginDescriptor.setGoalPrefix( goalPrefix );
try
{
Set mavenMojoDescriptors = mojoScanner.execute( project, pluginDescriptor );
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
createGenerator().execute( getOutputDirectory(), mavenMojoDescriptors, project, goalPrefix );
mojoScanner.populatePluginDescriptor( project, pluginDescriptor );
createGenerator().execute( getOutputDirectory(), pluginDescriptor );
}
catch ( IOException e )
{

View File

@ -16,13 +16,9 @@ package org.apache.maven.plugin.plugin;
* limitations under the License.
*/
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;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$

View File

@ -16,12 +16,8 @@ package org.apache.maven.plugin.plugin;
* limitations under the License.
*/
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;
import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator;
/**
* Generate a plugin descriptor.

View File

@ -16,11 +16,8 @@ package org.apache.maven.plugin.plugin;
* limitations under the License.
*/
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;
import org.apache.maven.tools.plugin.generator.jelly.JellyHarnessGenerator;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>