if (archive == null) {
throw new IllegalStateException("Archive with ID " + archiveId + " is not deployed");
}
// Use a ClassLoader with explicitly null parent to achieve isolation from --classpath
final ShrinkWrapClassLoader isolatedArchiveCL = new ShrinkWrapClassLoader((ClassLoader) null, archive);
final ClassLoader oldCl = SecurityActions.getTccl();
ObjectOutputStream objectOutstream = null;
try {
// We have to set the TCCL here due to ARQ-1181; if that's resolved we can remove all TCCL mucking
SecurityActions.setTccl(isolatedArchiveCL);
/*
* All reflection in this section is to avoid CCE when we load these classes from the isolated ClassLoader,
* we can't have them assignable to the ClassLoader which loaded this class.
*/
final Class<?> testClass;
try {
testClass = isolatedArchiveCL.loadClass(testClassName);
} catch (final ClassNotFoundException cnfe) {
throw new IllegalStateException("Could not load class " + testClassName + " from deployed archive: "
+ archive.toString());
}
final Class<?> testRunnersClass;
try {
testRunnersClass = isolatedArchiveCL.loadClass(CLASS_NAME_ARQ_TEST_RUNNERS);
} catch (final ClassNotFoundException cnfe) {
throw new IllegalStateException("Could not load class " + CLASS_NAME_ARQ_TEST_RUNNERS
+ " from deployed archive: " + archive.toString());
}
final Method getTestRunnerMethod = testRunnersClass.getMethod(METHOD_NAME_GET_TEST_RUNNER,
ClassLoader.class);
final Object testRunner = getTestRunnerMethod.invoke(null, isolatedArchiveCL);
final Class<?> testRunnerClass = testRunner.getClass();
final Method executeMethod = testRunnerClass.getMethod(METHOD_NAME_EXECUTE, Class.class, String.class);
final Serializable testResult = (Serializable) executeMethod.invoke(testRunner, testClass, methodName);
return testResult;
} catch (final IllegalAccessException iae) {
throw new RuntimeException(iae);
} catch (final InvocationTargetException ite) {
throw new RuntimeException(ite);
} catch (final NoSuchMethodException nsme) {
throw new RuntimeException(nsme);
} finally {
SecurityActions.setTccl(oldCl);
try {
isolatedArchiveCL.close();
} catch (final IOException ignore) {
}
if (objectOutstream != null) {
try {
objectOutstream.close();