[Git][java-team/plexus-compiler][upstream] New upstream version 2.8.5

Emmanuel Bourg gitlab at salsa.debian.org
Thu Sep 20 15:28:44 BST 2018


Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / plexus-compiler


Commits:
67de3a19 by Emmanuel Bourg at 2018-09-10T15:53:55Z
New upstream version 2.8.5
- - - - -


17 changed files:

- README.md
- plexus-compiler-api/pom.xml
- plexus-compiler-manager/pom.xml
- plexus-compiler-test/pom.xml
- plexus-compilers/plexus-compiler-aspectj/pom.xml
- plexus-compilers/plexus-compiler-csharp/pom.xml
- plexus-compilers/plexus-compiler-eclipse/pom.xml
- + plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java
- plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
- + plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java
- plexus-compilers/plexus-compiler-j2objc/pom.xml
- plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
- plexus-compilers/plexus-compiler-javac/pom.xml
- plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
- plexus-compilers/plexus-compiler-jikes/pom.xml
- plexus-compilers/pom.xml
- pom.xml


Changes:

=====================================
README.md
=====================================
@@ -1,3 +1,8 @@
-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-api/pom.xml
=====================================
@@ -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>


=====================================
plexus-compiler-manager/pom.xml
=====================================
@@ -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>


=====================================
plexus-compiler-test/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-aspectj/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-csharp/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-eclipse/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EcjFailureException.java
=====================================
@@ -0,0 +1,19 @@
+package org.codehaus.plexus.compiler.eclipse;
+
+/**
+ * @author <a href="mailto:jal at 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;
+    }
+}


=====================================
plexus-compilers/plexus-compiler-eclipse/src/main/java/org/codehaus/plexus/compiler/eclipse/EclipseJavaCompiler.java
=====================================
@@ -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();
-            if(! opt.startsWith("-"))
-                opt = "-" + opt;					// compiler mojo apparently messes with this; make sure we are safe
-            args.add(opt);
-            String value = entry.getValue();
-            if(null != value && ! value.isEmpty())
-                args.add(value);
+            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;
+                args.add(opt);
+                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()) {
-                    Set<String> ss = getSourceFilesForSourceRoot( config, source );
+                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(',');


=====================================
plexus-compilers/plexus-compiler-eclipse/src/test/java/org/codehaus/plexus/compiler/eclipse/EclipseCompilerDashedArgumentsTest.java
=====================================
@@ -0,0 +1,100 @@
+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 at 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)
+            );
+        }
+    }
+}


=====================================
plexus-compilers/plexus-compiler-j2objc/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-javac-errorprone/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-javac/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java
=====================================
@@ -158,7 +158,9 @@ public class JavacCompiler
                 }
                 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";
                 }
             }
@@ -590,7 +592,9 @@ public class JavacCompiler
         final Thread thread = Thread.currentThread();
         final ClassLoader contextClassLoader = thread.getContextClassLoader();
         thread.setContextClassLoader( javacClass.getClassLoader() );
-        getLogger().debug( "ttcl changed run compileInProcessWithProperClassloader" );
+        if ( (getLogger() != null ) && getLogger().isDebugEnabled()) {
+            getLogger().debug("ttcl changed run compileInProcessWithProperClassloader");
+        }
         try
         {
             return compileInProcessWithProperClassloader(javacClass, args);


=====================================
plexus-compilers/plexus-compiler-jikes/pom.xml
=====================================
@@ -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>


=====================================
plexus-compilers/pom.xml
=====================================
@@ -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>


=====================================
pom.xml
=====================================
@@ -10,7 +10,7 @@
   </parent>
 
   <artifactId>plexus-compiler</artifactId>
-  <version>2.8.4</version>
+  <version>2.8.5</version>
   <packaging>pom</packaging>
 
   <name>Plexus Compiler</name>
@@ -27,7 +27,7 @@
     <connection>${scm.url}</connection>
     <developerConnection>${scm.url}</developerConnection>
     <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>
   <issueManagement>
     <system>github</system>



View it on GitLab: https://salsa.debian.org/java-team/plexus-compiler/commit/67de3a19b8ec7a2d9ccd9da7070f302f81c31d1b

-- 
View it on GitLab: https://salsa.debian.org/java-team/plexus-compiler/commit/67de3a19b8ec7a2d9ccd9da7070f302f81c31d1b
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20180920/4472c3f2/attachment.html>


More information about the pkg-java-commits mailing list