incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r741168 - in /incubator/sling/trunk/extensions/jcrinstall/service/src: main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
Date Thu, 05 Feb 2009 16:31:45 GMT
Author: bdelacretaz
Date: Thu Feb  5 16:31:44 2009
New Revision: 741168

URL: http://svn.apache.org/viewvc?rev=741168&view=rev
Log:
SLING-738 - make jcrinstall folder names runmode-aware

Added:
    incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
  (with props)
    incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
  (with props)
    incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
  (with props)
Modified:
    incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java

Modified: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=741168&r1=741167&r2=741168&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Thu Feb  5 16:31:44 2009
@@ -40,6 +40,7 @@
 import org.apache.sling.jcr.jcrinstall.jcr.NodeConverter;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
 import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
+import org.apache.sling.runmode.RunMode;
 import org.osgi.framework.FrameworkEvent;
 import org.osgi.framework.FrameworkListener;
 import org.osgi.framework.ServiceReference;
@@ -69,7 +70,7 @@
 public class RepositoryObserver implements Runnable, FrameworkListener, JcrInstallService
{
 
     private final SortedSet<WatchedFolder> folders = new TreeSet<WatchedFolder>();
-    private RegexpFilter folderNameFilter;
+    private RunModeRegexpFilter folderNameFilter;
     private RegexpFilter filenameFilter;
     private ResourceOverrideRules roRules;
     private ComponentContext componentContext;
@@ -77,6 +78,9 @@
     private boolean observationCycleActive;
     private boolean activated;
     
+    /** @scr.reference */ 
+    private RunMode runMode;
+    
     /** @scr.reference */
     protected OsgiController osgiController;
     
@@ -176,7 +180,7 @@
     	} else {
             log.info("Using folder name regexp '{}' from context property '{}'", folderNameRegexp,
FOLDER_NAME_REGEXP_PROPERTY);
     	}
-        folderNameFilter = new RegexpFilter(folderNameRegexp);
+        folderNameFilter = new RunModeRegexpFilter(folderNameRegexp, runMode);
         serviceDataFile = getServiceDataFile(componentContext);
         
         // Listen for any new WatchedFolders created after activation

Added: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java?rev=741168&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
Thu Feb  5 16:31:44 2009
@@ -0,0 +1,88 @@
+/*
+ * 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.jcr.jcrinstall.jcr.impl;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.sling.runmode.RunMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** A RegexpFilter that is RunMode-aware: accepts names with a 
+ *  prefix that matches the supplied regexp, and suffixes that 
+ *  match the list of run mode strings provided by a RunMode service.
+ */
+class RunModeRegexpFilter extends RegexpFilter {
+    private final RunMode runMode;
+    private final Logger log = LoggerFactory.getLogger(getClass());
+    
+    RunModeRegexpFilter(String regexp, RunMode runMode) {
+        super(regexp);
+        this.runMode = runMode;
+    }
+    
+    @Override
+    boolean accept(final String path) {
+        // If path contains dots, remove suffixes starting with
+        // dots until path matches regexp, and accept if all suffixes
+        // are included in our list of runmodes
+        final char DOT = '.';
+        boolean result = false;
+        
+        if(path.indexOf(DOT) > 0) {
+            int pos = 0;
+            String prefix = path;
+            final List<String> modes = new LinkedList<String>();
+            while( (pos = prefix.lastIndexOf(DOT)) >= 0) {
+                modes.add(prefix.substring(pos + 1));
+                prefix = prefix.substring(0, pos);
+                if(super.accept(prefix)) {
+                    result = true;
+                    break;
+                }
+            }
+            
+            // If path prefix matches, check that all our runmodes match
+            if(result) {
+                for(String m : modes) {
+                    final String [] toTest = { m };
+                    if(!runMode.isActive(toTest)) {
+                        result = false;
+                        break;
+                    }
+                }
+            }
+            
+            if(log.isDebugEnabled()) {
+                log.debug("accept(" + path + ")=" + result + " (prefix=" + prefix + ", modes="
+ modes + ")");
+            }
+            
+        } else {
+            result = super.accept(path);
+        }
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        return super.toString() + ", RunMode=" + runMode;
+    }
+
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java?rev=741168&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
Thu Feb  5 16:31:44 2009
@@ -0,0 +1,33 @@
+package org.apache.sling.jcr.jcrinstall.jcr.impl;
+
+import org.apache.sling.runmode.RunMode;
+
+class MockRunMode implements RunMode {
+
+    private final String[] modes;
+    
+    MockRunMode(String [] modes) {
+        this.modes = modes;
+    }
+    
+    public String[] getCurrentRunModes() {
+        return modes;
+    }
+
+    public boolean isActive(String[] runModes) {
+        boolean result = false;
+        
+        main:
+        for(String a : runModes) {
+            for(String b : modes) {
+                if(b.equals(a)) {
+                    result = true;
+                    break main;
+                }
+            }
+        }
+        
+        return result;
+    }
+
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/MockRunMode.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java?rev=741168&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
Thu Feb  5 16:31:44 2009
@@ -0,0 +1,62 @@
+/*
+ * 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.jcr.jcrinstall.jcr.impl;
+
+import junit.framework.TestCase;
+
+public class RunModeRegexpFilterTest extends TestCase {
+    
+    public static final String DEFAULT_REGEXP =  ".*/install$";
+    
+    public void testNoRunMode() {
+        final RunModeRegexpFilter f = new RunModeRegexpFilter(DEFAULT_REGEXP, new MockRunMode(new
String[0]));
+        assertTrue(f.accept("/foo/install"));
+        assertFalse(f.accept("/foo/install.bar"));
+    }
+    
+    public void testSingleMode() {
+        final String [] m = { "dev" };
+        final RunModeRegexpFilter f = new RunModeRegexpFilter(DEFAULT_REGEXP, new MockRunMode(m));
+        assertTrue("Test 1", f.accept("/foo/install"));
+        assertFalse("Test 2", f.accept("/foo/install.bar"));
+        assertTrue("Test 3", f.accept("/foo/install.dev"));
+        assertFalse("Test 4", f.accept("/foo/install/dev"));
+        assertTrue("Test 5", f.accept("/foo/install.dev.dev"));
+        assertFalse("Test 6", f.accept("/foo/install.dev.bar"));
+        assertFalse("Test 7", f.accept("/foo/install.bar.dev"));
+    }
+    
+    public void testThreeModes() {
+        final String [] m = { "dev", "web", "staging" };
+        final RunModeRegexpFilter f = new RunModeRegexpFilter(DEFAULT_REGEXP, new MockRunMode(m));
+        assertTrue("Test 1",f.accept("/foo/install"));
+        assertFalse("Test 2",f.accept("/foo/install.bar"));
+        assertTrue("Test 3",f.accept("/foo/install.dev"));
+        assertTrue("Test 4",f.accept("/foo/install.web"));
+        assertTrue("Test 5",f.accept("/foo/install.staging"));
+        assertFalse("Test 6",f.accept("/foo/install/dev"));
+        assertTrue("Test 7",f.accept("/foo/install.dev.web.staging"));
+        assertTrue("Test 8",f.accept("/foo/install.web.dev.staging"));
+        assertTrue("Test 9",f.accept("/foo/install.staging.web.dev"));
+        assertTrue("Test 10",f.accept("/foo/install.staging.dev.web"));
+        assertTrue("Test 11",f.accept("/foo/install.dev.dev.web.staging.web"));
+        assertFalse("Test 12",f.accept("/foo/install.dev.bar"));
+        assertFalse("Test 13",f.accept("/foo/install.bar.dev"));
+    }
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RunModeRegexpFilterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message