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-ffa450edef68master
parent
77a87b0236
commit
18e8cb4178
|
|
@ -19,6 +19,7 @@ package org.apache.maven.plugin.plugin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
|
||||
|
|
@ -123,6 +124,16 @@ public abstract class AbstractGeneratorMojo
|
|||
*/
|
||||
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.
|
||||
*/
|
||||
|
|
@ -203,6 +214,7 @@ public abstract class AbstractGeneratorMojo
|
|||
PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
|
||||
request.setEncoding( encoding );
|
||||
request.setSkipErrorNoDescriptorsFound( skipErrorNoDescriptorsFound );
|
||||
request.setDependencies( dependencies );
|
||||
|
||||
mojoScanner.populatePluginDescriptor( request );
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import com.thoughtworks.qdox.JavaDocBuilder;
|
|||
import com.thoughtworks.qdox.model.DocletTag;
|
||||
import com.thoughtworks.qdox.model.JavaClass;
|
||||
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.InvalidPluginDescriptorException;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
|
|
@ -75,29 +74,23 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
|||
public List<MojoDescriptor> execute( PluginToolsRequest request )
|
||||
throws ExtractionException, InvalidPluginDescriptorException
|
||||
{
|
||||
try
|
||||
{
|
||||
MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
|
||||
|
||||
mojoAnnotationsScannerRequest.setClassesDirectories(
|
||||
Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) );
|
||||
MojoAnnotationsScannerRequest mojoAnnotationsScannerRequest = new MojoAnnotationsScannerRequest();
|
||||
|
||||
mojoAnnotationsScannerRequest.setDependencies(
|
||||
toFiles( request.getProject().getCompileClasspathElements() ) );
|
||||
mojoAnnotationsScannerRequest.setClassesDirectories(
|
||||
Arrays.asList( new File( request.getProject().getBuild().getOutputDirectory() ) ) );
|
||||
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
|
||||
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
|
||||
mojoAnnotationsScannerRequest.setDependencies( request.getDependencies() );
|
||||
|
||||
Map<String, JavaClass> javaClassesMap = discoverClasses( request );
|
||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses =
|
||||
mojoAnnotationsScanner.scan( mojoAnnotationsScannerRequest );
|
||||
|
||||
populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
|
||||
Map<String, JavaClass> javaClassesMap = discoverClasses( request );
|
||||
|
||||
populateDataFromJavadoc( mojoAnnotatedClasses, javaClassesMap );
|
||||
|
||||
return toMojoDescriptors( mojoAnnotatedClasses, request );
|
||||
|
||||
return toMojoDescriptors( mojoAnnotatedClasses, request );
|
||||
}
|
||||
catch ( DependencyResolutionRequiredException e )
|
||||
{
|
||||
throw new ExtractionException( e.getMessage(), e );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package org.apache.maven.tools.plugin.annotations.scanner;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.apache.maven.plugins.annotations.Execute;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
|
|
@ -66,17 +67,20 @@ public class DefaultMojoAnnotationsScanner
|
|||
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
|
||||
{
|
||||
mojoAnnotatedClasses.putAll( scanFile( dependencyFile, request.getIncludePatterns() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mojoAnnotatedClasses.putAll( scanFile( dependency, request.getIncludePatterns() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for ( File classDirectory : request.getClassesDirectories() )
|
||||
|
|
|
|||
|
|
@ -18,10 +18,14 @@ package org.apache.maven.tools.plugin.annotations.scanner;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Olivier Lamy
|
||||
|
|
@ -31,7 +35,7 @@ public class MojoAnnotationsScannerRequest
|
|||
{
|
||||
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" );
|
||||
|
||||
|
|
@ -52,12 +56,12 @@ public class MojoAnnotationsScannerRequest
|
|||
this.classesDirectories = classesDirectories;
|
||||
}
|
||||
|
||||
public List<File> getDependencies()
|
||||
public Set<Artifact> getDependencies()
|
||||
{
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public void setDependencies( List<File> dependencies )
|
||||
public void setDependencies( Set<Artifact> dependencies )
|
||||
{
|
||||
this.dependencies = dependencies;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,23 +19,27 @@ package org.apache.maven.tools.plugin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.codehaus.plexus.util.ReaderFactory;
|
||||
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
|
||||
* {@link MojoDescriptor} instances from different types of metadata for a given plugin.
|
||||
*
|
||||
*
|
||||
* @author jdcasey
|
||||
* @since 2.5
|
||||
*/
|
||||
public class DefaultPluginToolsRequest
|
||||
implements PluginToolsRequest
|
||||
{
|
||||
|
||||
|
||||
private static final String DEFAULT_ENCODING = ReaderFactory.FILE_ENCODING;
|
||||
|
||||
private PluginDescriptor pluginDescriptor;
|
||||
|
|
@ -46,6 +50,8 @@ public class DefaultPluginToolsRequest
|
|||
|
||||
private boolean skipErrorNoDescriptorsFound;
|
||||
|
||||
private Set<Artifact> dependencies;
|
||||
|
||||
public DefaultPluginToolsRequest( MavenProject project, PluginDescriptor pluginDescriptor )
|
||||
{
|
||||
this.project = project;
|
||||
|
|
@ -59,7 +65,7 @@ public class DefaultPluginToolsRequest
|
|||
{
|
||||
return pluginDescriptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
@ -76,7 +82,7 @@ public class DefaultPluginToolsRequest
|
|||
{
|
||||
return project;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
@ -127,4 +133,19 @@ public class DefaultPluginToolsRequest
|
|||
this.skipErrorNoDescriptorsFound = skipErrorNoDescriptorsFound;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@ package org.apache.maven.tools.plugin;
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Request that encapsulates all information relevant to the process of extracting {@link MojoDescriptor}
|
||||
* 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
|
||||
* descriptor generator mojo is bound to generate-resources phase.
|
||||
* But for annotations, the compiled classes are needed, so skip error
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
PluginToolsRequest setSkipErrorNoDescriptorsFound( boolean skipErrorNoDescriptorsFound );
|
||||
|
||||
/**
|
||||
* @since 3.0
|
||||
* @return
|
||||
* @since 3.0
|
||||
*/
|
||||
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 );
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue