geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r912586 - /geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java
Date Mon, 22 Feb 2010 14:39:34 GMT
Author: gawor
Date: Mon Feb 22 14:39:34 2010
New Revision: 912586

URL: http://svn.apache.org/viewvc?rev=912586&view=rev
Log:
re-implement JarUtils.jarDirectory() so that it does not try to include the jar file it is
creating in the jar file

Modified:
    geronimo/server/trunk/framework/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/util/JarUtils.java

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=912586&r1=912585&r2=912586&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
Mon Feb 22 14:39:34 2010
@@ -249,15 +249,51 @@
         }
     }
 
-    public static void jarDirectory(File sourceDirecotry, File destinationFile) throws IOException
{
-        JarFile inputJar = new UnpackedJarFile(sourceDirecotry);
+    public static void jarDirectory(File sourceDirectory, File destinationFile) throws IOException
{
+        JarOutputStream out = null;
         try {
-            copyToPackedJar(inputJar, destinationFile);
+            out = new JarOutputStream(new FileOutputStream(destinationFile));
+            jarDirectory(sourceDirectory, "", destinationFile, out);       
         } finally {
-            close(inputJar);
+            IOUtils.close(out);
         }
     }
 
+    private static void jarDirectory(File baseDirectory, 
+                                     String baseName, 
+                                     File destinationFile, 
+                                     JarOutputStream out) throws IOException {
+        File[] files = baseDirectory.listFiles();
+        if (null == files) {
+            return;
+        }
+        byte[] buffer = new byte[4096];
+        for (File file : files) {
+            // make sure not to include the file we're creating
+            if (file.equals(destinationFile)) {
+                continue;
+            }
+            String name = baseName + file.getName();
+            if (file.isDirectory()) {
+                out.putNextEntry(new ZipEntry(name));
+                out.closeEntry();            
+                jarDirectory(file, name + "/", destinationFile, out);
+            } else if (file.isFile()) {
+                out.putNextEntry(new ZipEntry(name));
+                InputStream in = new FileInputStream(file);
+                try {
+                    int count;
+                    while ((count = in.read(buffer)) > 0) {
+                        out.write(buffer, 0, count);
+                    }
+                } finally {
+                    IOUtils.close(in);
+                    out.closeEntry();
+                }              
+            }
+        }
+    }
+    
     private static void createDirectory(File dir) throws IOException {
         if (dir != null && !dir.exists()) {
             boolean success = dir.mkdirs();



Mime
View raw message