You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2008/09/08 17:54:31 UTC
svn commit: r693142 - in /incubator/sling/trunk/extensions/jcrinstall: ./
src/main/java/org/apache/sling/jcr/jcrinstall/jcr/
src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
src/test/java/org/apache/sling/jcr/jcrinstall/jcr/ src/test/java/org/ap...
Author: bdelacretaz
Date: Mon Sep 8 08:54:30 2008
New Revision: 693142
URL: http://svn.apache.org/viewvc?rev=693142&view=rev
Log:
SLING-646 - work in progress, starting to reorganize jcr component
Added:
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/
incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml (with props)
Modified:
incubator/sling/trunk/extensions/jcrinstall/pom.xml
Modified: incubator/sling/trunk/extensions/jcrinstall/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/pom.xml?rev=693142&r1=693141&r2=693142&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/pom.xml (original)
+++ incubator/sling/trunk/extensions/jcrinstall/pom.xml Mon Sep 8 08:54:30 2008
@@ -103,6 +103,10 @@
<artifactId>jmock-junit4</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
-
</project>
Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java?rev=693142&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java Mon Sep 8 08:54:30 2008
@@ -0,0 +1,35 @@
+/*
+ * 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.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/** Decide if a folder has a suitable name to be watched */
+class FolderNameFilter {
+ private final Pattern pattern;
+
+ FolderNameFilter(String regexp) throws PatternSyntaxException {
+ pattern = Pattern.compile(regexp);
+ }
+
+ boolean accept(String path) {
+ return pattern.matcher(path).matches();
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FolderNameFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java?rev=693142&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Mon Sep 8 08:54:30 2008
@@ -0,0 +1,121 @@
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.sling.jcr.api.SlingRepository;
+import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Observes a set of folders in the JCR repository, to
+ * detect added or updated resources that might be of
+ * interest to the OsgiController.
+ *
+ * Calls the OsgiController to install/remove resources.
+ */
+public class RepositoryObserver {
+
+ private Set<WatchedFolder> folders;
+
+ private FolderNameFilter folderNameFilter;
+
+ /** @scr.reference */
+ private OsgiController osgiController;
+
+ /** @scr.reference */
+ private SlingRepository repository;
+
+ /** Default set of root folders to watch */
+ public static String[] DEFAULT_ROOTS = {"/libs", "/apps"};
+
+ protected static final Logger log = LoggerFactory.getLogger(WatchedFolder.class);
+
+ /** Upon activation, find folders to watch under our roots, and observe those
+ * roots to detect new folders to watch.
+ */
+ protected void activate(ComponentContext context) throws RepositoryException {
+ folders = new HashSet<WatchedFolder>();
+
+ for(String root : DEFAULT_ROOTS) {
+ folders.addAll(findWatchedFolders(root));
+ }
+ }
+
+ protected void deactivate(ComponentContext oldContext) {
+ folders.clear();
+ }
+
+ /** Find all folders to watch under rootPath
+ * @throws RepositoryException */
+ Set<WatchedFolder> findWatchedFolders(String rootPath) throws RepositoryException {
+ final Set<WatchedFolder> result = new HashSet<WatchedFolder>();
+ Session s = null;
+
+ try {
+ s = repository.loginAdministrative(repository.getDefaultWorkspace());
+ if (!s.getRootNode().hasNode(relPath(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));
+ findWatchedFolders(n, result);
+ }
+ } finally {
+ if (s != null) {
+ s.logout();
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Add n to setToUpdate if it is a bundle folder, and recurse into its children
+ * to do the same.
+ */
+ void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException
+ {
+ if (folderNameFilter.accept(n.getPath())) {
+ setToUpdate.add(new WatchedFolder(n.getPath(), osgiController));
+ }
+ final NodeIterator it = n.getNodes();
+ while (it.hasNext()) {
+ findWatchedFolders(it.nextNode(), setToUpdate);
+ }
+ }
+
+ /**
+ * Return the relative path for supplied path
+ */
+ static String relPath(String path) {
+ if (path.startsWith("/")) {
+ return path.substring(1);
+ }
+ return path;
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java?rev=693142&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java Mon Sep 8 08:54:30 2008
@@ -0,0 +1,59 @@
+/*
+ * 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 org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Watch a single folder in the JCR Repository, detecting changes
+ * to it (non-recursively) and sending the appropriate messages
+ * to the OsgiController service.
+ */
+class WatchedFolder {
+ private final String path;
+ private final OsgiController controller;
+ protected static final Logger log = LoggerFactory.getLogger(WatchedFolder.class);
+
+ WatchedFolder(String path, OsgiController ctrl) {
+ this.path = path;
+ this.controller = ctrl;
+
+ log.info("Watching folder " + path);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof WatchedFolder)) {
+ return false;
+ }
+
+ final WatchedFolder other = (WatchedFolder) obj;
+ return path.equals(other.path);
+ }
+
+ @Override
+ public int hashCode() {
+ return path.hashCode();
+ }
+
+ String getPath() {
+ return path;
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java?rev=693142&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java Mon Sep 8 08:54:30 2008
@@ -0,0 +1,117 @@
+/*
+ * 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.lang.reflect.Field;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
+import org.apache.sling.jcr.api.SlingRepository;
+
+/** Test the "find watched folders" feature of the RepositoryObserver */
+public class FindWatchedFoldersTest extends RepositoryTestBase {
+
+ SlingRepository repo;
+ Session session;
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ session.getRootNode().getNode("libs").remove();
+ session.getRootNode().getNode("apps").remove();
+ session.logout();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ repo = getRepository();
+ session = repo.loginAdministrative(repo.getDefaultWorkspace());
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testInitialFind() throws Exception {
+ final String [] folders = {
+ "libs/foo/bar/install",
+ "libs/foo/wii/install",
+ "apps/install"
+ };
+ final String [] foldersToIgnore = {
+ "libs/foo/bar/installed",
+ "apps/noninstall"
+ };
+
+ for(String folder : folders) {
+ createFolder(folder);
+ }
+ for(String folder : foldersToIgnore) {
+ createFolder(folder);
+ }
+
+ final FolderNameFilter filter = new FolderNameFilter(".*/install$");
+ final RepositoryObserver ro = createRepositoryObserver(filter);
+ ro.activate(null);
+
+ final Field f = ro.getClass().getDeclaredField("folders");
+ f.setAccessible(true);
+ final Set<WatchedFolder> wfSet = (Set<WatchedFolder>)f.get(ro);
+ assertEquals("activate() must find all watched folders", folders.length, wfSet.size());
+
+ final Set<String> paths = new HashSet<String>();
+ for(WatchedFolder wf : wfSet) {
+ paths.add(wf.getPath());
+ }
+ for(String folder : folders) {
+ assertTrue("Folder " + folder + " must be watched (watched=" + paths + ")",
+ paths.contains("/" + folder));
+ }
+ }
+
+ void createFolder(String path) throws Exception {
+ final String [] parts = path.split("/");
+ Node n = session.getRootNode();
+ for(String part : parts) {
+ if(n.hasNode(part)) {
+ n = n.getNode(part);
+ } else {
+ n = n.addNode(part);
+ }
+ }
+ session.save();
+ }
+
+ RepositoryObserver createRepositoryObserver(FolderNameFilter filter) throws Exception {
+ final RepositoryObserver result = new RepositoryObserver();
+ setField(result, "repository", repo);
+ setField(result, "folderNameFilter", filter);
+ return result;
+ }
+
+ static void setField(Object target, String name, Object value) throws Exception, IllegalAccessException {
+ final Field f = target.getClass().getDeclaredField(name);
+ f.setAccessible(true);
+ f.set(target, value);
+
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Added: incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml?rev=693142&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml Mon Sep 8 08:54:30 2008
@@ -0,0 +1,117 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.2//EN"
+ "http://jackrabbit.apache.org/dtd/repository-1.2.dtd">
+<Repository>
+ <!--
+ virtual file system where the repository stores global state
+ (e.g. registered namespaces, custom node types, etc.)
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/repository"/>
+ </FileSystem>
+
+ <!--
+ security configuration
+ -->
+ <Security appName="Jackrabbit">
+ <!--
+ access manager:
+ class: FQN of class implementing the AccessManager interface
+ -->
+ <AccessManager class="org.apache.jackrabbit.core.security.SimpleAccessManager">
+ <!-- <param name="config" value="${rep.home}/access.xml"/> -->
+ </AccessManager>
+
+ <LoginModule class="org.apache.jackrabbit.core.security.SimpleLoginModule">
+ <!-- anonymous user name ('anonymous' is the default value) -->
+ <param name="anonymousId" value="anonymous"/>
+ <!--
+ default user name to be used instead of the anonymous user
+ when no login credentials are provided (unset by default)
+ -->
+ <param name="defaultUserId" value="superuser"/>
+ </LoginModule>
+ </Security>
+
+ <!--
+ location of workspaces root directory and name of default workspace
+ -->
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+ <!--
+ workspace configuration template:
+ used to create the initial workspace if there's no workspace yet
+ -->
+ <Workspace name="Jackrabbit Core">
+ <!--
+ virtual file system of the workspace:
+ class: FQN of class implementing the FileSystem interface
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${wsp.home}"/>
+ </FileSystem>
+ <!--
+ persistence manager of the workspace:
+ class: FQN of class implementing the PersistenceManager interface
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <param name="url" value="jdbc:derby:${wsp.home}/db;create=true"/>
+ <param name="schemaObjectPrefix" value="Jackrabbit Core_"/>
+ </PersistenceManager>
+ <!--
+ Search index and the file system it uses.
+ class: FQN of class implementing the QueryHandler interface
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${wsp.home}/index"/>
+ </SearchIndex>
+ </Workspace>
+
+ <!--
+ Configures the versioning
+ -->
+ <Versioning rootPath="${rep.home}/version">
+ <!--
+ Configures the filesystem to use for versioning for the respective
+ persistence manager
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${rep.home}/version" />
+ </FileSystem>
+
+ <!--
+ Configures the persistence manager to be used for persisting version state.
+ Please note that the current versioning implementation is based on
+ a 'normal' persistence manager, but this could change in future
+ implementations.
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.db.DerbyPersistenceManager">
+ <param name="url" value="jdbc:derby:${rep.home}/version/db;create=true"/>
+ <param name="schemaObjectPrefix" value="version_"/>
+ </PersistenceManager>
+ </Versioning>
+
+ <!--
+ Search index for content that is shared repository wide
+ (/jcr:system tree, contains mainly versions)
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
+ <param name="path" value="${rep.home}/repository/index"/>
+ </SearchIndex>
+</Repository>
+
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/test-config/jackrabbit-test-config.xml
------------------------------------------------------------------------------
svn:eol-style = native