Merge with Fabric 0.13, stage 3

This commit is contained in:
Juuz
2022-08-09 17:26:18 +03:00
14 changed files with 462 additions and 109 deletions

View File

@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
* Copyright (c) 2021-2022 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -138,4 +138,22 @@ public class LoomRepositoryPlugin implements Plugin<PluginAware> {
});
});
}
public static void forceLWJGLFromMavenCentral(Project project) {
// Force LWJGL from central, as it contains all the platform natives.
MavenArtifactRepository central = project.getRepositories().maven(repo -> {
repo.setName("MavenCentralLWJGL");
repo.setUrl(ArtifactRepositoryContainer.MAVEN_CENTRAL_URL);
repo.content(content -> {
content.includeGroup("org.lwjgl");
});
});
project.getRepositories().exclusiveContent(repository -> {
repository.forRepositories(central);
repository.filter(filter -> {
filter.includeGroup("org.lwjgl");
});
});
}
}

View File

@@ -83,12 +83,6 @@ public interface LoomGradleExtensionAPI {
Dependency layered(Action<LayeredMappingSpecBuilder> action);
/**
* @deprecated Broken due to be evaluated too early. Replaced with "fabric.loom.dontRemap" gradle property.
*/
@Deprecated(forRemoval = true)
Property<Boolean> getRemapArchives();
void runs(Action<NamedDomainObjectContainer<RunConfigSettings>> action);
NamedDomainObjectContainer<RunConfigSettings> getRunConfigs();
@@ -133,12 +127,6 @@ public interface LoomGradleExtensionAPI {
Property<String> getCustomMinecraftManifest();
/**
* @deprecated Broken due to be evaluated too early. Replaced with "fabric.loom.disableRemappedVariants" gradle property.
*/
@Deprecated(forRemoval = true)
Property<Boolean> getSetupRemappedVariants();
/**
* Disables the deprecated POM generation for a publication.
* This is useful if you want to suppress deprecation warnings when you're not using software components.

View File

@@ -33,12 +33,18 @@ import org.gradle.api.Project;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.internal.DefaultTaskExecutionRequest;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.configuration.ide.RunConfigSettings;
import net.fabricmc.loom.task.LoomTasks;
public class IdeaConfiguration {
public static void setup(Project project) {
TaskProvider<IdeaSyncTask> ideaSyncTask = project.getTasks().register("ideaSyncTask", IdeaSyncTask.class, task -> {
task.dependsOn(LoomTasks.getIDELaunchConfigureTaskName(project));
if (LoomGradleExtension.get(project).getRunConfigs().stream().anyMatch(RunConfigSettings::isIdeConfigGenerated)) {
task.dependsOn(LoomTasks.getIDELaunchConfigureTaskName(project));
} else {
task.setEnabled(false);
}
});
if (!IdeaUtils.isIdeaSync()) {

View File

@@ -0,0 +1,178 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2022 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.configuration.mods;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import java.util.stream.Stream;
import net.fabricmc.loom.task.AbstractRemapJarTask;
import net.fabricmc.loom.util.FileSystemUtil;
public class JarSplitter {
final Path inputJar;
public JarSplitter(Path inputJar) {
this.inputJar = inputJar;
}
public boolean split(Path commonOutputJar, Path clientOutputJar) throws IOException {
try (FileSystemUtil.Delegate input = FileSystemUtil.getJarFileSystem(inputJar)) {
final Manifest manifest = input.fromInputStream(Manifest::new, AbstractRemapJarTask.MANIFEST_PATH);
final List<String> clientEntries = readClientEntries(manifest);
if (clientEntries.isEmpty()) {
// No client entries, just copy the input jar
Files.copy(inputJar, commonOutputJar);
return false;
}
try (FileSystemUtil.Delegate commonOutput = FileSystemUtil.getJarFileSystem(commonOutputJar, true);
FileSystemUtil.Delegate clientOutput = FileSystemUtil.getJarFileSystem(clientOutputJar, true);
Stream<Path> walk = Files.walk(input.get().getPath("/"))) {
final Iterator<Path> iterator = walk.iterator();
while (iterator.hasNext()) {
final Path entry = iterator.next();
if (!Files.isRegularFile(entry)) {
continue;
}
final Path relativePath = input.get().getPath("/").relativize(entry);
if (relativePath.startsWith("META-INF")) {
if (isSignatureData(relativePath)) {
// Strip any signature data
continue;
}
}
final String entryPath = relativePath.toString();
/*
Copy the manifest to both jars
- Remove signature data
- Remove split data as its already been split.
*/
if (entryPath.equals(AbstractRemapJarTask.MANIFEST_PATH)) {
final Manifest outManifest = new Manifest(manifest);
final Attributes attributes = outManifest.getMainAttributes();
stripSignatureData(outManifest);
attributes.remove(Attributes.Name.SIGNATURE_VERSION);
Objects.requireNonNull(attributes.remove(AbstractRemapJarTask.MANIFEST_SPLIT_ENV_NAME));
Objects.requireNonNull(attributes.remove(AbstractRemapJarTask.MANIFEST_CLIENT_ENTRIES_NAME));
// TODO add an attribute to denote if the jar is common or client now
final ByteArrayOutputStream out = new ByteArrayOutputStream();
outManifest.write(out);
final byte[] manifestBytes = out.toByteArray();
writeBytes(manifestBytes, commonOutput.getPath(AbstractRemapJarTask.MANIFEST_PATH));
writeBytes(manifestBytes, clientOutput.getPath(AbstractRemapJarTask.MANIFEST_PATH));
continue;
}
final FileSystemUtil.Delegate target = clientEntries.contains(entryPath) ? clientOutput : commonOutput;
final Path outputEntry = target.getPath(entryPath);
final Path outputParent = outputEntry.getParent();
if (outputParent != null) {
Files.createDirectories(outputParent);
}
Files.copy(entry, outputEntry, StandardCopyOption.COPY_ATTRIBUTES);
}
}
}
return true;
}
private List<String> readClientEntries(Manifest manifest) {
final Attributes attributes = manifest.getMainAttributes();
final String splitEnvValue = attributes.getValue(AbstractRemapJarTask.MANIFEST_SPLIT_ENV_KEY);
final String clientEntriesValue = attributes.getValue(AbstractRemapJarTask.MANIFEST_CLIENT_ENTRIES_KEY);
if (splitEnvValue == null || !splitEnvValue.equals("true")) {
throw new UnsupportedOperationException("Cannot split jar that has not been built with a split env");
}
if (clientEntriesValue == null) {
throw new IllegalStateException("Split jar does not contain any client only classes");
}
return Arrays.stream(clientEntriesValue.split(";")).toList();
}
private boolean isSignatureData(Path path) {
final String fileName = path.getFileName().toString();
return fileName.endsWith(".SF")
|| fileName.endsWith(".DSA")
|| fileName.endsWith(".RSA")
|| fileName.startsWith("SIG-");
}
// Based off tiny-remapper's MetaInfFixer
private static void stripSignatureData(Manifest manifest) {
for (Iterator<Attributes> it = manifest.getEntries().values().iterator(); it.hasNext(); ) {
Attributes attrs = it.next();
for (Iterator<Object> it2 = attrs.keySet().iterator(); it2.hasNext(); ) {
Attributes.Name attrName = (Attributes.Name) it2.next();
String name = attrName.toString();
if (name.endsWith("-Digest") || name.contains("-Digest-") || name.equals("Magic")) {
it2.remove();
}
}
if (attrs.isEmpty()) it.remove();
}
}
private static void writeBytes(byte[] bytes, Path path) throws IOException {
final Path parent = path.getParent();
if (parent != null) {
Files.createDirectories(parent);
}
Files.write(path, bytes);
}
}

