You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2015/09/02 15:52:34 UTC

svn commit: r1700816 - in /sling/trunk/bundles/scripting/sightly: engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/ testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/ testing-content/src/main/...

Author: radu
Date: Wed Sep  2 13:52:34 2015
New Revision: 1700816

URL: http://svn.apache.org/r1700816
Log:
SLING-4554 - Support for OSGi-services in data-sly-use

* if the resolved class is an OSGi service return the service's instance

Added:
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/TestService.java
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/TestServiceImpl.java
Modified:
    sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
    sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html
    sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java

Modified: sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java?rev=1700816&r1=1700815&r2=1700816&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java (original)
+++ sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/JavaUseProvider.java Wed Sep  2 13:52:34 2015
@@ -89,6 +89,11 @@ public class JavaUseProvider implements
         Object result;
         try {
             Class<?> cls = classLoaderWriter.getClassLoader().loadClass(identifier);
+            // attempt OSGi service load
+            result = sling.getService(cls);
+            if (result != null) {
+                return ProviderOutcome.success(result);
+            }
             result = resource.adaptTo(cls);
             if (result == null) {
                 result = request.adaptTo(cls);

Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/TestService.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/TestService.java?rev=1700816&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/TestService.java (added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/TestService.java Wed Sep  2 13:52:34 2015
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * 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.scripting.sightly.testing.use;
+
+public interface TestService {
+
+    String sayHello();
+
+}

Added: sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/TestServiceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/TestServiceImpl.java?rev=1700816&view=auto
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/TestServiceImpl.java (added)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/java/org/apache/sling/scripting/sightly/testing/use/impl/TestServiceImpl.java Wed Sep  2 13:52:34 2015
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.scripting.sightly.testing.use.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.scripting.sightly.testing.use.TestService;
+
+@Component
+@Service(TestService.class)
+public class TestServiceImpl implements TestService {
+
+    @Override
+    public String sayHello() {
+        return "Hello World!";
+    }
+}

Modified: sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html?rev=1700816&r1=1700815&r2=1700816&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html (original)
+++ sling/trunk/bundles/scripting/sightly/testing-content/src/main/resources/SLING-INF/apps/sightly/scripts/use/use.html Wed Sep  2 13:52:34 2015
@@ -28,5 +28,6 @@
              data-sly-use.reqadapt="org.apache.sling.scripting.sightly.testing.adaptable.RequestAdapterUseObject">${reqadapt.title}</div>
         <div id="resadapt"
              data-sly-use.resadapt="org.apache.sling.scripting.sightly.testing.adaptable.ResourceAdapterUseObject">${resadapt.title}</div>
+        <div id="osgi" data-sly-use.osgi="org.apache.sling.scripting.sightly.testing.use.TestService">${osgi.sayHello}</div>
     </body>
 </html>
\ No newline at end of file

Modified: sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java?rev=1700816&r1=1700815&r2=1700816&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java (original)
+++ sling/trunk/bundles/scripting/sightly/testing/src/test/java/org/apache/sling/scripting/sightly/it/SlingSpecificsSightlyIT.java Wed Sep  2 13:52:34 2015
@@ -65,6 +65,13 @@ public class SlingSpecificsSightlyIT {
     }
 
     @Test
+    public void testUseAPIWithOSGIService() {
+        String url = launchpadURL + SLING_USE;
+        String pageContent = client.getStringContent(url, 200);
+        assertEquals("Hello World!", HTMLExtractor.innerHTML(url, pageContent, "#osgi"));
+    }
+
+    @Test
     public void testErroneousUseObject() {
         String url = launchpadURL + SLING_JAVA_USE_NPE;
         String pageContent = client.getStringContent(url, 500);