Skip to content
Snippets Groups Projects
Commit 67de3a19 authored by Emmanuel Bourg's avatar Emmanuel Bourg
Browse files

New upstream version 2.8.5

parent 4dd474ca
No related branches found
Tags upstream/2.8.5
No related merge requests found
Showing
with 268 additions and 40 deletions
The canonical git repository is located at https://github.com/codehaus-plexus/plexus-compiler Plexus-Compiler
===============
[![Apache License, Version 2.0, January 2004](https://img.shields.io/github/license/codehaus-plexus/plexus-compiler.svg?label=License)](http://www.apache.org/licenses/)
[![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-compiler.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.codehaus.plexus%22%20a%3A%22plexus-compiler%22)
[![Build Status](https://travis-ci.org/codehaus-plexus/plexus-compiler.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-compiler) [![Build Status](https://travis-ci.org/codehaus-plexus/plexus-compiler.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-compiler)
The canonical git repository is located at https://github.com/codehaus-plexus/plexus-compiler
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId> <artifactId>plexus-compiler</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-api</artifactId> <artifactId>plexus-compiler-api</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId> <artifactId>plexus-compiler</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-manager</artifactId> <artifactId>plexus-compiler-manager</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId> <artifactId>plexus-compiler</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-test</artifactId> <artifactId>plexus-compiler-test</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-aspectj</artifactId> <artifactId>plexus-compiler-aspectj</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-csharp</artifactId> <artifactId>plexus-compiler-csharp</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-eclipse</artifactId> <artifactId>plexus-compiler-eclipse</artifactId>
......
package org.codehaus.plexus.compiler.eclipse;
/**
* @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
* Created on 22-4-18.
*/
public class EcjFailureException extends RuntimeException {
private final String ecjOutput;
public EcjFailureException(String ecjOutput) {
super("Failed to run the ecj compiler: " + ecjOutput);
this.ecjOutput = ecjOutput;
}
public String getEcjOutput()
{
return ecjOutput;
}
}
...@@ -64,8 +64,10 @@ public class EclipseJavaCompiler ...@@ -64,8 +64,10 @@ public class EclipseJavaCompiler
public CompilerResult performCompile(CompilerConfiguration config ) public CompilerResult performCompile(CompilerConfiguration config )
throws CompilerException throws CompilerException
{ {
// Build settings from configuration
List<String> args = new ArrayList<>(); List<String> args = new ArrayList<>();
args.add("-noExit"); // Make sure ecj does not System.exit on us 8-/
// Build settings from configuration
if ( config.isDebug() ) if ( config.isDebug() )
{ {
args.add("-preserveAllLocals"); args.add("-preserveAllLocals");
...@@ -146,13 +148,44 @@ public class EclipseJavaCompiler ...@@ -146,13 +148,44 @@ public class EclipseJavaCompiler
for(Entry<String, String> entry : extras.entrySet()) for(Entry<String, String> entry : extras.entrySet())
{ {
/*
* The compiler mojo makes quite a mess of passing arguments, depending on exactly WHICH
* way is used to pass them. The method method using <compilerArguments> uses the tag names
* of its contents to denote option names, and so the compiler mojo happily adds a '-' to
* all of the names there and adds them to the "custom compiler arguments" map as a
* name, value pair where the name always contains a single '-'. The Eclipse compiler (and
* javac too, btw) has options with two dashes (like --add-modules for java 9). These cannot
* be passed using a <compilerArguments> tag.
*
* The other method is to use <compilerArgs>, where each SINGLE argument needs to be passed
* using an <arg>xxxx</arg> tag. In there the xxx is not manipulated by the compiler mojo, so
* if it starts with a dash or more dashes these are perfectly preserved. But of course these
* single <arg> entries are not a pair. So the compiler mojo adds them as pairs of (xxxx, null).
*
* We use that knowledge here: if a pair has a null value then do not mess up the key but
* render it as a single value. This should ensure that something like:
* <compilerArgs>
* <arg>--add-modules</arg>
* <arg>java.se.ee</arg>
* </compilerArgs>
*
* is actually added to the command like as such.
*
* (btw: the above example will still give an error when using ecj <= 4.8M6:
* invalid module name: java.se.ee
* but that seems to be a bug in ecj).
*/
String opt = entry.getKey(); String opt = entry.getKey();
if(! opt.startsWith("-")) String optionValue = entry.getValue();
opt = "-" + opt; // compiler mojo apparently messes with this; make sure we are safe if(null == optionValue) {
args.add(opt); //-- We have an option from compilerArgs: use the key as-is as a single option value
String value = entry.getValue(); args.add(opt);
if(null != value && ! value.isEmpty()) } else {
args.add(value); if(!opt.startsWith("-"))
opt = "-" + opt;
args.add(opt);
args.add(optionValue);
}
} }
// Output path // Output path
...@@ -209,7 +242,8 @@ public class EclipseJavaCompiler ...@@ -209,7 +242,8 @@ public class EclipseJavaCompiler
// Compile! Send all errors to xml temp file. // Compile! Send all errors to xml temp file.
File errorF = null; File errorF = null;
try { try
{
errorF = File.createTempFile("ecjerr-", ".xml"); errorF = File.createTempFile("ecjerr-", ".xml");
args.add("-log"); args.add("-log");
...@@ -217,57 +251,93 @@ public class EclipseJavaCompiler ...@@ -217,57 +251,93 @@ public class EclipseJavaCompiler
// Add all sources. // Add all sources.
int argCount = args.size(); int argCount = args.size();
for(String source : config.getSourceLocations()) { for(String source : config.getSourceLocations())
{
File srcFile = new File(source); File srcFile = new File(source);
if(srcFile.exists()) { if(srcFile.exists())
Set<String> ss = getSourceFilesForSourceRoot( config, source ); {
Set<String> ss = getSourceFilesForSourceRoot(config, source);
args.addAll(ss); args.addAll(ss);
} }
} }
args.addAll(extraSourceDirs); args.addAll(extraSourceDirs);
if(args.size() == argCount) { if(args.size() == argCount)
{
//-- Nothing to do -> bail out //-- Nothing to do -> bail out
return new CompilerResult(true, Collections.EMPTY_LIST); return new CompilerResult(true, Collections.EMPTY_LIST);
} }
getLogger().debug("ecj command line: " + args);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter devNull = new PrintWriter(sw); PrintWriter devNull = new PrintWriter(sw);
//BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() { //BatchCompiler.compile(args.toArray(new String[args.size()]), new PrintWriter(System.err), new PrintWriter(System.out), new CompilationProgress() {
BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() { boolean success = BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
@Override public void begin(int i) { @Override
public void begin(int i)
{
} }
@Override public void done() { @Override
public void done()
{
} }
@Override public boolean isCanceled() { @Override
public boolean isCanceled()
{
return false; return false;
} }
@Override public void setTaskName(String s) { @Override
public void setTaskName(String s)
{
} }
@Override public void worked(int i, int i1) { @Override
public void worked(int i, int i1)
{
} }
}); });
getLogger().debug(sw.toString()); getLogger().debug(sw.toString());
List<CompilerMessage> messageList; List<CompilerMessage> messageList;
boolean hasError = false; boolean hasError = false;
if(errorF.length() < 80) { if(errorF.length() < 80)
throw new IOException("Failed to run the ECJ compiler:\n" + sw.toString()); {
throw new EcjFailureException(sw.toString());
} }
messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings); messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings);
for(CompilerMessage compilerMessage : messageList) { for(CompilerMessage compilerMessage : messageList)
if(compilerMessage.isError()) { {
if(compilerMessage.isError())
{
hasError = true; hasError = true;
break; break;
} }
} }
return new CompilerResult(! hasError, messageList); if(!hasError && !success && !errorsAsWarnings)
{
CompilerMessage.Kind kind = errorsAsWarnings ? CompilerMessage.Kind.WARNING : CompilerMessage.Kind.ERROR;
//-- Compiler reported failure but we do not seem to have one -> probable exception
CompilerMessage cm = new CompilerMessage("[ecj] The compiler reported an error but has not written it to its logging", kind);
messageList.add(cm);
hasError = true;
//-- Try to find the actual message by reporting the last 5 lines as a message
String stdout = getLastLines(sw.toString(), 5);
if(stdout.length() > 0)
{
cm = new CompilerMessage("[ecj] The following line(s) might indicate the issue:\n" + stdout, kind);
messageList.add(cm);
}
}
return new CompilerResult(!hasError || errorsAsWarnings, messageList);
} catch(EcjFailureException x) {
throw x;
} catch(Exception x) { } catch(Exception x) {
throw new RuntimeException(x); // sigh throw new RuntimeException(x); // sigh
} finally { } finally {
...@@ -279,6 +349,36 @@ public class EclipseJavaCompiler ...@@ -279,6 +349,36 @@ public class EclipseJavaCompiler
} }
} }
private String getLastLines(String text, int lines)
{
List<String> lineList = new ArrayList<>();
text = text.replace("\r\n", "\n");
text = text.replace("\r", "\n"); // make sure eoln is \n
int index = text.length();
while(index > 0) {
int before = text.lastIndexOf('\n', index - 1);
if(before + 1 < index) { // Non empty line?
lineList.add(text.substring(before + 1, index));
lines--;
if(lines <= 0)
break;
}
index = before;
}
StringBuilder sb = new StringBuilder();
for(int i = lineList.size() - 1; i >= 0; i--)
{
String s = lineList.get(i);
sb.append(s);
sb.append(System.getProperty("line.separator")); // 8-/
}
return sb.toString();
}
static private void append(StringBuilder warns, String s) { static private void append(StringBuilder warns, String s) {
if(warns.length() > 0) if(warns.length() > 0)
warns.append(','); warns.append(',');
......
package org.codehaus.plexus.compiler.eclipse;
/**
* The MIT License
*
* Copyright (c) 2005, The Codehaus
*
* 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.
*/
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.compiler.Compiler;
import org.codehaus.plexus.compiler.CompilerConfiguration;
import org.codehaus.plexus.util.FileUtils;
import org.junit.Assert;
import java.io.File;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
* Created on 22-4-18.
*/
public class EclipseCompilerDashedArgumentsTest extends PlexusTestCase {
public static final String BAD_DOUBLEDASH_OPTION = "--grubbelparkplace";
private CompilerConfiguration getConfig() throws Exception {
String sourceDir = getBasedir() + "/src/test-input/src/main";
List<String> filenames = FileUtils.getFileNames( new File( sourceDir ), "**/*.java", null, false, true );
Collections.sort( filenames );
Set<File> files = new HashSet<>();
for(String filename : filenames)
{
files.add(new File(filename));
}
CompilerConfiguration compilerConfig = new CompilerConfiguration();
compilerConfig.setDebug(false);
compilerConfig.setShowDeprecation(false);
// compilerConfig.setClasspathEntries( getClasspath() );
compilerConfig.addSourceLocation( sourceDir );
compilerConfig.setOutputLocation( getBasedir() + "/target/eclipse/classes");
FileUtils.deleteDirectory( compilerConfig.getOutputLocation() );
// compilerConfig.addInclude( filename );
compilerConfig.setForceJavacCompilerUse(false);
compilerConfig.setSourceFiles(files);
compilerConfig.setTargetVersion("1.8");
compilerConfig.setSourceVersion("1.8");
return compilerConfig;
}
/**
* Start the eclipse compiler with a bad option that has two dashes. It should abort, and the error
* message should show the actual bad option with two dashes. This ensures that both dashes are passed
* to the compiler proper.
*
* This also tests that con-compile errors are shown properly, as the error caused by
* the invalid option is not part of the error output but part of the data sent to stdout/stderr.
*/
public void testDoubleDashOptionsArePassedWithTwoDashes() throws Exception
{
Compiler compiler = (Compiler) lookup( Compiler.ROLE, "eclipse" );
CompilerConfiguration config = getConfig();
config.addCompilerCustomArgument(BAD_DOUBLEDASH_OPTION, "b0rk3d");
try
{
compiler.performCompile(config);
Assert.fail("Expected an exception to be thrown");
} catch(EcjFailureException x) {
String ecjOutput = x.getEcjOutput();
Assert.assertTrue("The output should report the failure with two dashes: " + ecjOutput
, ecjOutput.contains(BAD_DOUBLEDASH_OPTION) && ! ecjOutput.contains("-" + BAD_DOUBLEDASH_OPTION)
);
}
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-j2objc</artifactId> <artifactId>plexus-compiler-j2objc</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-javac-errorprone</artifactId> <artifactId>plexus-compiler-javac-errorprone</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-javac</artifactId> <artifactId>plexus-compiler-javac</artifactId>
......
...@@ -158,7 +158,9 @@ public class JavacCompiler ...@@ -158,7 +158,9 @@ public class JavacCompiler
} }
catch ( IOException e ) catch ( IOException e )
{ {
getLogger().warn( "Unable to autodetect 'javac' path, using 'javac' from the environment." ); if ( (getLogger() != null ) && getLogger().isWarnEnabled()) {
getLogger().warn( "Unable to autodetect 'javac' path, using 'javac' from the environment." );
}
executable = "javac"; executable = "javac";
} }
} }
...@@ -590,7 +592,9 @@ public class JavacCompiler ...@@ -590,7 +592,9 @@ public class JavacCompiler
final Thread thread = Thread.currentThread(); final Thread thread = Thread.currentThread();
final ClassLoader contextClassLoader = thread.getContextClassLoader(); final ClassLoader contextClassLoader = thread.getContextClassLoader();
thread.setContextClassLoader( javacClass.getClassLoader() ); thread.setContextClassLoader( javacClass.getClassLoader() );
getLogger().debug( "ttcl changed run compileInProcessWithProperClassloader" ); if ( (getLogger() != null ) && getLogger().isDebugEnabled()) {
getLogger().debug("ttcl changed run compileInProcessWithProperClassloader");
}
try try
{ {
return compileInProcessWithProperClassloader(javacClass, args); return compileInProcessWithProperClassloader(javacClass, args);
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compiler-jikes</artifactId> <artifactId>plexus-compiler-jikes</artifactId>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.codehaus.plexus</groupId> <groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId> <artifactId>plexus-compiler</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
</parent> </parent>
<artifactId>plexus-compilers</artifactId> <artifactId>plexus-compilers</artifactId>
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
</parent> </parent>
<artifactId>plexus-compiler</artifactId> <artifactId>plexus-compiler</artifactId>
<version>2.8.4</version> <version>2.8.5</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Plexus Compiler</name> <name>Plexus Compiler</name>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<connection>${scm.url}</connection> <connection>${scm.url}</connection>
<developerConnection>${scm.url}</developerConnection> <developerConnection>${scm.url}</developerConnection>
<url>http://github.com/codehaus-plexus/plexus-compiler/tree/${project.scm.tag}/</url> <url>http://github.com/codehaus-plexus/plexus-compiler/tree/${project.scm.tag}/</url>
<tag>plexus-compiler-2.8.4</tag> <tag>plexus-compiler-2.8.5</tag>
</scm> </scm>
<issueManagement> <issueManagement>
<system>github</system> <system>github</system>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment