static Class<?> loadClass(String className) { try { return Class.forName(className, true, getThreadContextClassLoader()); } catch (ClassNotFoundException e) { try { return Class.forName(className, true, SecurityActions.class.getClassLoader()); } catch (ClassNotFoundException e2) { throw new RuntimeException("Could not load class " + className, e2); } } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }
static boolean isClassPresent(String name) { try { loadClass(name); return true; } catch (Exception e) { return false; } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
Constructor<T> constructor = getConstructor(implClass, argumentTypes); if (!constructor.isAccessible()) { constructor.setAccessible(true);
static boolean isClassPresent(String name) { try { loadClass(name); return true; } catch (Exception e) { return false; } }
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType, ClassLoader classLoader) { Class<?> clazz = null; try { clazz = Class.forName(className, false, classLoader); } catch (Exception e) { throw new RuntimeException("Could not load class " + className, e); } Object obj = newInstance(clazz, argumentTypes, arguments); try { return expectedType.cast(obj); } catch (Exception e) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType, e); } }
Constructor<T> constructor = getConstructor(implClass, argumentTypes); if (!constructor.isAccessible()) { constructor.setAccessible(true);
static <T> T newInstance(final String className, final Class<?>[] argumentTypes, final Object[] arguments, final Class<T> expectedType) { @SuppressWarnings("unchecked") Class<T> implClass = (Class<T>) loadClass(className); if (!expectedType.isAssignableFrom(implClass)) { throw new RuntimeException("Loaded class " + className + " is not of expected type " + expectedType); } return newInstance(implClass, argumentTypes, arguments); }
static Class<?> loadClass(String className) { try { return Class.forName(className, true, getThreadContextClassLoader()); } catch (ClassNotFoundException e) { try { return Class.forName(className, true, SecurityActions.class.getClassLoader()); } catch (ClassNotFoundException e2) { throw new RuntimeException("Could not load class " + className, e2); } } }
/** * Dynamically loads an instance of a test runner. * * @return A Initialized TestRunner * * @throws IllegalStateException * if multiple TestRunners found in classpath. */ public static TestRunner getTestRunner() { return getTestRunner(SecurityActions.getThreadContextClassLoader()); }
/** * Dynamically loads an instance of a test runner. * * @return A Initialized TestRunner * * @throws IllegalStateException * if multiple TestRunners found in classpath. */ public static TestRunner getTestRunner() { return getTestRunner(SecurityActions.getThreadContextClassLoader()); }