geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1156005 - in /geronimo/server/trunk: framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/ framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/ plugins/j2ee/geronimo-j2ee-builder/sr...
Date Wed, 10 Aug 2011 03:12:35 GMT
Author: xuhaihong
Date: Wed Aug 10 03:12:34 2011
New Revision: 1156005

URL: http://svn.apache.org/viewvc?rev=1156005&view=rev
Log:
GERONIMO-6106 Clean up temp files created in the deployment process

Modified:
    geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java
    geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
    geronimo/server/trunk/plugins/jetty8/geronimo-jetty8-builder/src/main/java/org/apache/geronimo/jetty8/deployment/JettyModuleBuilder.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java

Modified: geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java?rev=1156005&r1=1156004&r2=1156005&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-deployment/src/main/java/org/apache/geronimo/deployment/Deployer.java
Wed Aug 10 03:12:34 2011
@@ -329,7 +329,7 @@ public class Deployer implements GBeanLi
         return configID;
     }
 
-    private List install(File targetFile,
+    private List<String> install(File targetFile,
             boolean install,
             Manifest manifest,
             ConfigurationStore store,
@@ -346,7 +346,7 @@ public class Deployer implements GBeanLi
         Thread thread = Thread.currentThread();
         ClassLoader oldCl = thread.getContextClassLoader();
         //TODO OSGI fixme
-        thread.setContextClassLoader( new BundleClassLoader(context.getConfiguration().getBundle()));
+        thread.setContextClassLoader(new BundleClassLoader(context.getConfiguration().getBundle()));
         try {
             try {
                 configurationDatas.add(context.getConfigurationData());
@@ -384,7 +384,7 @@ public class Deployer implements GBeanLi
                 return deployedURIs;
             } else {
                 configsCleanupRequired = true;
-                return Collections.EMPTY_LIST;
+                return Collections.<String>emptyList();
             }
         } catch (DeploymentException e) {
             configsCleanupRequired = true;
@@ -403,6 +403,12 @@ public class Deployer implements GBeanLi
         } finally {
             thread.setContextClassLoader(oldCl);
             context.close();
+            //Clean up the temporary directory, now the deployment process is different with
the old strategy
+            //Due to the applications installed in the repository folder is of archived type,
+            //the deployed application will be extracted to a temporary folder for analysis.
+            if (context.getBaseDir() != null && !FileUtils.recursiveDelete(context.getBaseDir()))
{
+                reaper.delete(context.getBaseDir().getAbsolutePath(), "delete");
+            }
             if (configsCleanupRequired) {
                 // We do this after context is closed so the module jar isn't open
                 cleanupConfigurations(configurationDatas);

Modified: geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java?rev=1156005&r1=1156004&r2=1156005&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java
(original)
+++ geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java
Wed Aug 10 03:12:34 2011
@@ -41,11 +41,16 @@ import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * @version $Rev$ $Date$
  */
 public final class JarUtils {
 
+    private static final Logger logger = LoggerFactory.getLogger(JarUtils.class);
+
     private JarUtils() {
     }
 
@@ -200,6 +205,35 @@ public final class JarUtils {
         }
     }
 
+    public static void deleteJarFileURL(JarFile jarFile, URL jarFileUrl) {
+        try {
+            if (jarFile instanceof NestedJarFile) {
+                NestedJarFile nestedJar = (NestedJarFile) jarFile;
+                if (nestedJar.isUnpacked()) {
+                    JarFile baseJar = nestedJar.getBaseJar();
+                    if (baseJar instanceof UnpackedJarFile) {
+                        return;
+                    }
+                }
+            }
+            if (jarFile instanceof UnpackedJarFile) {
+                //Leave it there, as the URL is from a unpacked jar file
+                return;
+            } else {
+                if (jarUrlRewrite) {
+                    new File(jarFileUrl.getFile()).delete();
+                } else {
+                    //Leave it there, as it is a jar entry URL
+                    return;
+                }
+            }
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("unable to delete jar file URL " + jarFileUrl + " created from
" + jarFile.getName(), e);
+            }
+        }
+    }
+
     public static JarFile createJarFile(File jarFile) throws IOException {
         if (jarFile.isDirectory()) {
             return new UnpackedJarFile(jarFile);

Modified: geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java?rev=1156005&r1=1156004&r2=1156005&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
(original)
+++ geronimo/server/trunk/plugins/j2ee/geronimo-j2ee-builder/src/main/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
Wed Aug 10 03:12:34 2011
@@ -837,11 +837,17 @@ public class EARConfigBuilder implements
     }
 
     private void cleanupContext(EARContext earContext) {
-        if (earContext != null) {
-            try {
-                earContext.close();
-            } catch (Exception e) {
-            }
+        if (earContext == null) {
+            return;
+        }
+        File tempDirectory = earContext.getBaseDir();
+        try {
+            earContext.close();
+        } catch (Exception e) {
+        }
+        try {
+            cleanupConfigurationDir(tempDirectory);
+        } catch (Exception e) {
         }
     }
 

Modified: geronimo/server/trunk/plugins/jetty8/geronimo-jetty8-builder/src/main/java/org/apache/geronimo/jetty8/deployment/JettyModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/jetty8/geronimo-jetty8-builder/src/main/java/org/apache/geronimo/jetty8/deployment/JettyModuleBuilder.java?rev=1156005&r1=1156004&r2=1156005&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/jetty8/geronimo-jetty8-builder/src/main/java/org/apache/geronimo/jetty8/deployment/JettyModuleBuilder.java
(original)
+++ geronimo/server/trunk/plugins/jetty8/geronimo-jetty8-builder/src/main/java/org/apache/geronimo/jetty8/deployment/JettyModuleBuilder.java
Wed Aug 10 03:12:34 2011
@@ -268,9 +268,11 @@ public class JettyModuleBuilder extends 
         // parse the spec dd
         String specDD = null;
         WebApp webApp = null;
+        boolean specDDUrlCleanUpRequired = false;
         try {
             if (specDDUrl == null) {
                 specDDUrl = JarUtils.createJarURL(moduleFile, "WEB-INF/web.xml");
+                specDDUrlCleanUpRequired = true;
             }
 
             // read in the entire specDD as a string, we need this for getDeploymentDescriptor
@@ -350,6 +352,10 @@ public class JettyModuleBuilder extends 
         for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
             mbe.createModule(module, plan, moduleFile, targetPath, specDDUrl, environment,
contextRoot, earName, naming, idBuilder);
         }
+
+        if (specDDUrlCleanUpRequired && specDDUrl != null) {
+            JarUtils.deleteJarFileURL(moduleFile, specDDUrl);
+        }
         return module;
     }
 

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java?rev=1156005&r1=1156004&r2=1156005&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7-builder/src/main/java/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilder.java
Wed Aug 10 03:12:34 2011
@@ -270,7 +270,7 @@ public class TomcatModuleBuilder extends
         }
         return module;
     }
-    
+
     protected Module createModule(Object plan, JarFile moduleFile, String targetPath, URL
specDDUrl, Environment earEnvironment, String contextRoot, Module parentModule, Naming naming,
ModuleIDBuilder idBuilder) throws DeploymentException {
         assert moduleFile != null : "moduleFile is null";
         assert targetPath != null : "targetPath is null";
@@ -279,17 +279,19 @@ public class TomcatModuleBuilder extends
         // parse the spec dd
         String specDD = null;
         WebApp webApp = null;
+        boolean specDDUrlCleanUpRequired = false;
         try {
             if (specDDUrl == null) {
                 specDDUrl = JarUtils.createJarURL(moduleFile, "WEB-INF/web.xml");
+                specDDUrlCleanUpRequired = true;
             }
 
             // read in the entire specDD as a string, we need this for getDeploymentDescriptor
             // on the J2ee management object
             specDD = JarUtils.readAll(specDDUrl);
-             
+
             InputStream in = null;
-            
+
             // firstly validate the DD xml file, if it is defined by a schema.
             if (identifySpecDDSchemaVersion(specDD) >= 2.4f){
                 in = specDDUrl.openStream();
@@ -321,7 +323,7 @@ public class TomcatModuleBuilder extends
             if (e instanceof DeploymentException) {
                 throw new DeploymentException(e);
             }
-           
+
             if (!moduleFile.getName().endsWith(".war")) {
                 //not for us
                 return null;
@@ -381,6 +383,10 @@ public class TomcatModuleBuilder extends
         for (ModuleBuilderExtension mbe : moduleBuilderExtensions) {
             mbe.createModule(module, plan, moduleFile, targetPath, specDDUrl, environment,
contextRoot, earName, naming, idBuilder);
         }
+
+        if(specDDUrlCleanUpRequired && specDDUrl != null) {
+            JarUtils.deleteJarFileURL(moduleFile, specDDUrl);
+        }
         return module;
     }
 



Mime
View raw message