mirror of
https://github.com/architectury/architectury-plugin.git
synced 2026-03-28 04:07:01 -05:00
Update transformer to 2.1.24
This commit is contained in:
18
build.gradle
18
build.gradle
@@ -32,10 +32,6 @@ repositories {
|
||||
|
||||
apply plugin: 'java-gradle-plugin'
|
||||
|
||||
sourceSets {
|
||||
annotationsInject
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation gradleApi()
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72"
|
||||
@@ -54,20 +50,6 @@ dependencies {
|
||||
implementation "com.google.code.gson:gson:2.8.5"
|
||||
}
|
||||
|
||||
task annotationsInjectJar(type: Jar) {
|
||||
classifier = 'annotations-inject'
|
||||
from sourceSets.annotationsInject.output
|
||||
}
|
||||
|
||||
jar {
|
||||
dependsOn annotationsInjectJar
|
||||
|
||||
from(annotationsInjectJar.outputs) {
|
||||
into "annotations-inject"
|
||||
rename { "injection.jar" }
|
||||
}
|
||||
}
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
kotlin.code.style=official
|
||||
loom_version=0.6.67
|
||||
transformer_version=2.0.21
|
||||
transformer_version=2.1.24
|
||||
base_version=3.0
|
||||
@@ -1,22 +0,0 @@
|
||||
package me.shedaniel.architect.plugin.callsite;
|
||||
|
||||
public class PlatformExpectedError extends Error {
|
||||
public PlatformExpectedError() {
|
||||
}
|
||||
|
||||
public PlatformExpectedError(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public PlatformExpectedError(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public PlatformExpectedError(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public PlatformExpectedError(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
package me.shedaniel.architect.plugin.callsite;
|
||||
|
||||
import java.lang.invoke.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlatformMethods {
|
||||
public static CallSite platform(MethodHandles.Lookup lookup, String name, MethodType type) {
|
||||
Class<?> lookupClass = lookup.lookupClass();
|
||||
String lookupType = lookupClass.getName().replace("$", "") + "Impl";
|
||||
|
||||
String platformExpectedClass = lookupType.substring(0, lookupType.lastIndexOf('.')) + "." + getModLoader() + "." +
|
||||
lookupType.substring(lookupType.lastIndexOf('.') + 1);
|
||||
Class<?> newClass;
|
||||
try {
|
||||
newClass = Class.forName(platformExpectedClass, false, lookupClass.getClassLoader());
|
||||
} catch (ClassNotFoundException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the class doesn't exist!", exception);
|
||||
}
|
||||
MethodHandle platformMethod;
|
||||
try {
|
||||
platformMethod = lookup.findStatic(newClass, name, type);
|
||||
} catch (NoSuchMethodException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the method doesn't exist!", exception);
|
||||
} catch (IllegalAccessException exception) {
|
||||
throw new PlatformExpectedError(lookupClass.getName() + "#" + name + " expected platform implementation in " + platformExpectedClass +
|
||||
"#" + name + ", but the method's modifier doesn't match the access requirements!", exception);
|
||||
}
|
||||
return new ConstantCallSite(platformMethod);
|
||||
}
|
||||
|
||||
private static String modLoader = null;
|
||||
|
||||
public static String getModLoader() {
|
||||
if (modLoader == null) {
|
||||
try {
|
||||
modLoader = (String) Class.forName("me.shedaniel.architectury.platform.Platform").getDeclaredMethod("getModLoader").invoke(null);
|
||||
} catch (Throwable ignored) {
|
||||
List<String> loader = new ArrayList<>();
|
||||
HashMap<String, String> MOD_LOADERS = new HashMap<>();
|
||||
MOD_LOADERS.put("net.fabricmc.loader.FabricLoader", "fabric");
|
||||
MOD_LOADERS.put("net.minecraftforge.fml.common.Mod", "forge");
|
||||
for (Map.Entry<String, String> entry : MOD_LOADERS.entrySet()) {
|
||||
try {
|
||||
PlatformMethods.class.getClassLoader().loadClass(entry.getKey());
|
||||
loader.add(entry.getValue());
|
||||
break;
|
||||
} catch (ClassNotFoundException ignored1) {
|
||||
}
|
||||
}
|
||||
if (loader.isEmpty())
|
||||
throw new IllegalStateException("No detected mod loader!");
|
||||
if (loader.size() >= 2)
|
||||
System.err.println("Detected multiple mod loaders! Something is wrong on the classpath! " + String.join(", ", loader));
|
||||
modLoader = loader.get(0);
|
||||
}
|
||||
}
|
||||
return modLoader;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,8 @@ import java.util.jar.JarOutputStream
|
||||
import java.util.jar.Manifest
|
||||
|
||||
open class ArchitectPluginExtension(val project: Project) {
|
||||
var transformerVersion = "2.0.21"
|
||||
var transformerVersion = "2.1.24"
|
||||
var injectablesVersion = "1.0.4"
|
||||
var minecraft = ""
|
||||
var injectInjectables = true
|
||||
private val transforms = mutableMapOf<String, Transform>()
|
||||
@@ -83,11 +84,7 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
}
|
||||
|
||||
private fun getCompileClasspath(): Iterable<File> {
|
||||
if (!transformedLoom) {
|
||||
return project.configurations.getByName("compileClasspath")
|
||||
}
|
||||
|
||||
return project.configurations.getByName("architecturyTransformerClasspath")
|
||||
return project.configurations.findByName("architecturyTransformerClasspath") ?: project.configurations.getByName("compileClasspath")
|
||||
}
|
||||
|
||||
fun transform(name: String, action: Action<Transform>) {
|
||||
@@ -96,9 +93,12 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
project.configurations.create(transform.configName)
|
||||
|
||||
if (!transformedLoom) {
|
||||
project.configurations.create("architecturyTransformerClasspath") {
|
||||
it.extendsFrom(project.configurations.getByName("compileClasspath"))
|
||||
}
|
||||
var plsAddInjectables = false
|
||||
project.configurations.findByName("architecturyTransformerClasspath")
|
||||
?: project.configurations.create("architecturyTransformerClasspath") {
|
||||
it.extendsFrom(project.configurations.getByName("compileClasspath"))
|
||||
plsAddInjectables = true
|
||||
}
|
||||
val architecturyJavaAgents = project.configurations.create("architecturyJavaAgents") {
|
||||
project.configurations.getByName("runtimeOnly").extendsFrom(it)
|
||||
}
|
||||
@@ -107,6 +107,12 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
with(project.dependencies) {
|
||||
add("runtimeOnly", "me.shedaniel:architectury-transformer:$transformerVersion:runtime")
|
||||
add("architecturyJavaAgents", "me.shedaniel:architectury-transformer:$transformerVersion:agent")
|
||||
if (plsAddInjectables && injectInjectables) {
|
||||
add(
|
||||
"architecturyTransformerClasspath",
|
||||
"me.shedaniel:architectury-injectables:$injectablesVersion"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val loom = project.extensions.getByType(LoomGradleExtension::class.java)
|
||||
@@ -184,8 +190,19 @@ open class ArchitectPluginExtension(val project: Project) {
|
||||
fun common(action: Action<CommonSettings>) {
|
||||
val settings = CommonSettings().also { action.execute(it) }
|
||||
if (injectInjectables) {
|
||||
var plsAddInjectables = false
|
||||
project.configurations.findByName("architecturyTransformerClasspath")
|
||||
?: project.configurations.create("architecturyTransformerClasspath") {
|
||||
it.extendsFrom(project.configurations.getByName("compileClasspath"))
|
||||
plsAddInjectables = true
|
||||
}
|
||||
|
||||
with(project.dependencies) {
|
||||
add("compileOnly", "me.shedaniel:architectury-injectables:1.0.4")
|
||||
add("compileOnly", "me.shedaniel:architectury-injectables:$injectablesVersion")
|
||||
|
||||
if (plsAddInjectables) {
|
||||
add("architecturyTransformerClasspath", "me.shedaniel:architectury-injectables:$injectablesVersion")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,18 @@ package me.shedaniel.architect.plugin.transformers
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import me.shedaniel.architectury.transformer.Transform
|
||||
import me.shedaniel.architectury.transformer.input.OutputInterface
|
||||
import me.shedaniel.architectury.transformer.transformers.BuiltinProperties
|
||||
import me.shedaniel.architectury.transformer.transformers.base.AssetEditTransformer
|
||||
import me.shedaniel.architectury.transformer.transformers.base.edit.AssetEditSink
|
||||
import me.shedaniel.architectury.transformer.transformers.base.edit.TransformerContext
|
||||
import me.shedaniel.architectury.transformer.util.Logger
|
||||
import net.fabricmc.loom.LoomGradlePlugin
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
class AddRefmapName : AssetEditTransformer {
|
||||
override fun doEdit(context: TransformerContext, sink: AssetEditSink) {
|
||||
override fun doEdit(context: TransformerContext, output: OutputInterface) {
|
||||
val mixins = mutableSetOf<String>()
|
||||
sink.handle { path, bytes ->
|
||||
output.handle { path, bytes ->
|
||||
// Check JSON file in root directory
|
||||
if (path.endsWith(".json") && !Transform.stripLoadingSlash(path)
|
||||
.contains("/") && !Transform.stripLoadingSlash(path).contains("\\")
|
||||
@@ -41,7 +41,7 @@ class AddRefmapName : AssetEditTransformer {
|
||||
}
|
||||
val refmap = System.getProperty(BuiltinProperties.REFMAP_NAME)
|
||||
mixins.forEach { path ->
|
||||
sink.transformFile(path) {
|
||||
output.modifyFile(path) {
|
||||
val json: JsonObject = LoomGradlePlugin.GSON.fromJson<JsonObject>(
|
||||
ByteArrayInputStream(it).reader(),
|
||||
JsonObject::class.java
|
||||
|
||||
Reference in New Issue
Block a user