use of org.apache.xbean.asm9.ClassReader in project component-runtime by Talend.
the class RepositoryModelBuilderTest method createChainPlugin.
private File createChainPlugin(final File dir, final String plugin) {
final File target = new File(dir, plugin);
try (final JarOutputStream outputStream = new JarOutputStream(new FileOutputStream(target))) {
final String packageName = toPackage(target.getParentFile().getParentFile().getName()).replace(".", "/");
final String sourcePackage = "org/talend/test";
final String fromPack = sourcePackage.replace('/', '.');
final String toPack = packageName.replace('.', '/');
final File root = new File(jarLocation(getClass()), sourcePackage);
ofNullable(root.listFiles()).map(Stream::of).orElseGet(Stream::empty).filter(c -> c.getName().endsWith(".class")).forEach(clazz -> {
try (final InputStream is = new FileInputStream(clazz)) {
final ClassReader reader = new ClassReader(is);
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
reader.accept(new ClassRemapper(writer, new Remapper() {
@Override
public String map(final String key) {
return key.replace(sourcePackage, toPack).replace(fromPack, packageName);
}
}), EXPAND_FRAMES);
outputStream.putNextEntry(new JarEntry(toPack + '/' + clazz.getName()));
outputStream.write(writer.toByteArray());
} catch (final IOException e) {
fail(e.getMessage());
}
});
} catch (final IOException e) {
throw new IllegalStateException(e);
}
return target;
}
use of org.apache.xbean.asm9.ClassReader in project tomee by apache.
the class PersistenceContextAnnFactory method addAnnotations.
public void addAnnotations(final Class c) throws OpenEJBException {
if (!useAsm) {
return;
}
if (processed.contains(c.getName())) {
return;
}
try {
final URL u = c.getResource("/" + c.getName().replace('.', '/') + ".class");
final ClassReader r = new ClassReader(IO.read(u));
r.accept(new PersistenceContextReader(contexts), ClassReader.SKIP_DEBUG);
} catch (final IOException e) {
throw new OpenEJBException("Unable to read class " + c.getName());
}
processed.add(c.getName());
}
use of org.apache.xbean.asm9.ClassReader in project tomee by apache.
the class TempClassLoader method isAnnotationClass.
/**
* Fast-parse the given class bytecode to determine if it is an
* annotation class.
*/
private static boolean isAnnotationClass(final byte[] bytes) {
final IsAnnotationVisitor isAnnotationVisitor = new IsAnnotationVisitor();
final ClassReader classReader = new ClassReader(bytes);
classReader.accept(isAnnotationVisitor, ClassReader.SKIP_DEBUG);
return isAnnotationVisitor.isAnnotation;
}
use of org.apache.xbean.asm9.ClassReader in project tomee by apache.
the class ValidationGenerator method generate.
public byte[] generate() throws ProxyGenerationException {
generatedMethods.clear();
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
final String generatedClassName = getName().replace('.', '/');
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, generatedClassName, null, "java/lang/Object", null);
{
// public constructor
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
generateMethods(cw);
/**
* Read all parent classes and copy the public methods we need
* into our new class.
*/
Class current = clazz;
while (current != null && !current.equals(Object.class)) {
try {
final ClassReader classReader = new ClassReader(DynamicSubclass.readClassFile(current));
classReader.accept(new CopyMethodAnnotations(), ClassReader.SKIP_CODE);
} catch (final IOException e) {
throw new ProxyGenerationException(e);
}
current = current.getSuperclass();
}
return cw.toByteArray();
}
use of org.apache.xbean.asm9.ClassReader in project tomee by apache.
the class AnnotationFinder method readClassDef.
private void readClassDef(String className, final ClassVisitor visitor) {
classes++;
if (!className.endsWith(".class")) {
className = className.replace('.', '/') + ".class";
}
try {
final URL resource = classLoader.getResource(className);
if (resource != null) {
InputStream in = resource.openStream();
in = new BufferedInputStream(in);
try {
final ClassReader classReader = new ClassReader(in);
classReader.accept(visitor, ASM_FLAGS);
} finally {
in.close();
}
} else {
new Exception("Could not load " + className).printStackTrace();
}
} catch (final IOException e) {
e.printStackTrace();
}
}
Aggregations