use of org.apache.xbean.asm6.ClassWriter.COMPUTE_FRAMES 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.ClassWriter.COMPUTE_FRAMES 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.ClassWriter.COMPUTE_FRAMES 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.ClassWriter.COMPUTE_FRAMES 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.asm6.ClassWriter.COMPUTE_FRAMES in project component-runtime by Talend.
the class PluginGenerator method createService.
private byte[] createService(final JarOutputStream outputStream, final String packageName, final String name) throws IOException {
final String className = packageName + "/AService.class";
outputStream.putNextEntry(new ZipEntry(className));
final ClassWriter writer = new ClassWriter(COMPUTE_FRAMES);
writer.visitAnnotation(Type.getDescriptor(Service.class), true).visitEnd();
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);
final MethodVisitor action = writer.visitMethod(ACC_PUBLIC, "doAction", "(L" + packageName + "/AModel;)L" + packageName + "/AModel;", null, new String[0]);
final AnnotationVisitor actionAnnotation = action.visitAnnotation(Type.getDescriptor(Action.class), true);
actionAnnotation.visit("family", "proc");
actionAnnotation.visit("value", name + "Action");
actionAnnotation.visitEnd();
action.visitCode();
action.visitTypeInsn(NEW, packageName + "/AModel");
action.visitInsn(DUP);
action.visitMethodInsn(INVOKESPECIAL, packageName + "/AModel", "<init>", "()V", false);
action.visitInsn(ARETURN);
action.visitInsn(ARETURN);
action.visitMaxs(1, 1);
action.visitEnd();
writer.visitEnd();
return writer.toByteArray();
}
Aggregations