use of org.talend.sdk.component.classloader.ConfigurableClassLoader in project component-runtime by Talend.
the class BeamIOTransformer method transform.
@Override
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) {
if (className == null || !ConfigurableClassLoader.class.isInstance(loader)) {
return classfileBuffer;
}
final ConfigurableClassLoader classLoader = ConfigurableClassLoader.class.cast(loader);
final URLClassLoader tmpLoader = classLoader.createTemporaryCopy();
final Thread thread = Thread.currentThread();
final ClassLoader old = thread.getContextClassLoader();
thread.setContextClassLoader(tmpLoader);
try {
if (shouldForceContextualSerialization(tmpLoader, className)) {
return rewrite(classLoader, className, classfileBuffer, tmpLoader);
}
} finally {
thread.setContextClassLoader(old);
}
return classfileBuffer;
}
use of org.talend.sdk.component.classloader.ConfigurableClassLoader in project component-runtime by Talend.
the class NestedJarArchiveTest method xbeanNestedScanning.
@Test
void xbeanNestedScanning(final TestInfo info, final TemporaryFolder temporaryFolder) throws IOException {
final File jar = createPlugin(temporaryFolder.getRoot(), info.getTestMethod().get().getName());
final ConfigurableClassLoader configurableClassLoader = new ConfigurableClassLoader("", new URL[0], new URLClassLoader(new URL[] { jar.toURI().toURL() }, Thread.currentThread().getContextClassLoader()), n -> true, n -> true, new String[] { "com/foo/bar/1.0/bar-1.0.jar" });
try (final JarInputStream jis = new JarInputStream(configurableClassLoader.getResourceAsStream("MAVEN-INF/repository/com/foo/bar/1.0/bar-1.0.jar"))) {
assertNotNull(jis, "test is wrongly setup, no nested jar, fix the createPlugin() method please");
final AnnotationFinder finder = new AnnotationFinder(new NestedJarArchive(jis, configurableClassLoader));
final List<Class<?>> annotatedClasses = finder.findAnnotatedClasses(Processor.class);
assertEquals(1, annotatedClasses.size());
assertEquals("org.talend.test.generated." + info.getTestMethod().get().getName() + ".Components", annotatedClasses.iterator().next().getName());
} finally {
URLClassLoader.class.cast(configurableClassLoader.getParent()).close();
}
}
Aggregations