mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 13:05:27 -05:00
@@ -29,6 +29,7 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -36,6 +37,7 @@ import java.util.stream.StreamSupport;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import org.gradle.api.Project;
|
||||
@@ -108,7 +110,13 @@ public final class MixinRefmapHelper {
|
||||
|
||||
@NotNull
|
||||
private static Collection<String> getMixinConfigurationFiles(JsonObject fabricModJson) {
|
||||
return StreamSupport.stream(fabricModJson.getAsJsonArray("mixins").spliterator(), false)
|
||||
JsonArray mixins = fabricModJson.getAsJsonArray("mixins");
|
||||
|
||||
if (mixins == null) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
return StreamSupport.stream(mixins.spliterator(), false)
|
||||
.map(e -> {
|
||||
if (e instanceof JsonPrimitive str) {
|
||||
return str.getAsString();
|
||||
|
||||
@@ -25,7 +25,9 @@
|
||||
package net.fabricmc.loom.configuration.providers.mappings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.logging.Logger;
|
||||
@@ -36,12 +38,11 @@ import net.fabricmc.loom.configuration.providers.MinecraftProvider;
|
||||
public class GradleMappingContext implements MappingContext {
|
||||
private final Project project;
|
||||
private final LoomGradleExtension extension;
|
||||
private final String workingDirName;
|
||||
private File workingDir;
|
||||
|
||||
public GradleMappingContext(Project project, String workingDirName) {
|
||||
public GradleMappingContext(Project project) {
|
||||
this.project = project;
|
||||
this.extension = LoomGradleExtension.get(project);
|
||||
this.workingDirName = workingDirName;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,11 +61,29 @@ public class GradleMappingContext implements MappingContext {
|
||||
return extension.getMinecraftProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File workingDirectory() {
|
||||
if (workingDir == null) {
|
||||
workingDir = new File(mappingsProvider().getMappingsDir().toFile(), "layered/" + minecraftProvider().minecraftVersion());
|
||||
|
||||
if (workingDir.exists()) {
|
||||
try {
|
||||
FileUtils.deleteDirectory(workingDir);
|
||||
} catch (IOException e) {
|
||||
getLogger().warn("Failed to cleanup layered mappings working directory: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return workingDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File workingDirectory(String name) {
|
||||
File tempDir = new File(mappingsProvider().getMappingsDir().toFile(), workingDirName);
|
||||
tempDir.mkdirs();
|
||||
return new File(tempDir, name);
|
||||
File file = new File(workingDirectory(), name);
|
||||
file.mkdirs();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,8 +27,8 @@ package net.fabricmc.loom.configuration.providers.mappings;
|
||||
import java.util.List;
|
||||
|
||||
public record LayeredMappingSpec(List<MappingsSpec<?>> layers) {
|
||||
public String getVersion() {
|
||||
public String getVersion(MappingContext context) {
|
||||
// TODO something better?
|
||||
return "layered+hash.%d".formatted(Math.abs(hashCode()));
|
||||
return "layered+hash.%d.minecraft.%s".formatted(Math.abs(hashCode()), context.minecraftVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,17 +54,16 @@ public class LayeredMappingsDependency implements SelfResolvingDependency {
|
||||
|
||||
private final MappingContext mappingContext;
|
||||
private final LayeredMappingSpec layeredMappingSpec;
|
||||
private final String version;
|
||||
private String version = null;
|
||||
|
||||
public LayeredMappingsDependency(MappingContext mappingContext, LayeredMappingSpec layeredMappingSpec, String version) {
|
||||
public LayeredMappingsDependency(MappingContext mappingContext, LayeredMappingSpec layeredMappingSpec) {
|
||||
this.mappingContext = mappingContext;
|
||||
this.layeredMappingSpec = layeredMappingSpec;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<File> resolve() {
|
||||
Path mappingsDir = mappingContext.mappingsProvider().getMappingsDir();
|
||||
Path mappingsDir = mappingContext.workingDirectory().toPath();
|
||||
Path mappingsFile = mappingsDir.resolve(String.format("%s.%s-%s.tiny", GROUP, MODULE, getVersion()));
|
||||
|
||||
if (!Files.exists(mappingsFile) || LoomGradlePlugin.refreshDeps) {
|
||||
@@ -115,6 +114,10 @@ public class LayeredMappingsDependency implements SelfResolvingDependency {
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
if (version == null) {
|
||||
version = layeredMappingSpec.getVersion(mappingContext);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
@@ -129,7 +132,7 @@ public class LayeredMappingsDependency implements SelfResolvingDependency {
|
||||
|
||||
@Override
|
||||
public Dependency copy() {
|
||||
return new LayeredMappingsDependency(mappingContext, layeredMappingSpec, version);
|
||||
return new LayeredMappingsDependency(mappingContext, layeredMappingSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,8 @@ public interface MappingContext {
|
||||
return minecraftProvider().minecraftVersion();
|
||||
}
|
||||
|
||||
File workingDirectory();
|
||||
|
||||
/**
|
||||
* Creates a temporary working dir to be used to store working files.
|
||||
*/
|
||||
|
||||
@@ -44,14 +44,15 @@ import net.fabricmc.mappingio.MappingVisitor;
|
||||
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch;
|
||||
import net.fabricmc.mappingio.format.ProGuardReader;
|
||||
|
||||
public record MojangMappingLayer(MinecraftVersionMeta.Download clientDownload,
|
||||
public record MojangMappingLayer(String minecraftVersion,
|
||||
MinecraftVersionMeta.Download clientDownload,
|
||||
MinecraftVersionMeta.Download serverDownload,
|
||||
File workingDir,
|
||||
Logger logger) implements MappingLayer {
|
||||
@Override
|
||||
public void visit(MappingVisitor mappingVisitor) throws IOException {
|
||||
var clientMappings = new File(workingDir(), "client.txt");
|
||||
var serverMappings = new File(workingDir(), "server.txt");
|
||||
var clientMappings = new File(workingDir(), "%s.client.txt".formatted(minecraftVersion));
|
||||
var serverMappings = new File(workingDir(), "%s.server.txt".formatted(minecraftVersion));
|
||||
|
||||
download(clientMappings, serverMappings);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ public record MojangMappingsSpec() implements MappingsSpec<MojangMappingLayer> {
|
||||
}
|
||||
|
||||
return new MojangMappingLayer(
|
||||
context.minecraftVersion(),
|
||||
versionInfo.download(MANIFEST_CLIENT_MAPPINGS),
|
||||
versionInfo.download(MANIFEST_SERVER_MAPPINGS),
|
||||
context.workingDirectory("mojang"),
|
||||
|
||||
@@ -107,7 +107,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
|
||||
LayeredMappingSpecBuilder builder = new LayeredMappingSpecBuilder();
|
||||
action.execute(builder);
|
||||
LayeredMappingSpec builtSpec = builder.build();
|
||||
return new LayeredMappingsDependency(new GradleMappingContext(getProject(), "layers_" + builtSpec.getVersion().replace("+", "_").replace(".", "_")), builtSpec, builtSpec.getVersion());
|
||||
return new LayeredMappingsDependency(new GradleMappingContext(getProject()), builtSpec);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.gradle.api.Action
|
||||
import org.gradle.util.ConfigureUtil
|
||||
import spock.lang.Specification
|
||||
|
||||
class LayeredMappingSpecBuilderTest extends Specification {
|
||||
class LayeredMappingSpecBuilderTest extends LayeredMappingsSpecification {
|
||||
def "simple mojmap" () {
|
||||
when:
|
||||
def spec = layered() {
|
||||
@@ -41,7 +41,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
|
||||
}
|
||||
def layers = spec.layers()
|
||||
then:
|
||||
spec.version == "layered+hash.961"
|
||||
spec.getVersion(mappingContext) == "layered+hash.961.minecraft.null"
|
||||
layers.size() == 2
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -56,7 +56,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.version == "layered+hash.863714404"
|
||||
spec.getVersion(mappingContext) == "layered+hash.863714404.minecraft.null"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -76,7 +76,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.version == "layered+hash.863714410"
|
||||
spec.getVersion(mappingContext) == "layered+hash.863714410.minecraft.null"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
@@ -96,7 +96,7 @@ class LayeredMappingSpecBuilderTest extends Specification {
|
||||
def layers = spec.layers()
|
||||
def parchment = layers[2] as ParchmentMappingsSpec
|
||||
then:
|
||||
spec.version == "layered+hash.1144465487"
|
||||
spec.getVersion(mappingContext) == "layered+hash.1144465487.minecraft.null"
|
||||
layers.size() == 3
|
||||
layers[0].class == IntermediaryMappingsSpec
|
||||
layers[1].class == MojangMappingsSpec
|
||||
|
||||
@@ -108,6 +108,11 @@ abstract class LayeredMappingsSpecification extends Specification implements Lay
|
||||
return mockMinecraftProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
File workingDirectory() {
|
||||
return tempDir
|
||||
}
|
||||
|
||||
@Override
|
||||
File workingDirectory(String name) {
|
||||
return new File(tempDir, name)
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.gradle.testkit.runner.GradleRunner
|
||||
|
||||
trait ProjectTestTrait {
|
||||
final static String DEFAULT_GRADLE = "7.0.1"
|
||||
final static String PRE_RELEASE_GRADLE = "7.3-20210724022245+0000"
|
||||
final static String PRE_RELEASE_GRADLE = "7.3-20210807021145+0000"
|
||||
|
||||
static File gradleHome = File.createTempDir()
|
||||
File testProjectDir = File.createTempDir()
|
||||
|
||||
@@ -4,7 +4,7 @@ plugins {
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
name = "ldtteam"
|
||||
name = "ParchmentMC"
|
||||
url = "https://maven.parchmentmc.net/"
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ dependencies {
|
||||
minecraft "com.mojang:minecraft:1.16.5"
|
||||
mappings loom.layered() {
|
||||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-1.16.5:20210608-SNAPSHOT@zip")
|
||||
parchment("org.parchmentmc.data:parchment-1.16.5:2021.08.08@zip")
|
||||
}
|
||||
|
||||
modImplementation "net.fabricmc:fabric-loader:0.11.3"
|
||||
|
||||
Reference in New Issue
Block a user