public void savePluginXML()

in plugins/org.apache.geronimo.st.v21.core/src/main/java/org/apache/geronimo/st/v21/core/operations/GeronimoServerV21PluginManager.java [219:305]


    public void savePluginXML (String configId, Object pluginMetaData) {
        Trace.tracePoint("Entry", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", configId, pluginMetaData);

        PluginType metadata = (PluginType) pluginMetaData;
        
        Artifact artifact = Artifact.create(configId);
        File dir = new File (getArtifactLocation(artifact));

        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);
                        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()) {
                    String message = CommonMessages.bind(CommonMessages.errorDeletePlugin, dir.getAbsolutePath());
                    Trace.tracePoint("Throw", Activator.traceOperations, "GeronimoServerPluginManager.savePluginXML", message);
                    throw new Exception(message);
                }
                if (!temp.renameTo(dir)) {
                    String message = CommonMessages.bind(CommonMessages.errorMovePlugin, temp.getAbsolutePath(), dir.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");
    }