if(!dir.isDirectory()) { // must be a packed (JAR-formatted) plugin
try {
File temp = new File(dir.getParentFile(), dir.getName()+".temp");
JarFile input = new JarFile(dir);
Manifest manifest = input.getManifest();
JarOutputStream out = manifest == null ? new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)))
: new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)), manifest);
Enumeration en = input.entries();
byte[] buf = new byte[4096];
int count;
while (en.hasMoreElements()) {
JarEntry entry = (JarEntry) en.nextElement();
if(entry.getName().equals("META-INF/geronimo-plugin.xml")) {
entry = new JarEntry(entry.getName());
out.putNextEntry(entry);
Document doc = writePluginMetadata(metadata);
TransformerFactory xfactory = TransformerFactory.newInstance();
Transformer xform = xfactory.newTransformer();
xform.setOutputProperty(OutputKeys.INDENT, "yes");
xform.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
xform.transform(new DOMSource(doc), new StreamResult(out));
} else if(entry.getName().equals("META-INF/MANIFEST.MF")) {
// do nothing, already passed in a manifest
} else {
out.putNextEntry(entry);
InputStream in = input.getInputStream(entry);
while((count = in.read(buf)) > -1) {
out.write(buf, 0, count);
}
in.close();
out.closeEntry();
}
}
out.flush();
out.close();
input.close();
if(!dir.delete()) {
throw new IOException("Unable to delete old plugin at "+dir.getAbsolutePath());
}
if(!temp.renameTo(dir)) {