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