Forge Runtime

Signed-off-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
Juuxel
2021-07-11 02:10:03 +08:00
committed by shedaniel
parent e664640610
commit 0cd784512d
17 changed files with 122 additions and 111 deletions

3
.gitignore vendored
View File

@@ -20,4 +20,5 @@
!/settings.gradle
!/Jenkinsfile
!/checkstyle.xml
!/codenarc.groovy
!/codenarc.groovy
!/forge-runtime

View File

@@ -12,6 +12,7 @@ plugins {
id 'codenarc'
id "org.cadixdev.licenser" version "0.5.0"
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'net.kyori.blossom' version '1.2.0'
}
sourceCompatibility = 1.8
@@ -34,16 +35,6 @@ if (!isSnapshot) {
logger.lifecycle(":building plugin v${version}")
configurations {
forgeInjectShadow
forgeInjectCompileClasspath.extendsFrom(forgeInjectShadow)
forgeInjectRuntimeClasspath.extendsFrom(forgeInjectShadow)
}
sourceSets {
forgeInject
}
repositories {
mavenCentral()
maven { url "https://maven.fabricmc.net/" }
@@ -106,14 +97,6 @@ dependencies {
implementation ('de.oceanlabs.mcp:mcinjector:3.8.0')
implementation ('com.opencsv:opencsv:5.4')
// Forge injection
forgeInjectShadow ('net.fabricmc:tiny-mappings-parser:0.2.2.14')
forgeInjectImplementation ('cpw.mods:modlauncher:6.1.3')
forgeInjectImplementation ('org.spongepowered:mixin:0.8.2')
forgeInjectImplementation ('com.google.code.gson:gson:2.8.6')
forgeInjectImplementation ('com.google.guava:guava:21.0')
forgeInjectImplementation ('org.apache.logging.log4j:log4j-api:2.11.2')
// Testing
testImplementation(gradleTestKit())
testImplementation('org.spockframework:spock-core:1.3-groovy-2.4') {
@@ -124,11 +107,8 @@ dependencies {
compileOnly 'org.jetbrains:annotations:20.1.0'
}
task forgeInjectJar(type: ShadowJar, dependsOn: [compileForgeInjectJava, processForgeInjectResources]) {
configurations = [project.configurations.forgeInjectShadow]
classifier = 'forgeinject'
from compileForgeInjectJava.outputs
from processForgeInjectResources.outputs
blossom {
replaceToken '$LOOM_VERSION', version
}
jar {
@@ -136,13 +116,7 @@ jar {
}
task mainJar(type: Jar, dependsOn: jar) {
dependsOn forgeInjectJar
from zipTree(jar.archivePath)
from(forgeInjectJar.outputs) {
into "inject"
rename { "injection.jar" }
}
manifest {
attributes 'Implementation-Version': project.version + ' Build(' + buildNum + ')'
@@ -166,7 +140,6 @@ license {
exclude '**/loom/util/DownloadUtil.java'
exclude '**/projects'
exclude '**/loom/util/FileSystemUtil.java'
exclude '**/loom/inject/mixin/MixinIntermediaryDevRemapper.java'
}
checkstyle {

6
forge-runtime/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# Ignore everything
/*
!/src
!/build.gradle
!/.gitignore

View File

@@ -0,0 +1,87 @@
plugins {
id 'java'
id 'maven-publish'
id 'checkstyle'
id 'com.github.johnrengelman.shadow'
id 'org.cadixdev.licenser'
}
group = rootProject.group
archivesBaseName = 'architectury-loom-forge-runtime'
version = rootProject.version
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
configurations {
include
compileOnly.extendsFrom include
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 8
}
repositories {
mavenCentral()
maven { url "https://maven.fabricmc.net/" }
maven { url "https://maven.minecraftforge.net/" }
}
dependencies {
// shadowed
include ('net.fabricmc:tiny-mappings-parser:0.3.0+build.17')
// guaranteed to be there at runtime
compileOnly ('cpw.mods:modlauncher:6.1.3')
compileOnly ('org.spongepowered:mixin:0.8.2')
compileOnly ('com.google.code.gson:gson:2.8.6')
compileOnly ('com.google.guava:guava:21.0')
compileOnly ('org.apache.logging.log4j:log4j-api:2.11.2')
}
jar {
classifier = "slim"
}
shadowJar {
classifier = ""
configurations = [project.configurations.include]
relocate "net.fabricmc.mapping", "dev.architectury.loom.forgeruntime.shadow.mapping"
relocate "net.fabricmc.mappings", "dev.architectury.loom.forgeruntime.shadow.mappings"
}
assemble.dependsOn shadowJar
license {
header rootProject.file("HEADER")
include "**/*.java"
exclude '**/loom/forgeruntime/mixin/MixinIntermediaryDevRemapper.java'
}
checkstyle {
configFile = rootProject.checkstyle.configFile
toolVersion = rootProject.checkstyle.toolVersion
}
publishing {
publications {
maven(MavenPublication) {
artifactId = 'architectury-loom-forge-runtime'
shadow.component it
}
}
repositories {
if (System.getenv("MAVEN_PASS") != null) {
maven {
url = "https://deploy.shedaniel.me/"
credentials {
username = "shedaniel"
password = System.getenv("MAVEN_PASS")
}
}
}
}
}

View File

@@ -22,7 +22,7 @@
* SOFTWARE.
*/
package net.fabricmc.loom.inject;
package dev.architectury.loom.forgeruntime;
import java.io.BufferedReader;
import java.io.IOException;
@@ -30,6 +30,7 @@ import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.AbstractMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
@@ -56,7 +57,7 @@ public class YarnNamingService implements INameMappingService {
@Override
public Map.Entry<String, String> understanding() {
return new Pair<>("srg", "mcp");
return new AbstractMap.SimpleImmutableEntry<>("srg", "mcp");
}
@Override

View File

@@ -22,7 +22,7 @@
* SOFTWARE.
*/
package net.fabricmc.loom.inject.mixin;
package dev.architectury.loom.forgeruntime.mixin;
import java.io.BufferedReader;
import java.nio.file.Files;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package net.fabricmc.loom.inject.mixin;
package dev.architectury.loom.forgeruntime.mixin;
import java.util.ArrayDeque;
import java.util.Collection;

View File

@@ -25,7 +25,8 @@
package mcp;
/**
* A dummy class, required for some Forge classes to load.
* A dummy class, required for some Forge classes to load
* because {@code MethodsReturnNonnullByDefault} in MCP has runtime retention.
*
* @deprecated Don't use this in your mods. JetBrains annotations are there for you.
*/

View File

@@ -0,0 +1 @@
dev.architectury.loom.forgeruntime.YarnNamingService

View File

@@ -0,0 +1 @@
dev.architectury.loom.forgeruntime.mixin.ForgeLoomMixinRemapperInjectorService

View File

@@ -1 +1,2 @@
rootProject.name = "architectury-loom"
include "forge-runtime"

View File

@@ -1,52 +0,0 @@
/*
* This file is part of fabric-loom, licensed under the MIT License (MIT).
*
* Copyright (c) 2016, 2017, 2018 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.inject;
import java.util.Map;
final class Pair<A, B> implements Map.Entry<A, B> {
private final A first;
private final B second;
Pair(A first, B second) {
this.first = first;
this.second = second;
}
@Override
public A getKey() {
return first;
}
@Override
public B getValue() {
return second;
}
@Override
public B setValue(B value) {
throw new UnsupportedOperationException("Pairs are immutable!");
}
}

View File

@@ -1 +0,0 @@
net.fabricmc.loom.inject.YarnNamingService

View File

@@ -1 +0,0 @@
net.fabricmc.loom.inject.mixin.ForgeLoomMixinRemapperInjectorService

View File

@@ -72,6 +72,7 @@ public class LaunchProvider extends DependencyProvider {
if (getExtension().isForge()) {
launchConfig
// Should match YarnNamingService.PATH_TO_MAPPINGS in forge-runtime
.property("fabric.yarnWithSrg.path", getExtension().getMappingsProvider().tinyMappingsWithSrg.toAbsolutePath().toString())
.argument("--fml.mcVersion")
@@ -136,7 +137,8 @@ public class LaunchProvider extends DependencyProvider {
annotationDependency = addDependency(Constants.Dependencies.JETBRAINS_ANNOTATIONS + Constants.Dependencies.Versions.JETBRAINS_ANNOTATIONS, JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);
if (getExtension().isForge()) {
addDependency(Constants.Dependencies.JAVAX_ANNOTATIONS + Constants.Dependencies.Versions.JAVAX_ANNOTATIONS, "compileOnly");
addDependency(Constants.Dependencies.FORGE_RUNTIME + Constants.Dependencies.Versions.FORGE_RUNTIME, JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME);
addDependency(Constants.Dependencies.JAVAX_ANNOTATIONS + Constants.Dependencies.Versions.JAVAX_ANNOTATIONS, JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME);
}
postPopulationScheduler.accept(this::writeRemapClassPath);

View File

@@ -91,6 +91,8 @@ import net.fabricmc.loom.util.srg.SpecialSourceExecutor;
import net.fabricmc.mapping.tree.TinyTree;
public class MinecraftPatchedProvider extends DependencyProvider {
private static final String NAME_MAPPING_SERVICE_PATH = "/inject/META-INF/services/cpw.mods.modlauncher.api.INameMappingService";
// Step 1: Remap Minecraft to SRG
private File minecraftClientSrgJar;
private File minecraftServerSrgJar;
@@ -338,25 +340,6 @@ public class MinecraftPatchedProvider extends DependencyProvider {
copyAll(getExtension().getForgeUniversalProvider().getForge(), environment.patchedSrgJar.apply(this));
copyUserdevFiles(getExtension().getForgeUserdevProvider().getUserdevJar(), environment.patchedSrgJar.apply(this));
});
logger.lifecycle(":injecting loom classes into minecraft");
File injection = File.createTempFile("loom-injection", ".jar");
try (InputStream in = MinecraftProvider.class.getResourceAsStream("/inject/injection.jar")) {
FileUtils.copyInputStreamToFile(in, injection);
}
for (Environment environment : Environment.values()) {
String side = environment.side();
File target = environment.patchedSrgJar.apply(this);
walkFileSystems(injection, target, it -> {
if (it.getFileName().toString().equals("MANIFEST.MF")) {
return false;
}
return getExtension().useFabricMixin || !it.getFileName().toString().endsWith("cpw.mods.modlauncher.api.ITransformationService");
}, this::copyReplacing);
}
}
private void accessTransformForge(Logger logger) throws Exception {
@@ -575,7 +558,13 @@ public class MinecraftPatchedProvider extends DependencyProvider {
}
private void copyUserdevFiles(File source, File target) throws IOException {
walkFileSystems(source, target, file -> true, fs -> Collections.singleton(fs.getPath("inject")), (sourceFs, targetFs, sourcePath, targetPath) -> {
// Removes the Forge name mapping service definition so that our own is used.
// If there are multiple name mapping services with the same "understanding" pair
// (source -> target namespace pair), modlauncher throws a fit and will crash.
// To use our YarnNamingService instead of MCPNamingService, we have to remove this file.
Predicate<Path> filter = file -> !file.toString().equals(NAME_MAPPING_SERVICE_PATH);
walkFileSystems(source, target, filter, fs -> Collections.singleton(fs.getPath("inject")), (sourceFs, targetFs, sourcePath, targetPath) -> {
Path parent = targetPath.getParent();
if (parent != null) {

View File

@@ -104,6 +104,7 @@ public class Constants {
public static final String TERMINAL_CONSOLE_APPENDER = "net.minecrell:terminalconsoleappender:";
public static final String JETBRAINS_ANNOTATIONS = "org.jetbrains:annotations:";
public static final String JAVAX_ANNOTATIONS = "com.google.code.findbugs:jsr305:"; // I hate that I have to add these.
public static final String FORGE_RUNTIME = "dev.architectury:architectury-loom-forge-runtime:";
private Dependencies() {
}
@@ -117,6 +118,7 @@ public class Constants {
public static final String TERMINAL_CONSOLE_APPENDER = "1.2.0";
public static final String JETBRAINS_ANNOTATIONS = "19.0.0";
public static final String JAVAX_ANNOTATIONS = "3.0.2";
public static final String FORGE_RUNTIME = "$LOOM_VERSION"; // replaced with current version at build time
private Versions() {
}