diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
index 4e98d6aed2..580b59b145 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
@@ -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() );
}
}
}
diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
index 3b0ede69d0..655a519fd8 100644
--- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
+++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
@@ -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 );
diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo
index 3317adbe68..13efe620b9 100644
--- a/maven-model/maven.mdo
+++ b/maven-model/maven.mdo
@@ -2004,10 +2004,13 @@
if ( goalMap == null )
{
goalMap = new HashMap();
- for ( Iterator i = goals.iterator(); i.hasNext(); )
+ if ( goals != null )
{
- Goal g = (Goal) i.next();
- goalMap.put( g.getId(), g );
+ for ( Iterator i = goals.iterator(); i.hasNext(); )
+ {
+ Goal g = (Goal) i.next();
+ goalMap.put( g.getId(), g );
+ }
}
}
return goalMap;
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
index 7404ee38fe..e87cb8bc1d 100755
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/MojoDescriptor.java
@@ -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;
+ }
}
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
index 97ba67c14e..b8cad537b0 100644
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptor.java
@@ -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;
+ }
}
diff --git a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
index ff94e5af5b..02189811ee 100755
--- a/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
+++ b/maven-plugin-descriptor/src/main/java/org/apache/maven/plugin/descriptor/PluginDescriptorBuilder.java
@@ -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.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() );
diff --git a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/IdTag.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java
similarity index 55%
rename from maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/IdTag.java
rename to maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java
index 1e85e38a26..c39fc55ced 100644
--- a/maven-script/maven-script-marmalade/src/main/java/org/apache/maven/script/marmalade/tags/IdTag.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsException.java
@@ -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 Brett Porter
+ * @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 );
}
-}
\ No newline at end of file
+ public PluginToolsException( String message )
+ {
+ super( message );
+ }
+}
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java
index e9998b1e06..3596946426 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/AbstractScriptedMojoDescriptorExtractor.java
@@ -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();
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java
index 7fd9333238..fedd01ef12 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/InvalidParameterException.java
@@ -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 );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java
index 1c391354c8..244bc2c415 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/extractor/MojoDescriptorExtractor.java
@@ -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;
}
\ No newline at end of file
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java
index a736a40410..7daa746e0c 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/BeanGenerator.java
@@ -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 );
+ JSourceWriter sourceWriter = new JSourceWriter( writer );
- jClass.print( sourceWriter );
+ jClass.print( sourceWriter );
- writer.flush();
-
- writer.close();
+ writer.flush();
+ }
+ finally
+ {
+ IOUtil.close( writer );
+ }
}
- private JMethod createSetter( Parameter parameter, JClass jClass )
+ private JMethod createSetter( Parameter parameter )
{
String propertyName = capitalise( parameter.getName() );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java
index 307610877d..8555c0cff1 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/Generator.java
@@ -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 Jason van Zyl
* @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;
}
\ No newline at end of file
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
index 56034e89a2..38bd713b20 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java
@@ -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,39 +56,46 @@ public class PluginDescriptorGenerator
f.getParentFile().mkdirs();
}
- FileWriter writer = new FileWriter( f );
-
- XMLWriter w = new PrettyPrintXMLWriter( writer );
-
- w.startElement( "plugin" );
-
- element( w, "groupId", project.getGroupId() );
-
- element( w, "artifactId", project.getArtifactId() );
-
- element( w, "isolatedRealm", "true" );
-
- w.startElement( "mojos" );
-
- for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); )
+ FileWriter writer = null;
+ try
{
- MojoDescriptor descriptor = (MojoDescriptor) it.next();
- processPluginDescriptor( descriptor, w, project );
+ writer = new FileWriter( f );
+
+ XMLWriter w = new PrettyPrintXMLWriter( writer );
+
+ w.startElement( "plugin" );
+
+ element( w, "groupId", project.getGroupId() );
+
+ element( w, "artifactId", project.getArtifactId() );
+
+ element( w, "goalPrefix", goalPrefix );
+
+ element( w, "isolatedRealm", "true" );
+
+ w.startElement( "mojos" );
+
+ for ( Iterator it = mavenMojoDescriptors.iterator(); it.hasNext(); )
+ {
+ MojoDescriptor descriptor = (MojoDescriptor) it.next();
+ processPluginDescriptor( descriptor, w, project );
+ }
+
+ w.endElement();
+
+ PluginUtils.writeDependencies( w, project );
+
+ w.endElement();
+
+ writer.flush();
+ }
+ finally
+ {
+ IOUtil.close( writer );
}
-
- w.endElement();
-
- PluginUtils.writeDependencies( w, project );
-
- w.endElement();
-
- writer.flush();
-
- writer.close();
}
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
- 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 );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
index dffb0ee32a..fca1620bef 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginXdocGenerator.java
@@ -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" );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java
index b8bb6e0f89..6040000eff 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/jelly/JellyHarnessGenerator.java
@@ -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();
@@ -196,12 +206,12 @@ public class JellyHarnessGenerator
Parameter parameter = (Parameter) parameters.get( i );
String paramName = parameter.getAlias();
-
- if( StringUtils.isEmpty( paramName ) )
+
+ if ( StringUtils.isEmpty( paramName ) )
{
paramName = parameter.getName();
}
-
+
w.addAttribute( paramName, "${" + paramName + "}" );
}
@@ -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 );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
index 9f52f04a0b..d2f361273e 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScanner.java
@@ -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." );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
index 66e7127a3a..886accf075 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/scanner/MojoScanner.java
@@ -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;
}
\ No newline at end of file
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
index f62cc23c93..48ec622fd9 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/util/PluginUtils.java
@@ -60,7 +60,6 @@ public final class PluginUtils
}
public static void writeDependencies( XMLWriter w, MavenProject project )
- throws Exception
{
w.startElement( "dependencies" );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
index 144cd0dd39..943a925fcb 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/AbstractGeneratorTestCase.java
@@ -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();
}
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java
index 4cfcbb68e8..aca5c0137e 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGeneratorTest.java
@@ -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() );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScannerTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScannerTest.java
index 7bed58de7e..9f54ca10c6 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScannerTest.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/DefaultMojoScannerTest.java
@@ -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() );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/TestExtractor.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/TestExtractor.java
index 295e09945b..11a4cc13b1 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/TestExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/scanner/TestExtractor.java
@@ -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 );
diff --git a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
index e9b89b5ff9..21812e967d 100644
--- a/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
+++ b/maven-plugin-tools/maven-plugin-tools-api/src/test/java/org/apache/maven/tools/plugin/util/PluginUtilsTest.java
@@ -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 );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
index 5d3eacf0f4..f5b954743a 100644
--- a/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-java/src/main/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractor.java
@@ -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
diff --git a/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java b/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java
index 5535a08f85..abe457bde1 100644
--- a/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java
+++ b/maven-plugin-tools/maven-plugin-tools-java/src/test/java/org/apache/maven/tools/plugin/extractor/java/JavaMojoDescriptorExtractorTest.java
@@ -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() );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java b/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java
index 6f57ca82e8..49e0ddf255 100644
--- a/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java
+++ b/maven-plugin-tools/maven-plugin-tools-marmalade/src/main/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractor.java
@@ -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 );
diff --git a/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java b/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java
index 3e4f576545..15cafcf34f 100644
--- a/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java
+++ b/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/java/org/apache/maven/tools/plugin/extractor/marmalade/MarmaladeMojoDescriptorExtractorTest.java
@@ -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;
@@ -45,19 +46,21 @@ public class MarmaladeMojoDescriptorExtractorTest
project.setFile( new File( basedir, "pom.xml" ) );
- System.out.println("Basedir: " + basedir);
+ System.out.println( "Basedir: " + basedir );
project.addScriptSourceRoot( basedir.getPath() );
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() );
}
diff --git a/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/resources/testMojo.mmld b/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/resources/testMojo.mmld
index 0233165585..97dd43ffa3 100644
--- a/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/resources/testMojo.mmld
+++ b/maven-plugin-tools/maven-plugin-tools-marmalade/src/test/resources/testMojo.mmld
@@ -2,14 +2,13 @@
- testId
testGoal
This is a test mojo
testParam
TestValue
- #pom.file
+ ${pom.file}
true
This is a test parameter
@@ -18,4 +17,4 @@
testVal
-
\ No newline at end of file
+
diff --git a/maven-plugin-tools/maven-plugin-tools-pluggy/src/main/java/org/apache/maven/tools/plugin/pluggy/Main.java b/maven-plugin-tools/maven-plugin-tools-pluggy/src/main/java/org/apache/maven/tools/plugin/pluggy/Main.java
index 988e99e2da..c9290b2ff4 100644
--- a/maven-plugin-tools/maven-plugin-tools-pluggy/src/main/java/org/apache/maven/tools/plugin/pluggy/Main.java
+++ b/maven-plugin-tools/maven-plugin-tools-pluggy/src/main/java/org/apache/maven/tools/plugin/pluggy/Main.java
@@ -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