Merge remote-tracking branch 'FabricMC/exp/1.5' into exp/1.5

# Conflicts:
#	gradle/libs.versions.toml
#	src/main/java/net/fabricmc/loom/configuration/mods/ArtifactMetadata.java
#	src/main/java/net/fabricmc/loom/configuration/mods/ModConfigurationRemapper.java
#	src/main/java/net/fabricmc/loom/configuration/mods/ModProcessor.java
#	src/main/java/net/fabricmc/loom/task/RemapJarTask.java
#	src/main/java/net/fabricmc/loom/util/Constants.java
#	src/test/groovy/net/fabricmc/loom/test/integration/FabricAPITest.groovy
This commit is contained in:
shedaniel
2023-11-22 14:56:39 +08:00
31 changed files with 439 additions and 352 deletions

View File

@@ -35,7 +35,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import javax.inject.Inject;
@@ -67,19 +66,12 @@ import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.api.mappings.layered.MappingsNamespace;
import net.fabricmc.loom.build.IntermediaryNamespaces;
import net.fabricmc.loom.task.service.JarManifestService;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.ZipReprocessorUtil;
import net.fabricmc.loom.util.ZipUtils;
import net.fabricmc.loom.util.gradle.SourceSetHelper;
public abstract class AbstractRemapJarTask extends Jar {
public static final String MANIFEST_PATH = "META-INF/MANIFEST.MF";
public static final String MANIFEST_NAMESPACE_KEY = "Fabric-Mapping-Namespace";
public static final String MANIFEST_SPLIT_ENV_KEY = "Fabric-Loom-Split-Environment";
public static final String MANIFEST_CLIENT_ENTRIES_KEY = "Fabric-Loom-Client-Only-Entries";
public static final String MANIFEST_JAR_TYPE_KEY = "Fabric-Jar-Type";
public static final Attributes.Name MANIFEST_SPLIT_ENV_NAME = new Attributes.Name(MANIFEST_SPLIT_ENV_KEY);
public static final Attributes.Name MANIFEST_CLIENT_ENTRIES_NAME = new Attributes.Name(MANIFEST_CLIENT_ENTRIES_KEY);
@InputFile
public abstract RegularFileProperty getInputFile();
@@ -158,7 +150,7 @@ public abstract class AbstractRemapJarTask extends Jar {
}
if (getJarType().isPresent()) {
params.getManifestAttributes().put(MANIFEST_JAR_TYPE_KEY, getJarType().get());
params.getManifestAttributes().put(Constants.Manifest.JAR_TYPE, getJarType().get());
}
action.execute(params);
@@ -174,6 +166,18 @@ public abstract class AbstractRemapJarTask extends Jar {
Property<String> getSourceNamespace();
Property<String> getTargetNamespace();
/**
* Checks whether {@link #getSourceNamespace()} and {@link #getTargetNamespace()}
* have the same value. When this is {@code true}, the user does not intend for any
* remapping to occur. They are using the task for its other features, such as adding
* namespace to the manifest, nesting jars, reproducible builds, etc.
*
* @return whether the source and target namespaces match
*/
default boolean namespacesMatch() {
return this.getSourceNamespace().get().equals(this.getTargetNamespace().get());
}
Property<Boolean> getArchivePreserveFileTimestamps();
Property<Boolean> getArchiveReproducibleFileOrder();
Property<ZipEntryCompression> getEntryCompression();
@@ -186,8 +190,8 @@ public abstract class AbstractRemapJarTask extends Jar {
protected void applyClientOnlyManifestAttributes(AbstractRemapParams params, List<String> entries) {
params.getManifestAttributes().set(Map.of(
MANIFEST_SPLIT_ENV_KEY, "true",
MANIFEST_CLIENT_ENTRIES_KEY, String.join(";", entries)
Constants.Manifest.SPLIT_ENV, "true",
Constants.Manifest.CLIENT_ENTRIES, String.join(";", entries)
));
}
@@ -202,11 +206,11 @@ public abstract class AbstractRemapJarTask extends Jar {
}
protected void modifyJarManifest() throws IOException {
int count = ZipUtils.transform(outputFile, Map.of(MANIFEST_PATH, bytes -> {
int count = ZipUtils.transform(outputFile, Map.of(Constants.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());
manifest.getMainAttributes().putValue(Constants.Manifest.MAPPING_NAMESPACE, getParameters().getTargetNamespace().get());
ByteArrayOutputStream out = new ByteArrayOutputStream();
manifest.write(out);