Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add workaround to jdk bug https://bugs.openjdk.java.net/browse/JDK-8210649 found via https://issues.apache.org/jira/browse/MCOMPILER-346 add IT test from https://github.com/basil/MCOMPILER-346-mre #196

Merged
merged 6 commits into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plexus-compiler-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compiler-its/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-its</artifactId>
Expand Down
1 change: 1 addition & 0 deletions plexus-compiler-its/src/main/it/MCOMPILER-346-mre
Submodule MCOMPILER-346-mre added at 33fdb6
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<compilerId>eclipse</compilerId>
</configuration>
<dependencies>
<dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-api</artifactId>
<version>@pom.version@</version>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compiler-manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-manager</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compiler-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-test</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-aspectj/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-aspectj</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-csharp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-csharp</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-eclipse/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-eclipse</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-j2objc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-j2objc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-javac-errorprone</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/plexus-compiler-javac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compiler-javac</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.logging.LogEnabled;

public interface InProcessCompiler {
public interface InProcessCompiler extends LogEnabled {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to change that to be able to get logger.
The only usage of this in project is a manual construction of the only implementation available here and I bump version number.


CompilerResult compileInProcess(String[] args, final CompilerConfiguration config, String[] sourceFiles)
throws CompilerException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import org.codehaus.plexus.compiler.CompilerOutputStyle;
import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
Expand Down Expand Up @@ -106,6 +107,9 @@ public class JavacCompiler

private List<Class<?>> javaccClasses = new CopyOnWriteArrayList<>();

@Requirement
private InProcessCompiler inProcessCompiler;

// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -186,10 +190,10 @@ public CompilerResult performCompile( CompilerConfiguration config )
return result;
}

protected InProcessCompiler inProcessCompiler()
{
return new org.codehaus.plexus.compiler.javac.JavaxToolsCompiler();
}
protected InProcessCompiler inProcessCompiler()
{
return inProcessCompiler;
}

protected static boolean isJava16()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.codehaus.plexus.compiler.CompilerException;
import org.codehaus.plexus.compiler.CompilerResult;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.logging.AbstractLogEnabled;

import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
Expand All @@ -36,15 +37,16 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CopyOnWriteArrayList;

/**
* @author Olivier Lamy
* @author <a href="mailto:david.lloyd@redhat.com">David M. Lloyd</a>
* @since 2.0
*/
@Component( role = Compiler.class )
public class JavaxToolsCompiler implements InProcessCompiler
@Component( role = InProcessCompiler.class )
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a change but fix a bug to be able to use dependency injection for this...
it was simply wrong for very long but the only usage was new JavaxToolsCompiler() :)

public class JavaxToolsCompiler extends AbstractLogEnabled implements InProcessCompiler
{
/**
* is that thread safe ???
Expand Down Expand Up @@ -102,6 +104,7 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati
throws CompilerException
{
JavaCompiler compiler = getJavaCompiler( config );
CompilerResult compilerResult;
olamy marked this conversation as resolved.
Show resolved Hide resolved
try
{
if ( compiler == null )
Expand All @@ -111,14 +114,14 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati
CompilerMessage.Kind.ERROR );
return new CompilerResult( false, Collections.singletonList( message ) );
}
final String sourceEncoding = config.getSourceEncoding();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup removing useless final

final Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
final DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>();
try ( final StandardJavaFileManager standardFileManager =
String sourceEncoding = config.getSourceEncoding();
Charset sourceCharset = sourceEncoding == null ? null : Charset.forName( sourceEncoding );
DiagnosticCollector<JavaFileObject> collector = new DiagnosticCollector<>();
try ( StandardJavaFileManager standardFileManager =
compiler.getStandardFileManager( collector, null, sourceCharset ) )
{

final Iterable<? extends JavaFileObject> fileObjects =
Iterable<? extends JavaFileObject> fileObjects =
standardFileManager.getJavaFileObjectsFromStrings( Arrays.asList( sourceFiles ) );

/*(Writer out,
Expand All @@ -130,14 +133,27 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati

List<String> arguments = Arrays.asList( args );

final JavaCompiler.CompilationTask task =
JavaCompiler.CompilationTask task =
compiler.getTask( null, standardFileManager, collector, arguments, null, fileObjects );
final Boolean result = task.call();
final ArrayList<CompilerMessage> compilerMsgs = new ArrayList<>();
Boolean result = task.call();
List<CompilerMessage> compilerMsgs = new ArrayList<>();

for ( Diagnostic<? extends JavaFileObject> diagnostic : collector.getDiagnostics() )
{
CompilerMessage.Kind kind = convertKind(diagnostic);
String baseMessage = diagnostic.getMessage( null );
CompilerMessage.Kind kind = convertKind( diagnostic );

String baseMessage = null;
try
{
baseMessage = diagnostic.getMessage( Locale.getDefault() );
}
catch ( AssertionError e )
{
// workaround for https://bugs.openjdk.java.net/browse/JDK-8210649
getLogger().debug( "Ignore Issue get JavaCompiler Diagnostic message (see https://bugs.openjdk.java.net/browse/JDK-8210649):" + e.getMessage(), e );
// in this case we try to replace the baseMessage with toString (hoping this does not throw a new exception..
baseMessage = diagnostic.toString();
}
if ( baseMessage == null )
{
continue;
Expand Down Expand Up @@ -185,7 +201,6 @@ public CompilerResult compileInProcess( String[] args, final CompilerConfigurati
finally
{
releaseJavaCompiler( compiler, config );

}
}

Expand Down
2 changes: 1 addition & 1 deletion plexus-compilers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
</parent>

<artifactId>plexus-compilers</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>plexus-compiler</artifactId>
<version>2.10.1-SNAPSHOT</version>
<version>2.11.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Plexus Compiler</name>
Expand Down Expand Up @@ -45,7 +45,7 @@
<scm.url>scm:git:git@github.com:codehaus-plexus/plexus-compiler.git</scm.url>
<javaVersion>11</javaVersion>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<project.build.outputTimestamp>2022-02-08T11:49:09Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2022-03-06T00:54:21Z</project.build.outputTimestamp>
<jupiter.version>5.8.2</jupiter.version>
<aspectj.version>1.9.7.M3</aspectj.version>
<errorprone.version>2.11.0</errorprone.version>
Expand Down