From 0b38f3ecc56e3ec07a08007598794ab9e0318e60 Mon Sep 17 00:00:00 2001 From: asie Date: Sun, 23 Dec 2018 19:18:40 +0100 Subject: [PATCH] use more reliable renamer, update Stitch - fix #46 --- build.gradle | 2 +- .../net/fabricmc/loom/task/GenSourcesTask.java | 3 ++- .../java/net/fabricmc/loom/util/ModRemapper.java | 16 +++++++++++----- .../net/fabricmc/loom/util/SourceRemapper.java | 6 ++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index 37ac4e2..337c4a1 100644 --- a/build.gradle +++ b/build.gradle @@ -34,7 +34,7 @@ dependencies { implementation ('org.zeroturnaround:zt-zip:1.13') implementation ('com.google.code.gson:gson:2.8.5') implementation ('com.google.guava:guava:27.0.1-jre') - implementation ('net.fabricmc:stitch:0.1.1.32') + implementation ('net.fabricmc:stitch:0.1.1.36') implementation ('net.fabricmc:tiny-remapper:0.1.0.22') { transitive = false } diff --git a/src/main/java/net/fabricmc/loom/task/GenSourcesTask.java b/src/main/java/net/fabricmc/loom/task/GenSourcesTask.java index 51d65f9..4154ea7 100644 --- a/src/main/java/net/fabricmc/loom/task/GenSourcesTask.java +++ b/src/main/java/net/fabricmc/loom/task/GenSourcesTask.java @@ -25,6 +25,7 @@ package net.fabricmc.loom.task; import com.google.common.io.ByteStreams; +import com.google.common.io.Files; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.providers.MinecraftLibraryProvider; @@ -92,7 +93,7 @@ public class GenSourcesTask extends DefaultLoomTask { project.getLogger().lifecycle(":readjusting line numbers"); File tmpJar = new File(mappedJar.getAbsolutePath() + ".tmp"); - mappedJar.renameTo(tmpJar); + Files.move(mappedJar, tmpJar); try ( FileInputStream fis = new FileInputStream(tmpJar); JarInputStream jis = new JarInputStream(fis); diff --git a/src/main/java/net/fabricmc/loom/util/ModRemapper.java b/src/main/java/net/fabricmc/loom/util/ModRemapper.java index 1f6503e..cf383b4 100644 --- a/src/main/java/net/fabricmc/loom/util/ModRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/ModRemapper.java @@ -24,6 +24,7 @@ package net.fabricmc.loom.util; +import com.google.common.io.Files; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.providers.MappingsProvider; import net.fabricmc.loom.task.RemapJar; @@ -34,6 +35,7 @@ import org.gradle.api.Project; import org.gradle.api.artifacts.Dependency; import java.io.File; +import java.io.IOException; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; @@ -106,12 +108,16 @@ public class ModRemapper { } } - if (modJar.exists()) { - modJar.renameTo(modJarUnmappedCopy); - extension.addUnmappedMod(modJarUnmappedCopy); - } + try { + if (modJar.exists()) { + Files.move(modJar, modJarUnmappedCopy); + extension.addUnmappedMod(modJarUnmappedCopy); + } - modJarOutput.renameTo(modJar); + Files.move(modJarOutput, modJar); + } catch (IOException e) { + throw new RuntimeException(e); + } } } diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index d8724f7..1c3cf3e 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -91,8 +91,10 @@ public class SourceRemapper { } source = new File(destination.getAbsolutePath().substring(0, destination.getAbsolutePath().lastIndexOf('.')) + "-dev.jar"); - if (!destination.renameTo(source)) { - throw new RuntimeException("Could not rename " + destination.getName() + "!"); + try { + com.google.common.io.Files.move(destination, source); + } catch (IOException e) { + throw new RuntimeException("Could not rename " + destination.getName() + "!", e); } }