commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grobme...@apache.org
Subject svn commit: r765861 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/changes/ test/java/org/apache/commons/compress/changes/
Date Fri, 17 Apr 2009 06:27:14 GMT
Author: grobmeier
Date: Fri Apr 17 06:27:14 2009
New Revision: 765861

URL: http://svn.apache.org/viewvc?rev=765861&view=rev
Log:
Added ChangeSetResults which reports what actually has happened while performing the changeset.
Added Test.

Added:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java
Modified:
    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/ChangeSetPerformer.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetPerformer.java?rev=765861&r1=765860&r2=765861&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 17 06:27:14 2009
@@ -59,9 +59,12 @@
      *            the resulting OutputStream with all modifications
      * @throws IOException
      *             if an read/write error occurs
+     * @return the results of this operation
      */
-    public void perform(ArchiveInputStream in, ArchiveOutputStream out)
+    public ChangeSetResults perform(ArchiveInputStream in, ArchiveOutputStream out)
             throws IOException {
+        ChangeSetResults results = new ChangeSetResults();
+        
         Set workingSet = new LinkedHashSet(changes);
         
         for (Iterator it = workingSet.iterator(); it.hasNext();) {
@@ -70,6 +73,7 @@
             if (change.type() == Change.TYPE_ADD) {
                 copyStream(change.getInput(), out, change.getEntry());
                 it.remove();
+                results.addedFromChangeSet(change.getEntry().getName());
             }
         }
 
@@ -86,11 +90,13 @@
                     if (name.equals(change.targetFile())) {
                         copy = false;
                         it.remove();
+                        results.deleted(name);
                         break;
                     }
                 } else if(type == Change.TYPE_DELETE_DIR && name != null) {
                     if (name.startsWith(change.targetFile() + "/")) {
                         copy = false;
+                        results.deleted(name);
                         break;
                     }
                 }
@@ -99,9 +105,12 @@
             if (copy) {
                 if (!isDeletedLater(workingSet, entry)) {
                     copyStream(in, out, entry);
+                    results.addedFromStream(entry.getName());
                 }
             }
         }
+        
+        return results;
     }
 
     /**

Added: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java?rev=765861&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java
(added)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/changes/ChangeSetResults.java
Fri Apr 17 06:27:14 2009
@@ -0,0 +1,43 @@
+package org.apache.commons.compress.changes;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ChangeSetResults {
+    private List addedFromChangeSet = new ArrayList();
+    private List addedFromStream = new ArrayList();
+    private List deleted = new ArrayList();
+    
+    void deleted(String fileName) {
+        deleted.add(fileName);
+    }
+    
+    void addedFromStream(String fileName) {
+        addedFromStream.add(fileName);
+    }
+    
+    void addedFromChangeSet(String fileName) {
+        addedFromChangeSet.add(fileName);
+    }
+
+    /**
+     * @return the addedFromChangeSet
+     */
+    public List getAddedFromChangeSet() {
+        return addedFromChangeSet;
+    }
+
+    /**
+     * @return the addedFromStream
+     */
+    public List getAddedFromStream() {
+        return addedFromStream;
+    }
+
+    /**
+     * @return the deleted
+     */
+    public List getDeleted() {
+        return deleted;
+    }
+}

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=765861&r1=765860&r2=765861&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 17 06:27:14 2009
@@ -366,6 +366,65 @@
     }
     
     /**
+     * Checks for the correct ChangeSetResults
+     * 
+     * @throws Exception
+     */
+    public void testChangeSetResults() throws Exception {
+        final String archivename = "cpio";
+        File input = this.createArchive(archivename);
+
+        ArchiveOutputStream out = null;
+        ArchiveInputStream ais = null;
+        File result = File.createTempFile("test", "."+archivename);
+        result.deleteOnExit();
+        try {
+
+            final InputStream is = new FileInputStream(input);
+            ais = factory.createArchiveInputStream(archivename, is);
+            out = factory.createArchiveOutputStream(archivename,
+                    new FileOutputStream(result));
+
+            ChangeSet changes = new ChangeSet();
+            changes.deleteDir("bla");
+            archiveListDeleteDir("bla");
+
+            // Add a file
+            final File file1 = getFile("test.txt");
+            ArchiveEntry entry = out.createArchiveEntry(file1, "bla/test.txt");
+            changes.add(entry, new FileInputStream(file1));
+            archiveList.add("bla/test.txt");
+
+            ChangeSetPerformer performer = new ChangeSetPerformer(changes);
+            ChangeSetResults results = performer.perform(ais, out);
+            is.close();
+
+            // Checks
+            assertEquals(1,results.getAddedFromChangeSet().size());
+            assertEquals("bla/test.txt",(String)results.getAddedFromChangeSet().iterator().next());
+            assertEquals(3,results.getDeleted().size());
+            assertTrue(results.getDeleted().contains("bla/test4.xml"));
+            assertTrue(results.getDeleted().contains("bla/test5.xml"));
+            assertTrue(results.getDeleted().contains("bla/blubber/test6.xml"));
+            
+            assertTrue(results.getAddedFromStream().contains("testdata/test1.xml"));
+            assertTrue(results.getAddedFromStream().contains("testdata/test2.xml"));
+            assertTrue(results.getAddedFromStream().contains("test/test3.xml"));
+            assertTrue(results.getAddedFromStream().contains("test.txt"));
+            assertTrue(results.getAddedFromStream().contains("something/bla"));
+            assertTrue(results.getAddedFromStream().contains("test with spaces.txt"));
+            assertEquals(6,results.getAddedFromStream().size());
+        } finally {
+            if (out != null)
+                out.close();
+            if (ais != null)
+                ais.close();
+        }
+
+        this.checkArchiveContent(result, archiveList);
+    }
+    
+    /**
      * Tries to delete a directory with a file and adds a new directory with a
      * new file and with the same name. Should delete dir1/* and add
      * dir1/test.txt at the end



Mime
View raw message