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/11/12 18:38:42 UTC
svn commit: r713431 - in /incubator/sling/trunk/extensions/jcrinstall/src:
main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/
main/java/org/apache/sling/jcr/jcrinstall/osgi/
main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/
test/java/org/apache/sli...
Author: bdelacretaz
Date: Wed Nov 12 09:38:41 2008
New Revision: 713431
URL: http://svn.apache.org/viewvc?rev=713431&view=rev
Log:
SLING-728 - jcrinstall resources in /apps override the same resources found in /libs
Added:
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java (with props)
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java (with props)
Modified:
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java
incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
Modified: 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=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/RepositoryObserver.java Wed Nov 12 09:38:41 2008
@@ -41,6 +41,7 @@
import org.apache.sling.jcr.api.SlingRepository;
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.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
import org.osgi.service.component.ComponentContext;
@@ -68,6 +69,7 @@
protected Set<WatchedFolder> folders;
private RegexpFilter folderNameFilter;
private RegexpFilter filenameFilter;
+ private ResourceOverrideRules roRules;
private boolean running;
/** @scr.reference */
@@ -111,8 +113,13 @@
}
lastBundleEvent = System.currentTimeMillis();
- // TODO make this more configurable?
+ // TODO make this more configurable (in sync with ResourceOverrideRulesImpl)
final String [] roots = DEFAULT_ROOTS;
+ final String [] main = { "/libs/" };
+ final String [] override = { "/apps/" };
+
+ roRules = new ResourceOverrideRulesImpl(main, override);
+ osgiController.setResourceOverrideRules(roRules);
/** NodeConverters setup
* Using services and a whiteboard pattern for these would be nice,
@@ -202,7 +209,7 @@
final Set<String> paths = w.getAndClearPaths();
if(paths != null) {
for(String path : paths) {
- folders.add(new WatchedFolder(repository, path, osgiController, filenameFilter, scanDelayMsec));
+ folders.add(new WatchedFolder(repository, path, osgiController, filenameFilter, scanDelayMsec, roRules));
}
}
}
@@ -239,7 +246,7 @@
void findWatchedFolders(Node n, Set<WatchedFolder> setToUpdate) throws RepositoryException
{
if (folderNameFilter.accept(n.getPath())) {
- setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, filenameFilter, scanDelayMsec));
+ setToUpdate.add(new WatchedFolder(repository, n.getPath(), osgiController, filenameFilter, scanDelayMsec, roRules));
}
final NodeIterator it = n.getNodes();
while (it.hasNext()) {
@@ -294,7 +301,7 @@
// on / and use it to check for any deletions, even
// if the corresponding WatchFolders are gone
try {
- final WatchedFolder rootWf = new WatchedFolder(repository, "/", osgiController, filenameFilter, 0L);
+ final WatchedFolder rootWf = new WatchedFolder(repository, "/", osgiController, filenameFilter, 0L, null);
rootWf.checkDeletions(osgiController.getInstalledUris());
} catch(Exception e) {
log.warn("Exception in root WatchFolder.checkDeletions call", e);
Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java?rev=713431&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java Wed Nov 12 09:38:41 2008
@@ -0,0 +1,68 @@
+package org.apache.sling.jcr.jcrinstall.jcr.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
+
+/** Simple path-based ResourceOverrideRules */
+class ResourceOverrideRulesImpl implements ResourceOverrideRules {
+
+ private final String [] mainPaths;
+ private final String [] overridePaths;
+
+ private static final String SLASH = "/";
+
+ ResourceOverrideRulesImpl(String [] mainPaths, String [] overridePaths) {
+ if(mainPaths == null || overridePaths == null) {
+ throw new IllegalArgumentException("Null mainPaths or overridePaths");
+ }
+ if(mainPaths.length != overridePaths.length) {
+ throw new IllegalArgumentException("mainPaths and overridePaths are not the same size");
+ }
+
+ this.mainPaths = mainPaths;
+ this.overridePaths = overridePaths;
+ }
+
+ public String[] getHigherPriorityResources(String uri) {
+ return map(uri, mainPaths, overridePaths);
+ }
+
+ public String[] getLowerPriorityResources(String uri) {
+ return map(uri, overridePaths, mainPaths);
+ }
+
+ private String [] map(String uri, String [] from, String [] to) {
+ boolean addedSlash = false;
+ if(!uri.startsWith(SLASH)) {
+ uri = SLASH + uri;
+ addedSlash = true;
+ }
+
+ List<String> mapped = null;
+ for(int i=0; i < from.length; i++) {
+ if(uri.startsWith(from[i])) {
+ if(mapped == null) {
+ mapped = new ArrayList<String>();
+ }
+ String str = to[i] + uri.substring(from[i].length());
+ if(addedSlash) {
+ str = str.substring(1);
+ }
+ mapped.add(str);
+ }
+ }
+
+ if(mapped == null) {
+ return new String[0];
+ } else {
+ final String [] result = new String[mapped.size()];
+ int i=0;
+ for(String str : mapped) {
+ result[i++] = str;
+ }
+ return result;
+ }
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: 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=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/WatchedFolder.java Wed Nov 12 09:38:41 2008
@@ -19,7 +19,9 @@
package org.apache.sling.jcr.jcrinstall.jcr.impl;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import javax.jcr.Item;
@@ -36,6 +38,7 @@
import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,8 +51,11 @@
private final OsgiController controller;
private long nextScan;
private final Session session;
+ private final ResourceOverrideRules roRules;
protected final Logger log = LoggerFactory.getLogger(getClass());
+ private static List<WatchedFolder> allFolders = new ArrayList<WatchedFolder>();
+
/**
* After receiving JCR events, we wait for this many msec before
* re-scanning the folder, as events often come in bursts.
@@ -57,10 +63,11 @@
private final long scanDelayMsec;
WatchedFolder(SlingRepository repository, String path, OsgiController ctrl,
- RegexpFilter filenameFilter, long scanDelayMsec) throws RepositoryException {
+ RegexpFilter filenameFilter, long scanDelayMsec, ResourceOverrideRules ror) throws RepositoryException {
this.path = path;
this.controller = ctrl;
this.scanDelayMsec = scanDelayMsec;
+ this.roRules = ror;
session = repository.loginAdministrative(repository.getDefaultWorkspace());
@@ -72,11 +79,17 @@
final boolean noLocal = true;
session.getWorkspace().getObservationManager().addEventListener(this, eventTypes, path,
isDeep, null, null, noLocal);
-
+
+ synchronized(allFolders) {
+ allFolders.add(this);
+ }
log.info("Watching folder " + path);
}
void cleanup() {
+ synchronized(allFolders) {
+ allFolders.remove(this);
+ }
try {
session.getWorkspace().getObservationManager().removeEventListener(this);
session.logout();
@@ -113,6 +126,11 @@
* a bit before processing event bursts.
*/
public void onEvent(EventIterator it) {
+ scheduleScan();
+ }
+
+ /** Trigger a scan, after the usual delay */
+ void scheduleScan() {
nextScan = System.currentTimeMillis() + scanDelayMsec;
}
@@ -169,9 +187,11 @@
/** Check for deleted resources and uninstall them */
void checkDeletions(Set<String> installedUri) throws Exception {
// Check deletions
+ int count = 0;
for(String uri : installedUri) {
if(uri.startsWith(path)) {
if(!session.itemExists(uri)) {
+ count++;
log.info("Resource {} has been deleted, uninstalling", uri);
// a single failure must not block the whole thing (SLING-655)
try {
@@ -182,6 +202,26 @@
}
}
}
+
+ // If any deletions, resources in lower/higher priority folders might need to
+ // be re-installed
+ if(count > 0 && roRules!=null) {
+ for(String str : roRules.getLowerPriorityResources(path)) {
+ rescanFoldersForPath(path, "Scheduling scan of lower priority {} folder after deletes in {} folder");
+ }
+ for(String str : roRules.getHigherPriorityResources(path)) {
+ rescanFoldersForPath(path, "Scheduling scan of higher priority {} folder after deletes in {} folder");
+ }
+ }
+ }
+
+ private void rescanFoldersForPath(String pathToScan, String logFormat) {
+ for(WatchedFolder wf : allFolders) {
+ if(pathToScan.equals(wf.path)) {
+ log.info(logFormat, wf.path, path);
+ wf.scheduleScan();
+ }
+ }
}
/** Install or update the given resource, as needed */
Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java?rev=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/OsgiController.java Wed Nov 12 09:38:41 2008
@@ -51,4 +51,7 @@
* @return -1 if we don't have info for given uri
*/
String getDigest(String uri);
+
+ /** Optionally set ResourceOverrideRules */
+ void setResourceOverrideRules(ResourceOverrideRules r);
}
Added: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java?rev=713431&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java Wed Nov 12 09:38:41 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.osgi;
+
+/** Resources can be overridden by others based on their URIs.
+ * This interface returns a list of resources that have a lower,
+ * or higher priority than the provided one.
+ */
+public interface ResourceOverrideRules {
+ /** Return the list of URIs of lower priority resources, which
+ * might or might not exist.
+ */
+ public String [] getHigherPriorityResources(String uri);
+
+ /** Return the list of URIs of higher priority resources, which
+ * might or might not exist.
+ */
+ public String [] getLowerPriorityResources(String uri);
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/ResourceOverrideRules.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java?rev=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java Wed Nov 12 09:38:41 2008
@@ -30,6 +30,7 @@
import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.SynchronousBundleListener;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -58,6 +59,7 @@
private final Logger log = LoggerFactory.getLogger(this.getClass());
private boolean running;
private long loopDelay;
+ private ResourceOverrideRules roRules;
public static final String STORAGE_FILENAME = "controller.storage";
@@ -110,6 +112,30 @@
public int installOrUpdate(String uri, InstallableData data) throws IOException, JcrInstallException {
int result = IGNORED;
+
+ // If a corresponding higher priority resource is already installed, ignore this one
+ if(roRules != null) {
+ for(String r : roRules.getHigherPriorityResources(uri)) {
+ if(storage.contains(r)) {
+ log.info("Resource {} ignored, overridden by {} which has higher priority",
+ uri, r);
+ return IGNORED;
+ }
+ }
+ }
+
+ // If a corresponding lower priority resource is installed, uninstall it first
+ if(roRules != null) {
+ for(String r : roRules.getLowerPriorityResources(uri)) {
+ if(storage.contains(r)) {
+ log.info("Resource {} overrides {}, uninstalling the latter",
+ uri, r);
+ uninstall(uri);
+ }
+ }
+ }
+
+ // let suitable OsgiResourceProcessor process install
final OsgiResourceProcessor p = getProcessor(uri, data);
if (p != null) {
try {
@@ -218,4 +244,8 @@
log.info("{} thread {} ends", getClass().getSimpleName(), Thread.currentThread().getName());
}
+
+ public void setResourceOverrideRules(ResourceOverrideRules r) {
+ roRules = r;
+ }
}
\ No newline at end of file
Modified: 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=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FindWatchedFoldersTest.java Wed Nov 12 09:38:41 2008
@@ -26,6 +26,7 @@
import org.apache.sling.commons.testing.jcr.RepositoryTestBase;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -60,6 +61,7 @@
osgiController = mockery.mock(OsgiController.class);
final Set<String> installedUri = new HashSet<String>();
mockery.checking(new Expectations() {{
+ allowing(osgiController).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(osgiController).getInstalledUris(); will(returnValue(installedUri));
}});
}
Modified: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java?rev=713431&r1=713430&r2=713431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java (original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceDetectionTest.java Wed Nov 12 09:38:41 2008
@@ -36,6 +36,7 @@
import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
import org.apache.sling.jcr.jcrinstall.osgi.OsgiController;
+import org.apache.sling.jcr.jcrinstall.osgi.ResourceOverrideRules;
import org.apache.sling.jcr.jcrinstall.osgi.impl.MockInstallableData;
import org.jmock.Expectations;
import org.jmock.Mockery;
@@ -103,6 +104,7 @@
// Define the whole sequence of calls to OsgiController,
// Using getLastModified calls to mark the test phases
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
one(c).getDigest("phase1");
@@ -165,6 +167,7 @@
// Define the whole sequence of calls to OsgiController,
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
@@ -206,6 +209,7 @@
final OsgiController c = mockery.mock(OsgiController.class);
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
@@ -240,6 +244,7 @@
final RepositoryObserver ro = new MockRepositoryObserver(repo, c);
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).uninstall("/libs/foo/bar/install/dummy.jar");
@@ -264,6 +269,7 @@
final RepositoryObserver ro = new MockRepositoryObserver(repo, c);
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).uninstall("/libs/foo/bar/install/dummy.cfg");
@@ -297,6 +303,7 @@
// Define the whole sequence of calls to OsgiController,
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
@@ -343,6 +350,7 @@
// Test with first regexp
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).installOrUpdate(with(equal(resources[0])), with(any(InstallableData.class)));
@@ -365,6 +373,7 @@
// Test with a different regexp, install.A resources must be uninstalled
mockery.checking(new Expectations() {{
+ allowing(c).setResourceOverrideRules(with(any(ResourceOverrideRules.class)));
allowing(c).getInstalledUris(); will(returnValue(installedUri));
allowing(c).getDigest(with(any(String.class))); will(returnValue(null));
one(c).uninstall(resources[0]);
Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java?rev=713431&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java (added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java Wed Nov 12 09:38:41 2008
@@ -0,0 +1,46 @@
+package org.apache.sling.jcr.jcrinstall.jcr.impl;
+
+import static org.junit.Assert.assertEquals;
+
+public class ResourceOverrideRulesImplTest {
+ private static final String [] main = { "/libs/", "/foo/" };
+ private static final String [] override = { "/apps/", "/bar/" };
+
+ private final ResourceOverrideRulesImpl rr = new ResourceOverrideRulesImpl(main, override);
+
+ @org.junit.Test public void testNoMappings() {
+ final String [] input = { "", "/foox", "somethingelse" };
+ for(String path : input) {
+ String [] result = rr.getHigherPriorityResources(path);
+ assertEquals("Path '" + path + "' should not have higher priority resource", 0, result.length);
+ result = rr.getLowerPriorityResources(path);
+ assertEquals("Path '" + path + "' should not have lower priority resource", 0, result.length);
+ }
+ }
+
+ @org.junit.Test public void testHigherPriority() {
+ final String [] input = { "/libs/a/b", "libs/a/b", "libs/", "/libs/" };
+ final String [] output = { "/apps/a/b", "apps/a/b", "apps/", "/apps/" };
+
+ for(int i=0 ; i < input.length; i++) {
+ String [] result = rr.getHigherPriorityResources(input[i]);
+ assertEquals("Path '" + input[i] + "' should have one higher priority resource", 1, result.length);
+ assertEquals("Path '" + input[i] + "' should map to '" + output[i] + "'", output[i], result[0]);
+ result = rr.getLowerPriorityResources(input[i]);
+ assertEquals("Path '" + input[i] + "' should not have lower priority resource", 0, result.length);
+ }
+ }
+
+ @org.junit.Test public void testLowerPriority() {
+ final String [] input = { "/apps/a/b", "apps/a/b", "apps/", "/apps/" };
+ final String [] output = { "/libs/a/b", "libs/a/b", "libs/", "/libs/" };
+
+ for(int i=0 ; i < input.length; i++) {
+ String [] result = rr.getLowerPriorityResources(input[i]);
+ assertEquals("Path '" + input[i] + "' should have one lower priority resource", 1, result.length);
+ assertEquals("Path '" + input[i] + "' should map to '" + output[i] + "'", output[i], result[0]);
+ result = rr.getHigherPriorityResources(input[i]);
+ assertEquals("Path '" + input[i] + "' should not have higher priority resource", 0, result.length);
+ }
+ }
+}
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/ResourceOverrideRulesImplTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL