From 2cc95daa71745555654fd4cd8d89bd725b0ccebe Mon Sep 17 00:00:00 2001 From: liach <7806504+liach@users.noreply.github.com> Date: Fri, 15 Nov 2019 14:16:26 -0600 Subject: [PATCH] Improve support for custom self-resolving mappings (#145) Also allow mappings for 19w44a be used on 19w45b etc. with tinyv2 Signed-off-by: liach --- .../loom/providers/MappingsProvider.java | 6 +- .../loom/util/DependencyProvider.java | 51 +++++++++------- .../net/fabricmc/loom/util/DownloadUtil.java | 2 +- .../java/net/fabricmc/loom/util/Version.java | 59 ------------------- 4 files changed, 32 insertions(+), 86 deletions(-) delete mode 100644 src/main/java/net/fabricmc/loom/util/Version.java diff --git a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java index 77f8d15..fa71377 100644 --- a/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MappingsProvider.java @@ -48,7 +48,6 @@ import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.DependencyProvider; import net.fabricmc.loom.util.DownloadUtil; -import net.fabricmc.loom.util.Version; import net.fabricmc.mapping.reader.v2.TinyV2Factory; import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.stitch.Command; @@ -93,9 +92,8 @@ public class MappingsProvider extends DependencyProvider { boolean isV2 = doesJarContainV2Mappings(mappingsJar.toPath()); - Version mappingsVersion = new Version(version); - this.minecraftVersion = mappingsVersion.getMinecraftVersion(); - this.mappingsVersion = mappingsVersion.getMappingsVersion() + (isV2 ? "-v2" : ""); + this.minecraftVersion = minecraftProvider.minecraftVersion; + this.mappingsVersion = version + (isV2 ? "-v2" : ""); initFiles(project); diff --git a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java index 25bc1de..067db9f 100644 --- a/src/main/java/net/fabricmc/loom/util/DependencyProvider.java +++ b/src/main/java/net/fabricmc/loom/util/DependencyProvider.java @@ -39,13 +39,13 @@ import com.google.common.collect.Iterables; import com.google.gson.Gson; import com.google.gson.JsonObject; import org.apache.commons.io.FilenameUtils; -import org.zeroturnaround.zip.ZipUtil; import org.gradle.api.InvalidUserDataException; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.ResolvedDependency; import org.gradle.api.artifacts.SelfResolvingDependency; +import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradleExtension; @@ -154,7 +154,7 @@ public abstract class DependencyProvider { public static class FileDependencyInfo extends DependencyInfo { protected final Map classifierToFile = new HashMap<>(); - protected final String group = "net.fabricmc.synthetic", name, version; + protected final String group, name, version; FileDependencyInfo(Project project, SelfResolvingDependency dependency, Configuration configuration) { super(project, dependency, configuration); @@ -196,27 +196,34 @@ public abstract class DependencyProvider { } } - File root = classifierToFile.get(""); //We've built the classifierToFile map, now to try find a name and version for our dependency - - if ("jar".equals(FilenameUtils.getExtension(root.getName())) && ZipUtil.containsEntry(root, "fabric.mod.json")) { - //It's a Fabric mod, see how much we can extract out - JsonObject json = new Gson().fromJson(new String(ZipUtil.unpackEntry(root, "fabric.mod.json"), StandardCharsets.UTF_8), JsonObject.class); - - if (json == null || !json.has("id") || !json.has("version")) { - throw new IllegalArgumentException("Invalid Fabric mod jar: " + root + " (malformed json: " + json + ')'); - } - - if (json.has("name")) { //Go for the name field if it's got one - name = json.get("name").getAsString(); - } else { - name = json.get("id").getAsString(); - } - - version = json.get("version").getAsString(); + if (dependency.getGroup() != null && dependency.getVersion() != null) { + group = dependency.getGroup(); + name = dependency.getName(); + version = dependency.getVersion(); } else { - //Not a Fabric mod, just have to make something up - name = FilenameUtils.removeExtension(root.getName()); - version = "1.0"; + group = "net.fabricmc.synthetic"; + File root = classifierToFile.get(""); //We've built the classifierToFile map, now to try find a name and version for our dependency + + if ("jar".equals(FilenameUtils.getExtension(root.getName())) && ZipUtil.containsEntry(root, "fabric.mod.json")) { + //It's a Fabric mod, see how much we can extract out + JsonObject json = new Gson().fromJson(new String(ZipUtil.unpackEntry(root, "fabric.mod.json"), StandardCharsets.UTF_8), JsonObject.class); + + if (json == null || !json.has("id") || !json.has("version")) { + throw new IllegalArgumentException("Invalid Fabric mod jar: " + root + " (malformed json: " + json + ')'); + } + + if (json.has("name")) { //Go for the name field if it's got one + name = json.get("name").getAsString(); + } else { + name = json.get("id").getAsString(); + } + + version = json.get("version").getAsString(); + } else { + //Not a Fabric mod, just have to make something up + name = FilenameUtils.removeExtension(root.getName()); + version = "1.0"; + } } } diff --git a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java index 44dcb60..35f17d0 100644 --- a/src/main/java/net/fabricmc/loom/util/DownloadUtil.java +++ b/src/main/java/net/fabricmc/loom/util/DownloadUtil.java @@ -85,7 +85,7 @@ public class DownloadUtil { if ((code < 200 || code > 299) && code != HttpURLConnection.HTTP_NOT_MODIFIED) { //Didn't get what we expected - throw new IOException(connection.getResponseMessage()); + throw new IOException(connection.getResponseMessage() + " for " + from); } long modifyTime = connection.getHeaderFieldDate("Last-Modified", -1); diff --git a/src/main/java/net/fabricmc/loom/util/Version.java b/src/main/java/net/fabricmc/loom/util/Version.java deleted file mode 100644 index a6842e3..0000000 --- a/src/main/java/net/fabricmc/loom/util/Version.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of fabric-loom, licensed under the MIT License (MIT). - * - * Copyright (c) 2016, 2017, 2018 FabricMC - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package net.fabricmc.loom.util; - -public class Version { - private String mappingsVersion; - private String minecraftVersion; - - private String version; - - public Version(String version) { - this.version = version; - - if (version.contains("+build.")) { - this.minecraftVersion = version.substring(0, version.lastIndexOf('+')); - this.mappingsVersion = version.substring(version.lastIndexOf('.') + 1); - } else { - //TODO legacy remove when no longer needed - char verSep = version.contains("-") ? '-' : '.'; - this.minecraftVersion = version.substring(0, version.lastIndexOf(verSep)); - this.mappingsVersion = version.substring(version.lastIndexOf(verSep) + 1); - } - } - - public String getMappingsVersion() { - return mappingsVersion; - } - - public String getMinecraftVersion() { - return minecraftVersion; - } - - @Override - public String toString() { - return version; - } -}