in plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/operations/GeronimoServerPluginManager.java [218:303]
public void savePluginXML (String configId, PluginType metadata) {
Trace.tracePoint("Entry", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", configId, metadata);
Artifact artifact = Artifact.create(configId);
File dir = new File (getArtifactLocation(artifact));
File artifactFile = new File(addFilename(dir.getAbsolutePath(),artifact));
if (!artifactFile.isDirectory()) { // must be a packed (JAR-formatted) plugin
try {
File temp = new File(dir.getParentFile(), dir.getName() + ".temp");
JarFile input = new JarFile(artifactFile);
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);
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 (!artifactFile.delete()) {
String message = CommonMessages.bind(CommonMessages.errorDeletePlugin, artifactFile.getAbsolutePath());
Trace.tracePoint("Throw", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", message);
throw new Exception(message);
}
if (!temp.renameTo(artifactFile)) {
String message = CommonMessages.bind(CommonMessages.errorMovePlugin, temp.getAbsolutePath(), artifactFile.getAbsolutePath());
Trace.tracePoint("Throw", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", message);
throw new Exception(message);
}
} catch (Exception e) {
throw new RuntimeException(CommonMessages.errorUpdateMetadata, e);
}
} else {
File meta = new File(addFilename(dir.getAbsolutePath(), artifact), "META-INF");
if (!meta.isDirectory() || !meta.canRead()) {
String message = CommonMessages.bind(CommonMessages.badPlugin, artifact);
Trace.tracePoint("Throw", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", message);
throw new IllegalArgumentException(message);
}
File xml = new File(meta, "geronimo-plugin.xml");
FileOutputStream fos = null;
try {
if (!xml.isFile()) {
if (!xml.createNewFile()) {
String message = CommonMessages.bind(CommonMessages.errorCreateMetadata, artifact);
Trace.tracePoint("Throw", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", message);
throw new RuntimeException(message);
}
}
fos = new FileOutputStream(xml);
writePluginMetadata(metadata, fos);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception ignored) {
ignored.printStackTrace();
}
}
}
}
Trace.tracePoint("Exit", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML");
}