use of com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader in project pinpoint by naver.
the class JarProfilerPluginClassInjectorTest method createContextTypeMatchClassLoader.
private ClassLoader createContextTypeMatchClassLoader(URL[] urlArray) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, java.lang.reflect.InvocationTargetException {
final ClassLoader classLoader = this.getClass().getClassLoader();
final Class<ClassLoader> aClass = (Class<ClassLoader>) classLoader.loadClass(CONTEXT_TYPE_MATCH_CLASS_LOADER);
final Constructor<ClassLoader> constructor = aClass.getConstructor(ClassLoader.class);
ReflectionUtils.makeAccessible(constructor);
final LibClass libClassFilter = new LibClass() {
@Override
public boolean onLoadClass(String clazzName) {
if (clazzName.startsWith(LOG4_IMPL)) {
logger.debug("Loading {}", clazzName);
return ON_LOAD_CLASS;
}
return DELEGATE_PARENT;
}
};
PinpointURLClassLoader testClassLoader = new PinpointURLClassLoader(urlArray, ClassLoader.getSystemClassLoader(), libClassFilter);
final ClassLoader contextTypeMatchClassLoader = constructor.newInstance(testClassLoader);
logger.debug("cl:{}", contextTypeMatchClassLoader);
return contextTypeMatchClassLoader;
}
use of com.navercorp.pinpoint.bootstrap.PinpointURLClassLoader in project pinpoint by naver.
the class PinpointURLClassLoaderTest method testOnLoadClass.
@Test
public void testOnLoadClass() throws Exception {
PinpointURLClassLoader cl = new PinpointURLClassLoader(new URL[] {}, Thread.currentThread().getContextClassLoader());
try {
cl.loadClass("test");
Assert.fail();
} catch (ClassNotFoundException ignored) {
}
// try {
// cl.loadClass("com.navercorp.pinpoint.profiler.DefaultAgent");
// } catch (ClassNotFoundException e) {
//
// }
// should be able to test using the above code, but it is not possible from bootstrap testcase.
// it could be possible by specifying the full path to the URL classloader, but it would be harder to maintain.
// for now, just test if DefaultAgent is specified to be loaded
Assert.assertTrue(cl.onLoadClass("com.navercorp.pinpoint.profiler.DefaultAgent"));
}
Aggregations