From 8d6d9c34e0c572273e23eb02daf4bec845160180 Mon Sep 17 00:00:00 2001 From: bartolomeo sorrentino Date: Fri, 17 Apr 2020 01:37:10 +0200 Subject: [PATCH] issue #80 add support of javac option --module-path --- .../AbstractAnnotationProcessorMojo.java | 32 ++++++++++++++++--- .../MainAnnotationProcessorMojo.java | 15 ++++++--- .../TestAnnotationProcessorMojo.java | 13 ++++++-- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java index 56f0a72..6a59f84 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java @@ -34,6 +34,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; +import java.util.stream.Collector; +import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import javax.tools.JavaCompiler.CompilationTask; @@ -358,6 +360,8 @@ private String buildProcessor() return result.toString(); } + protected abstract java.util.Set getResourcesElements( java.util.Set result ); + protected abstract java.util.Set getClasspathElements( java.util.Set result ); private String buildCompileSourcepath( Consumer onSuccess) { @@ -379,7 +383,11 @@ private String buildCompileClasspath() { final java.util.Set pathElements = new java.util.LinkedHashSet<>(); - + + getResourcesElements(pathElements); + + getClasspathElements(pathElements); + if( pluginArtifacts!=null ) { for( Artifact a : pluginArtifacts ) { @@ -389,13 +397,13 @@ private String buildCompileClasspath() java.io.File f = a.getFile(); if( f!=null ) pathElements.add( a.getFile().getAbsolutePath() ); + } } } - - getClasspathElements(pathElements); - + + final StringBuilder result = new StringBuilder(); for( String elem : pathElements ) { @@ -404,6 +412,13 @@ private String buildCompileClasspath() return result.toString(); } + private String buildModulePath() + { + + return getClasspathElements(new java.util.LinkedHashSet<>()) + .stream() + .collect(Collectors.joining( File.pathSeparator) ); + } /** * @@ -557,7 +572,10 @@ private void executeWithExceptionsHandled() throws Exception options.add("-cp"); options.add(compileClassPath); - + + options.add("--module-path"); + options.add( buildModulePath() ); + buildCompileSourcepath( sourcepath -> { options.add("-sourcepath"); options.add(sourcepath); @@ -586,6 +604,10 @@ private void executeWithExceptionsHandled() throws Exception options.add( releaseVersion ); } + options.add("-source"); + options.add("9"); + options.add("-target"); + options.add("9"); if( getLog().isDebugEnabled() ) { for (String option : options) { diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java index a8ac2b3..fea224c 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/MainAnnotationProcessorMojo.java @@ -20,6 +20,8 @@ import java.io.File; import java.util.List; +import java.util.Set; + import org.apache.maven.model.Resource; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -94,10 +96,8 @@ public java.util.Set getSourceDirectories( final java.util.Set resul } @Override - @SuppressWarnings("unchecked") - protected java.util.Set getClasspathElements( final java.util.Set result) { - - List resources = project.getResources(); + protected Set getResourcesElements(Set result) { + final List resources = project.getResources(); if( resources!=null ) { for( Resource r : resources ) { @@ -105,6 +105,13 @@ protected java.util.Set getClasspathElements( final java.util.Set getClasspathElements( final java.util.Set result) { + result.addAll( classpathElements ); return result; diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java index ebdd5cd..a06aafe 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/TestAnnotationProcessorMojo.java @@ -20,6 +20,8 @@ import java.io.File; import java.util.List; +import java.util.Set; + import org.apache.maven.model.Resource; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -92,10 +94,8 @@ public java.util.Set getSourceDirectories( final java.util.Set resul return result; } - - @SuppressWarnings("unchecked") @Override - protected java.util.Set getClasspathElements( final java.util.Set result ) { + protected Set getResourcesElements(Set result) { final List resources = project.getTestResources(); if( resources!=null ) { @@ -104,6 +104,13 @@ protected java.util.Set getClasspathElements( final java.util.Set getClasspathElements( final java.util.Set result ) { + result.addAll( classpathElements ); return result;