Search in sources :

Example 11 with Verifier

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

the class NativeHeader method testWildcard.

public static void testWildcard() throws Exception {
    Verifier v = new Verifier(b);
    v.doNative("x.so ;y.so;osname=Linux;processor=amd64,*");
    assertOk(v);
}
Also used : Verifier(aQute.bnd.osgi.Verifier)

Example 12 with Verifier

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

the class NativeHeader method testWildcardNotAtEnd.

public static void testWildcardNotAtEnd() throws Exception {
    Verifier v = new Verifier(b);
    v.doNative("x.so;osname=win32,*,x.dll");
    assertBad(v, "may only END in wildcard");
}
Also used : Verifier(aQute.bnd.osgi.Verifier)

Example 13 with Verifier

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

the class VerifierTest method testFailedOSGiJar.

public static void testFailedOSGiJar() throws Exception {
    Jar jar = new Jar("jar/osgi.residential-4.3.0.jar");
    Verifier v = new Verifier(jar);
    assertTrue(v.check());
}
Also used : Jar(aQute.bnd.osgi.Jar) Verifier(aQute.bnd.osgi.Verifier)

Example 14 with Verifier

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

the class VerifierTest method verifyMetaPersistence.

/**
	 * Verify that the Meta-Persistence header is correctly verified
	 * 
	 * @throws Exception
	 */
public void verifyMetaPersistence() throws Exception {
    Builder b = new Builder();
    b.setIncludeResource("foo.xml;literal='I exist'");
    Jar inner = b.build();
    assertTrue(b.check());
    Jar outer = new Jar("x");
    outer.putResource("foo.jar", new JarResource(inner));
    Manifest m = new Manifest();
    m.getMainAttributes().putValue(Constants.META_PERSISTENCE, "foo.jar, foo.jar!/foo.xml, absent.xml");
    outer.setManifest(m);
    Verifier v = new Verifier(outer);
    v.verifyMetaPersistence();
    assertTrue(v.check("Meta-Persistence refers to resources not in the bundle: \\[absent.xml\\]"));
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) Verifier(aQute.bnd.osgi.Verifier)

Example 15 with Verifier

use of aQute.bnd.osgi.Verifier 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

Verifier (aQute.bnd.osgi.Verifier)15 Jar (aQute.bnd.osgi.Jar)6 File (java.io.File)6 Builder (aQute.bnd.osgi.Builder)5 Manifest (java.util.jar.Manifest)4 Attrs (aQute.bnd.header.Attrs)3 Parameters (aQute.bnd.header.Parameters)3 Analyzer (aQute.bnd.osgi.Analyzer)2 PackageRef (aQute.bnd.osgi.Descriptors.PackageRef)2 Domain (aQute.bnd.osgi.Domain)2 Resource (aQute.bnd.osgi.Resource)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 PomFromManifest (aQute.bnd.maven.PomFromManifest)1 Def (aQute.bnd.osgi.Clazz.Def)1 Descriptors (aQute.bnd.osgi.Descriptors)1 TypeRef (aQute.bnd.osgi.Descriptors.TypeRef)1 FileResource (aQute.bnd.osgi.FileResource)1