Does this unconditionally remove the config.xml entry? The original idea was to only remove the config.xml entry if it had no customizations: if it has customizations we tried to leave it with load="false"

thanks
david jencks

On Dec 13, 2006, at 8:54 AM, [EMAIL PROTECTED] wrote:

Author: vamsic007
Date: Wed Dec 13 08:54:14 2006
New Revision: 486734

URL: http://svn.apache.org/viewvc?view=rev&rev=486734
Log:
GERONIMO-2437 Empty dirs and config.xml entries left behind after undeploy o Removes the uninstalled configurations from PersistentConfigurationList o Checks for parent directories upto 3 levels and deletes empty directories o FIXME: Repository is assumed to be Maven2Repository (thus checking 3 levels up). May need a mechanism to determine the repository type and the number of directory levels to check for empty dirs.

Modified:
geronimo/server/branches/1.1/modules/system/src/java/org/apache/ geronimo/system/configuration/RepositoryConfigurationStore.java geronimo/server/branches/1.2/modules/geronimo-system/src/main/ java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java geronimo/server/branches/2.0-M1/modules/geronimo-system/src/ main/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java geronimo/server/trunk/modules/geronimo-system/src/main/java/org/ apache/geronimo/system/configuration/RepositoryConfigurationStore.java

Modified: geronimo/server/branches/1.1/modules/system/src/java/org/ apache/geronimo/system/configuration/RepositoryConfigurationStore.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/1.1/ modules/system/src/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java? view=diff&rev=486734&r1=486733&r2=486734 ====================================================================== ======== --- geronimo/server/branches/1.1/modules/system/src/java/org/apache/ geronimo/system/configuration/RepositoryConfigurationStore.java (original) +++ geronimo/server/branches/1.1/modules/system/src/java/org/apache/ geronimo/system/configuration/RepositoryConfigurationStore.java Wed Dec 13 08:54:14 2006
@@ -46,6 +46,7 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.config.IOUtil;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
import org.apache.geronimo.kernel.repository.WritableListableRepository;
@@ -338,7 +339,37 @@
         }
         File location = repository.getLocation(configId);
         IOUtil.recursiveDelete(location);
- //todo: for Maven 2 repo, delete the version directory if there's nothing left in it (probably the case) + // Number of directory levels up, to check and delete empty parent directories in the repo
+        int dirDepth = 0;
+
+        // FIXME: Determine the repository type
+ // For now assume the repo is a Maven2Repository. This should not cause any harm even if it is an + // Maven1Repository, for it would be deleting the 'repository' directory if it happens to be empty.
+        boolean m2repo = true;
+
+        if(m2repo) {
+ // Check version, artifact and group directories, i.e. 3 levels up
+            dirDepth = 3;
+        }
+
+        File temp = location;
+        for(int i = 0; i < dirDepth; ++i) {
+ if((temp = temp.getParentFile()).listFiles().length == 0) {
+                // Directory is empty.  Remove it.
+                temp.delete();
+            } else {
+ // Directory is not empty. No need to check any more parent directories
+                break;
+            }
+        }
+
+        try {
+ // Is this the right way to get hold of PersistentConfigurationList? + PersistentConfigurationList configList = (PersistentConfigurationList) kernel.getGBean (PersistentConfigurationList.class);
+            configList.removeConfiguration(configId);
+        } catch (Exception e) {
+ log.warn("Unable to remove configuration from persistent configurations. id = "+configId, e);
+        }

         if (configurationInfo != null) {
             IOException ioException = null;

Modified: geronimo/server/branches/1.2/modules/geronimo-system/src/ main/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/1.2/ modules/geronimo-system/src/main/java/org/apache/geronimo/system/ configuration/RepositoryConfigurationStore.java? view=diff&rev=486734&r1=486733&r2=486734 ====================================================================== ======== --- geronimo/server/branches/1.2/modules/geronimo-system/src/main/ java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java (original) +++ geronimo/server/branches/1.2/modules/geronimo-system/src/main/ java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java Wed Dec 13 08:54:14 2006
@@ -45,6 +45,7 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.config.IOUtil;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
import org.apache.geronimo.kernel.repository.WritableListableRepository;
@@ -333,7 +334,36 @@
         }
         File location = repository.getLocation(configId);
         IOUtil.recursiveDelete(location);
