Skip to content

Commit

Permalink
Merge branch 'release/3.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Apr 11, 2017
2 parents 344d377 + 91113cb commit 31dd746
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 94 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 kishikawa katsumi <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
[m2e-annotations](https://github.com/ilx/m2e-annotations) | eclipse plugin

## Releases ##
Apr 11,2017 | **Release 3.3.1**. | Available on **[MAVEN CENTRAL REPO](http://search.maven.org/#artifactdetails%7Corg.bsc.maven%7Cmaven-processor-plugin%7C3.3.1%7Cmaven-plugin)** |
----|----|----

* [Issue 66](https://github.com/bsorrentino/maven-annotation-plugin/issues/66) - source 1.8 ignored
* [Issue 67](https://github.com/bsorrentino/maven-annotation-plugin/issues/67) - options are not taking in consideration

Apr 10,2017 | **Release 3.3**. | Available on **[MAVEN CENTRAL REPO](http://search.maven.org/#artifactdetails%7Corg.bsc.maven%7Cmaven-processor-plugin%7C3.3%7Cmaven-plugin)** |
----|----|----

Expand Down
2 changes: 1 addition & 1 deletion 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.3</version>
<version>3.3.1</version>
<name>MAVEN PROCESSOR PLUGIN - ${project.version}</name>
<description>A maven plugin to process annotation for jdk6 at compile time

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
Expand All @@ -45,6 +46,7 @@
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.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.bsc.function.Consumer;
import org.codehaus.plexus.compiler.manager.CompilerManager;
Expand Down Expand Up @@ -263,6 +265,11 @@ interface ArtifactClosure {
* Allows running the compiler in a separate process.
* If false it uses the built in compiler, while if true it will use an executable.
*
* to set source and target use
* <pre>
* maven.processor.source
* maven.processor.target
* </pre>
* @since 3.3
*/
@Parameter(defaultValue = "false", property = "fork")
Expand Down Expand Up @@ -428,6 +435,54 @@ public void execute() throws MojoExecutionException

}

/**
* TODO remove the part with ToolchainManager lookup once we depend on
* 3.0.9 (have it as prerequisite). Define as regular component field then.
*
* @param jdkToolchain
*/
private Toolchain getToolchain(final Map<String, String> jdkToolchain)
{
Toolchain tc = null;

if ( jdkToolchain != null && !jdkToolchain.isEmpty())
{
// Maven 3.3.1 has plugin execution scoped Toolchain Support
try
{
final Method getToolchainsMethod =
toolchainManager.getClass().getMethod( "getToolchains",
MavenSession.class,
String.class,
Map.class );

@SuppressWarnings( "unchecked" )
final List<Toolchain> tcs =
(List<Toolchain>) getToolchainsMethod.invoke( toolchainManager,
session,
"jdk",
jdkToolchain );

if ( tcs != null && tcs.size() > 0 )
{
tc = tcs.get( 0 );
}
}
catch ( Exception e )
{
// ignore
}
}

if ( tc == null )
{
tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
}

return tc;
}


@SuppressWarnings("unchecked")
private void executeWithExceptionsHandled() throws Exception
{
Expand Down Expand Up @@ -615,19 +670,28 @@ public void execute(Artifact artifact) {
}
}
});

final java.util.Map<String,String> jdkToolchain =
java.util.Collections.emptyMap();

final Toolchain tc = getToolchain(jdkToolchain);

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

if( fork ) {
getLog().debug( "PROCESSOR COMPILER FORKED!");
}

//compileLock.lock();
try {


final JavaCompiler compiler = (fork) ?
AnnotationProcessorCompiler.createOutProcess(
toolchainManager,
tc,
compilerManager,
project,
session ) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.annotation.processing.Processor;
import javax.lang.model.SourceVersion;
Expand All @@ -26,7 +23,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerMessage;
Expand Down Expand Up @@ -230,6 +226,7 @@ protected CompilerResult performCompile( CompilerConfiguration config ) throws C

final String[] compilerArguments =
org.codehaus.plexus.compiler.javac.JavacCompiler.buildCompilerArguments(config, getSourceFiles(config) );

return compileOutOfProcess( config, getJavacExecutable(config), compilerArguments );

}
Expand All @@ -253,15 +250,15 @@ public class AnnotationProcessorCompiler implements JavaCompiler {
final MavenProject project;
final MavenSession session;
final CompilerManager plexusCompiler;
final ToolchainManager toolchainManager;
final Toolchain toolchain;

public static JavaCompiler createOutProcess( ToolchainManager toolchainManager,
public static JavaCompiler createOutProcess( Toolchain toolchain,
CompilerManager plexusCompiler,
MavenProject project,
MavenSession session )
{

return new AnnotationProcessorCompiler( toolchainManager, plexusCompiler, project, session);
return new AnnotationProcessorCompiler( toolchain, plexusCompiler, project, session);
}

public static JavaCompiler createInProcess() {
Expand All @@ -285,50 +282,7 @@ private static void printCommand( final org.codehaus.plexus.compiler.Compiler j
}


//TODO remove the part with ToolchainManager lookup once we depend on
//3.0.9 (have it as prerequisite). Define as regular component field then.
private Toolchain getToolchain(final Map<String, String> jdkToolchain)
{
Toolchain tc = null;

if ( jdkToolchain != null && !jdkToolchain.isEmpty())
{
// Maven 3.3.1 has plugin execution scoped Toolchain Support
try
{
final Method getToolchainsMethod =
toolchainManager.getClass().getMethod( "getToolchains",
MavenSession.class,
String.class,
Map.class );

@SuppressWarnings( "unchecked" )
final List<Toolchain> tcs =
(List<Toolchain>) getToolchainsMethod.invoke( toolchainManager,
session,
"jdk",
jdkToolchain );

if ( tcs != null && tcs.size() > 0 )
{
tc = tcs.get( 0 );
}
}
catch ( Exception e )
{
// ignore
}
}

if ( tc == null )
{
tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
}

return tc;
}

private AnnotationProcessorCompiler( ToolchainManager toolchainManager,
private AnnotationProcessorCompiler( Toolchain toolchain,
CompilerManager plexusCompiler,
MavenProject project,
MavenSession session )
Expand All @@ -337,7 +291,7 @@ private AnnotationProcessorCompiler( ToolchainManager toolchainManager,
this.project = project;
this.session = session;
this.plexusCompiler = plexusCompiler;
this.toolchainManager = toolchainManager;
this.toolchain = toolchain;

}

Expand All @@ -354,7 +308,6 @@ private void execute( final Iterable<String> options,
final java.util.Iterator<String> ii = options.iterator();

while( ii.hasNext() ) {

final String option = ii.next();

if( "-cp".equals(option)) {
Expand Down Expand Up @@ -386,7 +339,10 @@ else if( "-d".equals(option) ) {
else if( "-s".equals(option) ) {
javacConf.setGeneratedSourcesDirectory( new java.io.File(ii.next()));
}

else if( option.startsWith("-A") ) {
javacConf.addCompilerCustomArgument(option, "");

}
final java.util.Properties props = project.getProperties();

final String sourceVersion = props.getProperty(PROCESSOR_SOURCE,props.getProperty(COMPILER_SOURCE, DEFAULT_SOURCE_VERSION));
Expand All @@ -409,19 +365,12 @@ else if( "-s".equals(option) ) {
javacConf.setFork(true);
javacConf.setVerbose(false);

if( toolchainManager != null ) {
final java.util.Map<String,String> jdkToolchain =
java.util.Collections.emptyMap();

final Toolchain tc = getToolchain( jdkToolchain );

if( tc!=null ) {
final String executable = tc.findTool( "javac");
//out.print( "==> TOOLCHAIN EXECUTABLE: "); out.println( executable );
javacConf.setExecutable(executable);
}

if( toolchain != null ) {
final String executable = toolchain.findTool( "javac");
//out.print( "==> TOOLCHAIN EXECUTABLE: "); out.println( executable );
javacConf.setExecutable(executable);
}

CompilerResult result;

// USING STANDARD PLEXUS
Expand Down
Loading

0 comments on commit 31dd746

Please sign in to comment.