Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/integration-tests-base-groovy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
<name>Apache BookKeeper :: Tests :: Base module for Arquillian based integration tests using groovy</name>

<properties>
<groovy.version>2.4.13</groovy.version>
<groovy-eclipse-compiler.version>2.9.2-04</groovy-eclipse-compiler.version>
<groovy-eclipse-batch.version>2.4.13-02</groovy-eclipse-batch.version>
</properties>
Expand Down
6 changes: 6 additions & 0 deletions tests/integration-tests-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@
<version>${arquillian-cube.version}</version>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>${groovy.version}</version>
</dependency>

</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

import com.google.common.collect.Lists;

import groovy.lang.Closure;

import java.io.File;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
Expand Down Expand Up @@ -135,14 +139,25 @@ public Object callStaticMethod(String className, String methodName, ArrayList<?>
}
}

public Object createCallback(String interfaceName, Object closure) throws Exception {
public Object createCallback(String interfaceName, Closure closure) throws Exception {
final Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class.getDeclaredConstructor(
Class.class, int.class);
constructor.setAccessible(true);
return Proxy.newProxyInstance(classloader,
new Class<?>[]{ Class.forName(interfaceName, true, classloader) },
new InvocationHandler() {

@Override
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
Method call = closure.getClass().getMethod("call", Object[].class);
return call.invoke(closure, (Object)args);
if (args.length == closure.getMaximumNumberOfParameters()) {
return closure.call(args);
} else {
final Class<?> declaringClass = m.getDeclaringClass();
return constructor.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE)
.unreflectSpecial(m, declaringClass)
.bindTo(proxy)
.invokeWithArguments(args);
}
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<groupId>org.apache.bookkeeper.tests</groupId>
<artifactId>tests-parent</artifactId>
<name>Apache BookKeeper :: Tests</name>

<properties>
<groovy.version>2.4.13</groovy.version>
</properties>

<modules>
<module>shaded</module>
<module>docker-images</module>
Expand Down