Skip to content

Commit 46eea14

Browse files
authored
Merge pull request #6 from rhysdh540/master
add helper to get agent vm args
2 parents e523436 + d69023e commit 46eea14

File tree

7 files changed

+41
-26
lines changed

7 files changed

+41
-26
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ jobs:
66
build:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v4
1010

1111
- name: Set up JDK 17
12-
uses: actions/setup-java@v2
12+
uses: actions/setup-java@v4
1313
with:
1414
distribution: 'adopt'
1515
java-version: '17'
@@ -20,7 +20,7 @@ jobs:
2020
- name: Publish
2121
run: ./gradlew publish -Pmvn.user=${{ secrets.MAVEN_USER }} -Pmvn.key=${{ secrets.MAVEN_TOKEN }}
2222

23-
- uses: actions/upload-artifact@v2
23+
- uses: actions/upload-artifact@v4
2424
with:
2525
name: Artifacts
2626
path: ./build/libs/

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pluginManagement {
2424
and then add the plugin to your `build.gradle` file:
2525
```gradle
2626
plugins {
27-
id 'xyz.wagyourtail.unimined.expect-platform' version '1.0.5'
27+
id 'xyz.wagyourtail.unimined.expect-platform' version '1.1.1'
2828
}
2929
```
3030

@@ -68,8 +68,8 @@ tasks.create("PlatformJar", xyz.wagyourtail.unimined.expect.ExpectPlatformJar) {
6868
6969
```
7070

71-
if you need the agent on a runner that isn't implementing JavaExecSpec (i.e. the one in unimined 1.2)
72-
check [the implementation](src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt#L69) for how it actually applies the agent to a JavaExec task.
71+
if you need the agent on a runner that isn't implementing JavaExecSpec (i.e. the one in unimined 1.2), call
72+
`expectPlatform.getAgentArgs(platformName)` to get the args to pass to the jvm.
7373

7474
### Environment
7575

expect-platform-test/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ tasks.register("runAgentA", JavaExec::class) {
122122
mainClass = "xyz.wagyourtail.ept.Main"
123123
group = "ept"
124124

125-
expectPlatform.insertAgent(this, "a", mapOf(
125+
expectPlatform.insertAgent(this,"a", mapOf(
126126
"xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/a/Env",
127127
"xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/a/Env\$EnvType",
128128
"xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType.COMBINED" to "JOINED",
@@ -134,11 +134,11 @@ tasks.register("runAgentB", JavaExec::class) {
134134
mainClass = "xyz.wagyourtail.ept.Main"
135135
group = "ept"
136136

137-
expectPlatform.insertAgent(this, "b", mapOf(
137+
expectPlatform.insertAgent(this,"b", mapOf(
138138
"xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/b/OnlyIn",
139139
"xyz/wagyourtail/unimined/expect/annotation/Environment.value" to "env",
140140
"xyz/wagyourtail/unimined/expect/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/b/OnlyIn\$Type",
141-
))
141+
))
142142
}
143143

144144
tasks.register("runAgentC", JavaExec::class) {
@@ -150,7 +150,7 @@ tasks.register("runAgentC", JavaExec::class) {
150150
"xyz/wagyourtail/unimined/expect/annotation/Environment" to "xyz/wagyourtail/ept/c/Environment",
151151
"xyz/wagyourtail/expect/unimined/annotation/Environment.value" to "type",
152152
"xyz/wagyourtail/expect/unimined/annotation/Environment\$EnvType" to "xyz/wagyourtail/ept/c/Environment\$EnvType",
153-
))
153+
))
154154
}
155155

156156
val jarA by tasks.registering(ExpectPlatformJar::class) {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
kotlin.code.style=official
22

3-
version = 1.1.0
3+
version = 1.1.1
44

55
asmVersion = 9.8

src/agent/java/xyz/wagyourtail/unimined/expect/ExpectPlatformAgent.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,27 @@
88
import java.lang.instrument.Instrumentation;
99
import java.security.ProtectionDomain;
1010

11-
public class ExpectPlatformAgent {
12-
private static final String EXPECT_PLATFORM = "expect.platform";
13-
private static final String REMAP = "expect.remap";
14-
private static final String platform = System.getProperty(EXPECT_PLATFORM);
15-
private static final String remap = System.getProperty(REMAP);
11+
import static xyz.wagyourtail.unimined.expect.TransformPlatform.PROPERTY_PLATFORM;
12+
import static xyz.wagyourtail.unimined.expect.TransformPlatform.PROPERTY_REMAP;
1613

17-
private static final TransformPlatform transformPlatform = new TransformPlatform(platform, remap, false);
1814

19-
public static void premain(String args, Instrumentation inst) {
15+
public class ExpectPlatformAgent {
16+
private static final String platform = System.getProperty(PROPERTY_PLATFORM);
17+
private static final String remap = System.getProperty(PROPERTY_REMAP);
18+
19+
static {
2020
if (platform == null) {
21-
throw new IllegalStateException("-D" + EXPECT_PLATFORM + " not set");
21+
throw new IllegalStateException("-D" + PROPERTY_PLATFORM + " not set");
2222
}
2323

24+
if (remap == null) {
25+
throw new IllegalStateException("-D" + PROPERTY_REMAP + " not set");
26+
}
27+
}
28+
29+
private static final TransformPlatform transformPlatform = new TransformPlatform(platform, remap, false);
30+
31+
public static void premain(String args, Instrumentation inst) {
2432
if(!inst.isRetransformClassesSupported()) {
2533
System.out.println("[ExpectPlatformAgent] ur instrumentation is bad lol");
2634
}

src/main/kotlin/xyz/wagyourtail/unimined/expect/ExpectPlatformExtension.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.gradle.api.artifacts.Configuration
77
import org.gradle.api.attributes.Attribute
88
import org.gradle.process.JavaExecSpec
99
import org.jetbrains.annotations.VisibleForTesting
10+
import xyz.wagyourtail.unimined.expect.TransformPlatform.*
1011
import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformParams
1112
import xyz.wagyourtail.unimined.expect.transform.ExpectPlatformTransform
1213
import xyz.wagyourtail.unimined.expect.utils.FinalizeOnRead
@@ -18,7 +19,7 @@ val Project.expectPlatform: ExpectPlatformExtension
1819
abstract class ExpectPlatformExtension(val project: Project) {
1920

2021
@set:VisibleForTesting
21-
var version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.0.0-SNAPSHOT"
22+
var version = ExpectPlatformExtension::class.java.`package`.implementationVersion ?: "1.1.0-SNAPSHOT"
2223

2324
val annotationsDep by lazy { "xyz.wagyourtail.unimined.expect-platform:expect-platform-annotations:$version" }
2425
val agentDep by lazy { "xyz.wagyourtail.unimined.expect-platform:expect-platform-agent:$version:all" }
@@ -75,10 +76,15 @@ abstract class ExpectPlatformExtension(val project: Project) {
7576

7677
@JvmOverloads
7778
fun insertAgent(spec: JavaExecSpec, platformName: String, remap: Map<String, String> = emptyMap()) {
78-
spec.jvmArgs(
79+
spec.jvmArgs(getAgentArgs(platformName, remap))
80+
}
81+
82+
@JvmOverloads
83+
fun getAgentArgs(platformName: String, remap: Map<String, String> = emptyMap()): List<String> {
84+
return listOf(
7985
"-javaagent:${agentJar.absolutePath}",
80-
"-Dexpect.platform=${platformName}",
81-
"-Dexpect.remap=${TransformPlatform.mapToString(remap)}"
86+
"-D${PROPERTY_PLATFORM}=${platformName}",
87+
"-D${PROPERTY_REMAP}=${mapToString(remap)}"
8288
)
8389
}
8490

@@ -87,8 +93,6 @@ abstract class ExpectPlatformExtension(val project: Project) {
8793
config.resolve().first { it.extension == "jar" }
8894
}
8995

90-
operator fun invoke(action: ExpectPlatformExtension.() -> Unit) {
91-
action(this)
92-
}
96+
operator fun invoke(action: ExpectPlatformExtension.() -> Unit) = action(this)
9397

9498
}

src/shared/java/xyz/wagyourtail/unimined/expect/TransformPlatform.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
public class TransformPlatform {
1818
private static final int EXPECT_PLATFORM_ACCESS = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
1919

20+
public static final String PROPERTY_PLATFORM = "expect.platform";
21+
public static final String PROPERTY_REMAP = "expect.remap";
22+
2023
private static final String EXPECT_PLATFORM_DESC = "Lxyz/wagyourtail/unimined/expect/annotation/ExpectPlatform;";
2124
private static final String EXPECT_PLATFORM_TRANSFORMED_DESC = "Lxyz/wagyourtail/unimined/expect/annotation/ExpectPlatform$Transformed";
2225
private static final String PLATFORM_ONLY_DESC = "Lxyz/wagyourtail/unimined/expect/annotation/PlatformOnly;";

0 commit comments

Comments
 (0)