Search in sources :

Example 1 with Clazz

use of aQute.bnd.osgi.Clazz in project felix by apache.

the class BndJarResourceStore method accept.

public void accept(ResourceVisitor visitor) {
    try {
        // Collect all annotated classes
        Collection<Clazz> classes = m_analyzer.getClasses("", Clazz.QUERY.CLASSANNOTATIONS.name());
        classes = filter(classes);
        // Iterates over discovered resources
        for (Clazz clazz : classes) {
            visitor.visit(clazz.getAbsolutePath());
        }
    } catch (Exception e) {
        m_reporter.error("Cannot find iPOJO annotated types: " + e.getMessage());
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) IOException(java.io.IOException)

Example 2 with Clazz

use of aQute.bnd.osgi.Clazz in project felix by apache.

the class SCRDescriptorBndPlugin method getClassFiles.

private Collection<Source> getClassFiles(Analyzer analyzer) throws Exception {
    ArrayList<Source> files = new ArrayList<Source>();
    Collection<Clazz> expanded = analyzer.getClasses("", QUERY.NAMED.toString(), "*");
    for (final Clazz c : expanded) {
        files.add(new Source() {

            public File getFile() {
                log.debug("Found class " + c.getAbsolutePath());
                return new File(c.getAbsolutePath());
            }

            public String getClassName() {
                return c.getFQN();
            }
        });
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) Clazz(aQute.bnd.osgi.Clazz) File(java.io.File) Source(org.apache.felix.scrplugin.Source)

Example 3 with Clazz

use of aQute.bnd.osgi.Clazz in project sling by apache.

the class ConfigurationClassScannerPlugin method getClassesWithAnnotation.

/**
     * Get all classes that implement the given annotation via bnd Analyzer.
     * @param analyzer Analyzer
     * @param annotation Annotation
     * @return Class names
     */
private Collection<String> getClassesWithAnnotation(String annotationClassName, Analyzer analyzer) {
    SortedSet<String> classNames = new TreeSet<>();
    Collection<Clazz> clazzes = analyzer.getClassspace().values();
    Instruction instruction = new Instruction(annotationClassName);
    try {
        for (Clazz clazz : clazzes) {
            if (clazz.isAnnotation() && clazz.is(QUERY.ANNOTATED, instruction, analyzer)) {
                classNames.add(clazz.getClassName().getFQN());
            }
        }
    } catch (Exception ex) {
        reporter.exception(ex, "Error querying for classes with annotation: " + annotationClassName);
    }
    return classNames;
}
Also used : TreeSet(java.util.TreeSet) Clazz(aQute.bnd.osgi.Clazz) Instruction(aQute.bnd.osgi.Instruction)

Example 4 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class bnd method _xref.

/**
	 * Cross reference every class in the jar file to the files it references
	 */
@Description("Show a cross references for all classes in a set of jars.")
public void _xref(xrefOptions options) throws IOException, Exception {
    Analyzer analyzer = new Analyzer();
    final MultiMap<TypeRef, TypeRef> table = new MultiMap<TypeRef, TypeRef>();
    final MultiMap<PackageRef, PackageRef> packages = new MultiMap<PackageRef, PackageRef>();
    Set<TypeRef> set = Create.set();
    Instructions filter = new Instructions(options.match());
    for (String arg : options._arguments()) {
        try {
            File file = new File(arg);
            try (Jar jar = new Jar(file.getName(), file)) {
                for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
                    String key = entry.getKey();
                    Resource r = entry.getValue();
                    if (key.endsWith(".class")) {
                        TypeRef ref = analyzer.getTypeRefFromPath(key);
                        if (filter.matches(ref.toString())) {
                            set.add(ref);
                            try (InputStream in = r.openInputStream()) {
                                Clazz clazz = new Clazz(analyzer, key, r);
                                // TODO use the proper bcp instead
                                // of using the default layout
                                Set<TypeRef> s = clazz.parseClassFile();
                                for (Iterator<TypeRef> t = s.iterator(); t.hasNext(); ) {
                                    TypeRef tr = t.next();
                                    if (tr.isJava() || tr.isPrimitive())
                                        t.remove();
                                    else
                                        packages.add(ref.getPackageRef(), tr.getPackageRef());
                                }
                                table.addAll(ref, s);
                                set.addAll(s);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    boolean to = options.to();
    boolean from = options.from();
    if (to == false && from == false)
        to = from = true;
    if (options.classes()) {
        if (to)
            printxref(table, ">");
        if (from)
            printxref(table.transpose(), "<");
    } else {
        if (to)
            printxref(packages, ">");
        if (from)
            printxref(packages.transpose(), "<");
    }
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Instructions(aQute.bnd.osgi.Instructions) Analyzer(aQute.bnd.osgi.Analyzer) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) ZipException(java.util.zip.ZipException) MultiMap(aQute.lib.collections.MultiMap) Jar(aQute.bnd.osgi.Jar) Clazz(aQute.bnd.osgi.Clazz) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) File(java.io.File) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) Description(aQute.lib.getopt.Description)

Example 5 with Clazz

use of aQute.bnd.osgi.Clazz in project bnd by bndtools.

the class ClazzTest method test375.

/**
	 * {@code java.lang.IllegalArgumentException: Expected IDENTIFIER:
	 * <S:Z>()V;} This actually looks wrong since
	 */
public void test375() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseDescriptor("<S:[LFoo;>()V", Modifier.PUBLIC);
        c.parseDescriptor("<S:[Z>()V", Modifier.PUBLIC);
        c.parseDescriptor("<S:Z>()V", Modifier.PUBLIC);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer)

Aggregations

Clazz (aQute.bnd.osgi.Clazz)56 Analyzer (aQute.bnd.osgi.Analyzer)14 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)14 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)12 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)8 InputStream (java.io.InputStream)8 FileResource (aQute.bnd.osgi.FileResource)7 File (java.io.File)7 HashMap (java.util.HashMap)7 FileInputStream (java.io.FileInputStream)6 Resource (aQute.bnd.osgi.Resource)5 MethodDef (aQute.bnd.osgi.Clazz.MethodDef)4 Descriptors (aQute.bnd.osgi.Descriptors)4 Instruction (aQute.bnd.osgi.Instruction)4 Jar (aQute.bnd.osgi.Jar)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 Parameters (aQute.bnd.header.Parameters)3