From bfa827ab633d8d5238d614b3bb761866d5b04ef4 Mon Sep 17 00:00:00 2001 From: Daniel Platz Date: Mon, 29 Jun 2020 20:58:58 +0200 Subject: [PATCH] Suppress '-h' option which is not supported by eclipse jdt compiler --- .../gradle/ecj/EclipseCompilerAdapter.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/set/gradle/ecj/EclipseCompilerAdapter.java b/src/main/java/de/set/gradle/ecj/EclipseCompilerAdapter.java index 81472f1..4b473b5 100644 --- a/src/main/java/de/set/gradle/ecj/EclipseCompilerAdapter.java +++ b/src/main/java/de/set/gradle/ecj/EclipseCompilerAdapter.java @@ -1,6 +1,7 @@ package de.set.gradle.ecj; import java.io.File; +import java.util.Iterator; import java.util.List; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -37,9 +38,11 @@ public class EclipseCompilerAdapter implements Compiler { public WorkResult execute(JavaCompileSpec javaCompileSpec) { LOGGER.info("Compiling sources using eclipse compiler for java ["+this.ecjArtifact+"]"); - final List remainingArguments = + List remainingArguments = new JavaCompilerArgumentsBuilder(javaCompileSpec).includeSourceFiles(true).build(); + removeUnsupportedCompilerFlags(remainingArguments); + ExecResult result = project.javaexec(exec -> { exec.setWorkingDir(javaCompileSpec.getWorkingDir()); exec.setClasspath(compilerConfiguration); @@ -58,6 +61,21 @@ public WorkResult execute(JavaCompileSpec javaCompileSpec) { return () -> true; } + private void removeUnsupportedCompilerFlags(List remainingArguments) { + Iterator argsIterator = remainingArguments.iterator(); + while(argsIterator.hasNext()) { + String arg = argsIterator.next(); + if (arg.equals("-h")) { + LOGGER.warn("Suppressing unsupported compiler-flag '-h'"); + argsIterator.remove(); + if (argsIterator.hasNext()) { + argsIterator.next(); + argsIterator.remove(); + } + } + } + } + private Iterable shortenArgs(File tempDir, List args) { // for command file format, see http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html#commandlineargfile // use platform character and line encoding