- //todo: for Maven 2 repo, delete the version directory if there's nothing left in it (probably the case) + // Number of directory levels up, to check and delete empty parent directories in the repo
+        int dirDepth = 0;
+
+        // FIXME: Determine the repository type
+ // For now assume the repo is a Maven2Repository. This should not cause any harm even if it is an + // Maven1Repository, for it would be deleting the 'repository' directory if it happens to be empty.
+        boolean m2repo = true;
+        if(m2repo) {
+ // Check version, artifact and group directories, i.e. 3 levels up
+            dirDepth = 3;
+        }
+
+        File temp = location;
+        for(int i = 0; i < dirDepth; ++i) {
+ if((temp = temp.getParentFile()).listFiles().length == 0) {
+                // Directory is empty.  Remove it.
+                temp.delete();
+            } else {
+ // Directory is not empty. No need to check any more parent directories
+                break;
+            }
+        }
+
+        try {
+ // Is this the right way to get hold of PersistentConfigurationList? + PersistentConfigurationList configList = (PersistentConfigurationList) kernel.getGBean (PersistentConfigurationList.class);
+            configList.removeConfiguration(configId);
+        } catch (Exception e) {
+ log.warn("Unable to remove configuration from persistent configurations. id = "+configId, e);
+        }

         if (configurationInfo != null) {
             IOException ioException = null;

Modified: geronimo/server/branches/2.0-M1/modules/geronimo-system/ src/main/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0-M1/ modules/geronimo-system/src/main/java/org/apache/geronimo/system/ configuration/RepositoryConfigurationStore.java? view=diff&rev=486734&r1=486733&r2=486734 ====================================================================== ======== --- geronimo/server/branches/2.0-M1/modules/geronimo-system/src/ main/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java (original) +++ geronimo/server/branches/2.0-M1/modules/geronimo-system/src/ main/java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java Wed Dec 13 08:54:14 2006
@@ -45,6 +45,7 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.config.IOUtil;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
import org.apache.geronimo.kernel.repository.WritableListableRepository;
@@ -333,7 +334,37 @@
         }
         File location = repository.getLocation(configId);
         IOUtil.recursiveDelete(location);
- //todo: for Maven 2 repo, delete the version directory if there's nothing left in it (probably the case) + // Number of directory levels up, to check and delete empty parent directories in the repo
+        int dirDepth = 0;
+
+        // FIXME: Determine the repository type
+ // For now assume the repo is a Maven2Repository. This should not cause any harm even if it is an + // Maven1Repository, for it would be deleting the 'repository' directory if it happens to be empty.
+        boolean m2repo = true;
+
+        if(m2repo) {
+ // Check version, artifact and group directories, i.e. 3 levels up
+            dirDepth = 3;
+        }
+
+        File temp = location;
+        for(int i = 0; i < dirDepth; ++i) {
+ if((temp = temp.getParentFile()).listFiles().length == 0) {
+                // Directory is empty.  Remove it.
+                temp.delete();
+            } else {
+ // Directory is not empty. No need to check any more parent directories
+                break;
+            }
+        }
+
+        try {
+ // Is this the right way to get hold of PersistentConfigurationList? + PersistentConfigurationList configList = (PersistentConfigurationList) kernel.getGBean (PersistentConfigurationList.class);
+            configList.removeConfiguration(configId);
+        } catch (Exception e) {
+ log.warn("Unable to remove configuration from persistent configurations. id = "+configId, e);
+        }

         if (configurationInfo != null) {
             IOException ioException = null;

Modified: geronimo/server/trunk/modules/geronimo-system/src/main/ java/org/apache/geronimo/system/configuration/ RepositoryConfigurationStore.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/ geronimo-system/src/main/java/org/apache/geronimo/system/ configuration/RepositoryConfigurationStore.java? view=diff&rev=486734&r1=486733&r2=486734 ====================================================================== ======== --- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/ apache/geronimo/system/configuration/ RepositoryConfigurationStore.java (original) +++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/ apache/geronimo/system/configuration/ RepositoryConfigurationStore.java Wed Dec 13 08:54:14 2006
@@ -45,6 +45,7 @@
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.config.IOUtil;
+import org.apache.geronimo.kernel.config.PersistentConfigurationList;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
import org.apache.geronimo.kernel.repository.WritableListableRepository;
@@ -333,7 +334,37 @@
         }
         File location = repository.getLocation(configId);
         IOUtil.recursiveDelete(location);
- //todo: for Maven 2 repo, delete the version directory if there's nothing left in it (probably the case) + // Number of directory levels up, to check and delete empty parent directories in the repo
+        int dirDepth = 0;
+
+        // FIXME: Determine the repository type
+ // For now assume the repo is a Maven2Repository. This should not cause any harm even if it is an + // Maven1Repository, for it would be deleting the 'repository' directory if it happens to be empty.
+        boolean m2repo = true;
+
+        if(m2repo) {
+ // Check version, artifact and group directories, i.e. 3 levels up
+            dirDepth = 3;
+        }
+
+        File temp = location;
+        for(int i = 0; i < dirDepth; ++i) {
+ if((temp = temp.getParentFile()).listFiles().length == 0) {
+                // Directory is empty.  Remove it.
+                temp.delete();
+            } else {
+ // Directory is not empty. No need to check any more parent directories
+                break;
+            }
+        }
+
+        try {
+ // Is this the right way to get hold of PersistentConfigurationList? + PersistentConfigurationList configList = (PersistentConfigurationList) kernel.getGBean (PersistentConfigurationList.class);
+            configList.removeConfiguration(configId);
+        } catch (Exception e) {
+ log.warn("Unable to remove configuration from persistent configurations. id = "+configId, e);
+        }

         if (configurationInfo != null) {
             IOException ioException = null;



Reply via email to