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/net/fabricmc/loom/configuration | |
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/net/fabricmc/loom/configuration')
5 files changed, 139 insertions, 16 deletions
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"); |