mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-31 05:15:57 -05:00
Merge with Fabric 1.1, stage 5
This commit is contained in:
@@ -54,7 +54,7 @@ public abstract class ModSettings implements Named {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link SourceSet}'s output directories from the current project to be grouped with the named mod.
|
||||
* Add {@link SourceSet}'s output directories from the current project to be grouped with the named mod.
|
||||
*/
|
||||
public void sourceSet(SourceSet sourceSet) {
|
||||
Project project = getProject();
|
||||
@@ -72,12 +72,30 @@ public abstract class ModSettings implements Named {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link SourceSet}'s output directories from supplied project to be grouped with the named mod.
|
||||
* Add {@link SourceSet}'s output directories from the current project to be grouped with the named mod.
|
||||
*
|
||||
* @param name the name of the source set
|
||||
*/
|
||||
public void sourceSet(String name) {
|
||||
sourceSet(name, getProject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link SourceSet}'s output directories from the supplied project to be grouped with the named mod.
|
||||
*/
|
||||
public void sourceSet(SourceSet sourceSet, Project project) {
|
||||
getModSourceSets().add(new SourceSetReference(sourceSet, project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add {@link SourceSet}'s output directories from the supplied project to be grouped with the named mod.
|
||||
*
|
||||
* @param name the name of the source set
|
||||
*/
|
||||
public void sourceSet(String name, Project project) {
|
||||
sourceSet(SourceSetHelper.getSourceSetByName(name, project), project);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a number of {@link Dependency} to the mod's classpath group. Should be used to include all dependencies that are shaded into your mod.
|
||||
*
|
||||
|
||||
@@ -100,9 +100,13 @@ public abstract class AnnotationProcessorInvoker<T extends Task> {
|
||||
String refmapName = Objects.requireNonNull(MixinExtension.getMixinInformationContainer(sourceSet)).refmapNameProvider().get();
|
||||
Path mappings = loom.getMappingConfiguration().getReplacedTarget(loom, loom.getMixin().getRefmapTargetNamespace().get());
|
||||
|
||||
final File mixinMappings = getMixinMappingsForSourceSet(project, sourceSet);
|
||||
|
||||
task.getOutputs().file(mixinMappings).withPropertyName("mixin-ap-" + sourceSet.getName()).optional();
|
||||
|
||||
Map<String, String> args = new HashMap<>() {{
|
||||
put(Constants.MixinArguments.IN_MAP_FILE_NAMED_INTERMEDIARY, mappings.toFile().getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, getMixinMappingsForSourceSet(project, sourceSet).getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_MAP_FILE_NAMED_INTERMEDIARY, mixinMappings.getCanonicalPath());
|
||||
put(Constants.MixinArguments.OUT_REFMAP_FILE, getRefmapDestination(task, refmapName));
|
||||
put(Constants.MixinArguments.DEFAULT_OBFUSCATION_ENV, "named:" + IntermediaryNamespaces.replaceMixinIntermediaryNamespace(project, loom.getMixin().getRefmapTargetNamespace().get()));
|
||||
put(Constants.MixinArguments.QUIET, "true");
|
||||
|
||||
@@ -36,7 +36,6 @@ import net.fabricmc.accesswidener.AccessWidenerWriter;
|
||||
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJson;
|
||||
import net.fabricmc.loom.util.fmj.FabricModJsonFactory;
|
||||
import net.fabricmc.loom.util.fmj.ModEnvironment;
|
||||
|
||||
public class AccessWidenerUtils {
|
||||
/**
|
||||
@@ -59,7 +58,7 @@ public class AccessWidenerUtils {
|
||||
|
||||
public static AccessWidenerData readAccessWidenerData(Path inputJar) throws IOException {
|
||||
final FabricModJson fabricModJson = FabricModJsonFactory.createFromZip(inputJar);
|
||||
final List<String> classTweakers = fabricModJson.getClassTweakers(ModEnvironment.UNIVERSAL);
|
||||
final List<String> classTweakers = List.copyOf(fabricModJson.getClassTweakers().keySet());
|
||||
|
||||
if (classTweakers.isEmpty()) {
|
||||
return null;
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.task.RemapSourcesJarTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.DeletingFileVisitor;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.SourceRemapper;
|
||||
@@ -58,22 +57,24 @@ public final class SourceRemapperService implements SharedService {
|
||||
final String from = task.getSourceNamespace().get();
|
||||
final LoomGradleExtension extension = LoomGradleExtension.get(project);
|
||||
final String id = extension.getMappingConfiguration().getBuildServiceName("sourceremapper", from, to);
|
||||
final int javaCompileRelease = SourceRemapper.getJavaCompileRelease(project);
|
||||
|
||||
return serviceManager.getOrCreateService(id, () ->
|
||||
new SourceRemapperService(MappingsService.createDefault(project, serviceManager, from, to), task.getClasspath()
|
||||
));
|
||||
new SourceRemapperService(MappingsService.createDefault(project, serviceManager, from, to), task.getClasspath(), javaCompileRelease));
|
||||
}
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SourceRemapperService.class);
|
||||
|
||||
private final MappingsService mappingsService;
|
||||
private final ConfigurableFileCollection classpath;
|
||||
private final int javaCompileRelease;
|
||||
|
||||
private final Supplier<Mercury> mercury = Suppliers.memoize(this::createMercury);
|
||||
|
||||
private SourceRemapperService(MappingsService mappingsService, ConfigurableFileCollection classpath) {
|
||||
private SourceRemapperService(MappingsService mappingsService, ConfigurableFileCollection classpath, int javaCompileRelease) {
|
||||
this.mappingsService = mappingsService;
|
||||
this.classpath = classpath;
|
||||
this.javaCompileRelease = javaCompileRelease;
|
||||
}
|
||||
|
||||
public void remapSourcesJar(Path source, Path destination) throws IOException {
|
||||
@@ -122,7 +123,7 @@ public final class SourceRemapperService implements SharedService {
|
||||
private Mercury createMercury() {
|
||||
var mercury = new Mercury();
|
||||
mercury.setGracefulClasspathChecks(true);
|
||||
mercury.setSourceCompatibility(Constants.MERCURY_SOURCE_VERSION);
|
||||
mercury.setSourceCompatibilityFromRelease(javaCompileRelease);
|
||||
|
||||
try {
|
||||
mercury.getProcessors().add(MercuryRemapper.create(getMappings()));
|
||||
|
||||
@@ -35,7 +35,6 @@ public class Constants {
|
||||
public static final String FABRIC_REPOSITORY = "https://maven.fabricmc.net/";
|
||||
|
||||
public static final int ASM_VERSION = Opcodes.ASM9;
|
||||
public static final String MERCURY_SOURCE_VERSION = "17";
|
||||
|
||||
private Constants() {
|
||||
}
|
||||
|
||||
@@ -31,13 +31,17 @@ import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.cadixdev.lorenz.MappingSet;
|
||||
import org.cadixdev.mercury.Mercury;
|
||||
import org.cadixdev.mercury.remapper.MercuryRemapper;
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.internal.project.ProjectInternal;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.compile.JavaCompile;
|
||||
import org.gradle.internal.logging.progress.ProgressLogger;
|
||||
import org.gradle.internal.logging.progress.ProgressLoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
@@ -193,6 +197,7 @@ public class SourceRemapper {
|
||||
|
||||
Mercury mercury = extension.getOrCreateSrcMercuryCache(id, () -> {
|
||||
Mercury m = createMercuryWithClassPath(project, to.equals("named"));
|
||||
m.setSourceCompatibilityFromRelease(getJavaCompileRelease(project));
|
||||
|
||||
for (File file : extension.getUnmappedModCollection()) {
|
||||
Path path = file.toPath();
|
||||
@@ -233,6 +238,30 @@ public class SourceRemapper {
|
||||
return mercury;
|
||||
}
|
||||
|
||||
public static int getJavaCompileRelease(Project project) {
|
||||
AtomicInteger release = new AtomicInteger(-1);
|
||||
|
||||
project.getTasks().withType(JavaCompile.class, javaCompile -> {
|
||||
Property<Integer> releaseProperty = javaCompile.getOptions().getRelease();
|
||||
|
||||
if (!releaseProperty.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int compileRelease = releaseProperty.get();
|
||||
release.set(Math.max(release.get(), compileRelease));
|
||||
});
|
||||
|
||||
final int i = release.get();
|
||||
|
||||
if (i < 0) {
|
||||
// Unable to find the release used to compile with, default to the current version
|
||||
return Integer.parseInt(JavaVersion.current().getMajorVersion());
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
public static void copyNonJavaFiles(Path from, Path to, Logger logger, Path source) throws IOException {
|
||||
Files.walk(from).forEach(path -> {
|
||||
Path targetPath = to.resolve(from.relativize(path).toString());
|
||||
@@ -250,7 +279,6 @@ public class SourceRemapper {
|
||||
public static Mercury createMercuryWithClassPath(Project project, boolean toNamed) {
|
||||
Mercury m = new Mercury();
|
||||
m.setGracefulClasspathChecks(true);
|
||||
m.setSourceCompatibility(Constants.MERCURY_SOURCE_VERSION);
|
||||
|
||||
final List<Path> classPath = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.fabricmc.loom.util.fmj;
|
||||
import static net.fabricmc.loom.util.fmj.FabricModJsonUtils.readString;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -53,7 +54,7 @@ public abstract sealed class FabricModJson permits FabricModJsonV0, FabricModJso
|
||||
|
||||
public abstract List<String> getMixinConfigurations();
|
||||
|
||||
public abstract List<String> getClassTweakers(ModEnvironment modEnvironment);
|
||||
public abstract Map<String, ModEnvironment> getClassTweakers();
|
||||
|
||||
public final FabricModJsonSource getSource() {
|
||||
return source;
|
||||
|
||||
@@ -27,6 +27,7 @@ package net.fabricmc.loom.util.fmj;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -83,7 +84,7 @@ public final class FabricModJsonV0 extends FabricModJson {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getClassTweakers(ModEnvironment modEnvironment) {
|
||||
return Collections.emptyList();
|
||||
public Map<String, ModEnvironment> getClassTweakers() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import static net.fabricmc.loom.util.fmj.FabricModJsonUtils.readString;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
@@ -91,11 +92,11 @@ public final class FabricModJsonV1 extends FabricModJson {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getClassTweakers(ModEnvironment modEnvironment) {
|
||||
public Map<String, ModEnvironment> getClassTweakers() {
|
||||
if (!jsonObject.has("accessWidener")) {
|
||||
return Collections.emptyList();
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
return List.of(readString(jsonObject, "accessWidener"));
|
||||
return Map.of(readString(jsonObject, "accessWidener"), ModEnvironment.UNIVERSAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,10 @@
|
||||
|
||||
package net.fabricmc.loom.util.fmj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -35,6 +36,8 @@ import com.google.gson.JsonPrimitive;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import net.fabricmc.loom.util.Pair;
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public final class FabricModJsonV2 extends FabricModJson {
|
||||
FabricModJsonV2(JsonObject jsonObject, FabricModJsonSource source) {
|
||||
@@ -58,34 +61,34 @@ public final class FabricModJsonV2 extends FabricModJson {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return getConditionalConfigs(jsonObject.get("mixins"), ModEnvironment.UNIVERSAL);
|
||||
return List.copyOf(getConditionalConfigs(jsonObject.get("mixins")).keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getClassTweakers(ModEnvironment modEnvironment) {
|
||||
public Map<String, ModEnvironment> getClassTweakers() {
|
||||
if (!jsonObject.has("classTweakers")) {
|
||||
return Collections.emptyList();
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
return getConditionalConfigs(jsonObject.get("classTweakers"), modEnvironment);
|
||||
return getConditionalConfigs(jsonObject.get("classTweakers"));
|
||||
}
|
||||
|
||||
private List<String> getConditionalConfigs(JsonElement jsonElement, ModEnvironment modEnvironment) {
|
||||
final List<String> values = new ArrayList<>();
|
||||
private Map<String, ModEnvironment> getConditionalConfigs(JsonElement jsonElement) {
|
||||
final Map<String, ModEnvironment> values = new HashMap<>();
|
||||
|
||||
if (jsonElement instanceof JsonArray jsonArray) {
|
||||
for (JsonElement arrayElement : jsonArray) {
|
||||
final String value = readConditionalConfig(arrayElement, modEnvironment);
|
||||
final Pair<String, ModEnvironment> value = readConditionalConfig(arrayElement);
|
||||
|
||||
if (value != null) {
|
||||
values.add(value);
|
||||
values.put(value.left(), value.right());
|
||||
}
|
||||
}
|
||||
} else if (jsonElement instanceof JsonPrimitive jsonPrimitive && jsonPrimitive.isString()) {
|
||||
final String value = readConditionalConfig(jsonPrimitive, modEnvironment);
|
||||
final Pair<String, ModEnvironment> value = readConditionalConfig(jsonPrimitive);
|
||||
|
||||
if (value != null) {
|
||||
values.add(value);
|
||||
values.put(value.left(), value.right());
|
||||
}
|
||||
} else {
|
||||
throw new FabricModJsonUtils.ParseException("Must be a string or array of strings");
|
||||
@@ -95,26 +98,21 @@ public final class FabricModJsonV2 extends FabricModJson {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private String readConditionalConfig(JsonElement jsonElement, ModEnvironment modEnvironment) {
|
||||
private Pair<String, ModEnvironment> readConditionalConfig(JsonElement jsonElement) {
|
||||
if (jsonElement instanceof JsonPrimitive jsonPrimitive && jsonPrimitive.isString()) {
|
||||
return jsonElement.getAsString();
|
||||
return new Pair<>(jsonElement.getAsString(), ModEnvironment.UNIVERSAL);
|
||||
} else if (jsonElement instanceof JsonObject jsonObject) {
|
||||
final String config = FabricModJsonUtils.readString(jsonObject, "config");
|
||||
|
||||
if (!validForEnvironment(jsonObject, modEnvironment)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return config;
|
||||
return new Pair<>(config, getEnvironment(jsonObject));
|
||||
} else {
|
||||
throw new FabricModJsonUtils.ParseException("Must be a string or an object");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean validForEnvironment(JsonObject jsonObject, ModEnvironment modEnvironment) {
|
||||
private ModEnvironment getEnvironment(JsonObject jsonObject) {
|
||||
if (!jsonObject.has("environment")) {
|
||||
// Default enabled for all envs.
|
||||
return true;
|
||||
return ModEnvironment.UNIVERSAL;
|
||||
}
|
||||
|
||||
if (!(jsonObject.get("environment") instanceof JsonPrimitive jsonPrimitive) || !jsonPrimitive.isString()) {
|
||||
@@ -124,9 +122,9 @@ public final class FabricModJsonV2 extends FabricModJson {
|
||||
final String environment = jsonPrimitive.getAsString();
|
||||
|
||||
return switch (environment) {
|
||||
case "*" -> true;
|
||||
case "client" -> modEnvironment.isClient();
|
||||
case "server" -> modEnvironment.isServer();
|
||||
case "*" -> ModEnvironment.UNIVERSAL;
|
||||
case "client" -> ModEnvironment.CLIENT;
|
||||
case "server" -> ModEnvironment.SERVER;
|
||||
default -> throw new FabricModJsonUtils.ParseException("Invalid environment type: " + environment);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user