Search in sources :

Example 91 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testFieldCardinality.

public void testFieldCardinality() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*FieldCardinality");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkRequires(a, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$FieldCardinality.xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute("test.component.DSAnnotationTest$FieldCardinality", "scr:component/implementation/@class");
    xt.assertAttribute("log1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[1]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[1]/@policy");
    xt.assertNoAttribute("scr:component/reference[1]/@field-option");
    xt.assertAttribute("log2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[2]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[2]/@policy");
    xt.assertNoAttribute("scr:component/reference[2]/@field-option");
    xt.assertAttribute("log3", "scr:component/reference[3]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[3]/@interface");
    xt.assertNoAttribute("scr:component/reference[3]/@cardinality");
    xt.assertNoAttribute("scr:component/reference[3]/@policy");
    xt.assertNoAttribute("scr:component/reference[3]/@field-option");
    xt.assertAttribute("log4", "scr:component/reference[4]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[4]/@interface");
    xt.assertNoAttribute("scr:component/reference[4]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[4]/@policy");
    xt.assertNoAttribute("scr:component/reference[4]/@field-option");
    xt.assertAttribute("log5", "scr:component/reference[5]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[5]/@interface");
    xt.assertAttribute("0..n", "scr:component/reference[5]/@cardinality");
    xt.assertAttribute("dynamic", "scr:component/reference[5]/@policy");
    xt.assertAttribute("update", "scr:component/reference[5]/@field-option");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 92 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testPrototypes.

public void testPrototypes() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest*Prototypes");
    b.setProperty(Constants.DSANNOTATIONS_OPTIONS, "version;minimum=1.0.0");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkProvides(a);
    checkRequires(a, null, LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/prototypes.xml");
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.2.0");
    xt.assertAttribute("LogService", "scr:component/reference[1]/@name");
    xt.assertAttribute("setLogService", "scr:component/reference[1]/@bind");
    xt.assertAttribute("unsetLogService", "scr:component/reference[1]/@unbind");
    xt.assertAttribute("updatedLogService", "scr:component/reference[1]/@updated");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 93 with Attributes

use of java.util.jar.Attributes in project bnd by bndtools.

the class DSAnnotationTest method testFinalDynamicCollectionField.

public void testFinalDynamicCollectionField() throws Exception {
    Builder b = new Builder();
    b.setProperty(Constants.DSANNOTATIONS, "test.component.*FinalDynamicCollectionField");
    b.setProperty("Private-Package", "test.component");
    b.addClasspath(new File("bin"));
    Jar jar = b.build();
    assertOk(b);
    Attributes a = getAttr(jar);
    checkRequires(a, "1.3.0", LogService.class.getName());
    Resource r = jar.getResource("OSGI-INF/test.component.DSAnnotationTest$FinalDynamicCollectionField.xml");
    System.err.println(Processor.join(jar.getResources().keySet(), "\n"));
    assertNotNull(r);
    r.write(System.err);
    XmlTester xt = new XmlTester(r.openInputStream(), "scr", "http://www.osgi.org/xmlns/scr/v1.3.0");
    // Test the defaults
    xt.assertAttribute("test.component.DSAnnotationTest$FinalDynamicCollectionField", "scr:component/implementation/@class");
    xt.assertAttribute("logs1", "scr:component/reference[1]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[1]/@interface");
    xt.assertAttribute("dynamic", "scr:component/reference[1]/@policy");
    xt.assertAttribute("update", "scr:component/reference[1]/@field-option");
    xt.assertAttribute("logs2", "scr:component/reference[2]/@name");
    xt.assertAttribute(LogService.class.getName(), "scr:component/reference[2]/@interface");
    xt.assertNoAttribute("scr:component/reference[2]/@policy");
    xt.assertNoAttribute("scr:component/reference[2]/@field-option");
}
Also used : XmlTester(aQute.bnd.test.XmlTester) Builder(aQute.bnd.osgi.Builder) Attributes(java.util.jar.Attributes) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File) LogService(org.osgi.service.log.LogService)

Example 94 with Attributes

