throw new IllegalArgumentException(artifact + " is not installed.");
}
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);
PluginXmlUtil.writePluginMetadata(metadata, 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()) {
log.error("Unable to delete old plugin at " + dir.getAbsolutePath());
throw new IOException("Unable to delete old plugin at " + dir.getAbsolutePath());
}
if (!temp.renameTo(dir)) {