mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-03-30 21:05:58 -05:00
Merge with Fabric 0.13, stage 1
This commit is contained in:
@@ -26,7 +26,6 @@ package net.fabricmc.loom.task;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -47,7 +46,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.jar.Attributes;
|
||||
import java.util.jar.JarFile;
|
||||
@@ -58,7 +56,6 @@ import java.util.stream.StreamSupport;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -73,7 +70,6 @@ import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.provider.ListProperty;
|
||||
import org.gradle.api.provider.MapProperty;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.provider.Provider;
|
||||
import org.gradle.api.provider.SetProperty;
|
||||
@@ -100,7 +96,6 @@ import net.fabricmc.loom.build.nesting.JarNester;
|
||||
import net.fabricmc.loom.configuration.accesswidener.AccessWidenerFile;
|
||||
import net.fabricmc.loom.configuration.providers.minecraft.MinecraftSourceSets;
|
||||
import net.fabricmc.loom.extension.MixinExtension;
|
||||
import net.fabricmc.loom.task.service.JarManifestService;
|
||||
import net.fabricmc.loom.task.service.MappingsService;
|
||||
import net.fabricmc.loom.task.service.TinyRemapperService;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
@@ -108,6 +103,7 @@ import net.fabricmc.loom.util.ExceptionUtil;
|
||||
import net.fabricmc.loom.util.FileSystemUtil;
|
||||
import net.fabricmc.loom.util.LfWriter;
|
||||
import net.fabricmc.loom.util.ModPlatform;
|
||||
import net.fabricmc.loom.util.ModUtils;
|
||||
import net.fabricmc.loom.util.Pair;
|
||||
import net.fabricmc.loom.util.SidedClassVisitor;
|
||||
import net.fabricmc.loom.util.ZipUtils;
|
||||
@@ -116,9 +112,6 @@ import net.fabricmc.loom.util.service.UnsafeWorkQueueHelper;
|
||||
import net.fabricmc.lorenztiny.TinyMappingsReader;
|
||||
|
||||
public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
|
||||
public static final String MANIFEST_NAMESPACE_KEY = "Fabric-Mapping-Namespace";
|
||||
|
||||
@InputFiles
|
||||
public abstract ConfigurableFileCollection getNestedJars();
|
||||
|
||||
@@ -128,9 +121,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
@Input
|
||||
public abstract Property<Boolean> getAddNestedDependencies();
|
||||
|
||||
@Input
|
||||
public abstract Property<Boolean> getIncludesClientOnlyClasses();
|
||||
|
||||
/**
|
||||
* Gets the jar paths to the access wideners that will be converted to ATs for Forge runtime.
|
||||
* If you specify multiple files, they will be merged into one.
|
||||
@@ -170,7 +160,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
|
||||
getClasspath().from(getProject().getConfigurations().getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME));
|
||||
getAddNestedDependencies().convention(true).finalizeValueOnRead();
|
||||
getIncludesClientOnlyClasses().convention(false).finalizeValueOnRead();
|
||||
getReadMixinConfigsFromManifest().convention(LoomGradleExtension.get(getProject()).isForge()).finalizeValueOnRead();
|
||||
getInjectAccessWidener().convention(false);
|
||||
|
||||
@@ -221,7 +210,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
}
|
||||
}
|
||||
|
||||
params.getJarManifestService().set(JarManifestService.get(getProject()));
|
||||
params.getTinyRemapperBuildServiceUuid().set(UnsafeWorkQueueHelper.create(getProject(), tinyRemapperService.get()));
|
||||
params.getRemapClasspath().from(getClasspath());
|
||||
|
||||
@@ -246,20 +234,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
if (!getAtAccessWideners().get().isEmpty()) {
|
||||
params.getMappingBuildServiceUuid().set(UnsafeWorkQueueHelper.create(getProject(), MappingsService.createDefault(getProject(), getSourceNamespace().get(), getTargetNamespace().get())));
|
||||
}
|
||||
|
||||
if (getIncludesClientOnlyClasses().get()) {
|
||||
if (!extension.areEnvironmentSourceSetsSplit()) {
|
||||
throw new UnsupportedOperationException("Jar cannot include client only classes as the sources are not split");
|
||||
}
|
||||
|
||||
final List<String> clientOnlyJarEntries = getClientOnlyJarEntries();
|
||||
params.getManifestAttributes().set(Map.of(
|
||||
"Fabric-Loom-Split-Environment", "true",
|
||||
"Fabric-Loom-Client-Only-Entries", String.join(";", clientOnlyJarEntries)
|
||||
));
|
||||
|
||||
params.getClientOnlyClasses().set(clientOnlyJarEntries.stream().filter(s -> s.endsWith(".class")).toList());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -268,7 +242,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
final MixinExtension mixinExtension = extension.getMixin();
|
||||
Collection<String> allMixinConfigs = null;
|
||||
|
||||
final JsonObject fabricModJson = extension.getPlatform().get() == ModPlatform.FABRIC ? MixinRefmapHelper.readFabricModJson(getInputFile().getAsFile().get()) : null;
|
||||
final JsonObject fabricModJson = extension.getPlatform().get() == ModPlatform.FABRIC ? ModUtils.getFabricModJson(getInputFile().getAsFile().get().toPath()) : null;
|
||||
|
||||
if (fabricModJson == null) {
|
||||
if (extension.getPlatform().get() == ModPlatform.QUILT) {
|
||||
@@ -374,12 +348,8 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
record RefmapData(List<String> mixinConfigs, String refmapName) implements Serializable { }
|
||||
ListProperty<RefmapData> getMixinData();
|
||||
|
||||
Property<JarManifestService> getJarManifestService();
|
||||
Property<String> getTinyRemapperBuildServiceUuid();
|
||||
Property<String> getMappingBuildServiceUuid();
|
||||
|
||||
MapProperty<String, String> getManifestAttributes();
|
||||
ListProperty<String> getClientOnlyClasses();
|
||||
}
|
||||
|
||||
public abstract static class RemapAction extends AbstractRemapAction<RemapParams> {
|
||||
@@ -401,7 +371,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
|
||||
remap();
|
||||
|
||||
if (getParameters().getClientOnlyClasses().isPresent()) {
|
||||
if (getParameters().getClientOnlyEntries().isPresent()) {
|
||||
markClientOnlyClasses();
|
||||
}
|
||||
|
||||
@@ -439,7 +409,7 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
}
|
||||
|
||||
private void markClientOnlyClasses() throws IOException {
|
||||
final Stream<Pair<String, ZipUtils.UnsafeUnaryOperator<byte[]>>> tranformers = getParameters().getClientOnlyClasses().get().stream()
|
||||
final Stream<Pair<String, ZipUtils.UnsafeUnaryOperator<byte[]>>> tranformers = getParameters().getClientOnlyEntries().get().stream()
|
||||
.map(s -> new Pair<>(s,
|
||||
(ZipUtils.AsmClassOperator) classVisitor -> SidedClassVisitor.CLIENT.insertApplyVisitor(null, classVisitor)
|
||||
));
|
||||
@@ -564,21 +534,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
JarNester.nestJars(jars, forgeNestedJars.getOrElse(List.of()), outputFile.toFile(), getParameters().getPlatform().get(), LOGGER);
|
||||
}
|
||||
|
||||
private void modifyJarManifest() throws IOException {
|
||||
int count = ZipUtils.transform(outputFile, Map.of(MANIFEST_PATH, bytes -> {
|
||||
var manifest = new Manifest(new ByteArrayInputStream(bytes));
|
||||
|
||||
getParameters().getJarManifestService().get().apply(manifest, getParameters().getManifestAttributes().get());
|
||||
manifest.getMainAttributes().putValue(MANIFEST_NAMESPACE_KEY, getParameters().getTargetNamespace().get());
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
manifest.write(out);
|
||||
return out.toByteArray();
|
||||
}));
|
||||
|
||||
Preconditions.checkState(count > 0, "Did not transform any jar manifest");
|
||||
}
|
||||
|
||||
private void addRefmaps() throws IOException {
|
||||
if (getParameters().getUseMixinExtension().get()) {
|
||||
return;
|
||||
@@ -596,7 +551,8 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getClientOnlyJarEntries() {
|
||||
@Override
|
||||
protected List<String> getClientOnlyEntries() {
|
||||
final SourceSet clientSourceSet = MinecraftSourceSets.Split.getClientSourceSet(getProject());
|
||||
|
||||
final ConfigurableFileCollection output = getProject().getObjects().fileCollection();
|
||||
@@ -613,33 +569,6 @@ public abstract class RemapJarTask extends AbstractRemapJarTask {
|
||||
.toList();
|
||||
}
|
||||
|
||||
private static List<String> getRootPaths(Set<File> files) {
|
||||
return files.stream()
|
||||
.map(root -> {
|
||||
String rootPath = root.getAbsolutePath().replace("\\", "/");
|
||||
|
||||
if (rootPath.charAt(rootPath.length() - 1) != '/') {
|
||||
rootPath += '/';
|
||||
}
|
||||
|
||||
return rootPath;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private static Function<File, String> relativePath(List<String> rootPaths) {
|
||||
return file -> {
|
||||
String s = file.getAbsolutePath().replace("\\", "/");
|
||||
|
||||
for (String rootPath : rootPaths) {
|
||||
if (s.startsWith(rootPath)) {
|
||||
s = s.substring(rootPath.length());
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
};
|
||||
}
|
||||
|
||||
@Internal
|
||||
public TinyRemapperService getTinyRemapperService() {
|
||||
return tinyRemapperService.get();
|
||||
|
||||
Reference in New Issue
Block a user