geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From viol...@apache.org
Subject svn commit: r1359606 - in /geronimo/server/branches/3.0: framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ plugins/aries/ger...
Date Tue, 10 Jul 2012 11:34:09 GMT
Author: violalu
Date: Tue Jul 10 11:34:08 2012
New Revision: 1359606

URL: http://svn.apache.org/viewvc?rev=1359606&view=rev
Log:
GERONIMO-6370 update hotswapclass and updateebacontent:copy files to directory not jar file

Modified:
    geronimo/server/branches/3.0/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
    geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
    geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationUpdateHelper.java

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java?rev=1359606&r1=1359605&r2=1359606&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/ExtendedDeploymentManager.java
Tue Jul 10 11:34:08 2012
@@ -308,8 +308,8 @@ public abstract class ExtendedDeployment
     /**
      * Only support local bundle update
      */
-    public boolean hotSwapEBAContent(AbstractName applicationGBeanName, long bundleId, File
changesFile, boolean updateArchive) throws Exception {
-        Object[] arguments = new Object[] {bundleId, changesFile, updateArchive};
+    public boolean hotSwapEBAContent(AbstractName applicationGBeanName, long bundleId, File
changesDir, boolean updateArchive) throws Exception {
+        Object[] arguments = new Object[] {bundleId, changesDir, updateArchive};
         String[] argumentTypes = new String[] {long.class.getName(), File.class.getName(),
boolean.class.getName()};
         return (Boolean) kernel.invoke(applicationGBeanName, "hotSwapApplicationContent",
arguments, argumentTypes);
     }

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java?rev=1359606&r1=1359605&r2=1359606&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/FileUtils.java
Tue Jul 10 11:34:08 2012
@@ -43,6 +43,7 @@ import java.util.Set;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -218,6 +219,41 @@ public class FileUtils {
             }
         }
     }
