Skip to content

Commit

Permalink
issue #82 - JDK8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bsorrentino committed Jul 22, 2020
1 parent a813a22 commit 8117a6b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 75 deletions.
29 changes: 27 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
</distributionManagement>

<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- SONATYPE REPO -->
<snapshot.repo.id>sonatype-repo</snapshot.repo.id>
Expand Down Expand Up @@ -238,6 +236,33 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo.
</plugins>
</build>
</profile>

<!-- exact JDK 1.8 -->
<profile>
<id>JDK8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

</profile>

<!-- Equal and Greater Than of JDK 1.9 -->
<profile>
<id>JDK9.and.beyond</id>
<activation>
<jdk>[1.9,)</jdk>
</activation>
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
</profile>

</profiles>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,72 @@ private Toolchain getToolchain(final Map<String, String> jdkToolchain)
return tc;
}


private List<String> prepareOptions( JavaCompiler compiler ) {

final List<String> options = new ArrayList<>(10);

final String compileClassPath = buildCompileClasspath();

final String processor = buildProcessor();

options.add("-cp");
options.add(compileClassPath);

if( compiler.isSupportedOption("--module-path") == 1 ) {
options.add("--module-path");
options.add(buildModulePath());
}

buildCompileSourcepath( sourcepath -> {
options.add("-sourcepath");
options.add(sourcepath);
});

options.add("-proc:only");

addCompilerArguments(options);

if (processor != null) {
options.add("-processor");
options.add(processor);
}
else
{
getLog().warn("No processors specified. Using default discovery mechanism.");
}
options.add("-d");
options.add(getOutputClassDirectory().getPath());

options.add("-s");
options.add(outputDirectory.getPath());

ofNullable(releaseVersion).ifPresent( release -> {
options.add("--release");
options.add( releaseVersion );
});

ofNullable(project.getProperties()).ifPresent( properties -> {

ofNullable(properties.getProperty( "maven.compiler.source" )).ifPresent( source -> {
options.add("-source");
options.add(source);
});
ofNullable(properties.getProperty( "maven.compiler.target" )) .ifPresent( target -> {
options.add("-target");
options.add(target);
});
});

if( getLog().isDebugEnabled() ) {
for (String option : options) {
getLog().debug(String.format("javac option: %s", option));
}
}

return options;

}

private void executeWithExceptionsHandled() throws Exception
{
if (outputDirectory == null)
Expand Down Expand Up @@ -559,64 +624,6 @@ private void executeWithExceptionsHandled() throws Exception
files.addAll( FileUtils.getFiles(sourceDir, includesString, excludesString) );
}

final String compileClassPath = buildCompileClasspath();

final String processor = buildProcessor();

final List<String> options = new ArrayList<>(10);

options.add("-cp");
options.add(compileClassPath);

options.add("--module-path");
options.add( buildModulePath() );

buildCompileSourcepath( sourcepath -> {
options.add("-sourcepath");
options.add(sourcepath);
});

options.add("-proc:only");

addCompilerArguments(options);

if (processor != null) {
options.add("-processor");
options.add(processor);
}
else
{
getLog().warn("No processors specified. Using default discovery mechanism.");
}
options.add("-d");
options.add(getOutputClassDirectory().getPath());

options.add("-s");
options.add(outputDirectory.getPath());

ofNullable(releaseVersion).ifPresent( release -> {
options.add("--release");
options.add( releaseVersion );
});

ofNullable(project.getProperties()).ifPresent( properties -> {

ofNullable(properties.getProperty( "maven.compiler.source" )).ifPresent( source -> {
options.add("-source");
options.add(source);
});
ofNullable(properties.getProperty( "maven.compiler.target" )) .ifPresent( target -> {
options.add("-target");
options.add(target);
});
});

if( getLog().isDebugEnabled() ) {
for (String option : options) {
getLog().debug(String.format("javac option: %s", option));
}
}

final DiagnosticListener<JavaFileObject> dl = diagnostic -> {

if (!outputDiagnostics) {
Expand Down Expand Up @@ -704,8 +711,7 @@ private void executeWithExceptionsHandled() throws Exception

//compileLock.lock();
try {



final JavaCompiler compiler = (fork) ?
AnnotationProcessorCompiler.createOutProcess(
tc,
Expand All @@ -719,7 +725,8 @@ private void executeWithExceptionsHandled() throws Exception
getLog().error("JVM is not suitable for processing annotation! ToolProvider.getSystemJavaCompiler() is null.");
return;
}



Charset charset = null; ;

if( encoding != null ) {
Expand Down Expand Up @@ -755,7 +762,9 @@ private void executeWithExceptionsHandled() throws Exception
getLog().warn( "no source file(s) detected! Processor task will be skipped");
return;
}


final List<String> options = prepareOptions( compiler );

final CompilationTask task = compiler.getTask(
new PrintWriter(System.out),
fileManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,14 @@ public void setLocale(Locale locale) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override
// from JDK9
//@Override
public void addModules(Iterable<String> moduleNames) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

@Override

// from JDK9
//@Override
public Boolean call() {
try {
return execute(options, compilationUnits, out);
Expand Down
11 changes: 5 additions & 6 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
<artifactId>maven-processor-plugin-test</artifactId>
<packaging>jar</packaging>
<name>MAVEN PROCESSOR PLUGIN TEST</name>
<version>4.0-SNAPSHOT</version>
<description></description>

<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin-parent</artifactId>
<version>4.1-SNAPSHOT</version>
</parent>

<dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
*
*
*/
@SupportedSourceVersion(SourceVersion.RELEASE_9)
//@SupportedSourceVersion(SourceVersion.RELEASE_9)
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@SupportedAnnotationTypes( "*" )
//@SupportedOptions( {"subfolder", "filepath", "templateUri"})
//@SupportedAnnotationTypes( {"javax.ws.rs.GET", "javax.ws.rs.PUT", "javax.ws.rs.POST", "javax.ws.rs.DELETE"})
Expand Down

0 comments on commit 8117a6b

Please sign in to comment.