Skip to content

Commit

Permalink
issue55
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Sep 15, 2013
1 parent 2f7df43 commit 6106c78
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 17 deletions.
52 changes: 44 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>2.2.5-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<name>maven-processor-plugin - ${project.version}</name>
<description>A maven plugin to process annotation for jdk6 at compile time

This plugin helps to use from maven the new annotation processing provided by JDK6 integrated in java compiler

This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.codehaus.org/apt-maven-plugin/ </description>
<url>http://code.google.com/p/maven-annotation-plugin/</url>


<prerequisites>
<maven>3.0</maven>
</prerequisites>

<!--
LEGACY MAVEN2 REPORTING
Expand Down Expand Up @@ -106,12 +110,12 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
</dependency>


Expand All @@ -120,22 +124,54 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.1</version>
<version>3.2</version>
</dependency>
<!-- generated help mojo has a dependency to plexus-utils -->
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>3.0.1</version>
<version>3.0.15</version>
</dependency>


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<version>4.11</version>
<scope>test</scope>
</dependency>

<!--
===========================================================
AETHER
===========================================================
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<version>3.0.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-wagon</artifactId>
<version>1.11</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-connector-file</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>
<artifactId>aether-util</artifactId>
<version>1.13.1</version>
<scope>compile</scope>
</dependency>
-->

</dependencies>


Expand Down Expand Up @@ -192,7 +228,7 @@ MAVEN3 SITE GENERATION
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.1</version>
<version>3.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
Expand All @@ -36,6 +38,7 @@
import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.*;
import javax.tools.Diagnostic.Kind;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand All @@ -44,6 +47,15 @@
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.ArtifactType;
import org.eclipse.aether.artifact.ArtifactTypeRegistry;
import org.eclipse.aether.artifact.DefaultArtifact;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;


/**
Expand All @@ -53,7 +65,6 @@
*/
public abstract class AbstractAnnotationProcessorMojo extends AbstractMojo
{

interface ArtifactClosure {

void execute( Artifact artifact );
Expand Down Expand Up @@ -182,7 +193,48 @@ interface ArtifactClosure {
*/
@Parameter(property = "project.build.sourceEncoding")
private String encoding;


/**
* The entry point to Aether, i.e. the component doing all the work.
*
*/
@Component
private RepositorySystem repoSystem;

/**
* The current repository/network configuration of Maven.
*
*/
@Parameter( defaultValue = "${repositorySystemSession}",readonly = true )
private RepositorySystemSession repoSession;

/**
* The project's remote repositories to use for the resolution of plugins and their dependencies.
*
*/
@Parameter( defaultValue = "${project.remoteProjectRepositories}",readonly = true )
private List<RemoteRepository> remoteRepos;

/**
* List of artifacts on which perform sources scanning
*
* Each artifact must be specified in the form <b>grouId</b>:<b>artifactId</b>.
* If you need to include all artifacts belonging a groupId, specify as artifactId the character '*'
*
* <hr>
* e.g.
* <pre>
*
* org.bsc.maven:maven-confluence-plugin
* org.bsc.maven:*
*
* </pre>
*
* @since 2.2.5
*/
@Parameter()
private java.util.List<String> processSourceArtifacts = Collections.emptyList();

/**
* for execution synchronization
*/
Expand Down Expand Up @@ -286,7 +338,8 @@ public void execute() throws MojoExecutionException
}
catch (Exception e1)
{
super.getLog().error("error on execute: " + e1.getMessage());
super.getLog().error("error on execute: use -X to have details " );
super.getLog().debug(e1);
if (failOnError)
{
throw new MojoExecutionException("Error executing", e1);
Expand Down Expand Up @@ -624,18 +677,94 @@ private void ensureOutputDirectoryExists()
}
}

private boolean matchArtifact( Artifact dep/*, ArtifactFilter filter*/ ) {

if(processSourceArtifacts == null || processSourceArtifacts.isEmpty()) {
return false;
}

for( String a : processSourceArtifacts ) {

if( a == null || a.isEmpty() ) {
continue;
}

final String [] token = a.split(":");

final boolean matchGroupId = dep.getGroupId().equals(token[0]);

if( !matchGroupId ) {
continue;
}

if( token.length == 1 ) {
return true;
}

if( token[1].equals("*") ) {
return true;

}

return dep.getArtifactId().equals(token[1]);

}
return false;
}

private Artifact resolveSourceArtifact( Artifact dep ) throws ArtifactResolutionException {

if( !matchArtifact(dep) ) {
return null;
}

final ArtifactTypeRegistry typeReg = repoSession.getArtifactTypeRegistry();

final String extension = null;

final DefaultArtifact artifact =
new DefaultArtifact( dep.getGroupId(),
dep.getArtifactId(),
SOURCE_CLASSIFIER,
extension,
dep.getVersion(),
typeReg.get(dep.getType()));

final ArtifactRequest request = new ArtifactRequest();
request.setArtifact( artifact );
request.setRepositories(remoteRepos);

getLog().debug( String.format("Resolving artifact %s from %s", artifact, remoteRepos ));

final ArtifactResult result = repoSystem.resolveArtifact( repoSession, request );

return RepositoryUtils.toArtifact(result.getArtifact());
}

private void processSourceArtifacts( ArtifactClosure closure ) {
if( ! appendSourceArtifacts ) {
return;
}

for (Artifact dep : this.project.getDependencyArtifacts()) {
if ((dep.hasClassifier()) && (dep.getClassifier().equals(SOURCE_CLASSIFIER))) {

closure.execute(dep);
if (dep.hasClassifier() && SOURCE_CLASSIFIER.equals(dep.getClassifier()) ) {

if( appendSourceArtifacts ) {
closure.execute(dep);
}
//getLog().debug("Append source artifact to classpath: " + dep.getGroupId() + ":" + dep.getArtifactId());
//this.sourceArtifacts.add(dep.getFile());
}
else {
try {
final Artifact sourcesDep = resolveSourceArtifact(dep);
if( sourcesDep != null ) {
closure.execute(sourcesDep);
}

} catch (ArtifactResolutionException ex) {
getLog().warn( String.format(" sources for artifact [%s] not found!", dep.toString()));
getLog().debug(ex);

}
}
}
}

Expand Down

0 comments on commit 6106c78

Please sign in to comment.