Skip to content

Commit

Permalink
Update to Gradle 7.5 (#3594)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
(cherry picked from commit d4465ce)
  • Loading branch information
reta authored and github-actions[bot] committed Jul 14, 2022
1 parent 60379e5 commit bfe3d88
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -124,12 +127,32 @@ public List<ResourceLock> 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);
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bfe3d88

Please sign in to comment.