Skip to content

Commit

Permalink
Merge branch 'feature/issue#65' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Apr 9, 2017
2 parents 3504296 + 4e81968 commit 9d4e359
Show file tree
Hide file tree
Showing 5 changed files with 756 additions and 98 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
.classpath
.project
.settings/
branch.sh
release.sh
sign-and-deploy.sh
*.sh
target/
issue47.txt
pom.xml.versionsBackup
maven-compiler-plugin/
35 changes: 33 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>3.2.1-SNAPSHOT</version>
<version>3.3-SNAPSHOT</version>
<name>MAVEN PROCESSOR PLUGIN - ${project.version}</name>
<description>A maven plugin to process annotation for jdk6 at compile time

Expand Down Expand Up @@ -80,6 +80,26 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
</license>
</licenses>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
<version>2.8.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
Expand All @@ -104,7 +124,18 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
<artifactId>plexus-utils</artifactId>
<version>3.0.15</version>
</dependency>

<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-manager</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@
import javax.tools.Diagnostic.Kind;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.ToolchainManager;
import org.bsc.function.Consumer;
import org.codehaus.plexus.compiler.manager.CompilerManager;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;

Expand Down Expand Up @@ -256,6 +259,38 @@ interface ArtifactClosure {
@Parameter(defaultValue = "false", property = "skipAnnotationProcessing")
protected boolean skip;

/**
* Allows running the compiler in a separate process.
* If false it uses the built in compiler, while if true it will use an executable.
*
* @since 3.3
*/
@Parameter(defaultValue = "false", property = "fork")
protected boolean fork;

/**
* Maven Session
*
* @since 3.3
*/
@Component
protected MavenSession session;

/**
* Plexus compiler manager.
*
* @since 3.3
*/
@Component
protected CompilerManager compilerManager;

/**
*
* @since 3.3
*/
@Component
private ToolchainManager toolchainManager;

/**
* for execution synchronization
*/
Expand Down Expand Up @@ -502,6 +537,7 @@ public void accept(String sourcepath) {

final DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>()
{
@Override
public void report(Diagnostic< ? extends JavaFileObject> diagnostic) {

if (!outputDiagnostics) {
Expand All @@ -510,22 +546,23 @@ public void report(Diagnostic< ? extends JavaFileObject> diagnostic) {

final Kind kind = diagnostic.getKind();

if (Kind.ERROR == kind) {

getLog().error(String.format("diagnostic: %s", diagnostic));

} else if (Kind.MANDATORY_WARNING == kind || Kind.WARNING == kind) {

getLog().warn(String.format("diagnostic: %s", diagnostic));

} else if (Kind.NOTE == kind) {

getLog().info(String.format("diagnostic: %s", diagnostic));

} else if (Kind.OTHER == kind) {

getLog().info(String.format("diagnostic: %s", diagnostic));

if (null != kind)
switch (kind) {
case ERROR:
getLog().error(String.format("diagnostic: %s", diagnostic));
break;
case MANDATORY_WARNING:
case WARNING:
getLog().warn(String.format("diagnostic: %s", diagnostic));
break;
case NOTE:
getLog().info(String.format("diagnostic: %s", diagnostic));
break;
case OTHER:
getLog().info(String.format("diagnostic: %s", diagnostic));
break;
default:
break;
}

}
Expand All @@ -550,6 +587,7 @@ public void report(Diagnostic< ? extends JavaFileObject> diagnostic) {

processSourceArtifacts( new ArtifactClosure() {

@Override
public void execute(Artifact artifact) {
try {

Expand Down Expand Up @@ -578,9 +616,23 @@ public void execute(Artifact artifact) {
}
});

// If toolchain is set force fork compilation
if( toolchainManager != null ) {
fork = true;
}

//compileLock.lock();
try {
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();


final JavaCompiler compiler = (fork) ?
AnnotationProcessorCompiler.createOutProcess(
toolchainManager,
compilerManager,
project,
session ) :
AnnotationProcessorCompiler.createInProcess();


if( compiler==null ) {
getLog().error("JVM is not suitable for processing annotation! ToolProvider.getSystemJavaCompiler() is null.");
Expand Down

0 comments on commit 9d4e359

Please sign in to comment.