mirror of https://github.com/apache/maven.git
PR: MNG-225
use both groupId and artifactId in mojo descriptor git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ea036c2919
commit
85cc412a5f
|
@ -16,40 +16,37 @@ package org.apache.maven.lifecycle;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.MavenConstants;
|
||||
import org.apache.maven.artifact.handler.ArtifactHandler;
|
||||
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||
import org.apache.maven.execution.MavenExecutionResponse;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.Goal;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginManagement;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.plugin.AbstractPlugin;
|
||||
import org.apache.maven.plugin.PluginExecutionException;
|
||||
import org.apache.maven.plugin.PluginManager;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.DefaultMavenProjectBuilder;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
import org.apache.maven.project.DefaultMavenProjectBuilder;
|
||||
import org.apache.maven.project.ProjectBuildingException;
|
||||
import org.apache.maven.MavenConstants;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.logging.Logger;
|
||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
|
@ -120,9 +117,9 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( artifactHandler.additionalPlugin() != null )
|
||||
{
|
||||
String additionalPluginGroupId = AbstractPlugin.getDefaultPluginGroupId();
|
||||
String additionalPluginGroupId = PluginDescriptor.getDefaultPluginGroupId();
|
||||
|
||||
String additionalPluginArtifactId = AbstractPlugin.getDefaultPluginArtifactId(
|
||||
String additionalPluginArtifactId = PluginDescriptor.getDefaultPluginArtifactId(
|
||||
artifactHandler.additionalPlugin() );
|
||||
|
||||
injectHandlerPluginConfiguration( project, additionalPluginGroupId, additionalPluginArtifactId );
|
||||
|
@ -275,9 +272,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
// TODO: Right now this maven-foo-plugin so this is a hack right now.
|
||||
|
||||
pluginId = pluginId.substring( 6 );
|
||||
|
||||
pluginId = pluginId.substring( 0, pluginId.lastIndexOf( "-" ) );
|
||||
pluginId = PluginDescriptor.getPluginIdFromArtifactId( pluginId );
|
||||
|
||||
for ( Iterator i = plugin.getGoals().iterator(); i.hasNext(); )
|
||||
{
|
||||
|
@ -363,7 +358,7 @@ public class DefaultLifecycleExecutor
|
|||
|
||||
if ( mojoDescriptor == null )
|
||||
{
|
||||
String groupId = AbstractPlugin.getDefaultPluginGroupId();
|
||||
String groupId = PluginDescriptor.getDefaultPluginGroupId();
|
||||
|
||||
String pluginId = task;
|
||||
|
||||
|
@ -372,7 +367,7 @@ public class DefaultLifecycleExecutor
|
|||
pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) );
|
||||
}
|
||||
|
||||
String artifactId = AbstractPlugin.getDefaultPluginArtifactId( pluginId );
|
||||
String artifactId = PluginDescriptor.getDefaultPluginArtifactId( pluginId );
|
||||
|
||||
injectHandlerPluginConfiguration( session.getProject(), groupId, artifactId );
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ package org.apache.maven.plugin;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.MavenMetadataSource;
|
||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||
|
@ -126,12 +125,7 @@ public class DefaultPluginManager
|
|||
|
||||
public PluginDescriptor getPluginDescriptor( String groupId, String artifactId )
|
||||
{
|
||||
return (PluginDescriptor) pluginDescriptors.get( constructPluginKey( groupId, artifactId ) );
|
||||
}
|
||||
|
||||
private static String constructPluginKey( String groupId, String artifactId )
|
||||
{
|
||||
return groupId + ":" + artifactId;
|
||||
return (PluginDescriptor) pluginDescriptors.get( PluginDescriptor.constructPluginKey( groupId, artifactId ) );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -143,14 +137,15 @@ public class DefaultPluginManager
|
|||
public void processPluginDescriptor( MavenPluginDescriptor mavenPluginDescriptor )
|
||||
throws CycleDetectedException
|
||||
{
|
||||
if ( pluginsInProcess.contains( mavenPluginDescriptor.getPluginId() ) )
|
||||
PluginDescriptor pluginDescriptor = mavenPluginDescriptor.getPluginDescriptor();
|
||||
String key = pluginDescriptor.getId();
|
||||
|
||||
if ( pluginsInProcess.contains( key ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pluginsInProcess.add( mavenPluginDescriptor.getPluginId() );
|
||||
|
||||
PluginDescriptor pluginDescriptor = mavenPluginDescriptor.getPluginDescriptor();
|
||||
pluginsInProcess.add( key );
|
||||
|
||||
for ( Iterator it = mavenPluginDescriptor.getMavenMojoDescriptors().iterator(); it.hasNext(); )
|
||||
{
|
||||
|
@ -161,7 +156,6 @@ public class DefaultPluginManager
|
|||
mojoDescriptors.put( mojoDescriptor.getId(), mojoDescriptor );
|
||||
}
|
||||
|
||||
String key = constructPluginKey( pluginDescriptor.getGroupId(), pluginDescriptor.getArtifactId() );
|
||||
pluginDescriptors.put( key, pluginDescriptor );
|
||||
}
|
||||
|
||||
|
@ -196,28 +190,16 @@ public class DefaultPluginManager
|
|||
|
||||
public boolean isPluginInstalled( String groupId, String artifactId )
|
||||
{
|
||||
return pluginDescriptors.containsKey( constructPluginKey( groupId, artifactId ) );
|
||||
}
|
||||
|
||||
private static String getPluginId( String goalName )
|
||||
{
|
||||
String pluginId = goalName;
|
||||
|
||||
if ( pluginId.indexOf( ":" ) > 0 )
|
||||
{
|
||||
pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) );
|
||||
}
|
||||
|
||||
return AbstractPlugin.getDefaultPluginArtifactId( pluginId );
|
||||
return pluginDescriptors.containsKey( PluginDescriptor.constructPluginKey( groupId, artifactId ) );
|
||||
}
|
||||
|
||||
// TODO: don't throw Exception
|
||||
public void verifyPluginForGoal( String goalName, MavenSession session )
|
||||
throws Exception
|
||||
{
|
||||
String pluginId = getPluginId( goalName );
|
||||
String pluginId = PluginDescriptor.getPluginIdFromGoal( goalName );
|
||||
|
||||
verifyPlugin( AbstractPlugin.getDefaultPluginGroupId(), pluginId, session );
|
||||
verifyPlugin( PluginDescriptor.getDefaultPluginGroupId(), pluginId, session );
|
||||
}
|
||||
|
||||
// TODO: don't throw Exception
|
||||
|
@ -397,7 +379,8 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
// TODO: can probable refactor these a little when only the new plugin technique is in place
|
||||
Xpp3Dom dom = session.getProject().getGoalConfiguration( getPluginId( goalName ), goalId );
|
||||
Xpp3Dom dom = session.getProject().getGoalConfiguration( PluginDescriptor.getPluginIdFromGoal( goalName ),
|
||||
goalId );
|
||||
|
||||
PlexusConfiguration configuration;
|
||||
if ( dom == null )
|
||||
|
|
|
@ -38,12 +38,6 @@ public class MavenPluginDescriptor
|
|||
this.pluginDescriptor = pluginDescriptor;
|
||||
}
|
||||
|
||||
public String getPluginId()
|
||||
{
|
||||
// TODO: groupID
|
||||
return pluginDescriptor.getArtifactId();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Accessors
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -62,4 +56,5 @@ public class MavenPluginDescriptor
|
|||
{
|
||||
return pluginDescriptor.isIsolatedRealm();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.apache.maven.model.PluginManagement;
|
|||
import org.apache.maven.model.Repository;
|
||||
import org.apache.maven.model.Scm;
|
||||
import org.apache.maven.util.Xpp3DomUtils;
|
||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||
import org.codehaus.plexus.util.StringUtils;
|
||||
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||
|
||||
|
@ -44,7 +43,6 @@ import java.util.TreeMap;
|
|||
* model.
|
||||
*/
|
||||
public class DefaultModelInheritanceAssembler
|
||||
extends AbstractLogEnabled
|
||||
implements ModelInheritanceAssembler
|
||||
{
|
||||
public void assembleModelInheritance( Model child, Model parent )
|
||||
|
|
|
@ -86,19 +86,4 @@ public abstract class AbstractPlugin
|
|||
throw new PluginExecutionException( "You must override execute() if you implement the new paradigm" );
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove - harcoding.
|
||||
*/
|
||||
public static String getDefaultPluginArtifactId( String id )
|
||||
{
|
||||
return "maven-" + id + "-plugin";
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove - harcoding.
|
||||
*/
|
||||
public static String getDefaultPluginGroupId()
|
||||
{
|
||||
return "org.apache.maven.plugins";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,4 +87,59 @@ public class PluginDescriptor
|
|||
{
|
||||
return isolatedRealm;
|
||||
}
|
||||
|
||||
public static String constructPluginKey( String groupId, String artifactId )
|
||||
{
|
||||
return groupId + ":" + artifactId;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return constructPluginKey( groupId, artifactId );
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove - harcoding.
|
||||
*/
|
||||
public static String getPluginIdFromGoal( String goalName )
|
||||
{
|
||||
String pluginId = goalName;
|
||||
|
||||
if ( pluginId.indexOf( ":" ) > 0 )
|
||||
{
|
||||
pluginId = pluginId.substring( 0, pluginId.indexOf( ":" ) );
|
||||
}
|
||||
|
||||
return getDefaultPluginArtifactId( pluginId );
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove - harcoding.
|
||||
*/
|
||||
public static String getDefaultPluginArtifactId( String id )
|
||||
{
|
||||
return "maven-" + id + "-plugin";
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo remove - harcoding.
|
||||
*/
|
||||
public static String getDefaultPluginGroupId()
|
||||
{
|
||||
return "org.apache.maven.plugins";
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse maven-...-plugin.
|
||||
*
|
||||
* @todo remove - harcoding. What about clashes?
|
||||
*/
|
||||
public static String getPluginIdFromArtifactId( String artifactId )
|
||||
{
|
||||
int firstHyphen = artifactId.indexOf( "-" );
|
||||
|
||||
int lastHyphen = artifactId.lastIndexOf( "-" );
|
||||
|
||||
return artifactId.substring( firstHyphen + 1, lastHyphen );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.apache.maven.plugin.descriptor;
|
||||
|
||||
import org.apache.maven.plugin.AbstractPlugin;
|
||||
import org.codehaus.plexus.configuration.PlexusConfiguration;
|
||||
import org.codehaus.plexus.configuration.PlexusConfigurationException;
|
||||
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
|
||||
|
@ -24,8 +23,18 @@ public class PluginDescriptorBuilder
|
|||
|
||||
PluginDescriptor pluginDescriptor = new PluginDescriptor();
|
||||
|
||||
pluginDescriptor.setGroupId( AbstractPlugin.getDefaultPluginGroupId() );
|
||||
pluginDescriptor.setArtifactId( AbstractPlugin.getDefaultPluginArtifactId( c.getChild( "id" ).getValue() ) );
|
||||
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() );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Components
|
||||
|
|
|
@ -53,7 +53,9 @@ public class PluginDescriptorGenerator
|
|||
|
||||
w.startElement( "plugin" );
|
||||
|
||||
element( w, "id", PluginUtils.pluginId( project ) );
|
||||
element( w, "groupId", project.getGroupId() );
|
||||
|
||||
element( w, "artifactId", project.getArtifactId() );
|
||||
|
||||
element( w, "isolatedRealm", "true" );
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -46,13 +47,14 @@ 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 )
|
||||
throws Exception
|
||||
{
|
||||
FileWriter writer = new FileWriter( new File( destinationDirectory, "plugin.jelly" ) );
|
||||
|
||||
PrettyPrintXMLWriter w = new PrettyPrintXMLWriter( writer );
|
||||
|
||||
String pluginId = PluginUtils.pluginId( project );
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
//
|
||||
|
@ -133,7 +135,7 @@ public class JellyHarnessGenerator
|
|||
protected void processPluginDescriptor( MojoDescriptor mojoDescriptor, XMLWriter w, MavenProject project )
|
||||
throws Exception
|
||||
{
|
||||
String pluginId = PluginUtils.pluginId( project );
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
String goalName = mojoDescriptor.getGoal();
|
||||
|
||||
|
@ -252,7 +254,8 @@ public class JellyHarnessGenerator
|
|||
|
||||
if ( projectIndex > 0 )
|
||||
{
|
||||
expression = expression.substring( 0, projectIndex ) + "pom" + expression.substring( projectIndex + 7 );
|
||||
expression = expression.substring( 0, projectIndex ) + "pom" +
|
||||
expression.substring( projectIndex + 7 );
|
||||
}
|
||||
|
||||
if ( expression.startsWith( "#" ) )
|
||||
|
@ -275,8 +278,7 @@ public class JellyHarnessGenerator
|
|||
return str;
|
||||
}
|
||||
|
||||
return new StringBuffer( str.length() ).append( Character.toTitleCase( str.charAt( 0 ) ) )
|
||||
.append( str.substring( 1 ) )
|
||||
.toString();
|
||||
return new StringBuffer( str.length() ).append( Character.toTitleCase( str.charAt( 0 ) ) ).append(
|
||||
str.substring( 1 ) ).toString();
|
||||
}
|
||||
}
|
|
@ -34,25 +34,6 @@ public final class PluginUtils
|
|||
{
|
||||
}
|
||||
|
||||
public static String pluginId( MavenProject project )
|
||||
{
|
||||
// ----------------------------------------------------------------------
|
||||
// We will take the id from the artifactId of the POM. The artifactId is
|
||||
// always of the form maven-<pluginId>-plugin so we can extract the
|
||||
// pluginId from the artifactId.
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
String artifactId = project.getArtifactId();
|
||||
|
||||
int firstHyphen = artifactId.indexOf( "-" );
|
||||
|
||||
int lastHyphen = artifactId.lastIndexOf( "-" );
|
||||
|
||||
String pluginId = artifactId.substring( firstHyphen + 1, lastHyphen );
|
||||
|
||||
return pluginId;
|
||||
}
|
||||
|
||||
public static String[] findSources( String basedir, String include )
|
||||
{
|
||||
return PluginUtils.findSources( basedir, include, null );
|
||||
|
@ -73,7 +54,8 @@ public final class PluginUtils
|
|||
return scanner.getIncludedFiles();
|
||||
}
|
||||
|
||||
public static void writeDependencies( XMLWriter w, MavenProject project ) throws Exception
|
||||
public static void writeDependencies( XMLWriter w, MavenProject project )
|
||||
throws Exception
|
||||
{
|
||||
|
||||
w.startElement( "dependencies" );
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
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.util.xml.CompactXMLWriter;
|
||||
import org.codehaus.plexus.util.xml.XMLWriter;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author jdcasey
|
||||
*/
|
||||
|
@ -24,12 +24,13 @@ public class PluginUtilsTest
|
|||
|
||||
MavenProject project = new MavenProject( model );
|
||||
|
||||
String pluginId = PluginUtils.pluginId( project );
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
System.out.println( pluginId );
|
||||
}
|
||||
|
||||
public void testShouldWriteDependencies() throws Exception
|
||||
public void testShouldWriteDependencies()
|
||||
throws Exception
|
||||
{
|
||||
Dependency dependency = new Dependency();
|
||||
dependency.setArtifactId( "testArtifactId" );
|
||||
|
@ -49,9 +50,9 @@ public class PluginUtilsTest
|
|||
|
||||
String output = sWriter.toString();
|
||||
|
||||
String pattern = "<dependencies>" + "<dependency>" + "<groupId>testGroupId</groupId>"
|
||||
+ "<artifactId>testArtifactId</artifactId>" + "<type>pom</type>" + "<version>0.0.0</version>"
|
||||
+ "</dependency>" + "</dependencies>";
|
||||
String pattern = "<dependencies>" + "<dependency>" + "<groupId>testGroupId</groupId>" +
|
||||
"<artifactId>testArtifactId</artifactId>" + "<type>pom</type>" + "<version>0.0.0</version>" +
|
||||
"</dependency>" + "</dependencies>";
|
||||
|
||||
assertEquals( pattern, output );
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ import com.thoughtworks.qdox.model.JavaClass;
|
|||
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.util.PluginUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -121,7 +121,7 @@ public class JavaMojoDescriptorExtractor
|
|||
|
||||
DocletTag tag;
|
||||
|
||||
String pluginId = PluginUtils.pluginId( project );
|
||||
String pluginId = PluginDescriptor.getPluginIdFromArtifactId( project.getArtifactId() );
|
||||
|
||||
mojoDescriptor.setId( pluginId );
|
||||
|
||||
|
|
|
@ -71,6 +71,16 @@ public class Main
|
|||
|
||||
Model model = modelReader.read( reader );
|
||||
|
||||
// Not doing inheritence, except for groupId and version
|
||||
if ( model.getGroupId() == null )
|
||||
{
|
||||
model.setGroupId( model.getParent().getGroupId() );
|
||||
}
|
||||
if ( model.getVersion() == null )
|
||||
{
|
||||
model.setVersion( model.getParent().getVersion() );
|
||||
}
|
||||
|
||||
MavenProject project = new MavenProject( model );
|
||||
project.setFile( new File( pom ) );
|
||||
project.addCompileSourceRoot( sourceDirectory );
|
||||
|
|
Loading…
Reference in New Issue