This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag 
org.apache.sling.testing.sling-mock-1.5.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git

commit 169f6e064447315c6eaf10adbbb72ae6da66027b
Author: Stefan Seifert <[email protected]>
AuthorDate: Thu Aug 13 20:30:41 2015 +0000

    SLING-4932 switch back to old api/jcr.resource versions and ensure 
compatibility by initiating PathMapper service by reflection if it exists
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1695774 
13f79535-47bb-0310-9956-ffa450edef68
---
 pom.xml                                            | 25 +++++++++++++++++--
 .../mock/sling/MockJcrResourceResolverFactory.java | 29 ++++++++++++++++++----
 2 files changed, 47 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index 69b20be..3c0ca59 100644
--- a/pom.xml
+++ b/pom.xml
@@ -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>
diff --git 
a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
 
b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
index b82d513..8de58a1 100644
--- 
a/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
+++ 
b/src/main/java/org/apache/sling/testing/mock/sling/MockJcrResourceResolverFactory.java
@@ -32,7 +32,6 @@ import org.apache.sling.api.resource.ResourceResolver;
 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 extends 
AbstractMockResourceResolverFactory
             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 extends 
AbstractMockResourceResolverFactory
         }
     }
     
+    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
+        }
+    }
+    
 }

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to