Author: cziegeler
Date: Wed Jul 21 10:14:30 2010
New Revision: 966165
URL: http://svn.apache.org/viewvc?rev=966165&view=rev
Log:
Optimize path handling (trailing slashes)
Modified:
sling/trunk/installer/jcr/jcrinstall/pom.xml
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilter.java
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java
Modified: sling/trunk/installer/jcr/jcrinstall/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/pom.xml?rev=966165&r1=966164&r2=966165&view=diff
==============================================================================
--- sling/trunk/installer/jcr/jcrinstall/pom.xml (original)
+++ sling/trunk/installer/jcr/jcrinstall/pom.xml Wed Jul 21 10:14:30 2010
@@ -82,7 +82,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.osgi</artifactId>
- <version>2.0.2-incubator</version>
+ <version>2.0.6</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilter.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilter.java?rev=966165&r1=966164&r2=966165&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilter.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/FolderNameFilter.java
Wed Jul 21 10:14:30 2010
@@ -32,8 +32,8 @@ import org.slf4j.LoggerFactory;
* their names. To be accepted, a folder must have a name that
* matches the expression, followed by optional suffixes based
* on the current RunMode.
- *
- * See {...@link FolderNameFilterTest} for details.
+ *
+ * See {...@link FolderNameFilterTest} for details.
*/
class FolderNameFilter {
private final Pattern pattern;
@@ -42,19 +42,19 @@ class FolderNameFilter {
private final String [] rootPaths;
private Map<String, Integer> rootPriorities = new HashMap<String,
Integer>();
private final Logger log = LoggerFactory.getLogger(getClass());
-
+
/** getPriority computes priorities as follows: each root gets its own
base priority,
- * and paths that match one or several run levels get an
additional RUNMODE_PRIORITY_OFFSET
+ * and paths that match one or several run levels get an
additional RUNMODE_PRIORITY_OFFSET
* per matched run level
*/
public static final int RUNMODE_PRIORITY_BOOST = 1;
public static final int DEFAULT_ROOT_PRIORITY = 99;
-
+
FolderNameFilter(String [] rootsConfig, String regexp, RunMode runMode) {
this.regexp = regexp;
this.pattern = Pattern.compile(regexp);
this.runMode = runMode;
-
+
// Each entry in rootsConfig is like /libs:100, where 100
// is the priority.
// Break that up into paths and priorities
@@ -74,11 +74,15 @@ class FolderNameFilter {
log.debug("Root path {} has priority {}", rootPaths[i],
priority);
}
}
-
+
+ /**
+ * Return the list of root paths.
+ * Every entry in the list ends with a slash
+ */
String [] getRootPaths() {
return rootPaths;
}
-
+
static String cleanupRootPath(final String str) {
String result = str.trim();
if(!result.startsWith("/")) {
@@ -89,24 +93,24 @@ class FolderNameFilter {
}
return result;
}
-
+
/** If a folder at given path can contain installable resources
* (according to our regexp and current RunMode), return the
* priority to use for InstallableResource found in that folder.
- *
- * @return -1 if path is not an installable folder, else resource
priority
+ *
+ * @return -1 if path is not an installable folder, else resource
priority
*/
int getPriority(final String path) {
int result = 0;
List<String> modes = null;
boolean match = false;
-
- // If path contains dots after the last /, remove suffixes
- // starting with dots until path matches regexp, and accept
+
+ // If path contains dots after the last /, remove suffixes
+ // starting with dots until path matches regexp, and accept
// if all suffixes
// are included in our list of runmodes
final char DOT = '.';
-
+
String prefix = path;
final int lastSlash = prefix.lastIndexOf('/');
if(lastSlash > 0) {
@@ -123,7 +127,7 @@ class FolderNameFilter {
break;
}
}
-
+
// If path prefix matches, check that all our runmodes match
if(result > 0) {
for(String m : modes) {
@@ -136,12 +140,12 @@ class FolderNameFilter {
}
}
}
-
+
} else if(pattern.matcher(path).matches()) {
match = true;
result = getRootPriority(path);
}
-
+
if(modes != null) {
if(log.isDebugEnabled()) {
log.debug("getPriority(" + path + ")=" + result + " (prefix="
+ prefix + ", run modes=" + modes + ")");
@@ -151,14 +155,14 @@ class FolderNameFilter {
} else {
log.debug("getPriority({})={}, path doesn't match regexp",
path, result);
}
-
+
return result;
}
-
+
public String toString() {
return getClass().getSimpleName() + " (" + regexp + "), RunMode=" +
runMode;
}
-
+
int getRootPriority(String path) {
for(Map.Entry<String, Integer> e : rootPriorities.entrySet()) {
if(path.startsWith(e.getKey())) {
Modified:
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java
URL:
http://svn.apache.org/viewvc/sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java?rev=966165&r1=966164&r2=966165&view=diff
==============================================================================
---
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java
(original)
+++
sling/trunk/installer/jcr/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/impl/JcrInstaller.java
Wed Jul 21 10:14:30 2010
@@ -173,9 +173,9 @@ public class JcrInstaller implements Eve
private StoppableThread backgroundThread;
protected void activate(ComponentContext context) throws Exception {
+ log.info("Activating Apache Sling JCR Installer");
- log.info("activate()");
-
+ // open session
session =
repository.loginAdministrative(repository.getDefaultWorkspace());
newRoots.clear();
@@ -184,59 +184,44 @@ public class JcrInstaller implements Eve
converters.add(new ConfigNodeConverter());
// Configurable max depth, system property (via bundle context)
overrides default value
- Object obj = getPropertyValue(context, PROP_INSTALL_FOLDER_MAX_DEPTH);
- if(obj != null) {
+ final Object obj = getPropertyValue(context,
PROP_INSTALL_FOLDER_MAX_DEPTH);
+ if (obj != null) {
// depending on where it's coming from, obj might be a string
or integer
maxWatchedFolderDepth =
Integer.valueOf(String.valueOf(obj)).intValue();
- log.info("Using configured ({}) folder name max depth '{}'",
PROP_INSTALL_FOLDER_MAX_DEPTH, maxWatchedFolderDepth);
+ log.debug("Using configured ({}) folder name max depth '{}'",
PROP_INSTALL_FOLDER_MAX_DEPTH, maxWatchedFolderDepth);
} else {
maxWatchedFolderDepth = DEFAULT_FOLDER_MAX_DEPTH;
- log.info("Using default folder max depth {}, not provided by {}",
maxWatchedFolderDepth, PROP_INSTALL_FOLDER_MAX_DEPTH);
+ log.debug("Using default folder max depth {}, not provided by {}",
maxWatchedFolderDepth, PROP_INSTALL_FOLDER_MAX_DEPTH);
}
// Configurable folder regexp, system property overrides default value
String folderNameRegexp = (String)getPropertyValue(context,
FOLDER_NAME_REGEXP_PROPERTY);
if(folderNameRegexp != null) {
folderNameRegexp = folderNameRegexp.trim();
- log.info("Using configured ({}) folder name regexp '{}'",
FOLDER_NAME_REGEXP_PROPERTY, folderNameRegexp);
+ log.debug("Using configured ({}) folder name regexp '{}'",
FOLDER_NAME_REGEXP_PROPERTY, folderNameRegexp);
} else {
folderNameRegexp = DEFAULT_FOLDER_NAME_REGEXP;
- log.info("Using default folder name regexp '{}', not provided by
{}", folderNameRegexp, FOLDER_NAME_REGEXP_PROPERTY);
+ log.debug("Using default folder name regexp '{}', not provided by
{}", folderNameRegexp, FOLDER_NAME_REGEXP_PROPERTY);
}
// Setup folder filtering and watching
- String [] rootsConfig =
OsgiUtil.toStringArray(context.getProperties().get(PROP_SEARCH_PATH));
- if(rootsConfig == null) {
- rootsConfig = DEFAULT_SEARCH_PATH;
- }
+ final String [] rootsConfig =
OsgiUtil.toStringArray(context.getProperties().get(PROP_SEARCH_PATH),
DEFAULT_SEARCH_PATH);
folderNameFilter = new FolderNameFilter(rootsConfig, folderNameRegexp,
runMode);
roots = folderNameFilter.getRootPaths();
for (String path : roots) {
listeners.add(new RootFolderListener(session, folderNameFilter,
path, updateFoldersListTimer));
+ log.debug("Configured root folder: {}", path);
}
- // Get search paths, and make sure each part starts and ends with a /
- if (roots == null) {
- }
- for (int i = 0; i < roots.length; i++) {
- if (!roots[i].startsWith("/")) {
- roots[i] = "/" + roots[i];
- }
- if (!roots[i].endsWith("/")) {
- roots[i] += "/";
- }
- }
- for(int i = 0; i < roots.length; i++) {
- log.info("Configured root folder: {}", roots[i]);
- }
-
- // Watch for DELETE events on the root - that might be one of our root
folders
- int eventTypes = Event.NODE_ADDED | Event.NODE_REMOVED;
- boolean isDeep = false;
- boolean noLocal = true;
- session.getWorkspace().getObservationManager().addEventListener(this,
eventTypes, "/",
- isDeep, null, null, noLocal);
- log.info("Watching for NODE_REMOVED events on / to detect removal of
our root folders");
+ // Watch for events on the root - that might be one of our root folders
+ session.getWorkspace().getObservationManager().addEventListener(this,
+ Event.NODE_ADDED | Event.NODE_REMOVED,
+ "/",
+ false, // isDeep
+ null,
+ null,
+ true); // noLocal
+ log.debug("Watching for node events on / to detect removal/add of our
root folders");
// Find paths to watch and create WatchedFolders to manage them
@@ -253,10 +238,10 @@ public class JcrInstaller implements Eve
resources.addAll(r.toAdd);
}
- log.info("Registering {} resources with OSGi installer: {}",
resources.size(), resources);
+ log.debug("Registering {} resources with OSGi installer: {}",
resources.size(), resources);
installer.registerResources(resources, URL_SCHEME);
- if(backgroundThread != null) {
+ if (backgroundThread != null) {
throw new IllegalStateException("Expected backgroundThread to be
null in activate()");
}
backgroundThread = new StoppableThread();
@@ -264,7 +249,7 @@ public class JcrInstaller implements Eve
}
protected void deactivate(ComponentContext context) {
- log.info("deactivate()");
+ log.info("Deactivating Apache Sling JCR Installer");
final long timeout = 30000L;
try {
@@ -311,11 +296,11 @@ public class JcrInstaller implements Eve
try {
s =
repository.loginAdministrative(repository.getDefaultWorkspace());
- if (!s.getRootNode().hasNode(relPath(rootPath))) {
+ if (!s.getRootNode().hasNode(rootPath)) {
log.info("Bundles root node {} not found, ignored", rootPath);
} else {
log.debug("Bundles root node {} found, looking for bundle
folders inside it", rootPath);
- final Node n = s.getRootNode().getNode(relPath(rootPath));
+ final Node n = s.getRootNode().getNode(rootPath);
findPathsUnderNode(n, result);
}
} finally {
@@ -428,13 +413,13 @@ public class JcrInstaller implements Eve
}
public void onEvent(EventIterator it) {
- // Got a DELETE on root - schedule folders rescan if one
+ // Got a DELETE or ADD on root - schedule folders rescan if one
// of our root folders is impacted
try {
while(it.hasNext()) {
final Event e = it.nextEvent();
for(String root : roots) {
- if(root.startsWith(e.getPath())) {
+ if (root.equals(e.getPath())) {
if(e.getType() == Event.NODE_ADDED) {
synchronized (newRoots) {
newRoots.add(e.getPath());