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/16 10:12:13 UTC

[GitHub] ivankelly commented on a change in pull request #1156: Call static methods and build callbacks in MavenClassLoader

ivankelly commented on a change in pull request #1156: Call static methods and build callbacks in MavenClassLoader
URL: https://github.com/apache/bookkeeper/pull/1156#discussion_r168717152
 
 

 ##########
 File path: tests/integration-tests-utils/src/main/java/org/apache/bookkeeper/tests/MavenClassLoader.java
 ##########
 @@ -102,6 +106,47 @@ public static MavenClassLoader forBookKeeperVersion(String version) throws Excep
         return forArtifact("org.apache.bookkeeper:bookkeeper-server:" +  version);
     }
 
+    public Object getClass(String className) throws Exception {
+        return Class.forName(className, true, classloader);
+    }
+
+    public Object callStaticMethod(String className, String methodName, ArrayList<?> args) throws Exception {
+        Class<?> klass = Class.forName(className, true, classloader);
+
+        try {
+            Class<?>[] paramTypes = args.stream().map((a)-> a.getClass()).toArray(Class[]::new);
+            return klass.getMethod(methodName, paramTypes).invoke(null, args.stream().toArray(Object[]::new));
+        } catch (NoSuchMethodException nsme) {
+            // maybe the params are primitives
+            Class<?>[] paramTypes = args.stream().map((a) -> {
 
 Review comment:
   It is. int.class is different to Integer.class, so without this, it won't find the method. I hit it when trying to find the static constructor for BKException. Groovy passed in an Integer as the argument. The method itself takes an int.

----------------------------------------------------------------
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