Search in sources :

Example 36 with Resource

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

the class Project method reportNewer.

private void reportNewer(long lastModified, Jar jar) {
    if (isTrue(getProperty(Constants.REPORTNEWER))) {
        StringBuilder sb = new StringBuilder();
        String del = "Newer than " + new Date(lastModified);
        for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
            if (entry.getValue().lastModified() > lastModified) {
                sb.append(del);
                del = ", \n     ";
                sb.append(entry.getKey());
            }
        }
        if (sb.length() > 0)
            warning("%s", sb.toString());
    }
}
Also used : Resource(aQute.bnd.osgi.Resource) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Date(java.util.Date)

Example 37 with Resource

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

the class Classpath method visit.

/**
	 * Visit each class on the class path.
	 * 
	 * @param visitor the visitor
	 */
public void visit(ClassVisitor visitor) throws Exception {
    try (Analyzer analyzer = new Analyzer()) {
        for (File f : entries) {
            try (Jar jar = new Jar(f)) {
                for (String path : jar.getResources().keySet()) {
                    if (path.endsWith(".class")) {
                        Resource r = jar.getResource(path);
                        Clazz c = new Clazz(analyzer, path, r);
                        c.parseClassFile();
                        visitor.visit(c);
                    }
                }
            }
        }
    }
}
Also used : Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Clazz(aQute.bnd.osgi.Clazz) Analyzer(aQute.bnd.osgi.Analyzer) File(java.io.File)

Example 38 with Resource

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

the class JartoolSigner method sign.

public void sign(Builder builder, String alias) throws Exception {
    File f = builder.getFile(keystore);
    if (!f.isFile()) {
        builder.error("Invalid keystore %s", f.getAbsolutePath());
        return;
    }
    Jar jar = builder.getJar();
    File tmp = File.createTempFile("signdjar", ".jar");
    tmp.deleteOnExit();
    jar.write(tmp);
    Command command = new Command();
    command.add(path);
    if (keystore != null) {
        command.add("-keystore");
        command.add(f.getAbsolutePath());
    }
    if (storetype != null) {
        command.add("-storetype");
        command.add(storetype);
    }
    if (keypass != null) {
        command.add("-keypass");
        command.add(keypass);
    }
    if (storepass != null) {
        command.add("-storepass");
        command.add(storepass);
    }
    if (sigFile != null) {
        command.add("-sigFile");
        command.add(sigFile);
    }
    if (digestalg != null) {
        command.add("-digestalg");
        command.add(digestalg);
    }
    if (tsa != null) {
        command.add("-tsa");
        command.add(tsa);
    }
    if (tsacert != null) {
        command.add("-tsacert");
        command.add(tsacert);
    }
    if (tsapolicyid != null) {
        command.add("-tsapolicyid");
        command.add(tsapolicyid);
    }
    command.add(tmp.getAbsolutePath());
    command.add(alias);
    logger.debug("Jarsigner command: {}", command);
    command.setTimeout(20, TimeUnit.SECONDS);
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    int exitValue = command.execute(out, err);
    if (exitValue != 0) {
        builder.error("Signing Jar out: %s%nerr: %s", out, err);
    } else {
        logger.debug("Signing Jar out: {}\nerr: {}", out, err);
    }
    Jar signed = new Jar(tmp);
    builder.addClose(signed);
    Map<String, Resource> dir = signed.getDirectories().get("META-INF");
    for (Entry<String, Resource> entry : dir.entrySet()) {
        String path = entry.getKey();
        if (path.matches(".*\\.(DSA|RSA|SF|MF)$")) {
            jar.putResource(path, entry.getValue());
        }
    }
    jar.setDoNotTouchManifest();
}
Also used : Command(aQute.libg.command.Command) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 39 with Resource

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

the class Signer method doManifest.

private void doManifest(Jar jar, String[] digestNames, MessageDigest[] algorithms, OutputStream out) throws Exception {
    Writer w = IO.writer(out, UTF_8);
    try {
        for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
            String name = entry.getKey();
            if (!METAINFDIR.matcher(name).matches()) {
                w.write("\r\n");
                w.write("Name: ");
                w.write(name);
                w.write("\r\n");
                digest(algorithms, entry.getValue());
                for (int a = 0; a < algorithms.length; a++) {
                    if (algorithms[a] != null) {
                        byte[] digest = algorithms[a].digest();
                        String header = digestNames[a] + "-Digest: " + new Base64(digest) + "\r\n";
                        w.write(header);
                    }
                }
            }
        }
    } finally {
        w.flush();
    }
}
Also used : Base64(aQute.lib.base64.Base64) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Map(java.util.Map) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer)

Example 40 with Resource

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

the class BuilderTest method testExtra.

public static void testExtra() throws Exception {
    Builder b = new Builder();
    try {
        b.setProperty("Include-Resource", "jar/osgi.jar;extra=itworks, www/xyz.jar=jar/osgi.jar;extra='italsoworks'");
        b.setProperty("-resourceonly", "true");
        Jar jar = b.build();
        assertTrue(b.check());
        Resource r = jar.getResource("osgi.jar");
        assertNotNull(r);
        assertEquals("itworks", r.getExtra());
        Resource r2 = jar.getResource("www/xyz.jar");
        assertNotNull(r2);
        assertEquals("italsoworks", r2.getExtra());
    } finally {
        b.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar)

Aggregations

Resource (aQute.bnd.osgi.Resource)147 Jar (aQute.bnd.osgi.Jar)87 Builder (aQute.bnd.osgi.Builder)83 File (java.io.File)76 XmlTester (aQute.bnd.test.XmlTester)48 JarResource (aQute.bnd.osgi.JarResource)20 Attributes (java.util.jar.Attributes)20 Map (java.util.Map)19 Manifest (java.util.jar.Manifest)19 FileResource (aQute.bnd.osgi.FileResource)17 LogService (org.osgi.service.log.LogService)15 HashMap (java.util.HashMap)14 Document (org.w3c.dom.Document)14 Properties (java.util.Properties)12 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)11 DocumentBuilder (javax.xml.parsers.DocumentBuilder)11 InputStream (java.io.InputStream)9 Attrs (aQute.bnd.header.Attrs)8 ArrayList (java.util.ArrayList)8 TreeMap (java.util.TreeMap)8