Skip to content

Commit

Permalink
Update to ASM 9.7.1 (#1188)
Browse files Browse the repository at this point in the history
* Update to ASM 9.7.1

* Fix Gradle 8.12 nightlies
  • Loading branch information
modmuss50 authored Oct 10, 2024
1 parent c6e4025 commit ca9ed47
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.9.24"
asm = "9.6"
asm = "9.7.1"
commons-io = "2.15.1"
gson = "2.10.1"
guava = "33.0.0-jre"
Expand Down
2 changes: 1 addition & 1 deletion gradle/test.libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mockito = "5.13.0"
java-debug = "0.52.0"
mixin = "0.15.3+mixin.0.8.7"

gradle-nightly = "8.11-20240926001708+0000"
gradle-nightly = "8.12-20241009055624+0000"
fabric-loader = "0.16.5"
fabric-installer = "1.0.1"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.gradle.api.Transformer;
import org.gradle.process.internal.JvmOptions;
import org.gradle.workers.internal.DaemonForkOptions;
import org.gradle.workers.internal.WorkerDaemonClientsManager;

Expand All @@ -45,7 +46,7 @@ public static boolean stopIdleJVM(WorkerDaemonClientsManager manager, String jvm
Transformer<List<Object>, List<Object>> transformer = workerDaemonClients -> {
for (Object /* WorkerDaemonClient */ client : workerDaemonClients) {
DaemonForkOptions forkOptions = getForkOptions(client);
Map<String, Object> systemProperties = forkOptions.getJavaForkOptions().getSystemProperties();
Map<String, Object> systemProperties = getSystemProperties(forkOptions);

if (systemProperties == null || !jvmMarkerValue.equals(systemProperties.get(MARKER_PROP))) {
// Not the JVM we are looking for
Expand All @@ -70,6 +71,30 @@ public static boolean stopIdleJVM(WorkerDaemonClientsManager manager, String jvm
return stopped.get();
}

private static Map<String, Object> getSystemProperties(DaemonForkOptions forkOptions) {
try {
Method getJavaForkOptionsMethod = forkOptions.getClass().getDeclaredMethod("getJavaForkOptions");
getJavaForkOptionsMethod.setAccessible(true);
Object /* JavaForkOptions */ javaForkOptions = getJavaForkOptionsMethod.invoke(forkOptions);
Method getSystemPropertiesMethod = javaForkOptions.getClass().getDeclaredMethod("getSystemProperties");
getSystemPropertiesMethod.setAccessible(true);
//noinspection unchecked
return (Map<String, Object>) getSystemPropertiesMethod.invoke(javaForkOptions);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
// Gradle 8.11 and below
}

// Gradle 8.12+
try {
Method getJvmOptions = forkOptions.getClass().getDeclaredMethod("getJvmOptions");
getJvmOptions.setAccessible(true);
JvmOptions jvmOptions = (JvmOptions) getJvmOptions.invoke(forkOptions);
return jvmOptions.getMutableSystemProperties();
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException("Failed to daemon system properties", e);
}
}

private static DaemonForkOptions getForkOptions(Object /* WorkerDaemonClient */ client) {
try {
Method getForkOptionsMethod = client.getClass().getDeclaredMethod("getForkOptions");
Expand Down

0 comments on commit ca9ed47

Please sign in to comment.