use of java.util.jar.Attributes in project android_frameworks_base by AOSPA.

the class StrictJarVerifier method initEntry.

/**
     * Invoked for each new JAR entry read operation from the input
     * stream. This method constructs and returns a new {@link VerifierEntry}
     * which contains the certificates used to sign the entry and its hash value
     * as specified in the JAR MANIFEST format.
     *
     * @param name
     *            the name of an entry in a JAR file which is <b>not</b> in the
     *            {@code META-INF} directory.
     * @return a new instance of {@link VerifierEntry} which can be used by
     *         callers as an {@link OutputStream}.
     */
VerifierEntry initEntry(String name) {
    // been found, do not verify.
    if (manifest == null || signatures.isEmpty()) {
        return null;
    }
    Attributes attributes = manifest.getAttributes(name);
    // entry has no digest
    if (attributes == null) {
        return null;
    }
    ArrayList<Certificate[]> certChains = new ArrayList<Certificate[]>();
    Iterator<Map.Entry<String, HashMap<String, Attributes>>> it = signatures.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, HashMap<String, Attributes>> entry = it.next();
        HashMap<String, Attributes> hm = entry.getValue();
        if (hm.get(name) != null) {
            // Found an entry for entry name in .SF file
            String signatureFile = entry.getKey();
            Certificate[] certChain = certificates.get(signatureFile);
            if (certChain != null) {
                certChains.add(certChain);
            }
        }
    }
    // entry is not signed
    if (certChains.isEmpty()) {
        return null;
    }
    Certificate[][] certChainsArray = certChains.toArray(new Certificate[certChains.size()][]);
    for (int i = 0; i < DIGEST_ALGORITHMS.length; i++) {
        final String algorithm = DIGEST_ALGORITHMS[i];
        final String hash = attributes.getValue(algorithm + "-Digest");
        if (hash == null) {
            continue;
        }
        byte[] hashBytes = hash.getBytes(StandardCharsets.ISO_8859_1);
        try {
            return new VerifierEntry(name, MessageDigest.getInstance(algorithm), hashBytes, certChainsArray, verifiedEntries);
        } catch (NoSuchAlgorithmException ignored) {
        }
    }
    return null;
}
Also used : HashMap(java.util.HashMap) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) HashMap(java.util.HashMap) Map(java.util.Map) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 95 with Attributes

use of java.util.jar.Attributes in project processdash by dtuma.

the class QuickLauncher method useDashboardJarFile.

public boolean useDashboardJarFile(File f) {
    if (!(processFactory instanceof DashboardProcessFactoryForking)) {
        JOptionPane.showMessageDialog(frame, resources.getStrings("Errors.SameJVMCannotSwitch"), resources.getString("Errors.Dialog_Title"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    String packageID = null;
    String version = null;
    String mainClass = null;
    try {
        JarFile jar = new JarFile(f);
        Manifest mf = jar.getManifest();
        Attributes attrs = mf.getMainAttributes();
        packageID = attrs.getValue(DashPackage.ID_ATTRIBUTE);
        version = attrs.getValue(DashPackage.VERSION_ATTRIBUTE);
        mainClass = attrs.getValue("Main-Class");
        jar.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (!"pspdash".equals(packageID) || version == null || mainClass == null) {
        JOptionPane.showMessageDialog(frame, resources.format("Errors.Not_Pspdash_Jar_FMT", f.getAbsolutePath()), resources.getString("Errors.Dialog_Title"), JOptionPane.ERROR_MESSAGE);
        return false;
    }
    DashboardProcessFactoryForking pf = (DashboardProcessFactoryForking) processFactory;
    pf.setClasspath(f.getAbsolutePath());
    pf.setMainClassName(mainClass);
    String windowTitle = resources.format("Window_Title3_FMT", version, f.getParent());
    frame.setTitle(windowTitle);
    return true;
}
Also used : Attributes(java.util.jar.Attributes) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) IOException(java.io.IOException)

Aggregations

Attributes (java.util.jar.Attributes)629 Manifest (java.util.jar.Manifest)356 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32