Search in sources :

Example 36 with PackageRef

use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.

the class ClassParserTest method testParameterAnnotation.

public void testParameterAnnotation() throws Exception {
    InputStream in = getClass().getResourceAsStream("Test2.jclass");
    assertNotNull(in);
    Clazz clazz = new Clazz(a, "test", null);
    clazz.parseClassFile(in);
    Set<PackageRef> set = clazz.getReferred();
    assertTrue(set.contains(a.getPackageRef("test")));
    assertTrue(set.contains(a.getPackageRef("test/annotations")));
}
Also used : InputStream(java.io.InputStream) Clazz(aQute.bnd.osgi.Clazz) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef)

Example 37 with PackageRef

use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.

the class ClazzTest method testModuleInfo.

public void testModuleInfo() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/module-info.jclass"), new ClassDataCollector() {
        });
        assertTrue(c.isModule());
        Set<PackageRef> referred = c.getReferred();
        Descriptors d = new Descriptors();
        assertFalse(referred.contains(d.getPackageRef("")));
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Descriptors(aQute.bnd.osgi.Descriptors) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 38 with PackageRef

use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.

the class ClazzTest method testAnalyzerCrawlInvokeInterfaceAIOOBException.

public void testAnalyzerCrawlInvokeInterfaceAIOOBException() throws Exception {
    try (Analyzer a = new Analyzer()) {
        Clazz c = new Clazz(a, "", null);
        c.parseClassFile(new FileInputStream("jar/AnalyzerCrawlInvokerInterfaceAIOOBTest.jclass"), new ClassDataCollector() {
        });
        Set<PackageRef> referred = c.getReferred();
        System.out.println(referred);
    }
}
Also used : Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) ClassDataCollector(aQute.bnd.osgi.ClassDataCollector) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) FileInputStream(java.io.FileInputStream)

Example 39 with PackageRef

use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.

the class DescriptorsTest method testReferences.

public static void testReferences() {
    Descriptors d = new Descriptors();
    TypeRef r = d.getTypeRef("[B");
    assertNotNull(r);
    assertEquals("byte[]", r.getFQN());
    assertNotNull(r.getPackageRef());
    assertEquals(".", r.getPackageRef().getFQN());
    PackageRef a = d.getPackageRef("a.b.c");
    PackageRef b = d.getPackageRef("a/b/c");
    assertTrue(a == b);
}
Also used : TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Descriptors(aQute.bnd.osgi.Descriptors) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef)

Example 40 with PackageRef

use of aQute.bnd.osgi.Descriptors.PackageRef in project bndtools by bndtools.

the class Printer method doPrint.

private void doPrint(File file, int options) throws ZipException, IOException, Exception {
    try (Jar jar = new Jar(file.getName(), file)) {
        if ((options & VERIFY) != 0) {
            Verifier verifier = new Verifier(jar);
            verifier.setPedantic(isPedantic());
            verifier.verify();
            getInfo(verifier);
        }
        if ((options & MANIFEST) != 0) {
            Manifest manifest = jar.getManifest();
            if (manifest == null)
                warning("JAR has no manifest " + file);
            else {
                out.println("[MANIFEST " + jar.getName() + "]");
                printManifest(manifest);
            }
            out.println();
        }
        if ((options & IMPEXP) != 0) {
            out.println("[IMPEXP]");
            Manifest m = jar.getManifest();
            if (m != null) {
                Domain domain = Domain.domain(m);
                Parameters imports = domain.getImportPackage();
                Parameters exports = domain.getExportPackage();
                for (String p : exports.keySet()) {
                    if (imports.containsKey(p)) {
                        Attrs attrs = imports.get(p);
                        if (attrs.containsKey(VERSION_ATTRIBUTE)) {
                            exports.get(p).put("imported-as", attrs.get(VERSION_ATTRIBUTE));
                        }
                    }
                }
                print("Import-Package", new TreeMap<String, Attrs>(imports));
                print("Export-Package", new TreeMap<String, Attrs>(exports));
            } else
                warning("File has no manifest");
        }
        if ((options & (USES | USEDBY)) != 0) {
            out.println();
            try (Analyzer analyzer = new Analyzer()) {
                analyzer.setPedantic(isPedantic());
                analyzer.setJar(jar);
                analyzer.analyze();
                if ((options & USES) != 0) {
                    out.println("[USES]");
                    printMultiMap(analyzer.getUses());
                    out.println();
                }
                if ((options & USEDBY) != 0) {
                    out.println("[USEDBY]");
                    Map<PackageRef, Set<PackageRef>> usedBy = CollectionUtil.invertMapOfCollection(analyzer.getUses());
                    printMultiMap(usedBy);
                }
                analyzer.setJar((Jar) null);
            }
            out.println();
        }
        if ((options & COMPONENT) != 0) {
            printComponents(jar);
            out.println();
        }
        if ((options & METATYPE) != 0) {
            printMetatype(jar);
            out.println();
        }
        if ((options & LIST) != 0) {
            out.println("[LIST]");
            for (Map.Entry<String, Map<String, Resource>> entry : jar.getDirectories().entrySet()) {
                String name = entry.getKey();
                Map<String, Resource> contents = entry.getValue();
                out.println(name);
                if (contents != null) {
                    for (String element : contents.keySet()) {
                        int n = element.lastIndexOf('/');
                        if (n > 0)
                            element = element.substring(n + 1);
                        out.print("  ");
                        out.print(element);
                        String path = element;
                        if (name.length() != 0)
                            path = name + "/" + element;
                        Resource r = contents.get(path);
                        if (r != null) {
                            String extra = r.getExtra();
                            if (extra != null) {
                                out.print(" extra='" + escapeUnicode(extra) + "'");
                            }
                        }
                        out.println();
                    }
                }
            }
            out.println();
        }
    }
}
Also used : Parameters(aQute.bnd.header.Parameters) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) Set(java.util.Set) Attrs(aQute.bnd.header.Attrs) Resource(aQute.bnd.osgi.Resource) Verifier(aQute.bnd.osgi.Verifier) Manifest(java.util.jar.Manifest) Analyzer(aQute.bnd.osgi.Analyzer) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) PackageRef(aQute.bnd.osgi.Descriptors.PackageRef) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)40 Attrs (aQute.bnd.header.Attrs)18 Analyzer (aQute.bnd.osgi.Analyzer)9 Clazz (aQute.bnd.osgi.Clazz)8 Map (java.util.Map)8 Parameters (aQute.bnd.header.Parameters)7 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)7 MultiMap (aQute.lib.collections.MultiMap)7 HashSet (java.util.HashSet)7 TreeSet (java.util.TreeSet)7 Manifest (java.util.jar.Manifest)7 Jar (aQute.bnd.osgi.Jar)6 Resource (aQute.bnd.osgi.Resource)6 Descriptors (aQute.bnd.osgi.Descriptors)5 ClassDataCollector (aQute.bnd.osgi.ClassDataCollector)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 Entry (java.util.Map.Entry)4