Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HackyCompile for Gradle 5.1+ to ignore compilation time reporting. #625

Merged
merged 1 commit into from
Sep 12, 2019
Merged
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
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();
}

}