From 59edc1f09dd8f46ac2a350a2468748dac4af5760 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 26 Feb 2021 01:44:37 +0800 Subject: [PATCH] Update transformer to 2.1.24 --- build.gradle | 18 ------ gradle.properties | 2 +- .../callsite/PlatformExpectedError.java | 22 ------- .../plugin/callsite/PlatformMethods.java | 64 ------------------- .../plugin/ArchitectPluginExtension.kt | 37 ++++++++--- .../plugin/transformers/AddRefmapName.kt | 8 +-- 6 files changed, 32 insertions(+), 119 deletions(-) delete mode 100644 src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformExpectedError.java delete mode 100644 src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformMethods.java diff --git a/build.gradle b/build.gradle index 500217f..4e8189d 100644 --- a/build.gradle +++ b/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" diff --git a/gradle.properties b/gradle.properties index 3853aa9..3f4c37d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 \ No newline at end of file diff --git a/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformExpectedError.java b/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformExpectedError.java deleted file mode 100644 index 2622593..0000000 --- a/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformExpectedError.java +++ /dev/null @@ -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); - } -} diff --git a/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformMethods.java b/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformMethods.java deleted file mode 100644 index 78f7053..0000000 --- a/src/annotationsInject/java/me/shedaniel/architect/plugin/callsite/PlatformMethods.java +++ /dev/null @@ -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 loader = new ArrayList<>(); - HashMap MOD_LOADERS = new HashMap<>(); - MOD_LOADERS.put("net.fabricmc.loader.FabricLoader", "fabric"); - MOD_LOADERS.put("net.minecraftforge.fml.common.Mod", "forge"); - for (Map.Entry 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; - } -} diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/ArchitectPluginExtension.kt b/src/main/kotlin/me/shedaniel/architect/plugin/ArchitectPluginExtension.kt index b7d7018..ec86bdc 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/ArchitectPluginExtension.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/ArchitectPluginExtension.kt @@ -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() @@ -83,11 +84,7 @@ open class ArchitectPluginExtension(val project: Project) { } private fun getCompileClasspath(): Iterable { - 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) { @@ -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) { 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") + } } } diff --git a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/AddRefmapName.kt b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/AddRefmapName.kt index 2df745e..a9cef8f 100644 --- a/src/main/kotlin/me/shedaniel/architect/plugin/transformers/AddRefmapName.kt +++ b/src/main/kotlin/me/shedaniel/architect/plugin/transformers/AddRefmapName.kt @@ -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() - 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( ByteArrayInputStream(it).reader(), JsonObject::class.java