From bbf5e341e359885616fe957d6e57c7ad627d5748 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 4 Nov 2018 18:46:37 +0000 Subject: [PATCH] Fix some streams not being closed, clean up the mod reobfuscater, fix runClient task --- .../loom/mixin/MixinServiceGradle.java | 1 + .../net/fabricmc/loom/task/RunClientTask.java | 9 +++++++- .../net/fabricmc/loom/task/RunServerTask.java | 8 +++++++ .../net/fabricmc/loom/util/ModProcessor.java | 6 ++++- .../net/fabricmc/loom/util/ModRemapper.java | 23 ++++--------------- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/mixin/MixinServiceGradle.java b/src/main/java/net/fabricmc/loom/mixin/MixinServiceGradle.java index 17ba4d4..6b700a4 100644 --- a/src/main/java/net/fabricmc/loom/mixin/MixinServiceGradle.java +++ b/src/main/java/net/fabricmc/loom/mixin/MixinServiceGradle.java @@ -79,6 +79,7 @@ public class MixinServiceGradle extends MixinServiceLaunchWrapper implements ICl public byte[] getClassBytes(String name, String transformedName) throws IOException { InputStream inputStream = getResourceAsStream(name.replace(".", "/") + ".class"); byte[] classBytes = ByteStreams.toByteArray(inputStream); + inputStream.close(); if(classBytes == null){ return super.getClassBytes(name, transformedName); } diff --git a/src/main/java/net/fabricmc/loom/task/RunClientTask.java b/src/main/java/net/fabricmc/loom/task/RunClientTask.java index 370c87e..ef030a7 100644 --- a/src/main/java/net/fabricmc/loom/task/RunClientTask.java +++ b/src/main/java/net/fabricmc/loom/task/RunClientTask.java @@ -66,7 +66,6 @@ public class RunClientTask extends JavaExec { //Removes the deobf jars libs.removeIf(s -> s.contains(Constants.MINECRAFT_FINAL_JAR.get(extension).getName())); - libs.removeIf(s -> s.contains(getProject().getName() + "-" + getProject().getVersion() + "-deobf.jar")); classpath(libs); @@ -77,6 +76,14 @@ public class RunClientTask extends JavaExec { super.exec(); } + @Override + public void setWorkingDir(File dir) { + if(!dir.exists()){ + dir.mkdirs(); + } + super.setWorkingDir(dir); + } + @Override public String getMain() { return "net.minecraft.launchwrapper.Launch"; diff --git a/src/main/java/net/fabricmc/loom/task/RunServerTask.java b/src/main/java/net/fabricmc/loom/task/RunServerTask.java index 418643b..3d62eb7 100644 --- a/src/main/java/net/fabricmc/loom/task/RunServerTask.java +++ b/src/main/java/net/fabricmc/loom/task/RunServerTask.java @@ -77,6 +77,14 @@ public class RunServerTask extends JavaExec { return "net.minecraft.launchwrapper.Launch"; } + @Override + public void setWorkingDir(File dir) { + if(!dir.exists()){ + dir.mkdirs(); + } + super.setWorkingDir(dir); + } + @Override public List getJvmArgs() { LoomGradleExtension extension = this.getProject().getExtensions().getByType(LoomGradleExtension.class); diff --git a/src/main/java/net/fabricmc/loom/util/ModProcessor.java b/src/main/java/net/fabricmc/loom/util/ModProcessor.java index 3533307..bde2791 100644 --- a/src/main/java/net/fabricmc/loom/util/ModProcessor.java +++ b/src/main/java/net/fabricmc/loom/util/ModProcessor.java @@ -105,6 +105,7 @@ public class ModProcessor { remapper.read(mcDeps); remapper.apply(input.toPath(), outputConsumer); outputConsumer.finish(); + remapper.finish(); } catch (Exception e){ remapper.finish(); throw new RuntimeException("Failed to remap JAR to " + toM, e); @@ -121,7 +122,10 @@ public class ModProcessor { if (!entry.isDirectory() && entry.getName().endsWith(".json") && !entry.getName().contains("/") && !entry.getName().contains("\\")) { // JSON file in root directory try { - JsonObject json = gson.fromJson(new InputStreamReader(stream), JsonObject.class); + InputStreamReader inputStreamReader = new InputStreamReader(stream); + JsonObject json = gson.fromJson(inputStreamReader, JsonObject.class); + inputStreamReader.close(); + stream.close(); if (json != null && json.has("refmap")) { mixinRefmapFilenames.add(json.get("refmap").getAsString()); } diff --git a/src/main/java/net/fabricmc/loom/util/ModRemapper.java b/src/main/java/net/fabricmc/loom/util/ModRemapper.java index 187e137..03b127c 100644 --- a/src/main/java/net/fabricmc/loom/util/ModRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/ModRemapper.java @@ -28,7 +28,6 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyUtils; -import org.apache.commons.io.FileUtils; import org.gradle.api.Project; import java.io.File; @@ -43,25 +42,13 @@ public class ModRemapper { LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); // TODO: What's the proper way of doing this? File libsDir = new File(project.getBuildDir(), "libs"); - File deobfJar = new File(libsDir, project.getName() + "-" + project.getVersion() + "-deobf.jar"); File modJar = new File(libsDir, project.getName() + "-" + project.getVersion() + ".jar"); if (!modJar.exists()) { - project.getLogger().error("Could not find mod .JAR at" + deobfJar.getAbsolutePath()); project.getLogger().error("This is can be fixed by adding a 'settings.gradle' file specifying 'rootProject.name'"); return; } - if (deobfJar.exists()) { - deobfJar.delete(); - } - - FileUtils.touch(modJar); //Done to ensure that the file can be moved - //Move the pre existing mod jar to the deobf jar - if(!modJar.renameTo(deobfJar)){ - throw new RuntimeException("Failed to rename " + modJar); - } - Path mappings = Constants.MAPPINGS_TINY.get(extension).toPath(); String fromM = "named"; @@ -86,10 +73,10 @@ public class ModRemapper { try { OutputConsumerPath outputConsumer = new OutputConsumerPath(modJar.toPath()); - outputConsumer.addNonClassFiles(deobfJar.toPath()); - remapper.read(deobfJar.toPath()); + outputConsumer.addNonClassFiles(modJar.toPath()); + remapper.read(modJar.toPath()); remapper.read(classpath); - remapper.apply(deobfJar.toPath(), outputConsumer); + remapper.apply(modJar.toPath(), outputConsumer); outputConsumer.finish(); remapper.finish(); } catch (Exception e){ @@ -97,11 +84,9 @@ public class ModRemapper { throw new RuntimeException("Failed to remap JAR", e); } - if(!deobfJar.exists() || !modJar.exists()){ + if(!modJar.exists()){ throw new RuntimeException("Failed to reobfuscate JAR"); } - - deobfJar.delete(); } }