[testng] 261/355: Remove unnecessary reflection.

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:13 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.

commit ee7e8f613420c03ec2290a720214cef65211212c
Author: Cedric Beust <cedric at beust.com>
Date:   Sun May 3 19:42:08 2015 -0700

    Remove unnecessary reflection.
---
 src/main/java/org/testng/TestNG.java | 37 ++++++------------------------------
 1 file changed, 6 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/testng/TestNG.java b/src/main/java/org/testng/TestNG.java
index b84d81a..8f6ca1d 100644
--- a/src/main/java/org/testng/TestNG.java
+++ b/src/main/java/org/testng/TestNG.java
@@ -1,15 +1,9 @@
 package org.testng;
 
-import static org.testng.internal.Utils.defaultIfStringEmpty;
-import static org.testng.internal.Utils.isStringEmpty;
-import static org.testng.internal.Utils.isStringNotEmpty;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -17,6 +11,7 @@ import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Map;
+import java.util.ServiceLoader;
 import java.util.Set;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -67,6 +62,10 @@ import org.xml.sax.SAXException;
 import com.beust.jcommander.JCommander;
 import com.beust.jcommander.ParameterException;
 
+import static org.testng.internal.Utils.defaultIfStringEmpty;
+import static org.testng.internal.Utils.isStringEmpty;
+import static org.testng.internal.Utils.isStringNotEmpty;
+
 /**
  * This class is the main entry point for running tests in the TestNG framework.
  * Users can create their own TestNG object and invoke it in many different
@@ -941,37 +940,13 @@ public class TestNG {
    * Using reflection to remain Java 5 compliant.
    */
   private void addServiceLoaderListeners() {
-    try {
-      Class c = Class.forName("java.util.ServiceLoader");
-      List<Object> parameters = Lists.newArrayList();
-      parameters.add(ITestNGListener.class);
-      Method loadMethod;
-      if (m_serviceLoaderClassLoader != null) {
-        parameters.add(m_serviceLoaderClassLoader);
-        loadMethod = c.getMethod("load", Class.class, ClassLoader.class);
-      } else {
-        loadMethod = c.getMethod("load", Class.class);
-      }
       Iterable<ITestNGListener> loader =
-          (Iterable<ITestNGListener>) loadMethod.invoke(c, parameters.toArray());
-//      Object loader = c.
-//      ServiceLoader<ITestNGListener> loader = m_serviceLoaderClassLoader != null
-//      ? ServiceLoader.load(ITestNGListener.class, m_serviceLoaderClassLoader)
-//          : ServiceLoader.load(ITestNGListener.class);
+          ServiceLoader.load(ITestNGListener.class, m_serviceLoaderClassLoader);
       for (ITestNGListener l : loader) {
         Utils.log("[TestNG]", 2, "Adding ServiceLoader listener:" + l);
         addListener(l);
         addServiceLoaderListener(l);
       }
-    } catch (ClassNotFoundException ex) {
-      // Ignore
-    } catch(NoSuchMethodException ex) {
-      // Ignore
-    } catch(IllegalAccessException ex) {
-      // Ignore
-    } catch(InvocationTargetException ex) {
-      // Ignore
-    }
   }
 
   /**

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list