From cf0d2099125cdae7540ec68309c656e28be18c31 Mon Sep 17 00:00:00 2001
From: Rhys <98863820+rhysdh540@users.noreply.github.com>
Date: Sun, 14 Jul 2024 11:14:25 -0400
Subject: [PATCH 1/3] publish annotations sources, strengthen annotation
parsing
---
.gitignore | 1 +
ExpectPlatform.iml | 6 -----
build.gradle.kts | 15 ++++++++---
gradle.properties | 2 +-
.../unimined/expect/TransformPlatform.java | 27 ++++++++++++++-----
5 files changed, 34 insertions(+), 17 deletions(-)
delete mode 100644 ExpectPlatform.iml
diff --git a/.gitignore b/.gitignore
index 5df3627..1dc6bbd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ build/
### IntelliJ IDEA ###
.idea/
out/
+*.iml
!**/src/main/**/out/
!**/src/test/**/out/
diff --git a/ExpectPlatform.iml b/ExpectPlatform.iml
deleted file mode 100644
index 9e3449c..0000000
--- a/ExpectPlatform.iml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 46d5aad..d450a5e 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,3 +1,5 @@
+@file:Suppress("HasPlatformType")
+
import xyz.wagyourtail.gradle.shadow.ShadowJar
import java.net.URI
@@ -14,7 +16,7 @@ base {
archivesName.set("expect-platform")
}
-val annotations by sourceSets.creating {}
+val annotations by sourceSets.creating
val shared by sourceSets.creating {
compileClasspath += sourceSets.main.get().compileClasspath
@@ -97,6 +99,12 @@ val annotationJar = tasks.register("annotationJar") {
}
}
+val annotationSources = tasks.register("annotationSources") {
+ archiveBaseName.set("expect-platform-annotations-sources")
+ archiveClassifier.set("sources")
+ from(annotations.allSource)
+}
+
val agentShadeJar = tasks.register("agentShadowJar") {
archiveBaseName.set("expect-platform-agent")
@@ -157,7 +165,7 @@ publishing {
artifactId = "expect-platform-agent"
version = project.version.toString()
- artifact(agentShadeJar) {}
+ artifact(agentShadeJar)
}
create("annotations") {
@@ -165,7 +173,8 @@ publishing {
artifactId = "expect-platform-annotations"
version = project.version.toString()
- artifact(annotationJar) {}
+ artifact(annotationJar)
+ artifact(annotationSources)
}
}
}
diff --git a/gradle.properties b/gradle.properties
index 0f003c1..a6f0cec 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,5 +1,5 @@
kotlin.code.style=official
-version = 1.0.3
+version = 1.0.4
asmVersion=9.7
diff --git a/src/shared/java/xyz/wagyourtail/unimined/expect/TransformPlatform.java b/src/shared/java/xyz/wagyourtail/unimined/expect/TransformPlatform.java
index d6ebe62..b24fc52 100644
--- a/src/shared/java/xyz/wagyourtail/unimined/expect/TransformPlatform.java
+++ b/src/shared/java/xyz/wagyourtail/unimined/expect/TransformPlatform.java
@@ -15,6 +15,8 @@
import java.util.stream.Stream;
public class TransformPlatform {
+ private static final int EXPECT_PLATFORM_ACCESS = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
+
private final String platformName;
private final Map remap = new HashMap<>();
@@ -95,14 +97,15 @@ public ClassNode transform(ClassNode classNode) {
}
private void expectPlatform(MethodNode methodNode, ClassNode classNode, AnnotationNode annotationNode) {
- if (((methodNode.access & Opcodes.ACC_PUBLIC) == 0) || ((methodNode.access & Opcodes.ACC_STATIC) == 0)) {
+ if ((methodNode.access & EXPECT_PLATFORM_ACCESS) != EXPECT_PLATFORM_ACCESS) {
throw new RuntimeException("ExpectPlatform methods must be public and static");
}
String platformClass = null;
- if (annotationNode.values != null) {
- for (AnnotationNode platform : (List) annotationNode.values.get(1)) {
+ List platforms = getAnnotationValue(annotationNode, "platforms");
+ if (platforms != null) {
+ for (AnnotationNode platform : platforms) {
String name = null;
String target = null;
for (int i = 0; i < platform.values.size(); i += 2) {
@@ -114,8 +117,7 @@ private void expectPlatform(MethodNode methodNode, ClassNode classNode, Annotati
target = (String) value;
}
}
- assert name != null;
- if (name.equals(platformName)) {
+ if (platformName.equals(name) && target != null) {
platformClass = target;
break;
}
@@ -163,9 +165,9 @@ private void expectPlatform(MethodNode methodNode, ClassNode classNode, Annotati
}
private void platformOnly(MethodNode methodNode, ClassNode classNode, AnnotationNode annotationNode) {
- List platforms = (List) annotationNode.values.get(1);
+ List platforms = getAnnotationValue(annotationNode, "value");
- if (!platforms.contains(platformName)) {
+ if (platforms != null && !platforms.contains(platformName)) {
classNode.methods.remove(methodNode);
}
}
@@ -208,4 +210,15 @@ public static String mapToString(Map map) {
return sb.toString();
}
+ @SuppressWarnings("unchecked")
+ private T getAnnotationValue(AnnotationNode annotation, String key) {
+ if(annotation.values == null) return null;
+ for (int i = 0; i < annotation.values.size(); i += 2) {
+ if (annotation.values.get(i).equals(key)) {
+ return (T) annotation.values.get(i + 1);
+ }
+ }
+ return null;
+ }
+
}
From 604b0d83c0b8124d783321367908a76f6c26e53c Mon Sep 17 00:00:00 2001
From: Rhys <98863820+rhysdh540@users.noreply.github.com>
Date: Sun, 14 Jul 2024 11:15:27 -0400
Subject: [PATCH 2/3] silly
---
build.gradle.kts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index d450a5e..8e5eb61 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -100,7 +100,7 @@ val annotationJar = tasks.register("annotationJar") {
}
val annotationSources = tasks.register("annotationSources") {
- archiveBaseName.set("expect-platform-annotations-sources")
+ archiveBaseName.set("expect-platform-annotations")
archiveClassifier.set("sources")
from(annotations.allSource)
}
From 81121d5fc233e1c12840d3652f56626ce9d4d574 Mon Sep 17 00:00:00 2001
From: Rhys <98863820+rhysdh540@users.noreply.github.com>
Date: Sun, 14 Jul 2024 11:34:18 -0400
Subject: [PATCH 3/3] update readme too
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 9b59bdb..b041bb3 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ pluginManagement {
and then add the plugin to your `build.gradle` file:
```gradle
plugins {
- id 'xyz.wagyourtail.unimined.expect-platform' version '1.0.3'
+ id 'xyz.wagyourtail.unimined.expect-platform' version '1.0.4'
}
```
@@ -68,7 +68,7 @@ tasks.create("PlatformJar", xyz.wagyourtail.unimined.expect.ExpectPlatformJar) {
```
-if you need the agent on a runner that isn't implementing JavaExecSpec (ie, the one in unimined)
+if you need the agent on a runner that isn't implementing JavaExecSpec (i.e. the one in unimined 1.2)
check [the implementation](src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt#L69) for how it actually applies the agent to a JavaExec task.
### Environment