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
This commit is contained in:
shedaniel
2021-07-20 17:44:04 +08:00
13 changed files with 189 additions and 31 deletions

View File

@@ -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) {

View File

@@ -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!");
}

View File

@@ -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);
}

View File

@@ -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) {
}

View File

@@ -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());
}
}

View File

@@ -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.setInstallerData(new InstallerData(dependency.getVersion(), jsonObject));
handleInstallerJson(jsonObject, project);
}
project.getLogger().info("Found installer JSON in " + input);
extension.setInstallerJson(jsonObject);
handleInstallerJson(extension.getInstallerJson(), project);
}
}
if (extension.getInstallerJson() == null) {
if (extension.getInstallerData() == null) {
project.getLogger().warn("fabric-installer.json not found in classpath!");
}
}

View File

@@ -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");

View File

@@ -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());