+    
+    //Overwrite files in dest directory
+    public static void recursiveCopyOverwrite(File srcDir, File destDir) throws IOException
{
+        if (srcDir == null)
+            throw new NullPointerException("sourceDir is null");
+        if (destDir == null)
+            throw new NullPointerException("destDir is null");
+        if (!srcDir.isDirectory() || !srcDir.canRead()) {
+            throw new IllegalArgumentException("Source directory must be a readable directory
" + srcDir);
+        }
+        
+        if (srcDir.equals(destDir)) {
+            throw new IllegalArgumentException("Source and destination directory are the
same " + srcDir);
+        }
+        
+        if (!destDir.exists()) {
+            destDir.mkdirs();
+        }
+        
+        if (!destDir.exists()) {
+            throw new IOException("Could not create destination directory " + destDir);
+        }
+        File[] srcFiles = srcDir.listFiles();
+        if (srcFiles != null) {
+            for (int i = 0; i < srcFiles.length; i++) {
+                File srcFile = srcFiles[i];
+                File destFile = new File(destDir, srcFile.getName());
+                if (srcFile.isDirectory()) {
+                    recursiveCopyOverwrite(srcFile, destFile);
+                } else {
+                    copyFile(srcFile, destFile);
+                }
+            }
+        }
+    }
 
     public static boolean recursiveDelete(File root) {
         return recursiveDelete(root, null);
@@ -439,6 +475,49 @@ public class FileUtils {
             logger.debug(file.getPath());
         }
     }
+    
+    public static void unpackFile(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
+            }           
+        }
+    }
 
     public static String removeExtension(String name, String extension) {
         if (name.endsWith(extension)) {

Modified: geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationUpdateHelper.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationUpdateHelper.java?rev=1359606&r1=1359605&r2=1359606&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationUpdateHelper.java
(original)
+++ geronimo/server/branches/3.0/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationUpdateHelper.java
Tue Jul 10 11:34:08 2012
@@ -164,10 +164,10 @@ public class ApplicationUpdateHelper {
         }
         
         if (updateArchive) {
-            // create updated bundle jar & update archive
+            // create updated bundle directory
             File updatedBundleFile = null;
             try {
-                updatedBundleFile = createUpdatedJarFile(targetBundle, changesFile);
+                updatedBundleFile = createUpdatedJarDir(targetBundle, changesFile);
                 updateEBA(targetBundle, updatedBundleFile);
             } catch (Exception e) {
                 LOG.warn("Error updating application archive with the new contents. " +
@@ -180,6 +180,8 @@ public class ApplicationUpdateHelper {
         return true;
     }
     
+    
+    
     private boolean hotSwapClasses(Bundle bundle, File changesFile) {
         String bundleName = bundle.getSymbolicName();
         
@@ -339,7 +341,8 @@ public class ApplicationUpdateHelper {
        return builder.toString();
     }
     
-    private File createUpdatedJarFile(Bundle targetBundle, File changesFile) throws IOException
{
+        
+    private File createUpdatedJarDir(Bundle targetBundle, File changesFile) throws IOException
{
         File ebaArchive = applicationGBean.getApplicationArchive();
         
         String bundleNameInApp = getBundleNameInArchive(targetBundle);
@@ -352,20 +355,26 @@ public class ApplicationUpdateHelper {
     }
 
     private File createUpdateJarFileDirectory(File changesFile, File ebaArchive, String bundleNameInApp)
throws IOException {
+        if(bundleNameInApp.endsWith("/")){
+            bundleNameInApp = bundleNameInApp.substring(0, bundleNameInApp.length() - 1);
+        }
         File sourceFile = new File(ebaArchive, bundleNameInApp);
+        
         if (!sourceFile.exists()) {
             throw new IOException("Unable to locate " + bundleNameInApp + " in " + ebaArchive);
         }
-        File updatedFile = null;
+        File updatedDir = null;
         try {
-            updatedFile = File.createTempFile(bundleNameInApp, ".jar");
-            JarInputStream jarIn = new JarInputStream(new FileInputStream(sourceFile));
-            updateJarFile(jarIn, changesFile, updatedFile);
+            updatedDir = FileUtils.createTempDir();
+            //JarInputStream jarIn = new JarInputStream(new FileInputStream(sourceFile));
+            //Extract changes file in a jar to a temp directory
+            FileUtils.unpackFile(new FileInputStream(changesFile), updatedDir);         
  
+           
         } catch (IOException e) {
-            deleteFile(updatedFile);
+            FileUtils.recursiveDelete(updatedDir);
             throw e;
         }
-        return updatedFile;
+        return updatedDir;
     }
 
     private File createUpdateJarFileArchive(File changesFile, File ebaArchive, String bundleNameInApp)
throws IOException {
@@ -445,6 +454,10 @@ public class ApplicationUpdateHelper {
         File ebaArchive = applicationGBean.getApplicationArchive();
 
         String bundleNameInApp = getBundleNameInArchive(bundle);
+        
+        if(bundleNameInApp.endsWith("/")){
+            bundleNameInApp = bundleNameInApp.substring(0, bundleNameInApp.length() - 1);
+        }
 
         LOG.debug("Updating {} application archive with new contents for {}", ebaArchive,
bundleNameInApp);
 
@@ -458,7 +471,16 @@ public class ApplicationUpdateHelper {
     private void updateApplicationDirectory(File ebaArchive, File bundleFile, String bundleNameInApp)
throws IOException {
         File destinationFile = new File(ebaArchive, bundleNameInApp);
         LOG.debug("Updating contents of {} with {}", bundleNameInApp, bundleFile.getAbsolutePath());
-        FileUtils.copyFile(bundleFile, destinationFile);
+        if(bundleFile.isDirectory()){
+            FileUtils.recursiveCopyOverwrite(bundleFile, destinationFile);            
+        } else {
+           //First delete bundle directory, then extract bundle file to it
+            FileUtils.recursiveDelete(destinationFile);
+            FileUtils.unpackFile(new FileInputStream(bundleFile), destinationFile);
+            
+        }
+        
+        
     }
     
     private void updateApplicationArchive(File ebaArchive, File bundleFile, String bundleNameInApp)
throws IOException {



Mime
View raw message