[MPLUGIN-189] scan sources from dependencies if sources classifier found to get @since,@deprecated and text

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1336291 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-09 16:45:26 +00:00
parent ccc68be0c6
commit d85b22ec88
14 changed files with 550 additions and 31 deletions

View File

@ -106,6 +106,11 @@
<artifactId>plexus-utils</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
</dependencyManagement>

View File

@ -0,0 +1,5 @@
invoker.goals.1 = install
invoker.goals.2 = org.apache.maven.its.annotation-with-inheritance-from-deps:annotation-with-inheritance-from-deps:1.0:first
#FIXME disabled need to find a solution for the chicken and eggs issue.
#help sources are generated @generated-sources but need descriptor which need compile phase first for classes scanning
#invoker.goals.3 = org.apache.maven.its.basic-java-annotations:maven-it-basic-java-annotations:1.0::help

View File

@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.annotation-with-inheritance-from-deps</groupId>
<artifactId>annotation-with-inheritance-from-deps</artifactId>
<version>1.0</version>
<packaging>maven-plugin</packaging>
<name>Maven Integration Test :: annotation-with-inheritance-from-deps</name>
<description>
Test plugin-plugin, which tests maven-plugin-tools-api and
maven-plugin-tools-java. This will generate a plugin descriptor from
java-based mojo sources, install the plugin, and then use it.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<plexusCompilerVersion>1.8.6</plexusCompilerVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>@mavenVersion@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-annotations</artifactId>
<version>@project.version@</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>${plexusCompilerVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>${plexusCompilerVersion}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<phase>process-classes</phase>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,73 @@
package org.apache.maven.plugin.coreit;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.tools.plugin.annotations.FooMojo;
/**
* Touches a test file.
*
* @since 1.2
* @deprecated Don't use!
*/
@Mojo( name = "first", requiresDependencyResolution = "test", defaultPhase = LifecyclePhase.INTEGRATION_TEST )
public class FirstMojo
extends FooMojo
{
/**
* @since 0.1
* @deprecated As of 0.2
*/
@Parameter( alias = "alias" )
private String aliasedParam;
@Component( role = "org.apache.maven.project.MavenProjectHelper", roleHint = "default" )
private Object projectHelper;
public void execute()
throws MojoExecutionException
{
if (bar == null)
{
throw new MojoExecutionException( "bar == null" );
}
if (beer == null)
{
throw new MojoExecutionException( "beer == null" );
}
if ( projectHelper == null )
{
throw new MojoExecutionException( "projectHelper == null" );
}
if ( compilerManager == null )
{
throw new MojoExecutionException( "compilerManager == null" );
}
}
}

View File

@ -0,0 +1,17 @@
<lifecycles>
<lifecycle>
<id>my-lifecycle</id>
<phases>
<phase>
<id>process-classes</id>
</phase>
<phase>
<id>test</id>
<configuration>
<classesDirectory>${project.build.directory}/generated-classes/cobertura</classesDirectory>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</phase>
</phases>
</lifecycle>
</lifecycles>

View File

@ -0,0 +1,75 @@
File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" );
assert descriptorFile.isFile()
def pluginDescriptor = new XmlParser().parse( descriptorFile );
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first"}[0]
assert mojo.goal.text() == 'first'
assert mojo.implementation.text() == 'org.apache.maven.plugin.coreit.FirstMojo'
assert mojo.language.text() == 'java'
assert mojo.description.text() == 'Touches a test file.'
assert mojo.deprecated.text() == "Don't use!"
assert mojo.requiresDependencyResolution.text() == 'test'
assert mojo.requiresDependencyCollection.text() == ''
assert mojo.requiresProject.text() == 'true'
assert mojo.requiresOnline.text() == 'false'
assert mojo.requiresDirectInvocation.text() == 'false'
assert mojo.aggregator.text() == 'false'
assert mojo.threadSafe.text() == 'false'
assert mojo.phase.text() == 'integration-test'
assert mojo.executePhase.text() == 'package'
assert mojo.executeLifecycle.text() == 'my-lifecycle'
assert mojo.configuration.bar[0].text() == '${thebar}'
assert mojo.configuration.bar[0].'@implementation' == 'java.lang.String'
assert mojo.configuration.bar[0].'@default-value' == 'coolbar'
assert mojo.configuration.beer[0].text() == '${thebeer}'
assert mojo.configuration.beer[0].'@implementation' == 'java.lang.String'
assert mojo.configuration.beer[0].'@default-value' == 'coolbeer'
assert mojo.requirements.requirement.size() == 3
assert mojo.requirements.requirement[1].role.text() == 'org.codehaus.plexus.compiler.manager.CompilerManager'
assert mojo.requirements.requirement[1].'role-hint'.text() == ''
assert mojo.requirements.requirement[1].'field-name'.text() == 'compilerManager'
assert mojo.requirements.requirement[2].role.text() == 'org.apache.maven.project.MavenProjectHelper'
assert mojo.requirements.requirement[2].'role-hint'.text() == 'default'
assert mojo.requirements.requirement[2].'field-name'.text() == 'projectHelper'
assert mojo.parameters.parameter.size() == 3
def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam"}[0]
assert parameter.name.text() == 'aliasedParam'
assert parameter.alias.text() == 'alias'
assert parameter.type.text() == 'java.lang.String'
assert parameter.deprecated.text() == 'As of 0.2'
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == ''
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "beer"}[0]
assert parameter.name.text() == 'beer'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.deprecated.text() == "wine is better"
assert parameter.required.text() == 'false'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == 'beer for non french folks'
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "bar"}[0]
assert parameter.name.text() == 'bar'
assert parameter.alias.isEmpty()
assert parameter.type.text() == 'java.lang.String'
assert parameter.deprecated.isEmpty()
assert parameter.required.text() == 'true'
assert parameter.editable.text() == 'true'
assert parameter.description.text() == 'the cool bar to go'
return true;

