sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sseif...@apache.org
Subject svn commit: r1794553 - /sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
Date Tue, 09 May 2017 12:31:05 GMT
Author: sseifert
Date: Tue May  9 12:31:05 2017
New Revision: 1794553

URL: http://svn.apache.org/viewvc?rev=1794553&view=rev
Log:
SLING-6845 sling-mock: Support Sling Models Impl 1.4.0

Modified:
    sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java

Modified: sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java?rev=1794553&r1=1794552&r2=1794553&view=diff
==============================================================================
--- sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
(original)
+++ sling/branches/testing/mocks/sling-mock-1.x/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java
Tue May  9 12:31:05 2017
@@ -32,17 +32,7 @@ import org.apache.sling.api.resource.Res
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 import org.apache.sling.commons.mime.MimeTypeService;
-import org.apache.sling.models.impl.FirstImplementationPicker;
 import org.apache.sling.models.impl.ModelAdapterFactory;
-import org.apache.sling.models.impl.injectors.BindingsInjector;
-import org.apache.sling.models.impl.injectors.ChildResourceInjector;
-import org.apache.sling.models.impl.injectors.OSGiServiceInjector;
-import org.apache.sling.models.impl.injectors.RequestAttributeInjector;
-import org.apache.sling.models.impl.injectors.ResourcePathInjector;
-import org.apache.sling.models.impl.injectors.SelfInjector;
-import org.apache.sling.models.impl.injectors.SlingObjectInjector;
-import org.apache.sling.models.impl.injectors.ValueMapInjector;
-import org.apache.sling.models.spi.ImplementationPicker;
 import org.apache.sling.resourcebuilder.api.ResourceBuilder;
 import org.apache.sling.resourcebuilder.api.ResourceBuilderFactory;
 import org.apache.sling.resourcebuilder.impl.ResourceBuilderFactoryService;
@@ -139,21 +129,23 @@ public class SlingContextImpl extends Os
         registerInjectActivateService(new ScriptEngineManagerFactory());
         registerInjectActivateService(new BindingsValuesProvidersByContextImpl());
         
-        // adapter factories
+        // sling models
         registerInjectActivateService(new ModelAdapterFactory());
-
-        // sling models injectors
-        registerInjectActivateService(new BindingsInjector());
-        registerInjectActivateService(new ChildResourceInjector());
-        registerInjectActivateService(new OSGiServiceInjector());
-        registerInjectActivateService(new RequestAttributeInjector());
-        registerInjectActivateService(new ResourcePathInjector());
-        registerInjectActivateService(new SelfInjector());
-        registerInjectActivateService(new SlingObjectInjector());
-        registerInjectActivateService(new ValueMapInjector());
-
-        // sling models implementation pickers
-        registerService(ImplementationPicker.class, new FirstImplementationPicker());
+        registerInjectActivateServiceByClassName(
+                "org.apache.sling.models.impl.FirstImplementationPicker",
+                "org.apache.sling.models.impl.ResourceTypeBasedResourcePicker",
+                "org.apache.sling.models.impl.injectors.BindingsInjector",
+                "org.apache.sling.models.impl.injectors.ChildResourceInjector",
+                "org.apache.sling.models.impl.injectors.OSGiServiceInjector",
+                "org.apache.sling.models.impl.injectors.RequestAttributeInjector",
+                "org.apache.sling.models.impl.injectors.ResourcePathInjector",
+                "org.apache.sling.models.impl.injectors.SelfInjector",
+                "org.apache.sling.models.impl.injectors.SlingObjectInjector",
+                "org.apache.sling.models.impl.injectors.ValueMapInjector",
+                "org.apache.sling.models.impl.via.BeanPropertyViaProvider",
+                "org.apache.sling.models.impl.via.ChildResourceViaProvider",
+                "org.apache.sling.models.impl.via.ForcedResourceTypeViaProvider",
+                "org.apache.sling.models.impl.via.ResourceSuperTypeViaProvider");
 
         // other services
         registerService(SlingSettingsService.class, new MockSlingSettingService(DEFAULT_RUN_MODES));
@@ -163,6 +155,24 @@ public class SlingContextImpl extends Os
         // scan for models defined via bundle headers in classpath
         ModelAdapterFactoryUtil.addModelsForManifestEntries(this.bundleContext());
     }
+    
+    private void registerInjectActivateServiceByClassName(String... classNames) {
+        for (String className : classNames) {
+            try {
+                Class<?> clazz = Class.forName(className);
+                registerInjectActivateService(clazz.newInstance());
+            }
+            catch (ClassNotFoundException ex) {
+                // ignore - probably not the latest sling models impl version
+            }
+            catch (InstantiationException e) {
+                // ignore - probably not the latest sling models impl version
+            }
+            catch (IllegalAccessException e) {
+                // ignore - probably not the latest sling models impl version
+            }
+        }
+    }
 
     /**
      * Teardown actions after test method execution



Mime
View raw message