commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grobme...@apache.org
Subject svn commit: r764045 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/changes/ test/java/org/apache/commons/compress/changes/
Date Fri, 10 Apr 2009 20:45:12 GMT
Author: grobmeier
Date: Fri Apr 10 20:45:11 2009
New Revision: 764045

URL: http://svn.apache.org/viewvc?rev=764045&view=rev
Log:
added deleteDir method to ChangeSet to avoid confusion with delete for files
fixed ClassCastException in testcases which raised due to this fix 

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/Change.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/Change.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/Change.java?rev=764045&r1=764044&r2=764045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/Change.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/Change.java
Fri Apr 10 20:45:11 2009
@@ -38,20 +38,21 @@
 	static final int TYPE_DELETE = 1;
 	static final int TYPE_ADD = 2;
 	static final int TYPE_MOVE = 3; // NOT USED
+	static final int TYPE_DELETE_DIR = 4;
 	
 	/**
 	 * Constructor. Takes the filename of the file to be deleted
 	 * from the stream as argument.
 	 * @param pFilename the filename of the file to delete
 	 */
-	Change(final String pFilename) {
+	Change(final String pFilename, int type) {
 		if(pFilename == null) {
 			throw new NullPointerException();
 		}
-		targetFile = pFilename;
-		type = TYPE_DELETE;
-		input = null;
-		entry = null;
+		this.targetFile = pFilename;
+		this.type = type;
+		this.input = null;
+		this.entry = null;
 	}
 		
 	/**

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java?rev=764045&r1=764044&r2=764045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSet.java
Fri Apr 10 20:45:11 2009
@@ -42,11 +42,21 @@
      * @param pFilename
      *            the filename of the file to delete
      */
-    public void delete(final String pFilename) {
-        addDeletion(new Change(pFilename));
+    public void delete(final String filename) {
+        addDeletion(new Change(filename, Change.TYPE_DELETE));
     }
 
     /**
+     * Deletes the file with the filename from the archive. 
+     * 
+     * @param pFilename
+     *            the filename of the file to delete
+     */
+    public void deleteDir(final String dirName) {
+        addDeletion(new Change(dirName, Change.TYPE_DELETE_DIR));
+    }
+    
+    /**
      * Adds a new archive entry to the archive.
      * 
      * @param pEntry
@@ -65,8 +75,9 @@
      *            the change which should result in a deletion
      */
     private void addDeletion(Change pChange) {
-        if (Change.TYPE_DELETE != pChange.type()
-                || pChange.targetFile() == null) {
+        if ((Change.TYPE_DELETE != pChange.type() &&
+            Change.TYPE_DELETE_DIR != pChange.type()) ||    
+            pChange.targetFile() == null) {
             return;
         }
         String source = pChange.targetFile();
@@ -78,9 +89,10 @@
                         && change.getEntry() != null) {
                     String target = change.getEntry().getName();
 
-                    if (source.equals(target)) {
+                    if (Change.TYPE_DELETE == pChange.type() && source.equals(target))
{
                         it.remove();
-                    } else if (target.matches(source + "/.*")) {
+                    } else if (Change.TYPE_DELETE_DIR == pChange.type() && 
+                               target.matches(source + "/.*")) {
                         it.remove();
                     }
                 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java?rev=764045&r1=764044&r2=764045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java
Fri Apr 10 20:45:11 2009
@@ -80,13 +80,16 @@
             for (Iterator it = workingSet.iterator(); it.hasNext();) {
                 Change change = (Change) it.next();
 
-                if (change.type() == Change.TYPE_DELETE
-                        && entry.getName() != null) {
+                if (change.type() == Change.TYPE_DELETE && 
+                    entry.getName() != null) {
                     if (entry.getName().equals(change.targetFile())) {
                         copy = false;
                         it.remove();
                         break;
-                    } else if (entry.getName().matches(
+                    }
+                } else if(change.type() == Change.TYPE_DELETE_DIR && 
+                          entry.getName() != null) {
+                    if (entry.getName().matches(
                             change.targetFile() + "/.*")) {
                         copy = false;
                         break;
@@ -117,7 +120,7 @@
         if (!workingSet.isEmpty()) {
             for (Iterator it = workingSet.iterator(); it.hasNext();) {
                 Change change = (Change) it.next();
-                if (change.type() == Change.TYPE_DELETE) {
+                if (change.type() == Change.TYPE_DELETE || change.type() == Change.TYPE_DELETE_DIR)
{
                     String target = change.targetFile();
 
                     if (source.equals(target)) {

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java?rev=764045&r1=764044&r2=764045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/changes/ChangeSetTestCase.java
Fri Apr 10 20:45:11 2009
@@ -31,6 +31,7 @@
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
 import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
@@ -245,11 +246,11 @@
             ChangeSet changes = new ChangeSet();
 
             final File file1 = getFile("test.txt");
-            ArchiveEntry entry = new ZipArchiveEntry("blub/test.txt");
+            ArchiveEntry entry = new CpioArchiveEntry("blub/test.txt");
             changes.add(entry, new FileInputStream(file1));
             archiveList.add("blub/test.txt");
 
-            changes.delete("blub");
+            changes.deleteDir("blub");
             archiveListDelete("blub");
 
             ChangeSetPerformer performer = new ChangeSetPerformer(changes);
@@ -290,14 +291,14 @@
 
             ChangeSet changes = new ChangeSet();
 
-            changes.delete("bla");
+            changes.deleteDir("bla");
 
             final File file1 = getFile("test.txt");
-            ArchiveEntry entry = new ZipArchiveEntry("bla/test.txt");
+            ArchiveEntry entry = new CpioArchiveEntry("bla/test.txt");
             changes.add(entry, new FileInputStream(file1));
             archiveList.add("bla/test.txt");
 
-            changes.delete("bla");
+            changes.deleteDir("bla");
             archiveListDelete("bla");
 
             ChangeSetPerformer performer = new ChangeSetPerformer(changes);
@@ -400,7 +401,7 @@
         try {
             ChangeSet changes = new ChangeSet();
             changes.delete("test2.xml");
-            changes.delete("META-INF");
+            changes.deleteDir("META-INF");
             changes.delete(".classpath");
             changes.delete(".project");
 
@@ -484,7 +485,7 @@
         try {
             ChangeSet changes = new ChangeSet();
             changes.delete("test2.xml");
-            changes.delete("META-INF");
+            changes.deleteDir("META-INF");
             changes.delete(".classpath");
             changes.delete(".project");
 



Mime
View raw message