out.write(buf, 0, rd);
}
}
File spoolModified(InputStream ins) throws IOException {
JarInputStream jis = new JarInputStream(ins);
// immediately handle the manifest
JarOutputStream jos;
Manifest manifest = jis.getManifest();
if (manifest == null) {
throw new IOException("Missing Manifest !");
}
String symbolicName = manifest.getMainAttributes().getValue(
"Bundle-SymbolicName");
if (symbolicName == null || symbolicName.length() == 0) {
throw new IOException("Missing Symbolic Name in Manifest !");
}
String version = manifest.getMainAttributes().getValue("Bundle-Version");
Version v = Version.parseVersion(version);
if (v.getQualifier().indexOf("SNAPSHOT") >= 0) {
String tStamp;
synchronized (DATE_FORMAT) {
tStamp = DATE_FORMAT.format(new Date());
}
version = v.getMajor() + "." + v.getMinor() + "." + v.getMicro()
+ "." + v.getQualifier().replaceAll("SNAPSHOT", tStamp);
manifest.getMainAttributes().putValue("Bundle-Version", version);
}
File bundle = new File(this.repoLocation, symbolicName + "-" + v + ".jar");
OutputStream out = null;
try {
out = new FileOutputStream(bundle);
jos = new JarOutputStream(out, manifest);
jos.setMethod(JarOutputStream.DEFLATED);
jos.setLevel(Deflater.BEST_COMPRESSION);
JarEntry entryIn = jis.getNextJarEntry();
while (entryIn != null) {
JarEntry entryOut = new JarEntry(entryIn.getName());
entryOut.setTime(entryIn.getTime());
entryOut.setComment(entryIn.getComment());
jos.putNextEntry(entryOut);
if (!entryIn.isDirectory()) {
spool(jis, jos);
}
jos.closeEntry();
jis.closeEntry();
entryIn = jis.getNextJarEntry();
}
// close the JAR file now to force writing
jos.close();