use of org.apache.xbean.asm6.Opcodes.RETURN in project geronimo-xbean by apache.
the class XbeanAsmParameterNameLoader method createClassReader.
private static ClassReader createClassReader(Class declaringClass) throws IOException {
InputStream in = null;
try {
ClassLoader classLoader = declaringClass.getClassLoader();
in = classLoader.getResourceAsStream(declaringClass.getName().replace('.', '/') + ".class");
ClassReader reader = new ClassReader(in);
return reader;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
}
}
}
}
use of org.apache.xbean.asm6.Opcodes.RETURN in project component-runtime by Talend.
the class PluginGenerator method createChainPlugin.
public 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.asm6.Opcodes.RETURN in project component-runtime by Talend.
the class PluginGenerator method createChainPlugin.
public 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.asm6.Opcodes.RETURN in project component-runtime by Talend.
the class PluginGenerator method createModel.
private byte[] createModel(final JarOutputStream outputStream, String packageName) throws IOException {
final String className = packageName + "/AModel.class";
outputStream.putNextEntry(new ZipEntry(className));
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
writer.visit(V1_8, ACC_PUBLIC + ACC_SUPER, className.substring(0, className.length() - ".class".length()), null, Type.getInternalName(Object.class), null);
writer.visitSource(className.replace(".class", ".java"), null);
addConstructor(writer);
// no real content (fields/methods) for now
writer.visitEnd();
return writer.toByteArray();
}
use of org.apache.xbean.asm6.Opcodes.RETURN in project component-runtime by Talend.
the class ProxyGenerator method createConstructor.
private String createConstructor(final ClassWriter cw, final Class<?> classToProxy, final String classFileName, final String proxyClassFileName, final Constructor<?> constructor, final boolean withInterceptors) {
try {
Constructor superDefaultCt;
String parentClassFileName;
String[] exceptions = null;
if (classToProxy.isInterface()) {
parentClassFileName = Type.getInternalName(Object.class);
superDefaultCt = Object.class.getConstructor();
} else {
parentClassFileName = classFileName;
if (constructor == null) {
superDefaultCt = classToProxy.getConstructor();
} else {
superDefaultCt = constructor;
Class<?>[] exceptionTypes = constructor.getExceptionTypes();
exceptions = exceptionTypes.length == 0 ? null : new String[exceptionTypes.length];
for (int i = 0; i < exceptionTypes.length; i++) {
exceptions[i] = Type.getInternalName(exceptionTypes[i]);
}
}
}
final String descriptor = Type.getConstructorDescriptor(superDefaultCt);
final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
if (constructor != null) {
for (int i = 1; i <= constructor.getParameterTypes().length; i++) {
mv.visitVarInsn(ALOAD, i);
}
}
mv.visitMethodInsn(INVOKESPECIAL, parentClassFileName, "<init>", descriptor, false);
if (withInterceptors) {
mv.visitVarInsn(ALOAD, 0);
mv.visitInsn(ACONST_NULL);
mv.visitFieldInsn(PUTFIELD, proxyClassFileName, FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class));
}
mv.visitInsn(RETURN);
mv.visitMaxs(-1, -1);
mv.visitEnd();
return parentClassFileName;
} catch (final NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
Aggregations