use artifacts for scanning for future use

git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/branches/MPLUGIN-189@1335764 13f79535-47bb-0310-9956-ffa450edef68
master
Olivier Lamy 2012-05-08 21:00:44 +00:00
parent 77a87b0236
commit 18e8cb4178
6 changed files with 84 additions and 34 deletions

View File

@ -19,6 +19,7 @@ package org.apache.maven.plugin.plugin;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
@ -123,6 +124,16 @@ public abstract class AbstractGeneratorMojo
*/ */
protected boolean skip; protected boolean skip;
/**
* The set of dependencies for the current project
*
* @parameter default-value = "${project.artifacts}"
* @required
* @readonly
* @since 3.0
*/
protected Set<Artifact> dependencies;
/** /**
* @return the output directory where files will be generated. * @return the output directory where files will be generated.
*/ */
@ -203,6 +214,7 @@ public abstract class AbstractGeneratorMojo
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
request.setEncoding( encoding ); request.setEncoding( encoding );
request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound ); request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound );
request.setDependencies( dependencies );
mojoScanner.populatePluginDescriptor( request ); mojoScanner.populatePluginDescriptor( request );

View File

@ -22,7 +22,6 @@ import com.thoughtworks.qdox.JavaDocBuilder;
import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaField; import com.thoughtworks.qdox.model.JavaField;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.descriptor.DuplicateParameterException; import org.apache.maven.plugin.descriptor.DuplicateParameterException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
@ -75,15 +74,13 @@ public class JavaAnnotationsMojoDescriptorExtractor
public List<MojoDescriptor> execute( PluginToolsRequest request ) public List<MojoDescriptor> execute( PluginToolsRequest request )
throws ExtractionException, InvalidPluginDescriptorException throws ExtractionException, InvalidPluginDescriptorException
{ {
try
{
MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest(); MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
mojoAnnotationsScannerRequest.setClassesDirectories( mojoAnnotationsScannerRequest.setClassesDirectories(
Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) ); Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) );
mojoAnnotationsScannerRequest.setDependencies( mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() );
toFiles( request.getProject().getCompileClasspathElements() ) );
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses = Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest ); mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
@ -93,11 +90,7 @@ public class JavaAnnotationsMojoDescriptorExtractor
populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap ); populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
return toMojoDescriptors( mojoAnnotatedClasses, request ); return toMojoDescriptors( mojoAnnotatedClasses, request );
}
catch ( DependencyResolutionRequiredException e )
{
throw new ExtractionException( e.getMessage(), e );
}
} }
/** /**

View File

@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Execute; import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Mojo;
@ -66,17 +67,20 @@ public class DefaultMojoAnnotationsScanner
try try
{ {
for ( File dependency : request.getDependencies() ) for ( Artifact dependency : request.getDependencies() )
{ {
if ( dependency.isDirectory() ) File dependencyFile = dependency.getFile();
if ( dependencyFile != null && dependencyFile.exists() )
{ {
mojoAnnotatedClasses.putAll( scanDirectory( dependency, request.getIncludePatterns() ) ); if ( dependencyFile.isDirectory() )
{
mojoAnnotatedClasses.putAll( scanDirectory( dependencyFile, request.getIncludePatterns() ) );
} }
else else
{ {
mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns() ) ); mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns() ) );
}
} }
} }
for ( File classDirectory : request.getClassesDirectories() ) for ( File classDirectory : request.getClassesDirectories() )

View File

@ -18,10 +18,14 @@ package org.apache.maven.tools.plugin.annotations.scanner;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author Olivier Lamy * @author Olivier Lamy
@ -31,7 +35,7 @@ public class MojoAnnotationsScannerRequest
{ {
private List<File> classesDirectories = new ArrayList<File>(); private List<File> classesDirectories = new ArrayList<File>();
private List<File> dependencies = new ArrayList<File>(); private Set<Artifact> dependencies = new HashSet<Artifact>();
private List<String> includePatterns = Arrays.asList( "**/*.class" ); private List<String> includePatterns = Arrays.asList( "**/*.class" );
@ -52,12 +56,12 @@ public class MojoAnnotationsScannerRequest
this.classesDirectories = classesDirectories; this.classesDirectories = classesDirectories;
} }
public List<File> getDependencies() public Set<Artifact> getDependencies()
{ {
return dependencies; return dependencies;
} }
public void setDependencies( List<File> dependencies ) public void setDependencies( Set<Artifact> dependencies )
{ {
this.dependencies = dependencies; this.dependencies = dependencies;
} }

View File

@ -19,12 +19,16 @@ package org.apache.maven.tools.plugin;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.StringUtils;
import java.util.HashSet;
import java.util.Set;
/** /**
* Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract * Default implementation of {@link PluginToolsRequest}, which is used to pass parameters to components used to extract
* {@link MojoDescriptor} instances from different types of metadata for a given plugin. * {@link MojoDescriptor} instances from different types of metadata for a given plugin.
@ -46,6 +50,8 @@ public class DefaultPluginToolsRequest
private boolean skipErrorNoDescriptorsFound; private boolean skipErrorNoDescriptorsFound;
private Set<Artifact> dependencies;
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor ) public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
{ {
this.project = project; this.project = project;
@ -127,4 +133,19 @@ public class DefaultPluginToolsRequest
this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound; this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
return this; return this;
} }
public Set<Artifact> getDependencies()
{
if ( this.dependencies == null )
{
this.dependencies = new HashSet<Artifact>();
}
return dependencies;
}
public PluginToolsRequest setDependencies( Set<Artifact> dependencies )
{
this.dependencies = dependencies;
return this;
}
} }

View File

@ -19,10 +19,13 @@ package org.apache.maven.tools.plugin;
* under the License. * under the License.
*/ */
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.descriptor.MojoDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import java.util.Set;
/** /**
* Request that encapsulates all information relevant to the process of extracting {@link MojoDescriptor} * Request that encapsulates all information relevant to the process of extracting {@link MojoDescriptor}
* instances from metadata for a certain type of mojo. * instances from metadata for a certain type of mojo.
@ -74,16 +77,29 @@ public interface PluginToolsRequest
* By default an exception is throw if no mojo descriptor is found. As the maven-plugin is defined in core, the * 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. * descriptor generator mojo is bound to generate-resources phase.
* But for annotations, the compiled classes are needed, so skip error * But for annotations, the compiled classes are needed, so skip error
*
* @since 3.0 * @since 3.0
*/ */
PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound ); PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound );
/** /**
* @since 3.0
* @return * @return
* @since 3.0
*/ */
boolean isSkipErrorNoDescriptorsFound(); boolean isSkipErrorNoDescriptorsFound();
/**
* Returns the list of {@link Artifact} used in class path scanning for annotations
* @return
* @since 3.0
*/
Set<Artifact> getDependencies();
/**
*
* @param dependencies
* @return
*/
PluginToolsRequest setDependencies( Set<Artifact> dependencies );
} }