geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1359909 - in /geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries: ApplicationInstaller.java GeronimoApplication.java
Date Tue, 10 Jul 2012 21:21:35 GMT
Author: gawor
Date: Tue Jul 10 21:21:35 2012
New Revision: 1359909

URL: http://svn.apache.org/viewvc?rev=1359909&view=rev
Log:
GERONIMO-6370: Ability to store eba in packed or unpacked form and other minor cleanup

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=1359909&r1=1359908&r2=1359909&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
Tue Jul 10 21:21:35 2012
@@ -17,13 +17,18 @@
 package org.apache.geronimo.aries;
 
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
 import java.util.Collection;
-import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
 
 import org.apache.aries.application.ApplicationMetadata;
+import org.apache.aries.application.DeploymentMetadata;
 import org.apache.aries.application.management.AriesApplication;
-import org.apache.aries.application.utils.manifest.BundleManifest;
+import org.apache.aries.application.management.BundleInfo;
+import org.apache.aries.application.utils.AppConstants;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.service.EnvironmentBuilder;
@@ -49,6 +54,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.IOUtils;
 import org.apache.geronimo.kernel.util.JarUtils;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
@@ -129,9 +135,6 @@ 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,
@@ -146,33 +149,9 @@ public class ApplicationInstaller implem
 
             context.flush();
             context.initializeConfiguration();
-            
-            // 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);
-            
 
+            storeApplication(app, tempDirectory, true);
+            
             AbstractName name = naming.createChildName(moduleName, "AriesApplication", "GBean");
             GBeanData data = new GBeanData(name, ApplicationGBean.class);
             data.setAttribute("configId", configId);
@@ -187,6 +166,48 @@ public class ApplicationInstaller implem
             throw new DeploymentException("Error deploying application", e);
         }
     }
+    
+    private void storeApplication(AriesApplication app, File directory, boolean unpack) throws
IOException {
+        ApplicationMetadata appMetadata = app.getApplicationMetadata();
+        appMetadata.store(new File(directory, AppConstants.APPLICATION_MF));
+
+        DeploymentMetadata deploymentMetadata = app.getDeploymentMetadata();
+        if (deploymentMetadata != null) {
+            deploymentMetadata.store(new File(directory, AppConstants.DEPLOYMENT_MF));
+        }
+        
+        for (BundleInfo bi : app.getBundleInfo()) { 
+          // bi.getLocation() will return a URL to the source bundle. It may be of the form
+          // file:/path/to/my/file.jar, or
+          // jar:file:/my/path/to/eba.jar!/myBundle.jar
+          String bundleLocation = bi.getLocation();
+          String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/')
+ 1);
+          InputStream in = null;
+          try { 
+              URL bundleURL = new URL(bundleLocation);
+              in = bundleURL.openStream();
+              File target = new File(directory, bundleFileName);
+              if (unpack) {
+                  target.mkdirs();
+                  ZipInputStream zipIn = new ZipInputStream(in);
+                  try {
+                      JarUtils.unzipToDirectory(zipIn, target);
+                  } finally {
+                      IOUtils.close(zipIn);
+                  }
+              } else {
+                  FileOutputStream fileOut = new FileOutputStream(target);
+                  try {
+                      IOUtils.copy(in, fileOut);
+                  } finally {
+                      IOUtils.close(fileOut);
+                  }
+              }            
+          } finally {
+              IOUtils.close(in);
+          }
+        }
+    }
 
     public ConfigurationData finishInstall(DeploymentContext context, ConfigurationStore
targetConfigurationStore)
         throws ConfigurationAlreadyExistsException, DeploymentException {

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=1359909&r1=1359908&r2=1359909&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
Tue Jul 10 21:21:35 2012
@@ -17,9 +17,7 @@
 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;
@@ -27,8 +25,6 @@ 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;
@@ -37,11 +33,9 @@ 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.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.geronimo.kernel.util.IOUtils;
 import org.apache.xbean.osgi.bundle.util.BundleUtils;
 import org.osgi.framework.Bundle;
 
@@ -147,47 +141,5 @@ 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