Skip to content

Commit

Permalink
Bump project to Gradle 6.8 and upgrade ForgeGradle 4 as a version
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Jan 18, 2021
2 parents e2ed495 + 8f62e2d commit 72d4e9b
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 67 deletions.
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
plugins {
id 'java-gradle-plugin'
id 'eclipse'
id 'maven-publish'
id 'net.minecrell.licenser' version '0.4.1'
id 'org.ajoberstar.grgit' version '3.0.0'
id 'com.github.ben-manes.versions' version '0.20.0'
//id 'com.github.johnrengelman.shadow' version '2.0.4'
}

apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'eclipse'

sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}

group = 'net.minecraftforge.gradle'
version = gitVersion()
def gitVersion() {
Expand Down Expand Up @@ -69,7 +63,7 @@ license {
}

wrapper {
gradleVersion = '4.9'
gradleVersion = '6.8'
distributionType = Wrapper.DistributionType.ALL
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group=net.minecraftforge.gradle
1 change: 0 additions & 1 deletion gradle.settings

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
rootProject.name = 'ForgeGradle'
enableFeaturePreview('STABLE_PUBLISHING') //Make building shut up.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void write(int b) throws IOException {
});
java.exec();
} finally {
getProject().getTasks().remove(java);
java.setEnabled(false);
}

if (hasLog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.jar.Attributes;
Expand Down Expand Up @@ -119,7 +120,7 @@ public File execute(MCPEnvironment environment) throws IOException, InterruptedE
jarFile.close();

// Execute command
JavaExec java = environment.project.getTasks().create("_", JavaExec.class);
JavaExec java = environment.project.getTasks().create("_decompileJar" + new Random().nextInt(), JavaExec.class);
try (BufferedOutputStream log_out = new BufferedOutputStream(new FileOutputStream(environment.getFile("console.log")))) {
PrintWriter writer = new PrintWriter(log_out);
Function<String,String> quote = s -> '"' + s + '"';
Expand All @@ -137,7 +138,7 @@ public File execute(MCPEnvironment environment) throws IOException, InterruptedE
java.setStandardOutput(log_out);
java.exec();
} finally {
environment.project.getTasks().remove(java);
java.setEnabled(false);
}

// Return the output file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void apply() throws IOException {
workDir.mkdirs();
}

JavaExec java = getProject().getTasks().create("_", JavaExec.class);
JavaExec java = getProject().getTasks().create("_reobfuscateJar_" + getName() + new Random().nextInt(), JavaExec.class);
try (OutputStream log = new BufferedOutputStream(new FileOutputStream(new File(workDir, "log.txt")))) {
// Execute command
java.setArgs(_args);
Expand Down Expand Up @@ -153,7 +154,7 @@ public void write(int b) throws IOException {

output_temp.delete();
} finally {
getProject().getTasks().remove(java);
java.setEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,7 +1302,7 @@ private File compileJava(File source, File... extraDeps) {
e.printStackTrace();
return null;
} finally {
project.getTasks().remove(compile);
compile.setEnabled(false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,32 @@

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.file.impl.DefaultDeleter;
import org.gradle.internal.nativeintegration.filesystem.FileSystem;
import org.gradle.internal.nativeintegration.services.FileSystems;
import org.gradle.internal.os.OperatingSystem;
import org.gradle.internal.time.Clock;
import org.gradle.internal.time.Time;
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.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.function.LongSupplier;
import java.util.function.Predicate;

// A terrible hack to use JavaCompile while bypassing
// Gradle's normal task infrastructure.
public class HackyJavaCompile extends JavaCompile {

@SuppressWarnings({"rawtypes", "unchecked", "deprecation", "UnstableApiUsage"})
public void doHackyCompile() {

// What follows is a horrible hack to allow us to call JavaCompile
Expand All @@ -46,54 +54,27 @@ public void doHackyCompile() {
// invoking Gradle tasks in the normal way can lead to deadlocks
// when done from a dependency resolver.

// To avoid these issues, we invoke the 'compile' method on JavaCompile
// using reflection.
this.getOutputs().setPreviousOutputFiles(this.getProject().files());

// Normally, the output history is set by Gradle. Since we're bypassing
// the normal gradle task infrastructure, we need to do it ourselves.
final Clock clock = Time.clock();
final LongSupplier supplier = clock::getCurrentTime;
final FileSystem fileSystem = FileSystems.getDefault();
final Predicate<? super File> isSymLink = fileSystem::isSymlink;
final DefaultDeleter defaultDeleter = new DefaultDeleter(supplier, isSymLink, OperatingSystem.current().isWindows());

// TaskExecutionHistory is removed in 5.1.0, so we only try to set it
// on versions below 5.1.0

if (GradleVersion.current().compareTo(GradleVersion.version("5.1.0")) < 0) {
try {
Class<?> taskExectionHistory = Class.forName("org.gradle.api.internal.TaskExecutionHistory");
Method setHistory = this.getOutputs().getClass().getMethod("setHistory", taskExectionHistory);
Object dummyHistory = Class.forName("net.minecraftforge.gradle.userdev.util.DummyTaskExecutionHistory").newInstance();
setHistory.invoke(this.getOutputs(), dummyHistory);
} 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);
}
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(), defaultDeleter);
final WorkResult execute = compiler.execute(spec);
setDidWork(execute.getDidWork());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public File deobfBinary(File original, String mappings, String... cachePath) thr
rename.setMappings(names);
rename.setSignatureRemoval(true);
rename.apply();
project.getTasks().remove(rename);
rename.setEnabled(false);

Utils.updateHash(output, HashFunction.SHA1);
cache.save();
Expand Down

0 comments on commit 72d4e9b

Please sign in to comment.