View File

@ -20,6 +20,7 @@ package org.apache.maven.plugin.plugin;
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
@ -35,6 +36,7 @@ import org.codehaus.plexus.util.ReaderFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;
/**
@ -42,7 +44,6 @@ import java.util.Set;
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*
* @threadSafe
*/
public abstract class AbstractGeneratorMojo
@ -67,7 +68,7 @@ public abstract class AbstractGeneratorMojo
/**
* The file encoding of the source files.
*
*
* @parameter expression="${encoding}" default-value="${project.build.sourceEncoding}"
* @since 2.5
*/
@ -84,6 +85,7 @@ public abstract class AbstractGeneratorMojo
* By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the
* descriptor generator mojo is bound to generate-resources phase.
* But for annotations, the compiled classes are needed, so skip error
*
* @parameter expression="${maven.plugin.skipErrorNoDescriptorsFound}" default-value="false"
* @since 3.0
*/
@ -100,12 +102,12 @@ public abstract class AbstractGeneratorMojo
* <pre>
* &lt;!-- Use all mojo extractors --&gt;
* &lt;extractors/&gt;
*
*
* &lt;!-- Use no mojo extractors --&gt;
* &lt;extractors&gt;
* &lt;extractor/&gt;
* &lt;/extractors&gt;
*
*
* &lt;!-- Use only bsh mojo extractor --&gt;
* &lt;extractors&gt;
* &lt;extractor&gt;bsh&lt;/extractor&gt;
@ -134,6 +136,26 @@ public abstract class AbstractGeneratorMojo
*/
protected Set<Artifact> dependencies;
/**
* List of Remote Repositories used by the resolver
*
* @parameter expression="${project.remoteArtifactRepositories}"
* @readonly
* @required
* @since 3.0
*/
protected List<ArtifactRepository> 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 );
}
}

View File

@ -72,6 +72,11 @@
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>

View File

