incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r801611 - in /sling/trunk/contrib/extensions/jcrinstall/service/src/main: java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java resources/OSGI-INF/metatype/metatype.properties
Date Thu, 06 Aug 2009 11:44:44 GMT
Author: bdelacretaz
Date: Thu Aug  6 11:44:43 2009
New Revision: 801611

URL: http://svn.apache.org/viewvc?rev=801611&view=rev
Log:
SLING-1072 - configurable max depth for scanning install folders

Modified:
    sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
    sling/trunk/contrib/extensions/jcrinstall/service/src/main/resources/OSGI-INF/metatype/metatype.properties

Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=801611&r1=801610&r2=801611&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
Thu Aug  6 11:44:43 2009
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Dictionary;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -96,8 +97,16 @@
 
     /** Default regexp for watched folders */
     public static final String DEFAULT_FOLDER_NAME_REGEXP = ".*/install$";
+    
+    /** Configurable max. path depth for watched folders
+     *  @scr.property valueRef="DEFAULT_FOLDER_MAX_DEPTH" type="Integer"
+     */
+    public static final String PROP_INSTALL_FOLDER_MAX_DEPTH = "installFolder.maxDepth";
+
+    public static final int DEFAULT_FOLDER_MAX_DEPTH = 4;
+    private int maxWatchedFolderDepth;
 
-    /** ComponentContext property that overrides the folder name regepx */
+    /** ComponentContext property that overrides the folder name regexp */
     public static final String FOLDER_NAME_REGEXP_PROPERTY = "sling.jcrinstall.folder.name.regexp";
 
     public static final String DATA_FILE = "service.properties";
@@ -114,6 +123,14 @@
     protected void activate(ComponentContext context) throws Exception {
         componentContext = context;
 
+        final Dictionary<?, ?> properties = context.getProperties();
+        final Integer maxDepth = (Integer)properties.get(PROP_INSTALL_FOLDER_MAX_DEPTH);
+        if(maxDepth == null) {
+            maxWatchedFolderDepth = DEFAULT_FOLDER_MAX_DEPTH;
+        } else {
+            maxWatchedFolderDepth = maxDepth.intValue();
+        }
+        
         // Call startup() if we already have a repository, else that will be called
         // by the bind method
         if(repository != null) {
@@ -129,6 +146,7 @@
     /** Called at activation time, or when repository becomes available again
      *  after going away. */
     protected void startup() throws Exception {
+        final long start = System.currentTimeMillis();
         log.debug("startup()");
 
     	// TODO make this more configurable (in sync with ResourceOverrideRulesImpl)
@@ -177,6 +195,8 @@
         final Thread t = new Thread(this, getClass().getSimpleName() + "_" + System.currentTimeMillis());
         t.setDaemon(true);
         t.start();
+        
+        log.info("startup() took {} msec", System.currentTimeMillis() - start);
     }
 
     protected File getServiceDataFile(ComponentContext context) {
@@ -269,12 +289,19 @@
      */
     void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException
     {
-        if (folderNameFilter.accept(n.getPath())) {
-            setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, filenameFilter,
scanDelayMsec, roRules));
-        }
-        final NodeIterator it = n.getNodes();
-        while (it.hasNext()) {
-            findWatchedFolders(it.nextNode(), setToUpdate);
+        final String path = n.getPath();
+        if (folderNameFilter.accept(path)) {
+            setToUpdate.add(new WatchedFolder(repository, path, osgiController, filenameFilter,
scanDelayMsec, roRules));
+        }
+        final int depth = path.split("/").length;
+        if(depth > maxWatchedFolderDepth) {
+            log.debug("Not recursing into {} due to maxWatchedFolderDepth={}", path, maxWatchedFolderDepth);
+            return;
+        } else {
+            final NodeIterator it = n.getNodes();
+            while (it.hasNext()) {
+                findWatchedFolders(it.nextNode(), setToUpdate);
+            }
         }
     }
 

Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/main/resources/OSGI-INF/metatype/metatype.properties
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=801611&r1=801610&r2=801611&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/main/resources/OSGI-INF/metatype/metatype.properties
Thu Aug  6 11:44:43 2009
@@ -25,4 +25,8 @@
 
 jcrinstall.name = Apache Sling JCR Install
 jcrinstall.description = Installs OSGi bundles and configurations found \
- in the JCR Repository. 
\ No newline at end of file
+ in the JCR Repository. 
+ 
+installFolder.maxDepth.name = Max hierarchy depth of install folders
+installFolder.maxDepth.description = Folders that are nested deeper than \
+  this value under the repository root are ignored
\ No newline at end of file



Mime
View raw message