You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2015/08/13 22:30:41 UTC
svn commit: r1695774 - in /sling/trunk/testing/mocks/sling-mock: pom.xml
src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
Author: sseifert
Date: Thu Aug 13 20:30:41 2015
New Revision: 1695774
URL: http://svn.apache.org/r1695774
Log:
SLING-4932 switch back to old api/jcr.resource versions and ensure compatibility by initiating PathMapper service by reflection if it exists
Modified:
sling/trunk/testing/mocks/sling-mock/pom.xml
sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
Modified: sling/trunk/testing/mocks/sling-mock/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/pom.xml?rev=1695774&r1=1695773&r2=1695774&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/pom.xml (original)
+++ sling/trunk/testing/mocks/sling-mock/pom.xml Thu Aug 13 20:30:41 2015
@@ -77,7 +77,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.9.0</version>
+ <version>2.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -95,7 +95,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.jcr.resource</artifactId>
- <version>2.5.4</version>
+ <version>2.3.6</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -237,4 +237,25 @@
</plugins>
</build>
+ <!-- Profiles to run unit tests against different JCR Resource versions -->
+ <profiles>
+ <profile>
+ <id>jcr.resource-2.5.4</id>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.9.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.resource</artifactId>
+ <version>2.5.4</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
</project>
Modified: sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java?rev=1695774&r1=1695773&r2=1695774&view=diff
==============================================================================
--- sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java (original)
+++ sling/trunk/testing/mocks/sling-mock/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java Thu Aug 13 20:30:41 2015
@@ -32,7 +32,6 @@ import org.apache.sling.api.resource.Res
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.resource.internal.helper.jcr.JcrResourceProviderFactory;
-import org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper;
import org.apache.sling.testing.mock.osgi.MockOsgi;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
@@ -61,10 +60,9 @@ class MockJcrResourceResolverFactory ext
bundleContext.registerService(SlingRepository.class.getName(), this.slingRepository, null);
}
- // setup PathMapper which is a mandatory service for JcrProviderFactory
- if (bundleContext.getServiceReference(PathMapper.class.getName()) == null) {
- bundleContext.registerService(PathMapper.class.getName(), new PathMapper(), null);
- }
+ // setup PathMapper which is a mandatory service for JcrProviderFactory (since org.apache.sling.jcr.resource 2.5.4)
+ // use reflection to not depend on it if running with older version of org.apache.sling.jcr.resource
+ registerServiceIfFoundInClasspath("org.apache.sling.jcr.resource.internal.helper.jcr.PathMapper");
// setup real sling JCR resource provider implementation for use in
// mocked context
@@ -109,4 +107,25 @@ class MockJcrResourceResolverFactory ext
}
}
+ private void registerServiceIfFoundInClasspath(String className) {
+ try {
+ Class pathMapperClass = Class.forName(className);
+ if (bundleContext.getServiceReference(className) == null) {
+ Object instance = pathMapperClass.newInstance();
+ MockOsgi.injectServices(instance, bundleContext);
+ MockOsgi.activate(instance);
+ bundleContext.registerService(className, instance, null);
+ }
+ }
+ catch (ClassNotFoundException ex) {
+ // skip service registration
+ }
+ catch (InstantiationException e) {
+ // skip service registration
+ }
+ catch (IllegalAccessException e) {
+ // skip service registration
+ }
+ }
+
}