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();
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations