diff --git a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java index bb7717bd..0970717c 100644 --- a/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java +++ b/src/main/java/net/fabricmc/loom/configuration/accesswidener/AccessWidenerJarProcessor.java @@ -32,7 +32,6 @@ import java.nio.file.Path; import java.util.Arrays; import com.google.common.hash.Hashing; -import dev.architectury.tinyremapper.TinyRemapper; import org.gradle.api.Project; import org.objectweb.asm.commons.Remapper; import org.zeroturnaround.zip.ZipUtil; @@ -44,9 +43,6 @@ import net.fabricmc.accesswidener.AccessWidenerWriter; import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.processors.JarProcessor; -import net.fabricmc.loom.configuration.providers.minecraft.MinecraftMappedProvider; -import net.fabricmc.loom.util.Checksum; -import net.fabricmc.loom.util.Constants; public class AccessWidenerJarProcessor implements JarProcessor { // Filename used to store hash of input access widener in processed jar file diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeUserdevProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeUserdevProvider.java index df115d63..a8066544 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeUserdevProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeUserdevProvider.java @@ -162,14 +162,20 @@ public class ForgeUserdevProvider extends DependencyProvider { if (settings != null) { settings.evaluateLater(() -> { settings.defaultMainClass(value.getAsJsonPrimitive("main").getAsString()); - settings.vmArgs(StreamSupport.stream(value.getAsJsonArray("jvmArgs").spliterator(), false) - .map(JsonElement::getAsString) - .map(this::processTemplates) - .collect(Collectors.toList())); - for (Map.Entry env : value.getAsJsonObject("env").entrySet()) { - String string = processTemplates(env.getValue().getAsString()); - settings.envVariables.put(env.getKey(), string); + if (value.has("jvmArgs")) { + settings.vmArgs(StreamSupport.stream(value.getAsJsonArray("jvmArgs").spliterator(), false) + .map(JsonElement::getAsString) + .map(this::processTemplates) + .collect(Collectors.toList())); + } + + if (value.has("env")) { + for (Map.Entry env : value.getAsJsonObject("env").entrySet()) { + String string = processTemplates(env.getValue().getAsString()); + + settings.envVariables.put(env.getKey(), string); + } } }); } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java b/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java index 7b610e0f..44b6aadf 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/forge/MinecraftPatchedProvider.java @@ -442,7 +442,7 @@ public class MinecraftPatchedProvider extends DependencyProvider { } } - Files.writeString(outTrimmed, Tsrg2Writer.serialize(tree), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); + Files.writeString(outTrimmed, Tsrg2Writer.serialize(tree), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); mergedMojangTsrg2Files = new Path[]{out, outTrimmed}; } diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java index b570f428..32d66325 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingsProviderImpl.java @@ -468,7 +468,7 @@ public class MappingsProviderImpl extends DependencyProvider implements Mappings MappingsNamespace.INTERMEDIARY.toString(), MappingsNamespace.OFFICIAL.toString()); } catch (Exception e) { throw new RuntimeException("Could not merge mappings from " + intermediaryMappings.toString() - + " with mappings from " + yarnMappings, e); + + " with mappings from " + yarnMappings, e); } } diff --git a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java index 145bb82f..5f300aec 100644 --- a/src/main/java/net/fabricmc/loom/util/SourceRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/SourceRemapper.java @@ -40,7 +40,6 @@ import org.gradle.api.Project; import org.zeroturnaround.zip.ZipUtil; import net.fabricmc.loom.LoomGradleExtension; -import net.fabricmc.loom.api.mappings.layered.MappingsNamespace; import net.fabricmc.loom.configuration.RemappedConfigurationEntry; import net.fabricmc.loom.configuration.providers.mappings.MappingsProviderImpl; import net.fabricmc.loom.util.gradle.ProgressLogger; diff --git a/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java b/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java index b239fcc5..135cb170 100644 --- a/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java +++ b/src/main/java/net/fabricmc/loom/util/srg/SpecialSourceExecutor.java @@ -54,6 +54,7 @@ public class SpecialSourceExecutor { } else if (string.startsWith("/")) { return string.substring(1); } + return string; } @@ -78,10 +79,12 @@ public class SpecialSourceExecutor { if (!trimLeadingSlash.endsWith(".class")) continue; boolean has = filter.contains(trimLeadingSlash); String s = trimLeadingSlash; + while (s.contains("$") && !has) { s = s.substring(0, s.lastIndexOf("$")) + ".class"; has = filter.contains(s); } + if (!has) continue; Path to = output.get().getPath(trimLeadingSlash); Path parent = to.getParent(); @@ -123,7 +126,7 @@ public class SpecialSourceExecutor { // if running with INFO or DEBUG logging if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS - || project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) { + || project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) { spec.setStandardOutput(System.out); spec.setErrorOutput(System.err); } else { @@ -161,7 +164,7 @@ public class SpecialSourceExecutor { // if running with INFO or DEBUG logging if (project.getGradle().getStartParameter().getShowStacktrace() != ShowStacktrace.INTERNAL_EXCEPTIONS - || project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) { + || project.getGradle().getStartParameter().getLogLevel().compareTo(LogLevel.LIFECYCLE) < 0) { spec.setStandardOutput(System.out); spec.setErrorOutput(System.err); } else { diff --git a/src/main/java/net/fabricmc/loom/util/srg/Tsrg2Writer.java b/src/main/java/net/fabricmc/loom/util/srg/Tsrg2Writer.java index 29c31560..d4df312b 100644 --- a/src/main/java/net/fabricmc/loom/util/srg/Tsrg2Writer.java +++ b/src/main/java/net/fabricmc/loom/util/srg/Tsrg2Writer.java @@ -37,6 +37,7 @@ public class Tsrg2Writer { private static void writeMethod(List namespaces, MappingTree.MethodMapping def, StringBuilder builder) { writeMapped(true, namespaces, def, builder); + for (MappingTree.MethodArgMapping arg : def.getArgs()) { builder.append("\t\t").append(arg.getLvIndex()); writeMapped(true, namespaces, arg, builder); @@ -52,6 +53,7 @@ public class Tsrg2Writer { for (int i = 0; i < names.length; ++i) { String name = names[i]; + if (i == 0) { if (needFirst) { builder.append('\t'); @@ -61,8 +63,10 @@ public class Tsrg2Writer { } builder.append(name); + if (i == 0 && mapped instanceof MappingTreeView.MemberMappingView) { String descriptor = ((MappingTreeView.MemberMappingView) mapped).getSrcDesc(); + if (descriptor != null && !descriptor.isEmpty()) { builder.append(' '); builder.append(descriptor); diff --git a/src/test/groovy/net/fabricmc/loom/test/integration/forge/ForgeTest.groovy b/src/test/groovy/net/fabricmc/loom/test/integration/forge/ForgeTest.groovy new file mode 100644 index 00000000..28dfde1b --- /dev/null +++ b/src/test/groovy/net/fabricmc/loom/test/integration/forge/ForgeTest.groovy @@ -0,0 +1,58 @@ +/* + * 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.test.integration.forge + +import net.fabricmc.loom.test.util.GradleProjectTestTrait +import spock.lang.Specification +import spock.lang.Unroll + +import static net.fabricmc.loom.test.LoomTestConstants.DEFAULT_GRADLE +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class ForgeTest extends Specification implements GradleProjectTestTrait { + @Unroll + def "build #mcVersion #forgeVersion #mappings"() { + setup: + def gradle = gradleProject(project: "forge/simple", version: DEFAULT_GRADLE) + gradle.buildGradle.text = gradle.buildGradle.text.replace('@MCVERSION@', mcVersion) + .replace('@FORGEVERSION@', forgeVersion) + .replace('@MAPPINGS@', mappings) + + when: + def result = gradle.run(task: "build", args: "") + + then: + result.task(":build").outcome == SUCCESS + + where: + mcVersion | forgeVersion | mappings + '1.17.1' | "37.0.67" | "loom.officialMojangMappings()" + '1.17.1' | "37.0.67" | "\"net.fabricmc:yarn:1.17.1+build.61:v2\"" + '1.16.5' | "36.2.4" | "loom.officialMojangMappings()" + '1.16.5' | "36.2.4" | "\"net.fabricmc:yarn:1.16.5+build.5:v2\"" + '1.14.4' | "28.2.23" | "loom.officialMojangMappings()" + '1.14.4' | "28.2.23" | "\"net.fabricmc:yarn:1.14.4+build.18:v2\"" + } +} diff --git a/src/test/resources/projects/forge/simple/build.gradle b/src/test/resources/projects/forge/simple/build.gradle new file mode 100644 index 00000000..dcee84dc --- /dev/null +++ b/src/test/resources/projects/forge/simple/build.gradle @@ -0,0 +1,81 @@ +plugins { + id 'dev.architectury.loom' + id 'maven-publish' +} + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 + +archivesBaseName = project.archives_base_name +version = project.mod_version +group = project.maven_group + +def mcVersion = "@MCVERSION@" +def forgeVersion = "@FORGEVERSION@" + +repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. +} + +dependencies { + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:$mcVersion" + mappings @MAPPINGS@ + forge "net.minecraftforge:forge:$mcVersion-$forgeVersion" +} + +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + + // The Minecraft launcher currently installs Java 8 for users, so your mod probably wants to target Java 8 too + // JDK 9 introduced a new way of specifying this that will make sure no newer classes or methods are used. + // We'll use that if it's available, but otherwise we'll use the older option. + def targetVersion = 8 + if (JavaVersion.current().isJava9Compatible()) { + it.options.release = targetVersion + } +} + +java { + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}"} + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + // add all the jars that should be included when publishing to maven + artifact(remapJar) { + builtBy remapJar + } + artifact(sourcesJar) { + builtBy remapSourcesJar + } + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } +} diff --git a/src/test/resources/projects/forge/simple/gradle.properties b/src/test/resources/projects/forge/simple/gradle.properties new file mode 100644 index 00000000..f3b2ac32 --- /dev/null +++ b/src/test/resources/projects/forge/simple/gradle.properties @@ -0,0 +1,17 @@ +# Done to increase the memory available to gradle. +org.gradle.jvmargs=-Xmx1G + +# Fabric Properties +# check these on https://fabricmc.net/use +loader_version=0.11.2 + +# Mod Properties +mod_version = 1.0.0 +maven_group = com.example +archives_base_name = fabric-example-mod + +# Dependencies +# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api +fabric_version=0.31.0+1.16 + +loom.platform=forge diff --git a/src/test/resources/projects/forge/simple/settings.gradle b/src/test/resources/projects/forge/simple/settings.gradle new file mode 100644 index 00000000..c162c363 --- /dev/null +++ b/src/test/resources/projects/forge/simple/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = "fabric-example-mod" +