Fix codestyle, add forge tests

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
shedaniel
2021-09-18 15:28:28 +08:00
parent 7f54808315
commit dfba3a1dc3
11 changed files with 182 additions and 16 deletions

View File

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

View File

@@ -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<String, JsonElement> 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<String, JsonElement> env : value.getAsJsonObject("env").entrySet()) {
String string = processTemplates(env.getValue().getAsString());
settings.envVariables.put(env.getKey(), string);
}
}
});
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -37,6 +37,7 @@ public class Tsrg2Writer {
private static void writeMethod(List<String> 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);

View File

@@ -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\""
}
}

View File

@@ -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.
}
}

View File

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

View File

@@ -0,0 +1,2 @@
rootProject.name = "fabric-example-mod"