jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject svn commit: r1868224 - in /jackrabbit/commons/filevault/trunk/vault-core/src: main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
Date Thu, 10 Oct 2019 06:55:16 GMT
Author: kwin
Date: Thu Oct 10 06:55:15 2019
New Revision: 1868224

URL: http://svn.apache.org/viewvc?rev=1868224&view=rev
Log:
Merge branch 'feature/JCRVLT-382_correctly-reset-source' into trunk

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java?rev=1868224&r1=1868223&r2=1868224&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/DefaultWorkspaceFilter.java
Thu Oct 10 06:55:15 2019
@@ -26,7 +26,6 @@ import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -89,6 +88,7 @@ public class DefaultWorkspaceFilter impl
 
     protected double version = SUPPORTED_VERSION;
 
+    /** the serialized output of the current filter or {@code null} */
     private byte[] source;
 
     /**
@@ -119,6 +119,7 @@ public class DefaultWorkspaceFilter impl
             }
         }
         propsFilterSets.add(new PathFilterSet(set.getRoot()));
+        source = null;
     }
 
     /**
@@ -154,6 +155,7 @@ public class DefaultWorkspaceFilter impl
             }
         }
         referenceFilterSets.add(bothFilter);
+        source = null;
     }
 
     /**
@@ -174,6 +176,7 @@ public class DefaultWorkspaceFilter impl
             }
         }
         propsFilterSets.add(set);
+        source = null;
     }
 
     /**
@@ -334,7 +337,7 @@ public class DefaultWorkspaceFilter impl
      * @throws IOException if an I/O error occurs
      */
     public void load(final InputStream in) throws IOException, ConfigurationException {
-        source = IOUtils.toByteArray(in);
+        byte[] tmpSource = source = IOUtils.toByteArray(in);
         try (InputStream inCopy = getSource()) {
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
             factory.setNamespaceAware(true);
@@ -345,6 +348,8 @@ public class DefaultWorkspaceFilter impl
             Document document = builder.parse(inCopy);
             Element doc = document.getDocumentElement();
             load(doc);
+            // restore source
+            source = tmpSource;
         } catch (ParserConfigurationException e) {
             throw new ConfigurationException(
                     "Unable to create configuration XML parser", e);
@@ -371,6 +376,7 @@ public class DefaultWorkspaceFilter impl
         propsFilterSets.clear();
         referenceFilterSets = new LinkedList<>();
         read(doc);
+        source = null;
     }
 
     private void read(Element elem) throws ConfigurationException {
@@ -466,7 +472,9 @@ public class DefaultWorkspaceFilter impl
     }
 
     /**
-     * Reset the source content to a null state.
+     * Resets the source content to a null state.
+     * This leads to generating the source from scratch if necessary.
+     * Is called implicitly for every modifying operation ({@link #add(PathFilterSet)}, {@link
#add(PathFilterSet, PathFilterSet)}, {@link #addPropertyFilterSet(PathFilterSet)}, {@link
#load(Element)}, {@link #load(InputStream) and {@link #load(File)}).
      */
     @SuppressWarnings("unused")
     public void resetSource() {

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java?rev=1868224&r1=1868223&r2=1868224&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/test/java/org/apache/jackrabbit/vault/fs/filter/WorkspaceFilterTest.java
Thu Oct 10 06:55:15 2019
@@ -16,6 +16,12 @@
  */
 package org.apache.jackrabbit.vault.fs.filter;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.List;
@@ -31,12 +37,6 @@ import org.apache.jackrabbit.vault.fs.co
 import org.apache.tika.io.IOUtils;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 /**
  * {@code WorkspaceFilterTest}...
  */
@@ -117,8 +117,9 @@ public class WorkspaceFilterTest {
     public void testLoadingWorkspaceFilter()
             throws IOException, ConfigurationException {
         DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
-        filter.load(getClass().getResourceAsStream("workspacefilters/items.xml"));
-
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/items.xml"))
{
+            filter.load(input);
+        }
         List<PathFilterSet> nodeFilterSets = filter.getFilterSets();
         assertNotNull(nodeFilterSets);
         assertEquals(1, nodeFilterSets.size());
@@ -138,6 +139,12 @@ public class WorkspaceFilterTest {
         assertEquals(1, propertyFilters.size());
         FilterSet.Entry<PathFilter> propertyFilter = propertyFilters.get(0);
         assertFalse(propertyFilter.isInclude());
+        
+        // make sure serialization format is kept (including comments)
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/items.xml");
+             InputStream actualInput = filter.getSource()) {
+            assertEquals(IOUtils.toString(input), IOUtils.toString(actualInput));
+        }
     }
 
     @Test
@@ -195,7 +202,7 @@ public class WorkspaceFilterTest {
     }
 
     @Test
-    public  void testEquals() throws IOException, ConfigurationException {
+    public void testEquals() throws IOException, ConfigurationException {
         DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
         try (InputStream input = getClass().getResourceAsStream("workspacefilters/complex.xml"))
{
             filter.load(input);
@@ -214,4 +221,31 @@ public class WorkspaceFilterTest {
         filter2.setGlobalIgnored(PathFilter.NONE);
         assertNotEquals(filter, filter2);
     }
+
+    @Test
+    public void testModificationLeadsToDifferentSerialization() throws IOException, ConfigurationException
{
+        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/items.xml"))
{
+            filter.load(input);
+        }
+        // now modify the filter
+        filter.add(new PathFilterSet("/newroot"));
+        String previousSerialization;
+        try (InputStream input = getClass().getResourceAsStream("workspacefilters/items.xml"))
{
+            previousSerialization = IOUtils.toString(input);
+        }
+        // and check the serialization again
+        try (InputStream actualInput = filter.getSource()) {
+            String actual = IOUtils.toString(actualInput);
+            assertNotEquals(previousSerialization, actual);
+            previousSerialization = actual;
+        }
+        filter.add(new PathFilterSet("/someotherroot"), new PathFilterSet("/someotherroot"));
+        // and check the serialization again
+        try (InputStream actualInput = filter.getSource()) {
+            String actual = IOUtils.toString(actualInput);
+            assertNotEquals(previousSerialization, actual);
+            previousSerialization = actual;
+        }
+    }
 }
\ No newline at end of file



Mime
View raw message