geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsis...@apache.org
Subject svn commit: r412943 - /geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
Date Fri, 09 Jun 2006 06:07:24 GMT
Author: jsisson
Date: Thu Jun  8 23:07:24 2006
New Revision: 412943

URL: http://svn.apache.org/viewvc?rev=412943&view=rev
Log:
GERONIMO-2096 Fix issue where PluginInstallerGBean.updatePluginMetadata(..) may leave geronimo-plugin.xml
file open

Modified:
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java?rev=412943&r1=412942&r2=412943&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/plugin/PluginInstallerGBean.java
Thu Jun  8 23:07:24 2006
@@ -260,11 +260,11 @@
                 Manifest manifest = input.getManifest();
                 JarOutputStream out = manifest == null ? new JarOutputStream(new BufferedOutputStream(new
FileOutputStream(temp)))
                         : new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)),
manifest);
-                Enumeration enum = input.entries();
+                Enumeration en = input.entries();
                 byte[] buf = new byte[4096];
                 int count;
-                while (enum.hasMoreElements()) {
-                    JarEntry entry = (JarEntry) enum.nextElement();
+                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);
@@ -298,13 +298,14 @@
             } catch (Exception e) {
                 log.error("Unable to update plugin metadata", e);
                 throw new RuntimeException("Unable to update plugin metadata", e);
-            }
+            } // TODO this really should have a finally block to ensure streams are closed
         } else {
             File meta = new File(dir, "META-INF");
             if(!meta.isDirectory() || !meta.canRead()) {
                 throw new IllegalArgumentException(metadata.getModuleId()+" is not a plugin!");
             }
             File xml = new File(meta, "geronimo-plugin.xml");
+            FileOutputStream fos = null;
             try {
                 if(!xml.isFile()) {
                     if(!xml.createNewFile()) {
@@ -316,9 +317,21 @@
                 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(xml));
+                fos = new FileOutputStream(xml);
+                // use a FileOutputStream instead of a File on the StreamResult 
+                // constructor as problems were encountered with the file not being closed.
+                StreamResult sr = new StreamResult(fos); 
+                xform.transform(new DOMSource(doc), sr);
             } catch (Exception e) {
                 log.error("Unable to save plugin metadata for "+metadata.getModuleId(), e);
+            } finally {
+                if (fos != null) {
+                    try {
+                        fos.close();
+                    } catch (IOException ignored) {
+                        // ignored
+                    }
+                }
             }
         }
     }



Mime
View raw message