Skip to content

Commit

Permalink
Fix HackyCompile for Gradle 5.1+ to ignore compilation time reporting. (
Browse files Browse the repository at this point in the history
  • Loading branch information
gabizou authored and LexManos committed Sep 12, 2019
1 parent 33c57b7 commit e7b9b54
Showing 1 changed file with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
package net.minecraftforge.gradle.userdev.tasks;

import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.tasks.compile.CleaningJavaCompiler;
import org.gradle.api.internal.tasks.compile.DefaultJavaCompileSpec;
import org.gradle.api.internal.tasks.compile.JavaCompileSpec;
import org.gradle.api.tasks.WorkResult;
import org.gradle.api.tasks.compile.JavaCompile;
import org.gradle.internal.operations.BuildOperationExecutor;
import org.gradle.jvm.internal.toolchain.JavaToolChainInternal;
import org.gradle.language.base.internal.compile.Compiler;
import org.gradle.language.base.internal.compile.CompilerUtil;
import org.gradle.util.GradleVersion;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

// A terrible hack to use JavaCompile while bypassing
Expand Down Expand Up @@ -56,18 +65,36 @@ public void doHackyCompile() {
} catch (Exception e) {
throw new RuntimeException("Exception calling setHistory", e);
}

// Do the actual compilation,
// bypassing a bunch of Gradle's other stuff (e.g. internal event listener mechanism)
this.compile();
} else {
try {
Method setPreviousOutputFiles = this.getOutputs().getClass().getMethod("setPreviousOutputFiles", FileCollection.class);
setPreviousOutputFiles.invoke(this.getOutputs(), this.getProject().files());
} catch (Exception e) {
throw new RuntimeException("Exception calling setPreviousOutputFiles ", e);
}
try {
final DefaultJavaCompileSpec spec;
try {
Method createSpec = JavaCompile.class.getDeclaredMethod("createSpec");
createSpec.setAccessible(true);
spec = (DefaultJavaCompileSpec) createSpec.invoke(this);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Exception calling createSpec ", e);
}
spec.setSourceFiles(getSource());
Compiler<JavaCompileSpec> javaCompiler = CompilerUtil.castCompiler(((JavaToolChainInternal) getToolChain()).select(getPlatform()).newCompiler(spec.getClass()));
CleaningJavaCompiler compiler = new CleaningJavaCompiler(javaCompiler, getOutputs());
final WorkResult execute = compiler.execute(spec);
setDidWork(execute.getDidWork());
} catch (Exception e) {
throw new RuntimeException("Exception compiling ", e);
}
}

// Do the actual compilation,
// bypassing a bunch of Gradle's other stuff (e.g. internal event listener mechanism)
this.compile();
}

}

0 comments on commit e7b9b54

Please sign in to comment.