View File

@@ -35,6 +35,7 @@ import com.google.common.io.Files;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.FileCollectionDependency;
import org.gradle.api.artifacts.MutableVersionConstraint;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.dsl.DependencyHandler;
import org.gradle.api.artifacts.query.ArtifactResolutionQuery;
@@ -124,6 +125,20 @@ public class ModConfigurationRemapper {
// Add all of the remapped mods onto the config
for (ModDependencyInfo info : modDependencies) {
project.getDependencies().add(info.targetConfig.getName(), info.getRemappedNotation());
if (info.getArtifact() instanceof ArtifactRef.ResolvedArtifactRef mavenArtifact) {
final String dependencyCoordinate = "%s:%s".formatted(mavenArtifact.group(), mavenArtifact.name());
// Prevent adding the same un-remapped dependency to the target configuration.
targetConfig.getDependencyConstraints().add(dependencies.getConstraints().create(dependencyCoordinate, constraint -> {
constraint.because("configuration (%s) already contains the remapped module from configuration (%s)".formatted(
targetConfig.getName(),
sourceConfig.getName()
));
constraint.version(MutableVersionConstraint::rejectAll);
}));
}
}
// Export to other projects

View File

@@ -1,7 +1,7 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2021 FabricMC
* Copyright (c) 2021-2022 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,9 +31,11 @@ import static net.fabricmc.loom.util.OperatingSystem.WINDOWS;
import java.util.List;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ExternalModuleDependency;
import org.jetbrains.annotations.Nullable;
import net.fabricmc.loom.util.Architecture;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public class LWJGLVersionOverride {
@@ -81,6 +83,21 @@ public class LWJGLVersionOverride {
return project.getProperties().get("fabric.loom.override-lwjgl") != null;
}
public static void applyOverrides(Project project, boolean isMacOS) {
DEPENDENCIES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, s));
NATIVES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, s));
if (isMacOS) {
MACOS_DEPENDENCIES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, s));
MACOS_NATIVES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, s));
}
// Add the native support mod that fixes a handful of issues related to the LWJGL update at runtime.
ExternalModuleDependency dependency = (ExternalModuleDependency) project.getDependencies().create(Constants.Dependencies.NATIVE_SUPPORT + Constants.Dependencies.Versions.NATIVE_SUPPORT_VERSION);
dependency.setTransitive(false);
project.getDependencies().add("modLocalRuntime", dependency);
}
@Nullable
private static String getNativesClassifier() {
return switch (OperatingSystem.CURRENT_OS) {

View File

@@ -28,112 +28,155 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.gradle.api.Project;
import org.gradle.api.artifacts.ExternalModuleDependency;
import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.LoomRepositoryPlugin;
import net.fabricmc.loom.configuration.providers.BundleMetadata;
import net.fabricmc.loom.util.Architecture;
import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.OperatingSystem;
public class MinecraftLibraryProvider {
private static final Pattern NATIVES_PATTERN = Pattern.compile("^(?<group>.*)/(.*?)/(?<version>.*)/((?<name>.*?)-(\\k<version>)-)(?<classifier>.*).jar$");
private static final boolean IS_MACOS = OperatingSystem.CURRENT_OS.equals(OperatingSystem.MAC_OS);
public void provide(MinecraftProvider minecraftProvider, Project project) {
private final Project project;
private final MinecraftVersionMeta versionInfo;
private final BundleMetadata serverBundleMetadata;
private final boolean runtimeOnlyLog4j;
private final boolean provideClient;
private final boolean provideServer;
public MinecraftLibraryProvider(MinecraftProvider minecraftProvider, Project project) {
final LoomGradleExtension extension = LoomGradleExtension.get(project);
final MinecraftJarConfiguration jarConfiguration = extension.getMinecraftJarConfiguration().get();
final MinecraftVersionMeta versionInfo = minecraftProvider.getVersionInfo();
final BundleMetadata serverBundleMetadata = minecraftProvider.getServerBundleMetadata();
final boolean runtimeOnlyLog4j = extension.getRuntimeOnlyLog4j().get();
final boolean hasNativesToExtract = versionInfo.hasNativesToExtract();
final boolean overrideLWJGL = hasNativesToExtract && (LWJGLVersionOverride.overrideByDefault(versionInfo) || LWJGLVersionOverride.forceOverride(project) || Boolean.getBoolean("loom.test.lwjgloverride"));
final boolean isMacOS = OperatingSystem.CURRENT_OS.equals(OperatingSystem.MAC_OS);
this.project = project;
this.versionInfo = minecraftProvider.getVersionInfo();
this.serverBundleMetadata = minecraftProvider.getServerBundleMetadata();
this.runtimeOnlyLog4j = extension.getRuntimeOnlyLog4j().get();
this.provideClient = jarConfiguration.getSupportedEnvironments().contains("client");
this.provideServer = jarConfiguration.getSupportedEnvironments().contains("server");
assert provideClient || provideServer;
}
if (overrideLWJGL) {
project.getLogger().warn("Loom is upgrading Minecraft's LWJGL version to {}", LWJGLVersionOverride.LWJGL_VERSION);
public void provide() {
if (provideClient) {
// Modern 1.19 version put the natives on the classpath.
final boolean hasNativesToExtract = versionInfo.hasNativesToExtract();
final boolean overrideLWJGL = hasNativesToExtract && (LWJGLVersionOverride.overrideByDefault(versionInfo) || LWJGLVersionOverride.forceOverride(project) || Boolean.getBoolean("loom.test.lwjgloverride"));
if (overrideLWJGL) {
project.getLogger().warn("Loom is upgrading Minecraft's LWJGL version to {}", LWJGLVersionOverride.LWJGL_VERSION);
}
if (hasNativesToExtract) {
// Create a configuration for
project.getConfigurations().register(Constants.Configurations.MINECRAFT_NATIVES, configuration -> configuration.setTransitive(false));
}
provideClientLibraries(overrideLWJGL, hasNativesToExtract);
if (overrideLWJGL) {
LWJGLVersionOverride.applyOverrides(project, IS_MACOS);
}
}
if (hasNativesToExtract) {
project.getConfigurations().register(Constants.Configurations.MINECRAFT_NATIVES, configuration -> configuration.setTransitive(false));
if (provideServer) {
provideServerLibraries();
}
}
private void provideClientLibraries(boolean overrideLWJGL, boolean hasNativesToExtract) {
final boolean isArm = Architecture.CURRENT.isArm();
final boolean classpathArmNatives = !hasNativesToExtract && isArm;
if (classpathArmNatives) {
LoomRepositoryPlugin.forceLWJGLFromMavenCentral(project);
}
for (MinecraftVersionMeta.Library library : versionInfo.libraries()) {
if (overrideLWJGL && library.name().startsWith("org.lwjgl")) {
// Skip over Minecraft's LWJGL version, will will replace this with a newer version later.
continue;
}
if (library.isValidForOS() && !library.hasNatives() && library.artifact() != null) {
// 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version.
if ("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3".equals(library.name()) || "org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20131017".equals(library.name())) {
final String name = library.name();
if ("org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20130708-debug3".equals(name) || "org.lwjgl.lwjgl:lwjgl:2.9.1-nightly-20131017".equals(name)) {
// 1.4.7 contains an LWJGL version with an invalid maven pom, set the metadata sources to not use the pom for this version.
LoomRepositoryPlugin.setupForLegacyVersions(project);
} else if (library.name().startsWith("org.ow2.asm:asm-all")) {
}
if (name.startsWith("org.ow2.asm:asm-all")) {
// Don't want asm-all, use the modern split version.
continue;
}
if (runtimeOnlyLog4j && library.name().startsWith("org.apache.logging.log4j")) {
if (runtimeOnlyLog4j && name.startsWith("org.apache.logging.log4j")) {
// Make log4j a runtime only dep to force slf4j.
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name());
} else if (jarConfiguration.getSupportedEnvironments().contains("client")) {
// Client only library, or legacy version
project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, library.name());
} else {
project.getLogger().debug("Minecraft library ({}) was not added to any configuration", library.name());
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, name);
continue;
}
if (classpathArmNatives && name.startsWith("org.lwjgl:")
&& (name.endsWith("natives-windows") || name.endsWith("natives-linux"))) {
// Add windows and Linux arm64 natives for modern classpath native MC versions.
project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, name + "-arm64");
}
project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, name);
}
if (library.hasNativesForOS()) {
MinecraftVersionMeta.Download nativeDownload = library.classifierForOS();
if (nativeDownload == null) {
continue;
}
final String path = nativeDownload.path();
final Matcher matcher = NATIVES_PATTERN.matcher(path);
if (!matcher.find()) {
project.getLogger().warn("Failed to match regex for natives path : " + path);
continue;
}
final String group = matcher.group("group").replace("/", ".");
final String name = matcher.group("name");
final String version = matcher.group("version");
final String classifier = matcher.group("classifier");
final String dependencyNotation = "%s:%s:%s:%s".formatted(group, name, version, classifier);
if (overrideLWJGL && isMacOS && "java-objc-bridge".equals(name)) {
// Mojang split out the natives into their own jar, skip over Mojang's jar and use the official jar later on.
continue;
}
project.getLogger().debug("Add native dependency '{}'", dependencyNotation);
project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, dependencyNotation);
provideNativesForLibrary(library, overrideLWJGL, IS_MACOS);
}
}
}
private void provideServerLibraries() {
if (serverBundleMetadata != null) {
for (BundleMetadata.Entry library : serverBundleMetadata.libraries()) {
if (runtimeOnlyLog4j && library.name().startsWith("org.apache.logging.log4j")) {
// Make log4j a runtime only dep to force slf4j.
project.getDependencies().add(Constants.Configurations.MINECRAFT_RUNTIME_DEPENDENCIES, library.name());
continue;
}
project.getDependencies().add(Constants.Configurations.MINECRAFT_SERVER_DEPENDENCIES, library.name());
}
}
}
if (overrideLWJGL) {
LWJGLVersionOverride.DEPENDENCIES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, s));
LWJGLVersionOverride.NATIVES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, s));
private void provideNativesForLibrary(MinecraftVersionMeta.Library library, boolean overrideLWJGL, boolean isMacOS) {
MinecraftVersionMeta.Download nativeDownload = library.classifierForOS();
if (isMacOS) {
LWJGLVersionOverride.MACOS_DEPENDENCIES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_DEPENDENCIES, s));
LWJGLVersionOverride.MACOS_NATIVES.forEach(s -> project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, s));
}
// Add the native support mod that fixes a handful of issues related to the LWJGL update at runtime.
ExternalModuleDependency dependency = (ExternalModuleDependency) project.getDependencies().create(Constants.Dependencies.NATIVE_SUPPORT + Constants.Dependencies.Versions.NATIVE_SUPPORT_VERSION);
dependency.setTransitive(false);
project.getDependencies().add("modLocalRuntime", dependency);
if (nativeDownload == null) {
return;
}
final String path = nativeDownload.path();
final Matcher matcher = NATIVES_PATTERN.matcher(path);
if (!matcher.find()) {
project.getLogger().warn("Failed to match regex for natives path : " + path);
return;
}
final String group = matcher.group("group").replace("/", ".");
final String name = matcher.group("name");
final String version = matcher.group("version");
final String classifier = matcher.group("classifier");
final String dependencyNotation = "%s:%s:%s:%s".formatted(group, name, version, classifier);
if (overrideLWJGL && isMacOS && "java-objc-bridge".equals(name)) {
// Mojang split out the natives into their own jar, skip over Mojang's jar and use the official jar later on.
return;
}
project.getLogger().debug("Add native dependency '{}'", dependencyNotation);
project.getDependencies().add(Constants.Configurations.MINECRAFT_NATIVES, dependencyNotation);
}
}

