Search in sources :

Example 1 with ScannedClass

use of org.apache.felix.scrplugin.annotations.ScannedClass in project felix by apache.

the class ClassScanner method processClass.

/**
 * Scan a single class.
 */
private ClassDescription processClass(final Class<?> annotatedClass, final String location) throws SCRDescriptorFailureException, SCRDescriptorException {
    log.debug("Processing " + annotatedClass.getName());
    try {
        // get the class file for ASM
        final String pathToClassFile = annotatedClass.getName().replace('.', '/') + ".class";
        final InputStream input = project.getClassLoader().getResourceAsStream(pathToClassFile);
        final ClassReader classReader;
        try {
            classReader = new ClassReader(input);
        } finally {
            if (input != null) {
                input.close();
            }
        }
        final ClassNode classNode = new ClassNode();
        classReader.accept(classNode, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
        // create descriptions
        final List<ScannedAnnotation> annotations = extractAnnotation(classNode, annotatedClass);
        if (annotations.size() > 0) {
            // process annotations and create descriptions
            final ClassDescription desc = new ClassDescription(annotatedClass, location);
            aProcessor.process(new ScannedClass(annotations, annotatedClass), desc);
            log.debug("Found descriptions " + desc + " in " + annotatedClass.getName());
            return desc;
        }
    } catch (final IllegalArgumentException ioe) {
        throw new SCRDescriptorException("Unable to scan class files: " + annotatedClass.getName() + " (Class file format probably not supported by ASM ?)", location, ioe);
    } catch (final IOException ioe) {
        throw new SCRDescriptorException("Unable to scan class files: " + annotatedClass.getName(), location, ioe);
    }
    return null;
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClassReader(org.objectweb.asm.ClassReader) ScannedAnnotation(org.apache.felix.scrplugin.annotations.ScannedAnnotation) ClassDescription(org.apache.felix.scrplugin.description.ClassDescription) ScannedClass(org.apache.felix.scrplugin.annotations.ScannedClass) IOException(java.io.IOException) SCRDescriptorException(org.apache.felix.scrplugin.SCRDescriptorException)

Aggregations

FileInputStream (java.io.FileInputStream)1 FilterInputStream (java.io.FilterInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SCRDescriptorException (org.apache.felix.scrplugin.SCRDescriptorException)1 ScannedAnnotation (org.apache.felix.scrplugin.annotations.ScannedAnnotation)1 ScannedClass (org.apache.felix.scrplugin.annotations.ScannedClass)1 ClassDescription (org.apache.felix.scrplugin.description.ClassDescription)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassNode (org.objectweb.asm.tree.ClassNode)1