From 673f21c506216be6c7668b99f448e205d85c0964 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Fri, 10 Feb 2017 13:14:46 +0000 Subject: [PATCH] Add the ability to use custom mapping files. --- .../fabricmc/loom/LoomGradleExtension.java | 4 +++ .../net/fabricmc/loom/task/DownloadTask.java | 35 ++++++++++++++++++- .../net/fabricmc/loom/util/Constants.java | 8 +++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index 416a6a5..8e15932 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -34,6 +34,7 @@ public class LoomGradleExtension { public String fabricVersion; public String pomfVersion; public String refmapName; + public boolean localMappings = false; //Not to be set in the build.gradle public Project project; @@ -58,6 +59,9 @@ public class LoomGradleExtension { } public boolean hasPomf(){ + if(localMappings){ + return true; + } return pomfVersion != null && !pomfVersion.isEmpty(); } } diff --git a/src/main/java/net/fabricmc/loom/task/DownloadTask.java b/src/main/java/net/fabricmc/loom/task/DownloadTask.java index 3cc9c7b..f37191a 100644 --- a/src/main/java/net/fabricmc/loom/task/DownloadTask.java +++ b/src/main/java/net/fabricmc/loom/task/DownloadTask.java @@ -76,9 +76,27 @@ public class DownloadTask extends DefaultTask { this.getLogger().lifecycle(":downloading mappings"); FileUtils.copyURLToFile(new URL("http://modmuss50.me:8080/job/pomf/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip"), Constants.MAPPINGS_ZIP.get(extension)); } + if(!extension.hasPomf()){ + if(Constants.MAPPINGS_DIR_LOCAL.get(extension).exists()){ + if(Constants.MAPPINGS_TINY_GZ_LOCAL.get(extension).exists() && Constants.MAPPINGS_ZIP_LOCAL.get(extension).exists()){ + this.getLogger().lifecycle("Found local mapping files"); + extension.localMappings = true; + extension.pomfVersion = "local"; //TODO set this to include the hash or something to so the jar name is unique? + + //We delete this to make sure they are always re extracted. + deleteIfExists(Constants.MAPPINGS_ZIP.get(extension)); + deleteIfExists(Constants.MAPPINGS_TINY_GZ.get(extension)); + deleteIfExists(Constants.MAPPINGS_TINY.get(extension)); + deleteIfExists(Constants.MAPPINGS_DIR.get(extension)); + + Constants.MAPPINGS_TINY_GZ = Constants.MAPPINGS_TINY_GZ_LOCAL; + Constants.MAPPINGS_ZIP = Constants.MAPPINGS_ZIP_LOCAL; + } + } + } if (!Constants.MAPPINGS_TINY.get(extension).exists() && extension.hasPomf()) { - if (!Constants.MAPPINGS_TINY_GZ.get(extension).exists()) { + if (!Constants.MAPPINGS_TINY_GZ.get(extension).exists() && !extension.localMappings) { getLogger().lifecycle(":downloading tiny mappings"); FileUtils.copyURLToFile(new URL("http://modmuss50.me:8080/job/pomf/" + extension.version + "/" + extension.pomfVersion + "/artifact/build/libs/pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz"), Constants.MAPPINGS_TINY_GZ.get(extension)); } @@ -172,4 +190,19 @@ public class DownloadTask extends DefaultTask { } } } + + private static boolean deleteIfExists(File file){ + if(file.exists()){ + if(file.isDirectory()){ + try { + FileUtils.deleteDirectory(file); + return file.mkdir(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return file.delete(); + } + return false; + } } diff --git a/src/main/java/net/fabricmc/loom/util/Constants.java b/src/main/java/net/fabricmc/loom/util/Constants.java index 5442367..02a222a 100644 --- a/src/main/java/net/fabricmc/loom/util/Constants.java +++ b/src/main/java/net/fabricmc/loom/util/Constants.java @@ -44,12 +44,16 @@ public class Constants { public static final IDelayed MINECRAFT_FINAL_JAR = new DelayedFile(extension -> new File(CACHE_FILES, extension.getVersionString() + "-mixed-" + extension.pomfVersion + ".jar")); public static final IDelayed POMF_DIR = new DelayedFile(extension -> new File(extension.getFabricUserCache(), "pomf")); - public static final IDelayed MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip")); + public static IDelayed MAPPINGS_ZIP = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + ".zip")); public static final IDelayed MAPPINGS_DIR = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-enigma-" + extension.version + "." + extension.pomfVersion + "")); - public static final IDelayed MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz")); + public static IDelayed MAPPINGS_TINY_GZ = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion + ".gz")); public static final IDelayed MAPPINGS_TINY = new DelayedFile(extension -> new File(POMF_DIR.get(extension), "pomf-tiny-" + extension.version + "." + extension.pomfVersion)); public static final IDelayed MAPPINGS_MIXIN_EXPORT = new DelayedFile(extension -> new File(CACHE_FILES, "mixin-map-" + extension.version + "." + extension.pomfVersion + ".mappings")); + public static final IDelayed MAPPINGS_DIR_LOCAL = new DelayedFile(extension -> new File(WORKING_DIRECTORY, "mappings")); + public static final IDelayed MAPPINGS_ZIP_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-enigma-" + extension.version + ".zip")); + public static final IDelayed MAPPINGS_TINY_GZ_LOCAL = new DelayedFile(extension -> new File(MAPPINGS_DIR_LOCAL.get(extension), "pomf-tiny-" + extension.version + ".gz")); + public static final IDelayed REF_MAP = new DelayedFile(extension -> new File(CACHE_FILES, "mixin-refmap.json")); public static final IDelayed MINECRAFT_LIBS = new DelayedFile(extension -> new File(extension.getFabricUserCache(), extension.version + "-libs"));