@ -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<MojoDescriptor> execute( MavenProject project, PluginDescriptor pluginDescriptor )
throws ExtractionException, InvalidPluginDescriptorException
{
@ -95,6 +119,9 @@ public class JavaAnnotationsMojoDescriptorExtractor
// we currently only scan sources from reactors
List<MavenProject> mavenProjects = new ArrayList<MavenProject>();
// if we need to scan sources from external artifacts
Set<Artifact> externalArtifacts = new HashSet<Artifact>();
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<String, JavaClass> javaClassesMap = new HashMap<String, JavaClass>();
// 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<String, JavaClass> 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<String, JavaField> fieldsMap = extractFieldParameterTags( javaClass );
for ( Map.Entry<String, ParameterAnnotationContent> parameter : entry.getValue().getParameters().entrySet() )
Map<String, JavaField> fieldsMap =
extractFieldParameterTags( javaClass, javaClassesMap, mojoAnnotatedClasses );
Map<String, ParameterAnnotationContent> parameters =
getParametersParentHierarchy( entry.getValue(), new HashMap<String, ParameterAnnotationContent>(),
mojoAnnotatedClasses );
for ( Map.Entry<String, ParameterAnnotationContent> parameter : new TreeMap<String, ParameterAnnotationContent>(
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<String, JavaField> extractFieldParameterTags( JavaClass javaClass )
private Map<String, JavaField> extractFieldParameterTags( JavaClass javaClass,
Map<String, JavaClass> javaClassesMap,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
{
Map<String, JavaField> rawParams;
Map<String, JavaField> rawParams = new TreeMap<String, com.thoughtworks.qdox.model.JavaField>();
// 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<String, JavaField>();
}
@ -265,12 +378,11 @@ public class JavaAnnotationsMojoDescriptorExtractor
protected Map<String, JavaClass> discoverClasses( final String encoding, final MavenProject project )
{
JavaDocBuilder builder = new JavaDocBuilder();
builder.setEncoding( encoding );
List<File> sources = new ArrayList<File>();
for ( String source : (List<String>) 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<String, JavaClass> discoverClasses( final String encoding, List<File> 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<MojoDescriptor> toMojoDescriptors( Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
PluginToolsRequest request )
PluginToolsRequest request, Map<String, JavaClass> javaClassesMap )
throws DuplicateParameterException
{
List<MojoDescriptor> mojoDescriptors = new ArrayList<MojoDescriptor>( 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 );
}

View File

@ -35,6 +35,18 @@
<role>org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.artifact.resolver.ArtifactResolver</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<role-hint>default</role-hint>
</requirement>
<requirement>
<role>org.codehaus.plexus.archiver.manager.ArchiverManager</role>
<role-hint>default</role-hint>
</requirement>
</requirements>
</component>

View File

@ -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;

View File

@ -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<Artifact> dependencies;
private List<ArtifactRepository> 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<ArtifactRepository> getRemoteRepos()
{
return remoteRepos;
}
public PluginToolsRequest setRemoteRepos( List<ArtifactRepository> remoteRepos )
{
this.remoteRepos = remoteRepos;
return this;
}
public ArtifactRepository getLocal()
{
return local;
}
public PluginToolsRequest setLocal( ArtifactRepository local )
{
this.local = local;
return this;
}
}

View File

@ -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<Artifact> getDependencies();
/**
*
* @param dependencies
* @return
* @since 3.0
*/
PluginToolsRequest setDependencies( Set<Artifact> dependencies );
/**
*
* @return
* @since 3.0
*/
List<ArtifactRepository> getRemoteRepos();
/**
*
* @param remoteRepos
* @return
* @since 3.0
*/
PluginToolsRequest setRemoteRepos( List<ArtifactRepository> remoteRepos );
/**
*
* @return
* @since 3.0
*/
ArtifactRepository getLocal();
/**
*
* @param local
* @return
* @since 3.0
*/
PluginToolsRequest setLocal( ArtifactRepository local );
}

View File

@ -228,6 +228,11 @@
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-9-stable-1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>