Fixes for Mojang mappings handling (#264)

* Only resolve SelfResolvingDependencies once

* mojmap: Improve styling, move to a better group + artifact id
dev/0.11
zml 2020-08-26 00:31:42 -07:00 committed by GitHub
parent 9029a699d9
commit 37af4c8152
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 13 deletions

View File

@ -118,7 +118,7 @@ public class MigrateMappingsTask extends AbstractLoomTask {
Set<File> files;
try {
if (mappings.startsWith("net.mojang.minecraft:mappings:")) {
if (mappings.startsWith(MojangMappingsDependency.GROUP + ':' + MojangMappingsDependency.MODULE + ':')) {
if (!mappings.endsWith(":" + project.getExtensions().getByType(LoomGradleExtension.class).getMinecraftProvider().getMinecraftVersion())) {
throw new UnsupportedOperationException("Migrating Mojang mappings is currently only supported for the specified minecraft version");
}

View File

@ -175,12 +175,14 @@ public abstract class DependencyProvider {
public static class FileDependencyInfo extends DependencyInfo {
protected final Map<String, File> classifierToFile = new HashMap<>();
protected final Set<File> resolvedFiles;
protected final String group, name, version;
FileDependencyInfo(Project project, SelfResolvingDependency dependency, Configuration configuration) {
super(project, dependency, configuration);
Set<File> files = dependency.resolve();
this.resolvedFiles = files;
switch (files.size()) {
case 0: //Don't think Gradle would ever let you do this
throw new IllegalStateException("Empty dependency?");
@ -263,5 +265,10 @@ public abstract class DependencyProvider {
public String getResolvedDepString() {
return getDepString();
}
@Override
public Set<File> resolve() {
return this.resolvedFiles;
}
}
}

View File

@ -60,6 +60,12 @@ import net.fabricmc.lorenztiny.TinyMappingsReader;
import net.fabricmc.mapping.tree.TinyMappingFactory;
public class MojangMappingsDependency implements SelfResolvingDependency {
public static final String GROUP = "net.minecraft";
public static final String MODULE = "mappings";
// Keys in dependency manifest
private static final String MANIFEST_CLIENT_MAPPINGS = "client_mappings";
private static final String MANIFEST_SERVER_MAPPINGS = "server_mappings";
private final Project project;
private final LoomGradleExtension extension;
@ -71,9 +77,9 @@ public class MojangMappingsDependency implements SelfResolvingDependency {
@Override
public Set<File> resolve() {
Path mappingsDir = extension.getMappingsProvider().getMappingsDir();
Path mappingsFile = mappingsDir.resolve(String.format("net.mojang.minecraft-mappings-%s.tiny", getVersion()));
Path clientMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-client.map", getVersion()));
Path serverMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-server.map", getVersion()));
Path mappingsFile = mappingsDir.resolve(String.format("%s.%s-%s.tiny", GROUP, MODULE, getVersion()));
Path clientMappings = mappingsDir.resolve(String.format("%s.%s-%s-client.map", GROUP, MODULE, getVersion()));
Path serverMappings = mappingsDir.resolve(String.format("%s.%s-%s-server.map", GROUP, MODULE, getVersion()));
if (!Files.exists(mappingsFile) || project.getGradle().getStartParameter().isRefreshDependencies()) {
MappingSet mappingSet;
@ -95,17 +101,17 @@ public class MojangMappingsDependency implements SelfResolvingDependency {
}
try (BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8)) {
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
project.getLogger().warn("Using of the official minecraft mappings is at your own risk!");
project.getLogger().warn("Please make sure to read and understand the following license:");
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
String line;
while ((line = clientBufferedReader.readLine()).startsWith("#")) {
project.getLogger().warn(line);
}
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
project.getLogger().warn("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
} catch (IOException e) {
throw new RuntimeException("Failed to read client mappings", e);
}
@ -116,12 +122,12 @@ public class MojangMappingsDependency implements SelfResolvingDependency {
private MappingSet getMappingsSet(Path clientMappings, Path serverMappings) throws IOException {
MinecraftVersionInfo versionInfo = extension.getMinecraftProvider().getVersionInfo();
if (versionInfo.downloads.get("client_mappings") == null) {
if (versionInfo.downloads.get(MANIFEST_CLIENT_MAPPINGS) == null) {
throw new RuntimeException("Failed to find official mojang mappings for " + getVersion());
}
String clientMappingsUrl = versionInfo.downloads.get("client_mappings").url;
String serverMappingsUrl = versionInfo.downloads.get("server_mappings").url;
String clientMappingsUrl = versionInfo.downloads.get(MANIFEST_CLIENT_MAPPINGS).url;
String serverMappingsUrl = versionInfo.downloads.get(MANIFEST_SERVER_MAPPINGS).url;
DownloadUtil.downloadIfChanged(new URL(clientMappingsUrl), clientMappings.toFile(), project.getLogger());
DownloadUtil.downloadIfChanged(new URL(serverMappingsUrl), serverMappings.toFile(), project.getLogger());
@ -186,12 +192,12 @@ public class MojangMappingsDependency implements SelfResolvingDependency {
@Override
public String getGroup() {
return "net.mojang.minecraft";
return GROUP;
}
@Override
public String getName() {
return "mappings";
return MODULE;
}
@Override