View File

@@ -134,8 +134,8 @@ public abstract class MinecraftProvider {
}
public void provide() throws Exception {
libraryProvider = new MinecraftLibraryProvider();
libraryProvider.provide(this, getProject());
libraryProvider = new MinecraftLibraryProvider(this, project);
libraryProvider.provide();
}
protected void initFiles() {

View File

@@ -82,9 +82,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected final ConfigurableFileCollection log4jConfigs;
protected final RegularFileProperty accessWidener;
protected final Property<Boolean> shareCaches;
protected final Property<Boolean> remapArchives;
protected final Property<String> customManifest;
protected final Property<Boolean> setupRemappedVariants;
protected final Property<Boolean> transitiveAccessWideners;
protected final Property<Boolean> modProvidedJavadoc;
protected final Property<String> intermediary;
@@ -121,11 +119,7 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
this.accessWidener = project.getObjects().fileProperty();
this.shareCaches = project.getObjects().property(Boolean.class)
.convention(false);
this.remapArchives = project.getObjects().property(Boolean.class)
.convention(true);
this.customManifest = project.getObjects().property(String.class);
this.setupRemappedVariants = project.getObjects().property(Boolean.class)
.convention(true);
this.transitiveAccessWideners = project.getObjects().property(Boolean.class)
.convention(true);
this.transitiveAccessWideners.finalizeValueOnRead();
@@ -249,11 +243,6 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
protected abstract String getMinecraftVersion();
@Override
public Property<Boolean> getRemapArchives() {
return remapArchives;
}
@Override
public void runs(Action<NamedDomainObjectContainer<RunConfigSettings>> action) {
action.execute(runConfigs);
@@ -279,11 +268,6 @@ public abstract class LoomGradleExtensionApiImpl implements LoomGradleExtensionA
return customManifest;
}
@Override
public Property<Boolean> getSetupRemappedVariants() {
return setupRemappedVariants;
}
@Override
public String getModVersion() {
return versionParser.getModVersion();

View File

@@ -33,6 +33,7 @@ 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;
@@ -63,6 +64,10 @@ import net.fabricmc.loom.util.ZipUtils;
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 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();
@@ -142,8 +147,8 @@ public abstract class AbstractRemapJarTask extends Jar {
protected void applyClientOnlyManifestAttributes(AbstractRemapParams params, List<String> entries) {
params.getManifestAttributes().set(Map.of(
"Fabric-Loom-Split-Environment", "true",
"Fabric-Loom-Client-Only-Entries", String.join(";", entries)
MANIFEST_SPLIT_ENV_KEY, "true",
MANIFEST_CLIENT_ENTRIES_KEY, String.join(";", entries)
));
}

View File

@@ -24,15 +24,9 @@
package net.fabricmc.loom.util;
public class Architecture {
public record Architecture(String name) {
public static final Architecture CURRENT = new Architecture(System.getProperty("os.arch"));
private final String name;
public Architecture(String name) {
this.name = name;
}
public boolean is64Bit() {
return name.contains("64") || name.startsWith("armv8");
}
@@ -40,8 +34,4 @@ public class Architecture {
public boolean isArm() {
return name.startsWith("arm") || name.startsWith("aarch64");
}
public String getName() {
return name;
}
}

View File

@@ -26,6 +26,7 @@ package net.fabricmc.loom.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
@@ -38,8 +39,12 @@ import net.fabricmc.tinyremapper.FileSystemReference;
public final class FileSystemUtil {
public record Delegate(FileSystemReference reference) implements AutoCloseable, Supplier<FileSystem> {
public Path getPath(String path, String... more) {
return get().getPath(path, more);
}
public byte[] readAllBytes(String path) throws IOException {
Path fsPath = get().getPath(path);
Path fsPath = getPath(path);
if (Files.exists(fsPath)) {
return Files.readAllBytes(fsPath);
@@ -48,6 +53,12 @@ public final class FileSystemUtil {
}
}
public <T> T fromInputStream(IOFunction<InputStream, T> function, String path, String... more) throws IOException {
try (InputStream inputStream = Files.newInputStream(getPath(path, more))) {
return function.apply(inputStream);
}
}
public String readString(String path) throws IOException {
return new String(readAllBytes(path), StandardCharsets.UTF_8);
}

View File

@@ -0,0 +1,32 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2022 FabricMC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package net.fabricmc.loom.util;
import java.io.IOException;
@FunctionalInterface
public interface IOFunction<T, R> {
R apply(T t) throws IOException;
}