You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/06/05 19:57:23 UTC

svn commit: r663679 - /geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java

Author: gawor
Date: Thu Jun  5 10:57:22 2008
New Revision: 663679

URL: http://svn.apache.org/viewvc?rev=663679&view=rev
Log:
include empty directories in archive. related to GERONIMO-4086

Modified:
    geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java

Modified: geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java?rev=663679&r1=663678&r2=663679&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-plugin/src/main/java/org/apache/geronimo/system/plugin/ArchiverGBean.java Thu Jun  5 10:57:22 2008
@@ -101,6 +101,7 @@
 */
         
         // add in all files and mark them with default file permissions
+        Map<File, Boolean> emptyDirs = new HashMap<File, Boolean>();
         Map<String, File> all = IOUtil.listAllFileNames(source);
         removeExcludes(source, all);
         for (Map.Entry<String, File> entry : all.entrySet()) {
@@ -108,9 +109,44 @@
             File sourceFile = entry.getValue();
             if (sourceFile.isFile()) {
                 archiver.addFile(sourceFile, destFileName, UnixStat.DEFAULT_FILE_PERM);
+                // mark parent directories non-empty
+                for (File parentDir = sourceFile.getParentFile();
+                     parentDir != null && !parentDir.equals(source);
+                     parentDir = parentDir.getParentFile()) {               
+                    emptyDirs.put(parentDir, Boolean.FALSE);
+                }
+                
+            } else if (sourceFile.isDirectory()) {                           
+                Boolean isEmpty = emptyDirs.get(sourceFile);                
+                if (isEmpty == null) {       
+                    emptyDirs.put(sourceFile, Boolean.TRUE);
+                    // mark parent directories non-empty
+                    for (File parentDir = sourceFile.getParentFile();
+                         parentDir != null && !parentDir.equals(source);
+                         parentDir = parentDir.getParentFile()) {               
+                        emptyDirs.put(parentDir, Boolean.FALSE);
+                    }
+                }              
             }
         }
-
+        
+        if (!all.isEmpty()) {
+            emptyDirs.put(source, Boolean.FALSE);
+        }
+                
+        String sourceDirPath = source.getAbsolutePath();
+        for (Map.Entry<File, Boolean> entry : emptyDirs.entrySet()) {
+            if (entry.getValue().booleanValue()) {                
+                String emptyDirPath = entry.getKey().getAbsolutePath();
+                String relativeDir = emptyDirPath.substring(sourceDirPath.length());
+                relativeDir = relativeDir.replace('\\', '/');
+                archiver.addDirectory(entry.getKey(), serverName + relativeDir);
+            }
+        }
+        emptyDirs.clear();
+        
+        all.clear();
+        
         // add execute permissions to all non-batch files in the bin/ directory
         File bin = new File(source, "bin");
         if (bin.exists()) {