Search in sources :

Example 1 with Remapper

use of org.objectweb.asm.commons.Remapper in project ignite by apache.

the class HadoopHelperImpl method loadReplace.

/**
 * {@inheritDoc}
 */
@Override
public byte[] loadReplace(InputStream in, final String originalName, final String replaceName) {
    ClassReader rdr;
    try {
        rdr = new ClassReader(in);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    ClassWriter w = new ClassWriter(Opcodes.ASM4);
    rdr.accept(new RemappingClassAdapter(w, new Remapper() {

        /**
         */
        String replaceType = replaceName.replace('.', '/');

        /**
         */
        String nameType = originalName.replace('.', '/');

        @Override
        public String map(String type) {
            if (type.equals(replaceType))
                return nameType;
            return type;
        }
    }), ClassReader.EXPAND_FRAMES);
    return w.toByteArray();
}
Also used : RemappingClassAdapter(org.objectweb.asm.commons.RemappingClassAdapter) Remapper(org.objectweb.asm.commons.Remapper) ClassReader(org.objectweb.asm.ClassReader) IOException(java.io.IOException) ClassWriter(org.objectweb.asm.ClassWriter)

Example 2 with Remapper

use of org.objectweb.asm.commons.Remapper in project Lucee by lucee.

the class JarUtil method _getExternalImports.

private static void _getExternalImports(Set<String> imports, InputStream src, String[] ignores) throws IOException {
    final ClassReader reader = new ClassReader(src);
    final Remapper remapper = new Collector(imports, ignores);
    final ClassVisitor inner = new EmptyVisitor();
    final RemappingClassAdapter visitor = new RemappingClassAdapter(inner, remapper);
    reader.accept(visitor, 0);
}
Also used : Remapper(org.objectweb.asm.commons.Remapper) RemappingClassAdapter(org.objectweb.asm.commons.RemappingClassAdapter) ClassReader(org.objectweb.asm.ClassReader) ClassVisitor(org.objectweb.asm.ClassVisitor)

Example 3 with Remapper

use of org.objectweb.asm.commons.Remapper in project wildfly-swarm by wildfly-swarm.

the class FaviconFactory method createFaviconServletExtension.

static byte[] createFaviconServletExtension(String name) throws IOException {
    ClassReader reader = new ClassReader(FaviconServletExtension.class.getClassLoader().getResourceAsStream(FaviconServletExtension.class.getName().replace('.', '/') + ".class"));
    String slashName = name.replace('.', '/');
    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {

        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/undertow/internal/FaviconServletExtension")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };
    ClassRemapper adapter = new ClassRemapper(writer, remapper);
    reader.accept(adapter, ClassReader.EXPAND_FRAMES);
    writer.visitEnd();
    return writer.toByteArray();
}
Also used : Remapper(org.objectweb.asm.commons.Remapper) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) ClassReader(org.objectweb.asm.ClassReader) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) ClassWriter(org.objectweb.asm.ClassWriter)

Example 4 with Remapper

use of org.objectweb.asm.commons.Remapper in project wildfly-swarm by wildfly-swarm.

the class DefaultApplicationFactory method create.

public static byte[] create(String name, String path) throws IOException {
    ClassReader reader = new ClassReader(basicClassBytes());
    String slashName = name.replace('.', '/');
    ClassWriter writer = new ClassWriter(0);
    Remapper remapper = new Remapper() {

        @Override
        public String map(String typeName) {
            if (typeName.equals("org/wildfly/swarm/jaxrs/runtime/DefaultApplication")) {
                return slashName;
            }
            return super.map(typeName);
        }
    };
    ClassRemapper adapter = new ClassRemapper(writer, remapper);
    reader.accept(adapter, 0);
    AnnotationVisitor ann = writer.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true);
    ann.visit("value", path);
    ann.visitEnd();
    writer.visitEnd();
    return writer.toByteArray();
}
Also used : Remapper(org.objectweb.asm.commons.Remapper) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) AnnotationVisitor(org.objectweb.asm.AnnotationVisitor) ClassReader(org.objectweb.asm.ClassReader) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) ClassWriter(org.objectweb.asm.ClassWriter)

Example 5 with Remapper

use of org.objectweb.asm.commons.Remapper in project FoamFix by asiekierka.

the class FoamFixTransformer method replaceClasses.

public static ClassNode replaceClasses(final ClassNode nodeData, final byte[] dataSplice, final String className) {
    System.out.println("replacing " + nodeData.name + " with " + className);
    if (dataSplice == null) {
        throw new RuntimeException("Class " + className + " not found! This is a FoamFix bug!");
    }
    final ClassReader readerSplice = new ClassReader(dataSplice);
    final String className2 = className.replace('.', '/');
    final String targetClassName2 = nodeData.name;
    final String targetClassName = targetClassName2.replace('/', '.');
    final Remapper remapper = new Remapper() {

        public String map(final String name) {
            return className2.equals(name) ? targetClassName2 : name;
        }
    };
    ClassNode nodeSplice = new ClassNode();
    readerSplice.accept(new ClassRemapper(nodeSplice, remapper), ClassReader.EXPAND_FRAMES);
    return nodeSplice;
}
Also used : Remapper(org.objectweb.asm.commons.Remapper) ClassRemapper(org.objectweb.asm.commons.ClassRemapper) ClassReader(org.objectweb.asm.ClassReader) ClassRemapper(org.objectweb.asm.commons.ClassRemapper)

Aggregations

Remapper (org.objectweb.asm.commons.Remapper)12 ClassReader (org.objectweb.asm.ClassReader)9 ClassRemapper (org.objectweb.asm.commons.ClassRemapper)8 ClassWriter (org.objectweb.asm.ClassWriter)7 RemappingClassAdapter (org.objectweb.asm.commons.RemappingClassAdapter)3 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 JarOutputStream (java.util.jar.JarOutputStream)1 FileVisitDetails (org.gradle.api.file.FileVisitDetails)1 FileVisitor (org.gradle.api.file.FileVisitor)1 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 SimpleRemapper (org.objectweb.asm.commons.SimpleRemapper)1 ClassNode (org.objectweb.asm.tree.ClassNode)1