From 1ee49fa2ed347f26b71dae0239de0216f0c7fe15 Mon Sep 17 00:00:00 2001 From: Sebastian Hartte Date: Tue, 30 Jul 2024 01:32:27 +0200 Subject: [PATCH] Finish 1.19.2 vanilla --- .../actions/RecompileSourcesAction.java | 11 ++++++++ .../RecompileSourcesActionWithECJ.java | 9 +++--- .../RecompileSourcesActionWithJDK.java | 28 +++++++++---------- .../runtime/config/neoform/NeoFormConfig.java | 3 +- .../config/neoform/NeoFormDistConfig.java | 4 +++ .../neoform/runtime/engine/NeoFormEngine.java | 3 ++ 6 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesAction.java b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesAction.java index f557ead..c0202da 100644 --- a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesAction.java +++ b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesAction.java @@ -10,14 +10,17 @@ import java.util.List; public abstract class RecompileSourcesAction extends BuiltInAction implements ExecutionNodeAction { + private final ExtensibleClasspath classpath = new ExtensibleClasspath(); private final ExtensibleClasspath sourcepath = new ExtensibleClasspath(); + private int targetJavaVersion = 21; @Override public void computeCacheKey(CacheKeyBuilder ck) { super.computeCacheKey(ck); classpath.computeCacheKey("compile classpath", ck); sourcepath.computeCacheKey("compile sourcepath", ck); + ck.add("target java version", String.valueOf(targetJavaVersion)); } protected final List getEffectiveClasspath(ProcessingEnvironment environment) throws IOException { @@ -53,4 +56,12 @@ public ExtensibleClasspath getClasspath() { public ExtensibleClasspath getSourcepath() { return sourcepath; } + + public int getTargetJavaVersion() { + return targetJavaVersion; + } + + public void setTargetJavaVersion(int targetJavaVersion) { + this.targetJavaVersion = targetJavaVersion; + } } diff --git a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithECJ.java b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithECJ.java index 46e074c..92c5e50 100644 --- a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithECJ.java +++ b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithECJ.java @@ -47,6 +47,7 @@ public class RecompileSourcesActionWithECJ extends RecompileSourcesAction { @Override public void run(ProcessingEnvironment environment) throws IOException, InterruptedException { var sources = environment.getRequiredInputPath("sources"); + var javaRelease = String.valueOf(getTargetJavaVersion()); // Merge the original Minecraft classpath with the libs required by additional patches that we made var classpathPaths = getEffectiveClasspath(environment); @@ -69,7 +70,7 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt true, new AccessRuleSet(new AccessRule[0], AccessRestriction.COMMAND_LINE, library.getFileName().toString()), "none", - "21" + javaRelease )); } @@ -81,9 +82,9 @@ public void run(ProcessingEnvironment environment) throws IOException, Interrupt var policy = DefaultErrorHandlingPolicies.exitOnFirstError(); var options = new CompilerOptions(Map.of( - CompilerOptions.OPTION_Source, "21", - CompilerOptions.OPTION_Compliance, "21", - CompilerOptions.OPTION_TargetPlatform, "21", + CompilerOptions.OPTION_Source, javaRelease, + CompilerOptions.OPTION_Compliance, javaRelease, + CompilerOptions.OPTION_TargetPlatform, javaRelease, CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE, CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED, CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED, diff --git a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithJDK.java b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithJDK.java index 63baffe..64c8621 100644 --- a/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithJDK.java +++ b/src/main/java/net/neoforged/neoform/runtime/actions/RecompileSourcesActionWithJDK.java @@ -24,18 +24,6 @@ * Uses the current JDKs java compiler interface to recompile the sources. */ public class RecompileSourcesActionWithJDK extends RecompileSourcesAction { - private final List compilerOptions = new ArrayList<>(); - - public RecompileSourcesActionWithJDK() { - compilerOptions.add("--release"); - compilerOptions.add("21"); - compilerOptions.add("-proc:none"); // No annotation processing on Minecraft sources - compilerOptions.add("-nowarn"); // We have no influence on Minecraft sources, so no warnings - compilerOptions.add("-g"); // Gradle compiles with debug by default, so we replicate this - compilerOptions.add("-XDuseUnsharedTable=true"); // Gradle also adds this unconditionally - compilerOptions.add("-implicit:none"); // Prevents source files from the source-path from being emitted - } - @Override public void run(ProcessingEnvironment environment) throws IOException, InterruptedException { var sources = environment.getRequiredInputPath("sources"); @@ -84,7 +72,7 @@ public void report(Diagnostic d) { fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcepath); var sourceJavaFiles = fileManager.getJavaFileObjectsFromPaths(sourcePaths); - var task = compiler.getTask(null, fileManager, diagnostics, compilerOptions, null, sourceJavaFiles); + var task = compiler.getTask(null, fileManager, diagnostics, getCompilerOptions(), null, sourceJavaFiles); if (!task.call()) { throw new IOException("Compilation failed"); } @@ -106,6 +94,18 @@ public void report(Diagnostic d) { public void computeCacheKey(CacheKeyBuilder ck) { super.computeCacheKey(ck); ck.add("compiler type", "javac"); - ck.addStrings("compiler options", compilerOptions); + ck.addStrings("compiler options", getCompilerOptions()); + } + + private List getCompilerOptions() { + return List.of( + "--release", + String.valueOf(getTargetJavaVersion()), + "-proc:none", // No annotation processing on Minecraft sources + "-nowarn", // We have no influence on Minecraft sources, so no warnings + "-g", // Gradle compiles with debug by default, so we replicate this + "-XDuseUnsharedTable=true", // Gradle also adds this unconditionally + "-implicit:none" // Prevents source files from the source-path from being emitted + ); } } diff --git a/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormConfig.java b/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormConfig.java index cbb5ea1..a0f54c8 100644 --- a/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormConfig.java +++ b/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormConfig.java @@ -4,7 +4,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import com.google.gson.annotations.SerializedName; -import net.neoforged.neoform.runtime.config.neoforge.NeoForgeConfig; import net.neoforged.neoform.runtime.utils.MavenCoordinate; import org.jetbrains.annotations.Nullable; @@ -18,7 +17,7 @@ public record NeoFormConfig(int spec, @SerializedName("version") String minecraftVersion, boolean official, - @SerializedName("java_target") String javaVersion, + @SerializedName("java_target") int javaVersion, String encoding, Map data, Map> steps, diff --git a/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormDistConfig.java b/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormDistConfig.java index cc3fe6f..a87198f 100644 --- a/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormDistConfig.java +++ b/src/main/java/net/neoforged/neoform/runtime/config/neoform/NeoFormDistConfig.java @@ -21,6 +21,10 @@ public NeoFormDistConfig(NeoFormConfig config, String dist) { this.dist = dist; } + public int javaVersion() { + return config.javaVersion(); + } + public String minecraftVersion() { return config.minecraftVersion(); } diff --git a/src/main/java/net/neoforged/neoform/runtime/engine/NeoFormEngine.java b/src/main/java/net/neoforged/neoform/runtime/engine/NeoFormEngine.java index 53ca775..039f4f3 100644 --- a/src/main/java/net/neoforged/neoform/runtime/engine/NeoFormEngine.java +++ b/src/main/java/net/neoforged/neoform/runtime/engine/NeoFormEngine.java @@ -232,9 +232,12 @@ private NodeOutput addRecompileStep(NeoFormDistConfig distConfig, NodeOutput sou compileAction = new RecompileSourcesActionWithJDK(); } + compileAction.setTargetJavaVersion(distConfig.javaVersion()); + // Add NeoForm libraries or apply overridden classpath fully compileAction.getClasspath().setOverriddenClasspath(buildOptions.getOverriddenCompileClasspath()); compileAction.getClasspath().addMavenLibraries(distConfig.libraries()); + builder.action(compileAction); builder.build(); return compiledOutput;