From d4465ce33b0cfd9728c455416aab3b7bcf618496 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 14 Jul 2022 13:37:11 -0400 Subject: [PATCH] Update to Gradle 7.5 (#3594) Signed-off-by: Andriy Redko --- .../StandaloneRestIntegTestTask.java | 25 ++++++++++++++++++- gradle/wrapper/gradle-wrapper.properties | 4 +-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/testclusters/StandaloneRestIntegTestTask.java b/buildSrc/src/main/java/org/opensearch/gradle/testclusters/StandaloneRestIntegTestTask.java index bf17daa6e2e6f..abf5f3c1db198 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/testclusters/StandaloneRestIntegTestTask.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/testclusters/StandaloneRestIntegTestTask.java @@ -32,6 +32,7 @@ package org.opensearch.gradle.testclusters; import groovy.lang.Closure; + import org.opensearch.gradle.FileSystemOperationsAware; import org.opensearch.gradle.test.Fixture; import org.opensearch.gradle.util.GradleUtils; @@ -46,6 +47,8 @@ import org.gradle.internal.resources.ResourceLock; import org.gradle.internal.resources.SharedResource; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -124,12 +127,32 @@ public List getSharedResources() { int nodeCount = clusters.stream().mapToInt(cluster -> cluster.getNodes().size()).sum(); if (nodeCount > 0) { - locks.add(resource.getResourceLock(Math.min(nodeCount, resource.getMaxUsages()))); + locks.add(getResourceLock(resource, Math.min(nodeCount, resource.getMaxUsages()))); } return Collections.unmodifiableList(locks); } + private ResourceLock getResourceLock(SharedResource resource, int nUsages) { + try { + try { + // The getResourceLock(int) is used by Gradle pre-7.5 + return (ResourceLock) MethodHandles.publicLookup() + .findVirtual(SharedResource.class, "getResourceLock", MethodType.methodType(ResourceLock.class, int.class)) + .bindTo(resource) + .invokeExact(nUsages); + } catch (NoSuchMethodException | IllegalAccessException ex) { + // The getResourceLock() is used by Gradle post-7.4 + return (ResourceLock) MethodHandles.publicLookup() + .findVirtual(SharedResource.class, "getResourceLock", MethodType.methodType(ResourceLock.class)) + .bindTo(resource) + .invokeExact(); + } + } catch (Throwable ex) { + throw new IllegalStateException("Unable to find suitable ResourceLock::getResourceLock", ex); + } + } + @Override public Task dependsOn(Object... dependencies) { super.dependsOn(dependencies); diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a8e09684f1fd3..24c164f0f1e12 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -11,7 +11,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=e6d864e3b5bc05cc62041842b306383fc1fefcec359e70cebb1d470a6094ca82 +distributionSha256Sum=97a52d145762adc241bad7fd18289bf7f6801e08ece6badf80402fe2b9f250b1