geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viol...@apache.org
Subject svn commit: r1357538 - in /geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries: ApplicationInstaller.java GeronimoApplication.java
Date Thu, 05 Jul 2012 10:30:12 GMT
Author: violalu
Date: Thu Jul  5 10:30:12 2012
New Revision: 1357538

URL: http://svn.apache.org/viewvc?rev=1357538&view=rev
Log:
GERONIMO-6370 extract bundles when install EBA, and install it via reference:file

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

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java?rev=1357538&r1=1357537&r2=1357538&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationInstaller.java
Thu Jul  5 10:30:12 2012
@@ -19,9 +19,11 @@ package org.apache.geronimo.aries;
 import java.io.File;
 import java.io.IOException;
 import java.util.Collection;
+import java.util.zip.ZipFile;
 
 import org.apache.aries.application.ApplicationMetadata;
 import org.apache.aries.application.management.AriesApplication;
+import org.apache.aries.application.utils.manifest.BundleManifest;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
@@ -47,6 +49,7 @@ import org.apache.geronimo.kernel.reposi
 import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.util.BundleUtil;
 import org.apache.geronimo.kernel.util.FileUtils;
+import org.apache.geronimo.kernel.util.JarUtils;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.slf4j.Logger;
@@ -126,6 +129,9 @@ public class ApplicationInstaller implem
         Naming naming = kernel.getNaming();
         AbstractName moduleName = naming.createRootName(configId, configId.toString(), "AriesApplication");
         //Use a temporary folder to hold the extracted files for analysis use
+        File ariesTempDirectory = FileUtils.createTempDir();
+        app.store(ariesTempDirectory);
+        
         File tempDirectory = FileUtils.createTempDir();
         try {
             DeploymentContext context = new DeploymentContext(tempDirectory,
@@ -140,8 +146,32 @@ public class ApplicationInstaller implem
 
             context.flush();
             context.initializeConfiguration();
-
-            app.store(tempDirectory);
+            
+			// extract bundle in EBA applications
+			for (File file : ariesTempDirectory.listFiles()) {
+				if (file.isFile()) {
+					BundleManifest bm = BundleManifest.fromBundle(file);
+					if (bm != null && bm.isValid()) {
+						//extract it
+						File dir = new File(tempDirectory, file.getName());
+						
+						if (dir != null && !dir.exists()) {
+				            boolean success = dir.mkdirs();
+				            if (!success) {
+				                throw new IOException("Cannot create directory " + dir.getAbsolutePath());
+				            }
+				        }
+						JarUtils.unzipToDirectory(new ZipFile(file), dir);					
+					}
+				} else {
+					for(File f : file.listFiles()){
+						FileUtils.copyFile(f, new File(tempDirectory, file.getName() + '/' + f.getName()));
+					}
+				}
+			}
+			
+			FileUtils.recursiveDelete(ariesTempDirectory);
+            
 
             AbstractName name = naming.createChildName(moduleName, "AriesApplication", "GBean");
             GBeanData data = new GBeanData(name, ApplicationGBean.class);

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java?rev=1357538&r1=1357537&r2=1357538&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/GeronimoApplication.java
Thu Jul  5 10:30:12 2012
@@ -17,7 +17,9 @@
 package org.apache.geronimo.aries;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -25,6 +27,8 @@ import java.net.URL;
 import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 import org.apache.aries.application.ApplicationMetadata;
 import org.apache.aries.application.ApplicationMetadataFactory;
@@ -33,9 +37,11 @@ import org.apache.aries.application.Depl
 import org.apache.aries.application.management.AriesApplication;
 import org.apache.aries.application.management.BundleInfo;
 import org.apache.aries.application.utils.AppConstants;
-import org.apache.aries.application.utils.filesystem.IOUtils;
+import org.apache.geronimo.kernel.util.IOUtils;
 import org.apache.aries.application.utils.management.SimpleBundleInfo;
 import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.geronimo.kernel.repository.UnpackArtifactTypeHandler;
+import org.apache.geronimo.kernel.util.FileUtils;
 import org.apache.xbean.osgi.bundle.util.BundleUtils;
 import org.osgi.framework.Bundle;
 
@@ -109,11 +115,12 @@ public class GeronimoApplication impleme
    
     private void collectFileSystemBasedBundleInfos(File baseDir, ApplicationMetadataFactory
applicationFactory) throws IOException {
         for (File file : baseDir.listFiles()) {
-            if (file.isDirectory()) {
+            if (file.isDirectory() && !file.getCanonicalPath().endsWith(".jar"))
{
                 collectFileSystemBasedBundleInfos(file, applicationFactory);
                 continue;
             }
             BundleManifest bm = BundleManifest.fromBundle(file);
+            
             if (bm != null && bm.isValid()) {
                 /*
                  * Pass file:// url instead of reference:file:// as bundle location to make
sure
@@ -121,7 +128,8 @@ public class GeronimoApplication impleme
                  * application bundles are updated at runtime, specifically, when 
                  * ApplicationGBean.hotSwapApplicationContent() is called.
                  */
-                bundleInfo.add(new SimpleBundleInfo(applicationFactory, bm, file.toURI().toString()));
+                bundleInfo.add(new SimpleBundleInfo(applicationFactory, bm, "reference:"
+ file.toURI().toString()));       
+                
             }
         }
     }
@@ -139,4 +147,47 @@ public class GeronimoApplication impleme
             }
         }
     }
-}
+    
+    private void unpackBundleFile(InputStream source, File target) throws IOException{
+    	
+        ZipInputStream in = new ZipInputStream(source);
+        try {
+
+            int threshold = 10240;
+            byte[] buffer = new byte[10240];
+
+            for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry())
{
+                File file = new File(target, entry.getName());
+                if (entry.isDirectory()) {
+                    file.mkdirs();
+                } else {
+                    if (!entry.getName().equals("META-INF/startup-jar")) {
+                        file.getParentFile().mkdirs();
+                        OutputStream out = new FileOutputStream(file);
+                        try {
+                            int count;
+                            while ((count = in.read(buffer)) > 0) {
+                                out.write(buffer, 0, count);
+                                
+                                }
+                            } finally {
+                            IOUtils.flush(out);
+                            out.close();
+                        }
+                        in.closeEntry();
+                    }
+                }
+        }}
+            
+        catch (IOException e) {
+            FileUtils.recursiveDelete(target);
+            throw e;
+        } finally {
+            try {
+				in.close();
+			} catch (IOException e) {
+				//Ignore
+			}           
+        }
+    }
+}
\ No newline at end of file



Mime
View raw message