From a8f84d63ef39be7704a8d2c2b3617f4debddac2c Mon Sep 17 00:00:00 2001 From: Bartosz Skrzypczak Date: Sun, 2 Jan 2022 02:16:20 +0100 Subject: [PATCH] Use gradle home environment variable if specified (closes #7), try to also detect data run target --- build.gradle | 2 +- src/main/java/ofdev/common/FG3.java | 7 +------ src/main/java/ofdev/common/Utils.java | 9 +++++++++ .../OptifineDevTransformerWrapper.java | 19 ++++++++++--------- .../OFDevTransformationService.java | 4 ++-- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 7b91f6a..4a2afa2 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'java' -version = "2.6" +version = "2.6.1" group = "ofdev" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "aa_do_not_rename_OptiFineDevTweaker" diff --git a/src/main/java/ofdev/common/FG3.java b/src/main/java/ofdev/common/FG3.java index 0ff1b88..9aac54e 100644 --- a/src/main/java/ofdev/common/FG3.java +++ b/src/main/java/ofdev/common/FG3.java @@ -13,11 +13,6 @@ public static Path findObfMcJar(String mcVersion, boolean isClient) { // because MC_VERSION has invalid value in forge 1.12.2 2855, we can't use MC_VERSION generally //String mcVersion = System.getenv("MC_VERSION"); String dist = isClient ? "client" : "server"; - - return Paths.get(System.getProperty("user.home"), - ".gradle/caches/forge_gradle/minecraft_repo/versions", - mcVersion, - dist + ".jar" - ); + return Utils.gradleHome().resolve("caches/forge_gradle/minecraft_repo/versions").resolve(mcVersion).resolve(dist + ".jar"); } } diff --git a/src/main/java/ofdev/common/Utils.java b/src/main/java/ofdev/common/Utils.java index d30328a..1494095 100644 --- a/src/main/java/ofdev/common/Utils.java +++ b/src/main/java/ofdev/common/Utils.java @@ -5,11 +5,20 @@ import java.nio.file.FileVisitor; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.nio.file.attribute.BasicFileAttributes; public class Utils { + public static Path gradleHome() { + String gradleHome = System.getenv("GRADLE_USER_HOME"); + if (gradleHome == null || gradleHome.isEmpty()){ + gradleHome = System.getProperty("user.home") + "/.gradle"; + } + return Paths.get(gradleHome); + } + public static void rm(Path path) throws IOException { if (Files.exists(path)) { if (!Files.isDirectory(path)) { diff --git a/src/main/java/ofdev/launchwrapper/OptifineDevTransformerWrapper.java b/src/main/java/ofdev/launchwrapper/OptifineDevTransformerWrapper.java index 20f6016..f645048 100644 --- a/src/main/java/ofdev/launchwrapper/OptifineDevTransformerWrapper.java +++ b/src/main/java/ofdev/launchwrapper/OptifineDevTransformerWrapper.java @@ -39,7 +39,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -51,18 +50,20 @@ public class OptifineDevTransformerWrapper implements IClassTransformer { // TODO: will it work on windows? - private static final String MC_JAR; + private static final Path MC_JAR; static { - if (System.getProperty("net.minecraftforge.gradle.GradleStart.srg.notch-mcp") != null) { + String userJarValue = System.getProperty("ofdev.mcjar"); + if (userJarValue != null) { + MC_JAR = Paths.get(userJarValue); + } else if (System.getProperty("net.minecraftforge.gradle.GradleStart.srg.notch-mcp") != null) { // then using ForgeGradle 2.x or earlier. - MC_JAR = System.getProperty("ofdev.mcjar", - System.getProperty("user.home") + "/.gradle/caches/minecraft/net/minecraft/minecraft/" + - UtilsLW.mcVersion() + "/minecraft-" + UtilsLW.mcVersion() + ".jar"); + MC_JAR = Utils.gradleHome().resolve("caches/minecraft/net/minecraft/minecraft") + .resolve(UtilsLW.mcVersion()).resolve("/minecraft-" + UtilsLW.mcVersion() + ".jar"); } else { // then using ForgeGradle 3.x or later. boolean isClient = System.getenv("assetIndex") != null; - MC_JAR = FG3.findObfMcJar(UtilsLW.mcVersion(), isClient).toString(); + MC_JAR = FG3.findObfMcJar(UtilsLW.mcVersion(), isClient); } } @@ -70,7 +71,7 @@ public class OptifineDevTransformerWrapper implements IClassTransformer { static { try { - mcJar = FileSystems.newFileSystem(Paths.get(MC_JAR), Launch.classLoader); + mcJar = FileSystems.newFileSystem(MC_JAR, Launch.classLoader); } catch (IOException e) { throw new UncheckedIOException(e); } @@ -102,7 +103,7 @@ public class OptifineDevTransformerWrapper implements IClassTransformer { UtilsLW.setFieldValue(ofTransformerClass, "patterns", ofTransformer, patternsVal); System.out.println("Ignore the above, OptiFine should run anyway"); - Launch.classLoader.addURL(new File(MC_JAR).toURI().toURL()); + Launch.classLoader.addURL(MC_JAR.toUri().toURL()); } catch (InstantiationException | IllegalAccessException | IOException | URISyntaxException | ClassNotFoundException e) { throw new RuntimeException(e); } diff --git a/src/main/java/ofdev/modlauncher/OFDevTransformationService.java b/src/main/java/ofdev/modlauncher/OFDevTransformationService.java index aecf09f..0ea980d 100644 --- a/src/main/java/ofdev/modlauncher/OFDevTransformationService.java +++ b/src/main/java/ofdev/modlauncher/OFDevTransformationService.java @@ -73,8 +73,8 @@ private static Path findObfMcJar(IEnvironment env) { throw new IllegalStateException(ex); } } - String target = env.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).get();//target=fmluserdevclient for client - return FG3.findObfMcJar(mcVersion, target.toLowerCase(Locale.ROOT).contains("client")); + String target = env.getProperty(IEnvironment.Keys.LAUNCHTARGET.get()).get().toLowerCase(Locale.ROOT);//target=fmluserdevclient for client + return FG3.findObfMcJar(mcVersion, target.contains("client") || target.contains("data")); } private static IEnvironment env;