Author: rombert
Date: Sat Sep 14 20:40:39 2013
New Revision: 1523319

URL: http://svn.apache.org/r1523319
Log:
SLING-3065 - Content import does not work when filters do not match
content right below the root

Added:
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
   (with props)
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
   (with props)
Modified:
    
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/filter/FilterResult.java
    
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
    sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml
    
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilter.java

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/filter/FilterResult.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/filter/FilterResult.java?rev=1523319&r1=1523318&r2=1523319&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/filter/FilterResult.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/api/src/org/apache/sling/ide/filter/FilterResult.java
 Sat Sep 14 20:40:39 2013
@@ -17,5 +17,17 @@
 package org.apache.sling.ide.filter;
 
 public enum FilterResult {
-    ALLOW, DENY;
+    /**
+     * Signals that the resource is allowed by the filter
+     */
+    ALLOW,
+    /**
+     * Signals that the resource is not allowed by the filter
+     */
+    DENY,
+    /**
+     * Signals that the resources is not explicitly included in the filter 
definitions but it is a parent of a resource
+     * which is allowed
+     */
+    PREREQUISITE;
 }

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java?rev=1523319&r1=1523318&r2=1523319&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
 Sat Sep 14 20:40:39 2013
@@ -470,7 +470,7 @@ public class SlingLaunchpadBehaviour ext
         if (filter != null) {
             FilterResult filterResult = getFilterResult(resource, filter, 
syncDirectoryAsFile,
                     repository);
-            if (filterResult == FilterResult.DENY) {
+            if (filterResult == FilterResult.DENY || filterResult == 
FilterResult.PREREQUISITE) {
                 return null;
             }
         }

Modified: sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml?rev=1523319&r1=1523318&r2=1523319&view=diff
==============================================================================
--- sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml (original)
+++ sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/pom.xml Sat Sep 14 
20:40:39 2013
@@ -31,17 +31,54 @@
           <artifactId>org.apache.sling.ide.impl-vlt</artifactId>
           <version>${project.version}</version>
           <type>eclipse-plugin</type>
+          <scope>test</scope>
       </dependency>
       <!-- 
         we need to pull in all transitive dependencies of the impl-vlt
         bundle, since they are not exposed by Tycho(?) 
       -->
       <dependency>
+          <groupId>javax.jcr</groupId>
+          <artifactId>jcr</artifactId>
+          <version>2.0</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-api</artifactId>
+          <version>1.7.5</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>commons-io</groupId>
+          <artifactId>commons-io</artifactId>
+          <version>2.4</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-simple</artifactId>
+          <version>1.7.5</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
           <groupId>org.apache.jackrabbit</groupId>
           <artifactId>jackrabbit-jcr-commons</artifactId>
           <version>${jackrabbit.version}</version>
           <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.apache.jackrabbit.vault</groupId>
+          <artifactId>org.apache.jackrabbit.vault</artifactId>
+          <version>3.0.0-SNAPSHOT</version>
+          <scope>test</scope>
+      </dependency>
+      <dependency>
+          <groupId>org.apache.sling.ide</groupId>
+          <artifactId>org.apache.sling.ide.api</artifactId>
+          <version>${project.version}</version>
+          <scope>test</scope>
+      </dependency>
   </dependencies>
   
   <build>

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java?rev=1523319&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
 Sat Sep 14 20:40:39 2013
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.impl.vlt.filter;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.apache.sling.ide.filter.FilterResult;
+import org.junit.Test;
+
+public class VltFilterTest {
+
+    @Test
+    public void defaultFilterExcludedVarClasses() throws IOException, 
ConfigurationException {
+
+        assertThat(newFilter("filter-default.xml").filter(null, 
"/var/classes", null), is(FilterResult.DENY));
+        
+    }
+
+    private VltFilter newFilter(String filterFile) throws IOException, 
ConfigurationException {
+        InputStream input = getClass().getResourceAsStream(filterFile);
+        if (input == null) {
+            throw new IllegalArgumentException("Unable to load filter from 
classpath location " + filterFile);
+        }
+        return new VltFilter(input);
+    }
+
+    @Test
+    public void fallbackFilterExcludedVarClasses() throws IOException, 
ConfigurationException {
+
+        VltFilter filter = new VltFilter(null);
+
+        assertThat(filter.filter(null, "/var/classes", null), 
is(FilterResult.DENY));
+
+    }
+
+    @Test
+    public void defaultFilterIncludesLibs() throws IOException, 
ConfigurationException {
+
+        assertThat(newFilter("filter-default.xml").filter(null, "/libs", 
null), is(FilterResult.ALLOW));
+    }
+
+    @Test
+    public void pathMissingLeadingSlashIsCorrected() throws IOException, 
ConfigurationException {
+
+        assertThat(newFilter("filter-default.xml").filter(null, "libs", null), 
is(FilterResult.ALLOW));
+    }
+
+    @Test
+    public void deepFilterHasParentDirectoriesAsPrerequisites() throws 
IOException, ConfigurationException {
+
+        String[] parents = new String[] { "/libs", "/libs/sling", 
"/libs/sling/servlet" };
+        for (String parent : parents) {
+            assertThat("Parent '" + parent + "'", 
newFilter("filter-deep.xml").filter(null, parent, null),
+                    is(FilterResult.PREREQUISITE));
+        }
+    }
+
+}

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/filter/VltFilterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml?rev=1523319&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
 Sat Sep 14 20:40:39 2013
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<!--
+    Defines which repository items are generally included
+-->
+<workspaceFilter vesion="1.0">
+    <filter root="/libs/sling/servlet/default"/>
+</workspaceFilter>

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-deep.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml?rev=1523319&view=auto
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
 (added)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
 Sat Sep 14 20:40:39 2013
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+
+<!--
+    Defines which repository items are generally included
+-->
+<workspaceFilter vesion="1.0">
+    <filter root="/">
+        <exclude pattern="/jcr:system" />
+        <exclude pattern="/var/classes" />
+        <exclude pattern="^.*/rep:accessControl" />
+    </filter>
+</workspaceFilter>

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt-test/src/test/resources/org/apache/sling/ide/impl/vlt/filter/filter-default.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilter.java
URL: 
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilter.java?rev=1523319&r1=1523318&r2=1523319&view=diff
==============================================================================
--- 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilter.java
 (original)
+++ 
sling/branches/tooling-ide-vlt/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/filter/VltFilter.java
 Sat Sep 14 20:40:39 2013
@@ -20,6 +20,7 @@ import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
 import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
 import org.apache.jackrabbit.vault.fs.config.DefaultWorkspaceFilter;
 import org.apache.jackrabbit.vault.fs.impl.AggregateManagerImpl;
@@ -51,7 +52,17 @@ public class VltFilter implements Filter
             relativeFilePath = '/' + relativeFilePath;
         }
 
-        return filter.contains(relativeFilePath) ? FilterResult.ALLOW : 
FilterResult.DENY;
+        if (filter.contains(relativeFilePath)) {
+            return FilterResult.ALLOW;
+        }
+
+        for (PathFilterSet pathFilterSet : filter.getFilterSets()) {
+            if (pathFilterSet.getRoot().startsWith(relativeFilePath)) {
+                return FilterResult.PREREQUISITE;
+            }
+        }
+
+        return FilterResult.DENY;
     }
 
 }


Reply via email to