Improve support for custom self-resolving mappings (#145)
Also allow mappings for 19w44a be used on 19w45b etc. with tinyv2 Signed-off-by: liach <liach@users.noreply.github.com>dev/0.11
parent
55a9d90690
commit
2cc95daa71
|
@ -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);
|
||||
|
||||
|
|
|
@ -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<String, File> 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue