summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-01 05:07:54 (EDT)
committerEike Stepper2007-08-01 05:07:54 (EDT)
commit21657dcc5778521bfccc7c44f327517fcd0580e4 (patch)
treea0e5e52f183b4f81ddff65c9aa532218d16da45d
parent9d555b37b8b59e4f2397376c9839d421462b00b1 (diff)
downloadcdo-21657dcc5778521bfccc7c44f327517fcd0580e4.zip
cdo-21657dcc5778521bfccc7c44f327517fcd0580e4.tar.gz
cdo-21657dcc5778521bfccc7c44f327517fcd0580e4.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java102
1 files changed, 100 insertions, 2 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
index e1a0443..32db901 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/ZIPUtil.java
@@ -17,7 +17,10 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
+import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
@@ -29,6 +32,10 @@ public final class ZIPUtil
{
public static final int DEFALULT_BUFFER_SIZE = 4096;
+ private static final int ORDER_KEEP = -1;
+
+ private static final int ORDER_SWAP = 1;
+
private ZIPUtil()
{
}
@@ -56,7 +63,7 @@ public final class ZIPUtil
try
{
- String name = context.getName();
+ String name = context.getName().replace(File.separatorChar, '/');
entry = new ZipEntry(name);
zos.putNextEntry(entry);
@@ -229,7 +236,98 @@ public final class ZIPUtil
++sourceFolderLength;
}
- files = IOUtil.listBreadthFirst(sourceFolder).iterator();
+ final int baseLength = sourceFolder.getAbsolutePath().length();
+ List<File> list = IOUtil.listBreadthFirst(sourceFolder);
+ Collections.sort(list, new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ File f1 = (File)o1;
+ File f2 = (File)o2;
+
+ String path1 = getPath(f1, baseLength);
+ String path2 = getPath(f2, baseLength);
+ if (path1.length() == 0) return ORDER_KEEP;
+ if (path2.length() == 0) return ORDER_SWAP;
+
+ if (f1.isDirectory())
+ {
+ if (f2.isDirectory())
+ {
+ // f1=dir, f2=dir
+ if (path1.equalsIgnoreCase("/META-INF"))
+ {
+ return ORDER_KEEP;
+ }
+
+ if (path2.equalsIgnoreCase("/META-INF"))
+ {
+ return ORDER_SWAP;
+ }
+
+ return path1.compareTo(path2);
+ }
+ else
+ {
+ // f1=dir, f2=file
+ if (path1.equalsIgnoreCase("/META-INF"))
+ {
+ return ORDER_KEEP;
+ }
+
+ if (path2.equalsIgnoreCase("/META-INF/MANIFEST.MF"))
+ {
+ return ORDER_SWAP;
+ }
+
+ return ORDER_KEEP;
+ }
+ }
+ else
+ {
+ if (f2.isDirectory())
+ {
+ // f1=file, f2=dir
+ if (path2.equalsIgnoreCase("/META-INF"))
+ {
+ return ORDER_SWAP;
+ }
+
+ if (path1.equalsIgnoreCase("/META-INF/MANIFEST.MF"))
+ {
+ return ORDER_KEEP;
+ }
+
+ return ORDER_SWAP;
+ }
+ else
+ {
+ // f1=file, f2=file
+ if (path1.equalsIgnoreCase("/META-INF/MANIFEST.MF"))
+ {
+ return ORDER_KEEP;
+ }
+
+ if (path2.equalsIgnoreCase("/META-INF/MANIFEST.MF"))
+ {
+ return ORDER_SWAP;
+ }
+
+ return path1.compareTo(path2);
+ }
+ }
+ }
+
+ private String getPath(File file, int baseLength)
+ {
+ String absolutePath = file.getAbsolutePath();
+ String substring = absolutePath.substring(baseLength);
+ String replace = substring.replace(File.separatorChar, '/');
+ return replace;
+ }
+ });
+
+ files = list.iterator();
if (excludeRoot)
{
files.next();