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:09:51 UTC

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

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

 ##########
 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:
   I never used such kind of code for coercions. Do you this it is needed?
   I will look into my code and send some pointer

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