Search in sources :

Example 91 with Resource

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

the class bnd method printMetatype.

/**
	 * Print the metatypes in this JAR.
	 * 
	 * @param jar
	 */
private void printMetatype(PrintStream out, Jar jar) throws Exception {
    out.println("[METATYPE]");
    Manifest manifest = jar.getManifest();
    if (manifest == null) {
        out.println("No manifest");
        return;
    }
    Map<String, Resource> map = jar.getDirectories().get("OSGI-INF/metatype");
    if (map != null) {
        for (Map.Entry<String, Resource> entry : map.entrySet()) {
            out.println(entry.getKey());
            IO.copy(entry.getValue().openInputStream(), out);
            out.println();
        }
        out.println();
    }
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Manifest(java.util.jar.Manifest) PomFromManifest(aQute.bnd.maven.PomFromManifest) MultiMap(aQute.lib.collections.MultiMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 92 with Resource

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

the class bnd method _extract.

@Description("Extract files from a JAR file, equivalent jar command x[vf] (syntax supported)")
public void _extract(extractOptions opts) throws Exception {
    Jar jar;
    if (opts.file() != null) {
        File f = getFile(opts.file());
        if (!f.isFile()) {
            messages.NoSuchFile_(f);
            return;
        }
        jar = new Jar(f);
    } else {
        jar = new Jar("cin", System.in);
    }
    try {
        Instructions instructions = new Instructions(opts._arguments());
        Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
        File store = getBase();
        if (opts.cdir() != null)
            store = getFile(opts.cdir());
        IO.mkdirs(store);
        Jar.Compression compression = jar.hasCompression();
        for (String path : selected) {
            if (opts.verbose())
                System.err.printf("%8s: %s\n", compression.toString().toLowerCase(), path);
            File f = getFile(store, path);
            File pf = f.getParentFile();
            IO.mkdirs(pf);
            Resource r = jar.getResource(path);
            IO.copy(r.openInputStream(), f);
        }
    } finally {
        jar.close();
    }
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Instructions(aQute.bnd.osgi.Instructions) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 93 with Resource

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

the class bnd method _type.

@Description("List files int a JAR file, equivalent jar command t[vf] (syntax supported)")
public void _type(typeOptions opts) throws Exception {
    Jar jar;
    if (opts.file() != null) {
        File f = getFile(opts.file());
        if (!f.isFile()) {
            messages.NoSuchFile_(f);
            return;
        }
        jar = new Jar(f);
    } else {
        jar = new Jar("cin", System.in);
    }
    try {
        Instructions instructions = new Instructions(opts._arguments());
        Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
        for (String path : selected) {
            if (opts.verbose()) {
                Resource r = jar.getResource(path);
                err.printf("%8s %-32s %s\n", r.size(), new Date(r.lastModified()), path);
            } else
                err.printf("%s\n", path);
        }
    } finally {
        jar.close();
    }
}
Also used : FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Instructions(aQute.bnd.osgi.Instructions) File(java.io.File) Date(java.util.Date) Description(aQute.lib.getopt.Description)

Example 94 with Resource

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

the class BuilderTest method testCopyDirectory.

public static void testCopyDirectory() throws Exception {
    Builder bmaker = new Builder();
    try {
        Properties p = new Properties();
        p.setProperty("-resourceonly", "true");
        p.setProperty("Include-Resource", "bnd=bnd");
        bmaker.setProperties(p);
        Jar jar = bmaker.build();
        assertTrue(bmaker.check());
        Map<String, Resource> map = jar.getDirectories().get("bnd");
        assertNotNull(map);
        assertEquals(2, map.size());
    } finally {
        bmaker.close();
    }
}
Also used : Builder(aQute.bnd.osgi.Builder) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 95 with Resource

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

the class MakeTest method testComplexOnDemand.

/**
	 * Check if we can create a jar on demand through the make facility with a
	 * new name.
	 * 
	 * @throws Exception
	 */
public static void testComplexOnDemand() throws Exception {
    Builder bmaker = new Builder();
    Properties p = new Properties();
    p.setProperty("-resourceonly", "true");
    p.setProperty("-plugin", "aQute.bnd.make.MakeBnd, aQute.bnd.make.MakeCopy");
    p.setProperty("-make", "(*).jar;type=bnd;recipe=bnd/$1.bnd");
    p.setProperty("Include-Resource", "www/xyz.jar=ondemand.jar");
    bmaker.setProperties(p);
    bmaker.setClasspath(new String[] { "bin" });
    Jar jar = bmaker.build();
    Resource resource = jar.getResource("www/xyz.jar");
    assertNotNull(resource);
    assertTrue(resource instanceof JarResource);
    report(bmaker);
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) JarResource(aQute.bnd.osgi.JarResource) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

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