You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/02/20 17:08:05 UTC

[GitHub] ivankelly closed pull request #1187: Allow default methods in MavenClassloader callbacks

ivankelly closed pull request #1187: Allow default methods in MavenClassloader callbacks
URL: https://github.com/apache/bookkeeper/pull/1187
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/tests/integration-tests-base-groovy/pom.xml b/tests/integration-tests-base-groovy/pom.xml
index 9bf71b081..738e81368 100644
--- a/tests/integration-tests-base-groovy/pom.xml
+++ b/tests/integration-tests-base-groovy/pom.xml
@@ -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>
diff --git a/tests/integration-tests-utils/pom.xml b/tests/integration-tests-utils/pom.xml
index 35fb4c821..811efe243 100644
--- a/tests/integration-tests-utils/pom.xml
+++ b/tests/integration-tests-utils/pom.xml
@@ -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>
diff --git a/tests/integration-tests-utils/src/main/java/org/apache/bookkeeper/tests/MavenClassLoader.java b/tests/integration-tests-utils/src/main/java/org/apache/bookkeeper/tests/MavenClassLoader.java
index d25dbc2ff..2c3bb30d8 100644
--- a/tests/integration-tests-utils/src/main/java/org/apache/bookkeeper/tests/MavenClassLoader.java
+++ b/tests/integration-tests-utils/src/main/java/org/apache/bookkeeper/tests/MavenClassLoader.java
@@ -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;
@@ -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);
+                                              }
                                           }
                                       });
     }
diff --git a/tests/pom.xml b/tests/pom.xml
index fa8484cfa..db0d46e4f 100644
--- a/tests/pom.xml
+++ b/tests/pom.xml
@@ -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>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services