geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r1164356 - in /geronimo/server/trunk/plugins/tomcat: geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/ geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/ tomcat7/src/main/plan/
Date Fri, 02 Sep 2011 06:21:17 GMT
Author: xuhaihong
Date: Fri Sep  2 06:21:17 2011
New Revision: 1164356

URL: http://svn.apache.org/viewvc?rev=1164356&view=rev
Log:
GERONIMO-5743 Use DeploymentWatcher to delete the temporary directories while uninstalling
the applications

Added:
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
Modified:
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
    geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
    geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/plan/plan.xml

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java?rev=1164356&r1=1164355&r2=1164356&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/GeronimoStandardContext.java
Fri Sep  2 06:21:17 2011
@@ -106,6 +106,8 @@ import org.apache.tomcat.InstanceManager
 import org.apache.tomcat.util.IntrospectionUtils;
 import org.apache.webbeans.config.WebBeansContext;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
 
@@ -658,6 +660,7 @@ public class GeronimoStandardContext ext
         boolean getRealPathSupportRequired = applicationGetRealPathConfiguration == null
? !"false".equalsIgnoreCase(globalGetRealPathConfiguration) : !"false"
                 .equalsIgnoreCase(applicationGetRealPathConfiguration);
 
+        deleteTempDirectoryOnUndeployed(tomcatContext, tempRootDirectory);
         /**
          * Compute & check module checksum in order to determine if the expanded module
          * contents should be updated (old contents deleted & module re-expanded).
@@ -797,6 +800,32 @@ public class GeronimoStandardContext ext
         }
     }
 
+    private void deleteTempDirectoryOnUndeployed(TomcatContext tomcatContext, File tempDirectory)
{
+        if (!(tomcatContext instanceof TomcatWebAppContext)) {
+            return;
+        }
+        TomcatWebAppContext tomcatWebAppContext = (TomcatWebAppContext) tomcatContext;
+        BundleContext bundleContext = bundle.getBundleContext();
+        ServiceReference tomcatDeploymentWatcherReference = null;
+        try {
+            tomcatDeploymentWatcherReference = bundleContext.getServiceReference(TomcatDeploymentWatcher.class.getName());
+            if (tomcatDeploymentWatcherReference == null) {
+                return;
+            }
+            TomcatDeploymentWatcher tomcatDeploymentWatcher = (TomcatDeploymentWatcher) bundleContext.getService(tomcatDeploymentWatcherReference);
+            tomcatDeploymentWatcher.deleteOnUndeployed(tomcatWebAppContext.getAbstractName(),
tempDirectory);
+        } catch (Exception e) {
+            logger.warn("Unable to add temporary directory " + tempDirectory + "to the Tomcat
deployment watcher, that folder will not be delete on the undeployment", e);
+        } finally {
+            if (tomcatDeploymentWatcherReference != null) {
+                try {
+                    bundleContext.ungetService(tomcatDeploymentWatcherReference);
+                } catch (Exception e) {
+                }
+            }
+        }
+    }
+    
     private class SystemMethodValve extends ValveBase {
 
         public SystemMethodValve(){

Added: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java?rev=1164356&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
(added)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatDeploymentWatcher.java
Fri Sep  2 06:21:17 2011
@@ -0,0 +1,59 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.tomcat;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.OsgiService;
+import org.apache.geronimo.kernel.config.DeploymentWatcher;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.util.FileUtils;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@GBean
+@OsgiService
+public class TomcatDeploymentWatcher implements DeploymentWatcher {
+
+    private Map<AbstractName, File> abstractNameTempDirectoryMap = new ConcurrentHashMap<AbstractName,
File>();
+
+    @Override
+    public void deployed(Artifact artifact) {
+    }
+
+    @Override
+    public void undeployed(Artifact artifact) {
+        for (Iterator<Map.Entry<AbstractName, File>> it = abstractNameTempDirectoryMap.entrySet().iterator();
it.hasNext();) {
+            Map.Entry<AbstractName, File> entry = it.next();
+            if (entry.getKey().getArtifact().equals(artifact)) {
+                FileUtils.recursiveDelete(entry.getValue());
+                it.remove();
+            }
+        }
+    }
+
+    public void deleteOnUndeployed(AbstractName abName, File tempDirectory) {
+        abstractNameTempDirectoryMap.put(abName, tempDirectory);
+    }
+}

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java?rev=1164356&r1=1164355&r2=1164356&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/main/java/org/apache/geronimo/tomcat/TomcatWebAppContext.java
Fri Sep  2 06:21:17 2011
@@ -123,6 +123,7 @@ public class TomcatWebAppContext impleme
     private final Map<String,String> contextAttributes;
     private final WebBeansContext owbContext;
     private final InstanceManager instanceManager;
+    private final AbstractName abName;
 
     // JSR 77
     private final String j2EEServer;
@@ -169,7 +170,8 @@ public class TomcatWebAppContext impleme
             @ParamAttribute(name = "webAppInfo") WebAppInfo webAppInfo,
             @ParamAttribute(name = "contextAttributes") Map<String, String> contextAttributes,
             @ParamReference(name = "SharedOwbContext")SharedOwbContext sharedOwbContext,
-            @ParamSpecial(type = SpecialAttributeType.kernel) Kernel kernel)
+            @ParamSpecial(type = SpecialAttributeType.kernel) Kernel kernel,
+            @ParamSpecial(type = SpecialAttributeType.abstractName) AbstractName abName)
             throws Exception {
         assert classLoader != null;
         assert bundle != null;
@@ -185,6 +187,7 @@ public class TomcatWebAppContext impleme
         }
 
         this.objectName = objectName;
+        this.abName = abName;
         this.deploymentAttributes = deploymentAttributes;
         this.webAppInfo = webAppInfo;
         this.container = container;
@@ -496,6 +499,10 @@ public class TomcatWebAppContext impleme
         return webAppInfo;
     }
 
+    public AbstractName getAbstractName() {
+        return abName;
+    }
+
     /**
      * ObjectName must match this pattern: <p/>
      * domain:j2eeType=WebModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication

Modified: geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=1164356&r1=1164355&r2=1164356&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
(original)
+++ geronimo/server/trunk/plugins/tomcat/geronimo-tomcat7/src/test/java/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
Fri Sep  2 06:21:17 2011
@@ -31,6 +31,7 @@ import javax.transaction.TransactionMana
 
 import org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator;
 import org.apache.geronimo.connector.outbound.connectiontracking.GeronimoTransactionListener;
+import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.j2ee.jndi.ContextSource;
 import org.apache.geronimo.j2ee.jndi.WebContextSource;
 import org.apache.geronimo.kernel.config.ConfigurationData;
@@ -143,7 +144,8 @@ public abstract class AbstractWebModuleT
                 webAppInfo, //webAppinfo
                 new HashMap<String, String>(), // Map<String,String> contextAttributes;
                 null,
-                null);  //kernel
+                null,
+                new AbstractName(new URI("default/test/1.0/war?J2EEApplication=null,j2eeType=WebModule,name=default/test/1.0/war")));
 //kernel
         app.doStart();
         return app;
     }

Modified: geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/plan/plan.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/plan/plan.xml?rev=1164356&r1=1164355&r2=1164356&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/plan/plan.xml (original)
+++ geronimo/server/trunk/plugins/tomcat/tomcat7/src/main/plan/plan.xml Fri Sep  2 06:21:17
2011
@@ -98,6 +98,7 @@
         </reference>
     </gbean>
 
+    <gbean name="TomcatDeploymentWatcher" class="org.apache.geronimo.tomcat.TomcatDeploymentWatcher"/>
     <!--
     <gbean name="AprLifecycleListener" class="org.apache.geronimo.tomcat.LifecycleListenerGBean">
         <attribute name="className">org.apache.geronimo.tomcat.listener.GeronimoAprLifecycleListener</attribute>



Mime
View raw message