diff --git a/maven-plugin-plugin/pom.xml b/maven-plugin-plugin/pom.xml
index fb90486..1b99f8b 100644
--- a/maven-plugin-plugin/pom.xml
+++ b/maven-plugin-plugin/pom.xml
@@ -106,6 +106,11 @@
* <!-- Use all mojo extractors -->
* <extractors/>
- *
+ *
* <!-- Use no mojo extractors -->
* <extractors>
* <extractor/>
* </extractors>
- *
+ *
* <!-- Use only bsh mojo extractor -->
* <extractors>
* <extractor>bsh</extractor>
@@ -134,6 +136,26 @@ public abstract class AbstractGeneratorMojo
*/
protected Set dependencies;
+ /**
+ * List of Remote Repositories used by the resolver
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ * @readonly
+ * @required
+ * @since 3.0
+ */
+ protected List remoteRepos;
+
+ /**
+ * Location of the local repository.
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ * @required
+ * @since 3.0
+ */
+ protected ArtifactRepository local;
+
/**
* @return the output directory where files will be generated.
*/
@@ -144,7 +166,9 @@ public abstract class AbstractGeneratorMojo
*/
protected abstract Generator createGenerator();
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ */
public void execute()
throws MojoExecutionException
{
@@ -158,11 +182,11 @@ public abstract class AbstractGeneratorMojo
return;
}
- if ( project.getArtifactId().toLowerCase().startsWith( "maven-" )
- && project.getArtifactId().toLowerCase().endsWith( "-plugin" )
- && !"org.apache.maven.plugins".equals( project.getGroupId() ) )
+ if ( project.getArtifactId().toLowerCase().startsWith( "maven-" )
+ && project.getArtifactId().toLowerCase().endsWith( "-plugin" ) && !"org.apache.maven.plugins".equals(
+ project.getGroupId() ) )
{
- getLog().error( "\n\nArtifact Ids of the format maven-___-plugin are reserved for \n"
+ getLog().error( "\n\nArtifact Ids of the format maven-___-plugin are reserved for \n"
+ "plugins in the Group Id org.apache.maven.plugins\n"
+ "Please change your artifactId to the format ___-maven-plugin\n"
+ "In the future this error will break the build.\n\n" );
@@ -176,8 +200,8 @@ public abstract class AbstractGeneratorMojo
else if ( !goalPrefix.equals( defaultGoalPrefix ) )
{
getLog().warn(
- "\n\nGoal prefix is specified as: '" + goalPrefix + "'. "
- + "Maven currently expects it to be '" + defaultGoalPrefix + "'.\n" );
+ "\n\nGoal prefix is specified as: '" + goalPrefix + "'. " + "Maven currently expects it to be '"
+ + defaultGoalPrefix + "'.\n" );
}
mojoScanner.setActiveExtractors( extractors );
@@ -200,21 +224,23 @@ public abstract class AbstractGeneratorMojo
if ( encoding == null || encoding.length() < 1 )
{
getLog().warn( "Using platform encoding (" + ReaderFactory.FILE_ENCODING
- + " actually) to read mojo metadata, i.e. build is platform dependent!" );
+ + " actually) to read mojo metadata, i.e. build is platform dependent!" );
}
else
{
getLog().info( "Using '" + encoding + "' encoding to read mojo metadata." );
}
-
+
try
{
pluginDescriptor.setDependencies( PluginUtils.toComponentDependencies( project.getRuntimeDependencies() ) );
-
+
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
request.setEncoding( encoding );
request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound );
request.setDependencies( dependencies );
+ request.setLocal( this.local );
+ request.setRemoteRepos( this.remoteRepos );
mojoScanner.populatePluginDescriptor( request );
@@ -239,7 +265,8 @@ public abstract class AbstractGeneratorMojo
catch ( LinkageError e )
{
throw new MojoExecutionException( "The API of the mojo scanner is not compatible with this plugin version."
- + " Please check the plugin dependencies configured in the POM and ensure the versions match.", e );
+ + " Please check the plugin dependencies configured in the POM and ensure the versions match.",
+ e );
}
}
diff --git a/maven-plugin-tools-annotations/pom.xml b/maven-plugin-tools-annotations/pom.xml
index b8d8705..c2fdcf8 100644
--- a/maven-plugin-tools-annotations/pom.xml
+++ b/maven-plugin-tools-annotations/pom.xml
@@ -72,6 +72,11 @@
3.3.1
+
+ org.codehaus.plexus
+ plexus-archiver
+
+
com.thoughtworks.qdox
qdox
diff --git a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
index 48a7d1b..3ec1c72 100644
--- a/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
+++ b/maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/annotations/JavaAnnotationsMojoDescriptorExtractor.java
@@ -23,6 +23,10 @@ import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
@@ -41,6 +45,9 @@ import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner;
import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.archiver.manager.ArchiverManager;
+import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
@@ -50,8 +57,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
@@ -69,6 +78,21 @@ public class JavaAnnotationsMojoDescriptorExtractor
*/
private MojoAnnotationsScanner mojoAnnotationsScanner;
+ /**
+ * @requirement
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * @requirement
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @requirement
+ */
+ private ArchiverManager archiverManager;
+
public List execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws ExtractionException, InvalidPluginDescriptorException
{
@@ -95,6 +119,9 @@ public class JavaAnnotationsMojoDescriptorExtractor
// we currently only scan sources from reactors
List mavenProjects = new ArrayList();
+ // if we need to scan sources from external artifacts
+ Set externalArtifacts = new HashSet();
+
for ( MojoAnnotatedClass mojoAnnotatedClass : mojoAnnotatedClasses.values() )
{
if ( !StringUtils.equals( mojoAnnotatedClass.getArtifact().getArtifactId(),
@@ -106,11 +133,31 @@ public class JavaAnnotationsMojoDescriptorExtractor
{
mavenProjects.add( mavenProject );
}
+ else
+ {
+ externalArtifacts.add( mojoAnnotatedClass.getArtifact() );
+ }
}
}
Map javaClassesMap = new HashMap();
+ // try to get artifact with classifier sources
+ // extract somewhere then scan doclet for @since, @deprecated
+ for ( Artifact artifact : externalArtifacts )
+ {
+ // parameter for test-sources too ?? olamy I need that for it test only
+ if ( StringUtils.equalsIgnoreCase( "tests", artifact.getClassifier() ) )
+ {
+ javaClassesMap.putAll( discoverClassesFromSourcesJar( artifact, request, "test-sources" ) );
+ }
+ else
+ {
+ javaClassesMap.putAll( discoverClassesFromSourcesJar( artifact, request, "sources" ) );
+ }
+
+ }
+
for ( MavenProject mavenProject : mavenProjects )
{
javaClassesMap.putAll( discoverClasses( request.getEncoding(), mavenProject ) );
@@ -120,10 +167,59 @@ public class JavaAnnotationsMojoDescriptorExtractor
populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
- return toMojoDescriptors( mojoAnnotatedClasses, request );
+ return toMojoDescriptors( mojoAnnotatedClasses, request, javaClassesMap );
}
+
+ protected Map discoverClassesFromSourcesJar( Artifact artifact, PluginToolsRequest request,
+ String classifier )
+ throws ExtractionException
+ {
+ try
+ {
+ Artifact sourcesArtifact =
+ artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact.getArtifactId(),
+ artifact.getVersion(), artifact.getType(), classifier );
+
+ artifactResolver.resolve( sourcesArtifact, request.getRemoteRepos(), request.getLocal() );
+ if ( sourcesArtifact.getFile() != null && sourcesArtifact.getFile().exists() )
+ {
+ File extractDirectory = new File( request.getProject().getBuild().getDirectory(),
+ "maven-plugin-plugin-sources/" + sourcesArtifact.getGroupId() + "/"
+ + sourcesArtifact.getArtifactId() + "/"
+ + sourcesArtifact.getVersion() + "/"
+ + sourcesArtifact.getClassifier() );
+ if ( !extractDirectory.exists() )
+ {
+ extractDirectory.mkdirs();
+ }
+ // extract sources in a directory
+ //target/maven-plugin-plugin/${groupId}/${artifact}/sources
+ UnArchiver unArchiver = archiverManager.getUnArchiver( "jar" );
+ unArchiver.setSourceFile( sourcesArtifact.getFile() );
+ unArchiver.setDestDirectory( extractDirectory );
+ unArchiver.extract();
+
+ return discoverClasses( request.getEncoding(), Arrays.asList( extractDirectory ) );
+ }
+ }
+ catch ( ArtifactResolutionException e )
+ {
+ throw new ExtractionException( e.getMessage(), e );
+ }
+ catch ( ArtifactNotFoundException e )
+ {
+ //throw new ExtractionException( e.getMessage(), e );
+ getLogger().debug( "skip ArtifactNotFoundException:" + e.getMessage() );
+ }
+ catch ( NoSuchArchiverException e )
+ {
+ throw new ExtractionException( e.getMessage(), e );
+ }
+ return Collections.emptyMap();
+ }
+
/**
* from sources scan to get @since and @deprecated and description of classes and fields.
*
@@ -155,8 +251,13 @@ public class JavaAnnotationsMojoDescriptorExtractor
mojoAnnotationContent.setDeprecated( deprecated.getValue() );
}
}
- Map fieldsMap = extractFieldParameterTags( javaClass );
- for ( Map.Entry parameter : entry.getValue().getParameters().entrySet() )
+ Map fieldsMap =
+ extractFieldParameterTags( javaClass, javaClassesMap, mojoAnnotatedClasses );
+ Map parameters =
+ getParametersParentHierarchy( entry.getValue(), new HashMap(),
+ mojoAnnotatedClasses );
+ for ( Map.Entry parameter : new TreeMap(
+ parameters ).entrySet() )
{
JavaField javaField = fieldsMap.get( parameter.getKey() );
if ( javaField != null )
@@ -206,7 +307,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
* @param tagName not null
* @return docletTag instance
*/
- private static DocletTag findInClassHierarchy( JavaClass javaClass, String tagName )
+ private DocletTag findInClassHierarchy( JavaClass javaClass, String tagName )
{
DocletTag tag = javaClass.getTagByName( tagName );
@@ -229,9 +330,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
* @param javaClass not null
* @return map with Mojo parameters names as keys
*/
- private Map extractFieldParameterTags( JavaClass javaClass )
+ private Map extractFieldParameterTags( JavaClass javaClass,
+ Map javaClassesMap,
+ Map mojoAnnotatedClasses )
{
- Map rawParams;
+ Map rawParams = new TreeMap();
// we have to add the parent fields first, so that they will be overwritten by the local fields if
// that actually happens...
@@ -239,10 +342,20 @@ public class JavaAnnotationsMojoDescriptorExtractor
if ( superClass != null )
{
- rawParams = extractFieldParameterTags( superClass );
+ if ( superClass.getFields().length > 0 )
+ {
+ rawParams = extractFieldParameterTags( superClass, javaClassesMap, mojoAnnotatedClasses );
+ }
+ // maybe sources comes from scan of sources artifact
+ superClass = javaClassesMap.get( superClass.getFullyQualifiedName() );
+ if ( superClass != null )
+ {
+ rawParams = extractFieldParameterTags( superClass, javaClassesMap, mojoAnnotatedClasses );
+ }
}
else
{
+
rawParams = new TreeMap();
}
@@ -265,12 +378,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
protected Map discoverClasses( final String encoding, final MavenProject project )
{
- JavaDocBuilder builder = new JavaDocBuilder();
- builder.setEncoding( encoding );
+ List sources = new ArrayList();
for ( String source : (List) project.getCompileSourceRoots() )
{
- builder.addSourceTree( new File( source ) );
+ sources.add( new File( source ) );
}
// TODO be more dynamic
@@ -278,7 +390,20 @@ public class JavaAnnotationsMojoDescriptorExtractor
if ( !project.getCompileSourceRoots().contains( generatedPlugin.getAbsolutePath() )
&& generatedPlugin.exists() )
{
- builder.addSourceTree( generatedPlugin );
+ sources.add( generatedPlugin );
+ }
+
+ return discoverClasses( encoding, sources );
+ }
+
+ protected Map discoverClasses( final String encoding, List sourceDirectories )
+ {
+ JavaDocBuilder builder = new JavaDocBuilder();
+ builder.setEncoding( encoding );
+
+ for ( File source : sourceDirectories )
+ {
+ builder.addSourceTree( source );
}
JavaClass[] javaClasses = builder.getClasses();
@@ -298,9 +423,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
return javaClassMap;
}
-
private List toMojoDescriptors( Map mojoAnnotatedClasses,
- PluginToolsRequest request )
+ PluginToolsRequest request, Map javaClassesMap )
throws DuplicateParameterException
{
List mojoDescriptors = new ArrayList( mojoAnnotatedClasses.size() );
@@ -367,6 +491,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
parameter.setEditable( !parameterAnnotationContent.readonly() );
parameter.setExpression( parameterAnnotationContent.expression() );
parameter.setType( parameterAnnotationContent.getClassName() );
+ parameter.setSince( parameterAnnotationContent.getSince() );
parameter.setRequired( parameterAnnotationContent.required() );
mojoDescriptor.addParameter( parameter );
@@ -385,7 +510,8 @@ public class JavaAnnotationsMojoDescriptorExtractor
parameter.setRequirement(
new Requirement( componentAnnotationContent.role(), componentAnnotationContent.roleHint() ) );
parameter.setEditable( false );
-
+ parameter.setDeprecated( componentAnnotationContent.getDeprecated() );
+ parameter.setSince( componentAnnotationContent.getSince() );
mojoDescriptor.addParameter( parameter );
}
diff --git a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
index 91df740..18fb315 100644
--- a/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
+++ b/maven-plugin-tools-annotations/src/main/resources/META-INF/plexus/components.xml
@@ -35,6 +35,18 @@
org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner
default
+
+ org.apache.maven.artifact.resolver.ArtifactResolver
+ default
+
+
+ org.apache.maven.artifact.factory.ArtifactFactory
+ default
+
+
+ org.codehaus.plexus.archiver.manager.ArchiverManager
+ default
+
diff --git a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
index 68021ae..1f9da50 100644
--- a/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
+++ b/maven-plugin-tools-annotations/src/test/java/org/apache/maven/tools/plugin/annotations/FooMojo.java
@@ -40,7 +40,6 @@ public class FooMojo
/**
* the cool bar to go
* @since 1.0
- *
*/
@Parameter( expression = "${thebar}", required = true, defaultValue = "coolbar" )
protected String bar;
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
index 73ef0fc..9c70400 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/DefaultPluginToolsRequest.java
@@ -20,6 +20,7 @@ package org.apache.maven.tools.plugin;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
@@ -27,6 +28,7 @@ import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
/**
@@ -52,6 +54,10 @@ public class DefaultPluginToolsRequest
private Set dependencies;
+ private List remoteRepos;
+
+ private ArtifactRepository local;
+
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
{
this.project = project;
@@ -148,4 +154,26 @@ public class DefaultPluginToolsRequest
this.dependencies = dependencies;
return this;
}
+
+ public List getRemoteRepos()
+ {
+ return remoteRepos;
+ }
+
+ public PluginToolsRequest setRemoteRepos( List remoteRepos )
+ {
+ this.remoteRepos = remoteRepos;
+ return this;
+ }
+
+ public ArtifactRepository getLocal()
+ {
+ return local;
+ }
+
+ public PluginToolsRequest setLocal( ArtifactRepository local )
+ {
+ this.local = local;
+ return this;
+ }
}
diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
index 0cdf998..03fe386 100644
--- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
+++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/PluginToolsRequest.java
@@ -20,10 +20,12 @@ package org.apache.maven.tools.plugin;
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
+import java.util.List;
import java.util.Set;
/**
@@ -90,16 +92,47 @@ public interface PluginToolsRequest
/**
* Returns the list of {@link Artifact} used in class path scanning for annotations
+ *
* @return
* @since 3.0
*/
Set getDependencies();
/**
- *
* @param dependencies
* @return
+ * @since 3.0
*/
PluginToolsRequest setDependencies( Set dependencies );
+ /**
+ *
+ * @return
+ * @since 3.0
+ */
+ List getRemoteRepos();
+
+ /**
+ *
+ * @param remoteRepos
+ * @return
+ * @since 3.0
+ */
+ PluginToolsRequest setRemoteRepos( List remoteRepos );
+
+ /**
+ *
+ * @return
+ * @since 3.0
+ */
+ ArtifactRepository getLocal();
+
+ /**
+ *
+ * @param local
+ * @return
+ * @since 3.0
+ */
+ PluginToolsRequest setLocal( ArtifactRepository local );
+
}
diff --git a/pom.xml b/pom.xml
index 6dec851..d603983 100644
--- a/pom.xml
+++ b/pom.xml
@@ -228,6 +228,11 @@
plexus-container-default
1.0-alpha-9-stable-1
+
+ org.codehaus.plexus
+ plexus-archiver
+ 2.1.1
+
com.thoughtworks.qdox