diff options
author | shedaniel <daniel@shedaniel.me> | 2021-07-20 17:44:04 +0800 |
---|---|---|
committer | shedaniel <daniel@shedaniel.me> | 2021-07-20 17:44:04 +0800 |
commit | 07bc4eab7b23fee28d0036890337c5af97cc3d2f (patch) | |
tree | 3d3fe446554db0cb665c7d1ced616f7c645360f6 /src/main/java | |
parent | 3a354be4d757dcb93c8bf96bd74d50888a3f6e2f (diff) | |
parent | 2259a4efc8f4dad35880b41cb8be59bc5b857f9b (diff) | |
download | architectury-loom-07bc4eab7b23fee28d0036890337c5af97cc3d2f.tar.gz architectury-loom-07bc4eab7b23fee28d0036890337c5af97cc3d2f.tar.bz2 architectury-loom-07bc4eab7b23fee28d0036890337c5af97cc3d2f.zip |
Merge branch 'upstream-0.9' into dev/0.9
# Conflicts:
# src/main/java/net/fabricmc/loom/LoomGradlePlugin.java
# src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java
# src/main/java/net/fabricmc/loom/task/RemapJarTask.java
Diffstat (limited to 'src/main/java')
8 files changed, 177 insertions, 26 deletions
diff --git a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java index 8832beb7..6ea1a3ed 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradleExtension.java +++ b/src/main/java/net/fabricmc/loom/LoomGradleExtension.java @@ -39,7 +39,6 @@ import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; -import com.google.gson.JsonObject; import org.cadixdev.lorenz.MappingSet; import org.cadixdev.mercury.Mercury; import org.gradle.api.Action; @@ -53,6 +52,7 @@ import org.gradle.api.tasks.SourceSet; import org.jetbrains.annotations.ApiStatus; import net.fabricmc.loom.api.decompilers.LoomDecompiler; +import net.fabricmc.loom.configuration.InstallerData; import net.fabricmc.loom.configuration.LoomDependencyManager; import net.fabricmc.loom.configuration.LoomProjectData; import net.fabricmc.loom.configuration.ide.RunConfig; @@ -107,7 +107,7 @@ public class LoomGradleExtension { private List<String> dataGenMods = new ArrayList<>(); private LoomDependencyManager dependencyManager; private JarProcessorManager jarProcessorManager; - private JsonObject installerJson; + private InstallerData installerData; private MappingSet[] srcMappingCache = new MappingSet[2]; private Mercury[] srcMercuryCache = new Mercury[2]; private ModPlatform platform; @@ -273,12 +273,12 @@ public class LoomGradleExtension { return unmappedMods; } - public void setInstallerJson(JsonObject object) { - this.installerJson = object; + public void setInstallerData(InstallerData data) { + this.installerData = data; } - public JsonObject getInstallerJson() { - return installerJson; + public InstallerData getInstallerData() { + return installerData; } public void accessWidener(Object file) { diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index ecac6a76..3f7d710f 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -24,6 +24,8 @@ package net.fabricmc.loom; +import java.util.Objects; + import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -49,6 +51,7 @@ public class LoomGradlePlugin implements BootstrappedPlugin { public static boolean refreshDeps; public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + public static final String LOOM_VERSION = Objects.requireNonNullElse(LoomGradlePlugin.class.getPackage().getImplementationVersion(), "0.0.0+unknown"); @Override public void apply(PluginAware target) { @@ -60,13 +63,12 @@ public class LoomGradlePlugin implements BootstrappedPlugin { } public void apply(Project project) { - String loomVersion = LoomGradlePlugin.class.getPackage().getImplementationVersion(); Set<String> loggedVersions = new HashSet<>(Arrays.asList(System.getProperty("loom.printed.logged", "").split(","))); - if (!loggedVersions.contains(loomVersion)) { - loggedVersions.add(loomVersion); + if (!loggedVersions.contains(LOOM_VERSION)) { + loggedVersions.add(LOOM_VERSION); System.setProperty("loom.printed.logged", String.join(",", loggedVersions)); - project.getLogger().lifecycle("Architectury Loom: " + loomVersion); + project.getLogger().lifecycle("Architectury Loom: " + LOOM_VERSION); project.getLogger().lifecycle("You are using an unstable version of Architectury Loom! Please report any issues found!"); } diff --git a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java index 3cf81dcb..6b7e1f02 100644 --- a/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java +++ b/src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java @@ -29,9 +29,9 @@ import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; import org.gradle.api.tasks.SourceSet; -import org.gradle.api.tasks.bundling.AbstractArchiveTask; import org.gradle.api.tasks.compile.JavaCompile; import org.gradle.api.tasks.javadoc.Javadoc; +import org.gradle.jvm.tasks.Jar; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.build.mixin.JavaApInvoker; @@ -190,7 +190,7 @@ public final class CompileConfiguration { if (extension.remapMod) { RemapConfiguration.setupDefaultRemap(project); } else { - AbstractArchiveTask jarTask = (AbstractArchiveTask) project.getTasks().getByName("jar"); + Jar jarTask = (Jar) project.getTasks().getByName("jar"); extension.getUnmappedModCollection().from(jarTask); } diff --git a/src/main/java/net/fabricmc/loom/configuration/InstallerData.java b/src/main/java/net/fabricmc/loom/configuration/InstallerData.java new file mode 100644 index 00000000..9196b04d --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/InstallerData.java @@ -0,0 +1,30 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2021 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; + +import com.google.gson.JsonObject; + +public record InstallerData(String version, JsonObject installerJson) { +} diff --git a/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java b/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java new file mode 100644 index 00000000..2cc68401 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/configuration/JarManifestConfiguration.java @@ -0,0 +1,91 @@ +/* + * This file is part of fabric-loom, licensed under the MIT License (MIT). + * + * Copyright (c) 2021 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; + +import java.util.Optional; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +import org.gradle.api.Project; +import org.gradle.util.GradleVersion; + +import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.LoomGradlePlugin; +import net.fabricmc.loom.util.Constants; +import net.fabricmc.tinyremapper.TinyRemapper; + +public final record JarManifestConfiguration(Project project) { + public void configure(Manifest manifest) { + // Dont set when running the reproducible build tests as it will break them when anything updates + if (Boolean.getBoolean("loom.test.reproducible")) { + return; + } + + LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + + Attributes attributes = manifest.getMainAttributes(); + var tinyRemapperVersion = Optional.ofNullable(TinyRemapper.class.getPackage().getImplementationVersion()); + + attributes.putValue("Fabric-Gradle-Version", GradleVersion.current().getVersion()); + attributes.putValue("Fabric-Loom-Version", LoomGradlePlugin.LOOM_VERSION); + attributes.putValue("Fabric-Mixin-Compile-Extensions-Version", Constants.Dependencies.Versions.MIXIN_COMPILE_EXTENSIONS); + attributes.putValue("Fabric-Minecraft-Version", extension.getMinecraftProvider().minecraftVersion()); + tinyRemapperVersion.ifPresent(s -> attributes.putValue("Fabric-Tiny-Remapper-Version", s)); + getLoaderVersion().ifPresent(s -> attributes.putValue("Fabric-Loader-Version", s)); + + // This can be overridden by mods if required + if (!attributes.containsKey("Fabric-Mixin-Version")) { + addMixinVersion(attributes); + } + } + + private void addMixinVersion(Attributes attributes) { + // Not super ideal that this uses the mod compile classpath, should prob look into making this not a thing at somepoint + var dependency = project.getConfigurations().getByName(Constants.Configurations.LOADER_DEPENDENCIES) + .getDependencies() + .stream() + .filter(dep -> "sponge-mixin".equals(dep.getName())) + .findFirst(); + + if (dependency.isEmpty()) { + project.getLogger().warn("Could not determine Mixin version for jar manifest"); + return; + } + + attributes.putValue("Fabric-Mixin-Version", dependency.get().getVersion()); + attributes.putValue("Fabric-Mixin-Group", dependency.get().getGroup()); + } + + private Optional<String> getLoaderVersion() { + LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + + if (extension.getInstallerData() == null) { + project.getLogger().warn("Could not determine fabric loader version for jar manifest"); + return Optional.empty(); + } + + return Optional.of(extension.getInstallerData().version()); + } +} diff --git a/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java b/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java index 9daaa7c7..a33d7293 100644 --- a/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java +++ b/src/main/java/net/fabricmc/loom/configuration/LoomDependencyManager.java @@ -141,27 +141,29 @@ public class LoomDependencyManager { String platformSuffix = extension.isForge() ? "_forge" : ""; String mappingsKey = mappingsProvider.getMappingsKey() + platformSuffix; - if (extension.getInstallerJson() == null && !extension.isForge()) { + if (extension.getInstallerData() == null && !extension.isForge()) { //If we've not found the installer JSON we've probably skipped remapping Fabric loader, let's go looking project.getLogger().info("Searching through modCompileClasspath for installer JSON"); final Configuration configuration = project.getConfigurations().getByName(Constants.Configurations.MOD_COMPILE_CLASSPATH); - for (File input : configuration.resolve()) { - JsonObject jsonObject = ModProcessor.readInstallerJson(input, project); + for (Dependency dependency : configuration.getAllDependencies()) { + for (File input : configuration.files(dependency)) { + JsonObject jsonObject = ModProcessor.readInstallerJson(input, project); - if (jsonObject != null) { - if (extension.getInstallerJson() != null) { - project.getLogger().info("Found another installer JSON in, ignoring it! " + input); - continue; - } + if (jsonObject != null) { + if (extension.getInstallerData() != null) { + project.getLogger().info("Found another installer JSON in, ignoring it! " + input); + continue; + } - project.getLogger().info("Found installer JSON in " + input); - extension.setInstallerJson(jsonObject); - handleInstallerJson(extension.getInstallerJson(), project); + project.getLogger().info("Found installer JSON in " + input); + extension.setInstallerData(new InstallerData(dependency.getVersion(), jsonObject)); + handleInstallerJson(jsonObject, project); + } } } - if (extension.getInstallerJson() == null) { + if (extension.getInstallerData() == null) { project.getLogger().warn("fabric-installer.json not found in classpath!"); } } diff --git a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java index cecfba3c..0d31192d 100644 --- a/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java +++ b/src/main/java/net/fabricmc/loom/configuration/ide/RunConfig.java @@ -158,7 +158,7 @@ public class RunConfig { if (extension.getLoaderLaunchMethod().equals("launchwrapper")) { // if installer.json found... - JsonObject installerJson = extension.getInstallerJson(); + JsonObject installerJson = extension.getInstallerData().installerJson(); if (installerJson != null) { List<String> sideKeys = ImmutableList.of(environment, "common"); @@ -305,7 +305,7 @@ public class RunConfig { } private static String getMainClass(String side, LoomGradleExtension extension, String defaultMainClass) { - JsonObject installerJson = extension.getInstallerJson(); + JsonObject installerJson = extension.getInstallerData().installerJson(); if (installerJson != null && installerJson.has("mainClass")) { JsonElement mainClassJson = installerJson.get("mainClass"); diff --git a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java index c82dec79..7929b319 100644 --- a/src/main/java/net/fabricmc/loom/task/RemapJarTask.java +++ b/src/main/java/net/fabricmc/loom/task/RemapJarTask.java @@ -27,6 +27,8 @@ package net.fabricmc.loom.task; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.io.Reader; import java.net.URI; import java.nio.charset.StandardCharsets; @@ -43,6 +45,8 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; @@ -70,6 +74,8 @@ import org.gradle.jvm.tasks.Jar; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import org.zeroturnaround.zip.ZipUtil; +import org.zeroturnaround.zip.transform.StreamZipEntryTransformer; +import org.zeroturnaround.zip.transform.ZipEntryTransformerEntry; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.build.JarRemapper; @@ -80,6 +86,7 @@ import net.fabricmc.loom.build.nesting.MergedNestedJarProvider; import net.fabricmc.loom.build.nesting.NestedDependencyProvider; import net.fabricmc.loom.build.nesting.NestedJarPathProvider; import net.fabricmc.loom.build.nesting.NestedJarProvider; +import net.fabricmc.loom.configuration.JarManifestConfiguration; import net.fabricmc.loom.configuration.accesswidener.AccessWidenerJarProcessor; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.util.Constants; @@ -93,6 +100,8 @@ import net.fabricmc.mapping.tree.TinyTree; import net.fabricmc.stitch.util.Pair; public class RemapJarTask extends Jar { + private static final String MANIFEST_PATH = "META-INF/MANIFEST.MF"; + private final RegularFileProperty input; private final Property<Boolean> addNestedDependencies; private final Property<Boolean> addDefaultNestedDependencies; @@ -283,6 +292,23 @@ public class RemapJarTask extends Jar { Preconditions.checkArgument(replaced, "Failed to remap access widener"); } + // Add data to the manifest + boolean transformed = ZipUtil.transformEntries(data.output.toFile(), new ZipEntryTransformerEntry[]{ + new ZipEntryTransformerEntry(MANIFEST_PATH, new StreamZipEntryTransformer() { + @Override + protected void transform(ZipEntry zipEntry, InputStream in, OutputStream out) throws IOException { + var manifest = new Manifest(in); + var manifestConfiguration = new JarManifestConfiguration(project); + + manifestConfiguration.configure(manifest); + manifest.getMainAttributes().putValue("Fabric-Mapping-Namespace", toM); + + manifest.write(out); + } + }) + }); + Preconditions.checkArgument(transformed, "Failed to transform jar manifest"); + if (isReproducibleFileOrder() || !isPreserveFileTimestamps()) { try { ZipReprocessorUtil.reprocessZip(output.toFile(), isReproducibleFileOrder(), isPreserveFileTimestamps()); |