Skip to content
This repository was archived by the owner on May 10, 2022. It is now read-only.

Suppress '-h' option which is not supported by eclipse jdt compiler #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
20 changes: 19 additions & 1 deletion src/main/java/de/set/gradle/ecj/EclipseCompilerAdapter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -37,9 +38,11 @@ public class EclipseCompilerAdapter implements Compiler<JavaCompileSpec> {
public WorkResult execute(JavaCompileSpec javaCompileSpec) {
LOGGER.info("Compiling sources using eclipse compiler for java ["+this.ecjArtifact+"]");

final List<String> remainingArguments =
List<String> remainingArguments =
new JavaCompilerArgumentsBuilder(javaCompileSpec).includeSourceFiles(true).build();

removeUnsupportedCompilerFlags(remainingArguments);

ExecResult result = project.javaexec(exec -> {
exec.setWorkingDir(javaCompileSpec.getWorkingDir());
exec.setClasspath(compilerConfiguration);
Expand All @@ -58,6 +61,21 @@ public WorkResult execute(JavaCompileSpec javaCompileSpec) {
return () -> true;
}

private void removeUnsupportedCompilerFlags(List<String> remainingArguments) {
Iterator<String> 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<String> shortenArgs(File tempDir, List<String> 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
Expand Down