geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1467077 - /geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
Date Thu, 11 Apr 2013 20:29:29 GMT
Author: gawor
Date: Thu Apr 11 20:29:29 2013
New Revision: 1467077

URL: http://svn.apache.org/r1467077
Log:
GERONIMO-6448: Make sure we always close input stream - work-around a bug in Aries' BundleManfiest

Modified:
    geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java?rev=1467077&r1=1467076&r2=1467077&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplicationManager.java
Thu Apr 11 20:29:29 2013
@@ -17,6 +17,7 @@
 package org.apache.geronimo.aries;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -196,7 +197,7 @@ public class GeronimoApplicationManager 
         for (File file : baseDir.listFiles()) {
             if (file.isDirectory()) {
                 if (file.getName().endsWith(".jar")) {
-                    BundleManifest bm = BundleManifest.fromBundle(file);
+                    BundleManifest bm = fromBundle(file);
                     if (bm != null && bm.isValid()) {
                         bundleInfos.add(new SimpleBundleInfo(applicationMetadataFactory,
bm, "reference:" + file.toURI().toString()));                
                     }
@@ -205,7 +206,7 @@ public class GeronimoApplicationManager 
                     continue;
                 }
             } else {
-                BundleManifest bm = BundleManifest.fromBundle(file);
+                BundleManifest bm = fromBundle(file);
                 if (bm != null && bm.isValid()) {
                     /*
                      * Pass file:// url instead of reference:file:// as bundle location to
make sure
@@ -219,6 +220,47 @@ public class GeronimoApplicationManager 
         }
     }
     
+    private BundleManifest fromBundle(File file) {
+        if (file.isFile()) {
+            // it's a jar file
+            FileInputStream in = null;
+            try {
+                in = new FileInputStream(file);
+                return BundleManifest.fromBundle(in);
+            } catch (IOException e) {
+                LOG.debug("Error reading file: " + file, e);
+            } finally {
+                IOUtils.close(in);
+            }
+            return null;
+        } else if (file.isDirectory()) {
+            // it's a jar directory
+            File manifestFile = new File(file, JarFile.MANIFEST_NAME);
+            if (manifestFile.isFile()) {
+                FileInputStream in = null;
+                try {
+                    in = new FileInputStream(manifestFile);
+                    return new BundleManifest(in);
+                } catch (IOException e) {
+                    LOG.debug("Error reading manifest file: " + file, e);
+                } finally {
+                    IOUtils.close(in);
+                }
+            }
+            return null;
+        } else {
+            throw new IllegalArgumentException("Unsupported file type: " + file);
+        }
+    }
+    
+    private BundleManifest fromBundle(InputStream jarInputStream) {
+        try {
+            return BundleManifest.fromBundle(jarInputStream);
+        } finally {
+            IOUtils.close(jarInputStream);
+        }
+    }
+    
     private Set<BundleInfo> getBundleInfos(Bundle bundle) throws IOException, ManagementException
{
         ApplicationMetadataFactory applicationMetadataFactory = getApplicationMetadataFactory();
         Set<BundleInfo> bundleInfos = new HashSet<BundleInfo>();
@@ -228,7 +270,7 @@ public class GeronimoApplicationManager 
             if (url.getPath().endsWith("/")) {
                 continue;
             }
-            BundleManifest bm = BundleManifest.fromBundle(url.openStream());
+            BundleManifest bm = fromBundle(url.openStream());
             if (bm != null && bm.isValid()) {
                 bundleInfos.add(new SimpleBundleInfo(applicationMetadataFactory, bm, url.toExternalForm()));
             }



Mime
View raw message