From e21ba90d9fe200cb2ca2fc347d632e5be1700505 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Tue, 16 Nov 2021 21:28:37 -0800 Subject: [PATCH] Clean up code to transfer to QuiltMC --- README.md | 6 +- build.gradle.kts | 9 +-- .../loom/QuiltMappingsOnLoomPlugin.java | 73 +++++++++---------- test/build.gradle.kts | 10 +-- test/settings.gradle.kts | 2 +- 5 files changed, 47 insertions(+), 53 deletions(-) rename src/main/java/{com/oroarmor => org/quiltmc}/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java (61%) diff --git a/README.md b/README.md index 0391f84..58c0926 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Currently, 1.17.1+ is only has support, with no plans of backporting to earlier ```groovy pluginManagement { repositories { - maven { url = "https://maven.oroarmor.com" } + maven { url = "https://maven.quiltmc.org/repository/release" } } } ``` @@ -30,14 +30,14 @@ pluginManagement { ```groovy plugins { // ... - id "quilt-mappings-on-loom" version "2.0.0" + id "quilt-mappings-on-loom" version "3.0.0" } // ... dependencies { mappings(loom.layered { - addLayer(quiltmappings.mappings("org.quiltmc:quilt-mappings:${minecraft_version}+build.${project.quilt_mappings}:v2", true)) + addLayer(quiltmappings.mappings("org.quiltmc:quilt-mappings:${minecraft_version}+build.${project.quilt_mappings}:v2")) }) } ``` diff --git a/build.gradle.kts b/build.gradle.kts index a04334f..eecb46d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,8 +4,8 @@ plugins { `maven-publish` } -group = "com.oroarmor" -version = "2.0.0" +group = "org.quiltmc" +version = "3.0.0" repositories { mavenCentral() @@ -19,14 +19,13 @@ dependencies { implementation("net.fabricmc:mapping-io:0.2.1") implementation("net.fabricmc:lorenz-tiny:4.0.2") implementation("net.fabricmc:tiny-mappings-parser:0.2.2.14") - implementation("net.fabricmc:stitch:0.6.1") } gradlePlugin { plugins { create("quiltMappingsLoom") { id = "quilt-mappings-on-loom" - implementationClass = "com.oroarmor.quiltmappings.loom.QuiltMappingsOnLoomPlugin" + implementationClass = "org.quiltmc.quiltmappings.loom.QuiltMappingsOnLoomPlugin" } } } @@ -47,7 +46,7 @@ publishing { username = System.getenv("MAVEN_USERNAME") password = System.getenv("MAVEN_PASSWORD") } - name = "OroArmorMaven" + name = "Maven" } } } diff --git a/src/main/java/com/oroarmor/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java b/src/main/java/org/quiltmc/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java similarity index 61% rename from src/main/java/com/oroarmor/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java rename to src/main/java/org/quiltmc/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java index 6d89d66..0c546f7 100644 --- a/src/main/java/com/oroarmor/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java +++ b/src/main/java/org/quiltmc/quiltmappings/loom/QuiltMappingsOnLoomPlugin.java @@ -1,15 +1,12 @@ -package com.oroarmor.quiltmappings.loom; +package org.quiltmc.quiltmappings.loom; -import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.Collections; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; -import java.util.Set; import org.gradle.api.Plugin; import org.gradle.api.Project; @@ -21,9 +18,6 @@ import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.api.mappings.layered.spec.MappingsSpec; import net.fabricmc.mappingio.MappingVisitor; import net.fabricmc.mappingio.MappingWriter; -import net.fabricmc.mappingio.adapter.MappingDstNsReorder; -import net.fabricmc.mappingio.adapter.MappingNsRenamer; -import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch; import net.fabricmc.mappingio.format.MappingFormat; import net.fabricmc.mappingio.format.Tiny2Reader; import net.fabricmc.mappingio.tree.MemoryMappingTree; @@ -32,7 +26,7 @@ import net.fabricmc.mappingio.tree.MemoryMappingTree; public class QuiltMappingsOnLoomPlugin implements Plugin { @Override public void apply(Project target) { - target.getExtensions().create("quiltmappings", QuiltMappingsOnLoomExtension.class, target); + target.getExtensions().create("quiltMappings", QuiltMappingsOnLoomExtension.class); target.getRepositories().maven(repo -> { repo.setName("Quilt Releases"); @@ -52,48 +46,54 @@ public class QuiltMappingsOnLoomPlugin implements Plugin { this.project = project; } + @Deprecated public MappingsSpec mappings(String quiltMappings, boolean snapshot) { - return new MappingsSpec<>() { - @Override - public MappingLayer createLayer(MappingContext context) { - return new QuiltMappingsLayer(context, project, quiltMappings, snapshot); - } + return mappings(quiltMappings); + } - @Override - public int hashCode() { - return Objects.hash(quiltMappings, snapshot); - } - }; + public MappingsSpec mappings(String quiltMappings) { + return new MappingLayerMappingsSpec(project, quiltMappings); + } + + private record MappingLayerMappingsSpec(Project project, String quiltMappings) + implements MappingsSpec { + @Override + public MappingLayer createLayer(MappingContext context) { + return new QuiltMappingsLayer(context, project, quiltMappings); + } + + @Override + public int hashCode() { + return Objects.hash(quiltMappings); + } } } - private record QuiltMappingsLayer(MappingContext context, Project project, String quiltMappings, - boolean snapshot) implements MappingLayer { - + private record QuiltMappingsLayer(MappingContext context, Project project, String quiltMappings) + implements MappingLayer { @Override public void visit(MappingVisitor mappingVisitor) throws IOException { String minecraftVersion = context.minecraftProvider().minecraftVersion(); - File intermediaryToQm = project.file(".gradle/qm/qm_to_intermediary_" + quiltMappings.split(':')[2] + ".tiny"); + String quiltMappingsBuild = "+build" + quiltMappings.substring(quiltMappings.lastIndexOf("."), quiltMappings.lastIndexOf(":")); + File intermediaryToQm = project.file(".gradle/qm/qm_to_intermediary_" + minecraftVersion + quiltMappingsBuild + ".tiny"); if (!intermediaryToQm.exists()) { - Set quiltmappings = project.getConfigurations().detachedConfiguration(project.getDependencies().create(quiltMappings)).resolve(); - Set hashedFiles = project.getConfigurations().detachedConfiguration(project.getDependencies().create("org.quiltmc:hashed:" + minecraftVersion + (snapshot ? "-SNAPSHOT" : ""))).resolve(); + List quiltMappings = new ArrayList<>(project.getConfigurations().detachedConfiguration(project.getDependencies().create(this.quiltMappings)).resolve()); - File hashedFile = project.file(".gradle/qm/hashed_" + minecraftVersion + ".tiny"); - downloadFile(hashedFiles, hashedFile); + File hashedFile = project.file(".gradle/qm/hashed_" + minecraftVersion + quiltMappingsBuild + ".tiny"); + downloadFile(quiltMappings.get(1), hashedFile); - File quiltMappingsFile = project.file(".gradle/qm/qm_" + minecraftVersion + ".tiny"); - downloadFile(quiltmappings, quiltMappingsFile); + File quiltMappingsFile = project.file(".gradle/qm/qm_" + minecraftVersion + quiltMappingsBuild + ".tiny"); + downloadFile(quiltMappings.get(0), quiltMappingsFile); MemoryMappingTree mappings = new MemoryMappingTree(); - MappingSourceNsSwitch sourceNsSwitch = new MappingSourceNsSwitch(mappings, MappingsNamespace.OFFICIAL.toString()); MemoryMappingTree hashed = new MemoryMappingTree(); try (FileReader reader = new FileReader(hashedFile)) { Tiny2Reader.read(reader, hashed); } - hashed.accept(sourceNsSwitch); + hashed.accept(mappings); try (FileReader reader = new FileReader(quiltMappingsFile)) { Tiny2Reader.read(reader, mappings); @@ -107,10 +107,10 @@ public class QuiltMappingsOnLoomPlugin implements Plugin { Tiny2Reader.read(new FileReader(intermediaryToQm), mappingVisitor); } - private void downloadFile(Set dependency, File output) { + private void downloadFile(File dependency, File output) { if (!output.exists()) { GFileUtils.copyFile(project - .zipTree(dependency.stream().iterator().next()) + .zipTree(dependency) .getFiles() .stream() .filter(file -> file.getName().endsWith("mappings.tiny")) @@ -123,10 +123,5 @@ public class QuiltMappingsOnLoomPlugin implements Plugin { public MappingsNamespace getSourceNamespace() { return MappingsNamespace.OFFICIAL; } - - @Override - public int hashCode() { - return quiltMappings.hashCode(); - } } } diff --git a/test/build.gradle.kts b/test/build.gradle.kts index b69bfd5..d0acc93 100644 --- a/test/build.gradle.kts +++ b/test/build.gradle.kts @@ -1,10 +1,10 @@ plugins { java id("fabric-loom") version "0.10-SNAPSHOT" - id("quilt-mappings-on-loom") version "1.0.0" + id("quilt-mappings-on-loom") version "3.0.0" } -group = "com.oroarmor" +group = "org.quiltmc" version = "1.0.0" repositories { @@ -14,14 +14,14 @@ repositories { } } -var minecraft_version = "21w42a" -var quilt_mappings = "21w42a+build.1" +var minecraft_version = "1.18-pre2" +var quilt_mappings = "1.18-pre2+build.3" var loader_version = "0.12.2" dependencies { minecraft("com.mojang:minecraft:${minecraft_version}") mappings(loom.layered { - addLayer(quiltmappings.mappings("org.quiltmc:quilt-mappings:${quilt_mappings}:v2", true)) + addLayer(quiltMappings.mappings("org.quiltmc:quilt-mappings:${quilt_mappings}:v2")) }) modImplementation("net.fabricmc:fabric-loader:${loader_version}") } diff --git a/test/settings.gradle.kts b/test/settings.gradle.kts index d4bd6b1..c9fbc39 100644 --- a/test/settings.gradle.kts +++ b/test/settings.gradle.kts @@ -5,7 +5,7 @@ pluginManagement { maven { url = uri("https://maven.fabricmc.net/") } - maven { url = uri("https://maven.oroarmor.com") } + maven { url = uri("https://maven.quiltmc.org/repository/release") } } }