Skip to content
Commits on Source (5)
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)
The canonical git repository is located at https://github.com/codehaus-plexus/plexus-compiler
plexus-compiler (2.8.5-1) unstable; urgency=medium
* Team upload.
* New upstream release
- Refreshed the patches
* Standards-Version updated to 4.2.1
-- Emmanuel Bourg <ebourg@apache.org> Thu, 20 Sep 2018 16:23:39 +0200
plexus-compiler (2.8.4-2) unstable; urgency=medium
* Team upload.
......
......@@ -19,7 +19,7 @@ Build-Depends:
libplexus-utils2-java,
libplexus-utils2-java-doc,
maven-debian-helper (>= 1.5)
Standards-Version: 4.1.4
Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/java-team/plexus-compiler.git
Vcs-Browser: https://salsa.debian.org/java-team/plexus-compiler
Homepage: https://codehaus-plexus.github.io/plexus-compiler/
......
......@@ -3,7 +3,7 @@ Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
+++ b/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
@@ -339,12 +339,20 @@
@@ -341,12 +341,20 @@
}
else
{
......@@ -25,7 +25,7 @@ Forwarded: not-needed
}
else
{
@@ -356,7 +364,13 @@
@@ -358,7 +366,13 @@
{
// If omitted, later JDKs complain about a 1.1 target
args.add( "-source" );
......
......@@ -5,16 +5,11 @@ Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: not-needed
--- a/pom.xml
+++ b/pom.xml
@@ -64,6 +64,16 @@
@@ -64,6 +64,11 @@
<scope>test</scope>
<version>4.12</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>3.0.22</version>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-api</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-manager</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-test</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-aspectj</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-csharp</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<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
public CompilerResult performCompile(CompilerConfiguration config )
throws CompilerException
{
// Build settings from configuration
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() )
{
args.add("-preserveAllLocals");
......@@ -146,13 +148,44 @@ public class EclipseJavaCompiler
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 optionValue = entry.getValue();
if(null == optionValue) {
//-- We have an option from compilerArgs: use the key as-is as a single option value
args.add(opt);
} else {
if(!opt.startsWith("-"))
opt = "-" + opt; // compiler mojo apparently messes with this; make sure we are safe
opt = "-" + opt;
args.add(opt);
String value = entry.getValue();
if(null != value && ! value.isEmpty())
args.add(value);
args.add(optionValue);
}
}
// Output path
......@@ -209,7 +242,8 @@ public class EclipseJavaCompiler
// Compile! Send all errors to xml temp file.
File errorF = null;
try {
try
{
errorF = File.createTempFile("ecjerr-", ".xml");
args.add("-log");
......@@ -217,57 +251,93 @@ public class EclipseJavaCompiler
// Add all sources.
int argCount = args.size();
for(String source : config.getSourceLocations()) {
for(String source : config.getSourceLocations())
{
File srcFile = new File(source);
if(srcFile.exists()) {
if(srcFile.exists())
{
Set<String> ss = getSourceFilesForSourceRoot(config, source);
args.addAll(ss);
}
}
args.addAll(extraSourceDirs);
if(args.size() == argCount) {
if(args.size() == argCount)
{
//-- Nothing to do -> bail out
return new CompilerResult(true, Collections.EMPTY_LIST);
}
getLogger().debug("ecj command line: " + args);
StringWriter sw = new StringWriter();
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()]), devNull, devNull, new CompilationProgress() {
@Override public void begin(int i) {
boolean success = BatchCompiler.compile(args.toArray(new String[args.size()]), devNull, devNull, new CompilationProgress() {
@Override
public void begin(int i)
{
}
@Override public void done() {
@Override
public void done()
{
}
@Override public boolean isCanceled() {
@Override
public boolean isCanceled()
{
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());
List<CompilerMessage> messageList;
boolean hasError = false;
if(errorF.length() < 80) {
throw new IOException("Failed to run the ECJ compiler:\n" + sw.toString());
if(errorF.length() < 80)
{
throw new EcjFailureException(sw.toString());
}
messageList = new EcjResponseParser().parse(errorF, errorsAsWarnings);
for(CompilerMessage compilerMessage : messageList) {
if(compilerMessage.isError()) {
for(CompilerMessage compilerMessage : messageList)
{
if(compilerMessage.isError())
{
hasError = true;
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) {
throw new RuntimeException(x); // sigh
} finally {
......@@ -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) {
if(warns.length() > 0)
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 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-j2objc</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-javac</artifactId>
......
......@@ -158,7 +158,9 @@ public class JavacCompiler
}
catch ( IOException e )
{
if ( (getLogger() != null ) && getLogger().isWarnEnabled()) {
getLogger().warn( "Unable to autodetect 'javac' path, using 'javac' from the environment." );
}
executable = "javac";
}
}
......@@ -590,7 +592,9 @@ public class JavacCompiler
final Thread thread = Thread.currentThread();
final ClassLoader contextClassLoader = thread.getContextClassLoader();
thread.setContextClassLoader( javacClass.getClassLoader() );
if ( (getLogger() != null ) && getLogger().isDebugEnabled()) {
getLogger().debug("ttcl changed run compileInProcessWithProperClassloader");
}
try
{
return compileInProcessWithProperClassloader(javacClass, args);
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compilers</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compiler-jikes</artifactId>
......
......@@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler</artifactId>
<version>2.8.4</version>
<version>2.8.5</version>
</parent>
<artifactId>plexus-compilers</artifactId>
......