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

sseifert pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git


The following commit(s) were added to refs/heads/master by this push:
     new b57dd98  SLING-7500 sling-mock: Make compatible with 
org.apache.sling.commons.mime 2.1.10
b57dd98 is described below

commit b57dd98b0fedf70c4a8239974b1623ee0a0da235
Author: sseifert <sseif...@pro-vision.de>
AuthorDate: Wed Feb 14 16:54:32 2018 +0100

    SLING-7500 sling-mock: Make compatible with org.apache.sling.commons.mime 
2.1.10
---
 .../mock/sling/services/MockMimeTypeService.java   | 28 +++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/sling/testing/mock/sling/services/MockMimeTypeService.java
 
b/src/main/java/org/apache/sling/testing/mock/sling/services/MockMimeTypeService.java
index a13ffa3..b5a8f2f 100644
--- 
a/src/main/java/org/apache/sling/testing/mock/sling/services/MockMimeTypeService.java
+++ 
b/src/main/java/org/apache/sling/testing/mock/sling/services/MockMimeTypeService.java
@@ -20,10 +20,15 @@ package org.apache.sling.testing.mock.sling.services;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Map;
 
 import org.apache.sling.commons.mime.MimeTypeService;
 import org.apache.sling.commons.mime.internal.MimeTypeServiceImpl;
+import org.apache.sling.testing.mock.osgi.MapUtil;
 import org.apache.sling.testing.mock.osgi.MockOsgi;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.component.annotations.Component;
 
@@ -45,7 +50,28 @@ public final class MockMimeTypeService extends 
MimeTypeServiceImpl {
             // activate service in simulated OSGi environment
             ComponentContext componentContext = MockOsgi.newComponentContext();
             this.bindLogService(MockOsgi.newLogService(getClass()));
-            activate(componentContext);
+            
+            // call activate method of MimeTypeServiceImpl
+            // via reflection because the method signature changed between 
org.apache.sling.commons.mime 2.1.8 and 2.1.10
+            try {
+                Method activateMethod;
+                try {
+                    activateMethod = 
MimeTypeServiceImpl.class.getDeclaredMethod("activate", ComponentContext.class);
+                    activateMethod.invoke(this, componentContext);
+                }
+                catch (NoSuchMethodException ex) {
+                    try {
+                        activateMethod = 
MimeTypeServiceImpl.class.getDeclaredMethod("activate", BundleContext.class, 
Map.class);
+                        activateMethod.invoke(this, 
componentContext.getBundleContext(), 
MapUtil.toMap(componentContext.getProperties()));
+                    }
+                    catch (NoSuchMethodException ex1) {
+                        throw new RuntimeException("Did not found activate 
method of MimeTypeServiceImpl with any matching signature.");
+                    }
+                }
+            }
+            catch (SecurityException | InvocationTargetException | 
IllegalAccessException ex) {
+                throw new RuntimeException("Unable to activate 
MimeTypeServiceImpl.", ex);
+            }
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
sseif...@apache.org.

Reply via email to