You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2020/04/29 19:51:49 UTC

[sling-org-apache-sling-scripting-sightly] branch issues/SLING-9406 created (now c997fe8)

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

pauls pushed a change to branch issues/SLING-9406
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git.


      at c997fe8  SLING-9406: Add bundled script support to the servlets resolver

This branch includes the following new commits:

     new c997fe8  SLING-9406: Add bundled script support to the servlets resolver

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-scripting-sightly] 01/01: SLING-9406: Add bundled script support to the servlets resolver

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch issues/SLING-9406
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git

commit c997fe81a8a5eb7d3b4a6d39259aa459e8f2b41c
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Wed Apr 29 21:51:30 2020 +0200

    SLING-9406: Add bundled script support to the servlets resolver
---
 bnd.bnd                                            |  1 -
 pom.xml                                            | 11 +++++-
 .../sightly/engine/BundledUnitManager.java         |  2 +-
 .../engine/bundled/BundledUnitManagerImpl.java     | 46 +++-------------------
 .../engine/extension/use/ScriptUseProvider.java    |  3 +-
 5 files changed, 17 insertions(+), 46 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
index 1afbf00..768c55b 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -11,6 +11,5 @@ Import-Package:     org.apache.sling.scripting.sightly.compiler.*;resolution:=op
                     org.apache.sling.scripting.sightly.java.compiler.*;resolution:=optional, \\
                     org.apache.sling.commons.compiler.*;resolution:=optional, \\
                     org.apache.sling.commons.classloader.*;resolution:=optional, \\
-                    org.apache.sling.scripting.bundle.tracker.*;resolution:=optional, \\
                     org.apache.sling.models.*;resolution:=optional, \\
                     *
diff --git a/pom.xml b/pom.xml
index 0d8ede1..e0b20e3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,6 +126,13 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.servlets.resolver</artifactId>
+            <version>2.6.5-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+
         <!-- OSGi -->
         <dependency>
             <groupId>org.osgi</groupId>
@@ -191,7 +198,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.scripting.core</artifactId>
-            <version>2.0.32</version>
+            <version>2.2.1-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -287,7 +294,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.sling-mock.junit4</artifactId>
-            <version>2.3.4</version>
+            <version>2.5.1-SNAPSHOT</version>
             <scope>test</scope>
         </dependency>
     </dependencies>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/engine/BundledUnitManager.java b/src/main/java/org/apache/sling/scripting/sightly/engine/BundledUnitManager.java
index 3a04d88..ad3d18d 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/engine/BundledUnitManager.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/engine/BundledUnitManager.java
@@ -22,7 +22,7 @@ import java.net.URL;
 
 import javax.script.Bindings;
 
-import org.apache.sling.scripting.bundle.tracker.BundledRenderUnit;
+import org.apache.sling.scripting.core.BundledRenderUnit;
 import org.apache.sling.scripting.sightly.render.RenderUnit;
 import org.jetbrains.annotations.Nullable;
 import org.osgi.annotation.versioning.ProviderType;
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
index acfba82..7f8dddd 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
@@ -39,9 +39,9 @@ import org.apache.sling.commons.compiler.source.JavaEscapeHelper;
 import org.apache.sling.scripting.api.CachedScript;
 import org.apache.sling.scripting.api.ScriptCache;
 import org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider;
-import org.apache.sling.scripting.bundle.tracker.BundledRenderUnit;
-import org.apache.sling.scripting.bundle.tracker.ResourceType;
-import org.apache.sling.scripting.bundle.tracker.TypeProvider;
+import org.apache.sling.scripting.core.BundledRenderUnit;
+import org.apache.sling.servlets.resolver.bundle.tracker.ResourceType;
+import org.apache.sling.servlets.resolver.bundle.tracker.TypeProvider;
 import org.apache.sling.scripting.core.ScriptNameAwareReader;
 import org.apache.sling.scripting.sightly.engine.BundledUnitManager;
 import org.apache.sling.scripting.sightly.impl.engine.SightlyCompiledScript;
@@ -50,34 +50,22 @@ import org.apache.sling.scripting.sightly.impl.utils.BindingsUtils;
 import org.apache.sling.scripting.sightly.render.RenderUnit;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
 import org.osgi.framework.wiring.BundleWiring;
-import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.service.component.annotations.Reference;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * The {@code BundledUnitManager} is an optional service, which is made available only if the {@link
- * org.apache.sling.scripting.bundle.tracker} APIs are available. This service allows various components to work with {@link
+ * This service allows various components to work with {@link
  * BundledRenderUnit} instance and perform dependency resolution based on their availability in
  * the {@link Bindings} maps passed to the HTL Script Engine.
  */
-@Component(
-        service = {}
-        /*
-         * this component will register itself as a service only if the org.apache.sling.scripting.bundle.tracker API is present
-         */
-        )
+@Component
 public class BundledUnitManagerImpl implements BundledUnitManager {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(BundledUnitManagerImpl.class);
 
-    private final ServiceRegistration<?> serviceRegistration;
-
     @Reference
     private ScriptEngineManager scriptEngineManager;
 
@@ -87,18 +75,6 @@ public class BundledUnitManagerImpl implements BundledUnitManager {
     @Reference
     private ScriptingResourceResolverProvider scriptingResourceResolverProvider;
 
-    @Activate
-    public BundledUnitManagerImpl(BundleContext bundleContext) {
-        serviceRegistration = register(bundleContext);
-    }
-
-    @Deactivate
-    public void deactivate() {
-        if (serviceRegistration != null) {
-            serviceRegistration.unregister();
-        }
-    }
-
 
     /**
      * Given a {@link Bindings} map, this method will check if the {@code bindings} contain a value for the {@link
@@ -275,18 +251,6 @@ public class BundledUnitManagerImpl implements BundledUnitManager {
         return null;
     }
 
-    private ServiceRegistration<?> register(BundleContext bundleContext) {
-        try {
-            BundledUnitManager.class.getClassLoader().loadClass("org.apache.sling.scripting.bundle.tracker.BundledRenderUnit");
-            return bundleContext.registerService(new String[] {BundledUnitManager.class.getName(),
-                            BundledUnitManagerImpl.class.getName()}, this,
-                    null);
-        } catch (ClassNotFoundException e) {
-            LOGGER.info("No support for bundled RenderUnits.");
-        }
-        return null;
-    }
-
     @Nullable
     private BundledRenderUnit getBundledRenderUnit(Bindings bindings) {
         Object bru = bindings.get(BundledRenderUnit.VARIABLE);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/ScriptUseProvider.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/ScriptUseProvider.java
index c525f6b..1855f5d 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/ScriptUseProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/ScriptUseProvider.java
@@ -42,6 +42,7 @@ import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.scripting.api.CachedScript;
 import org.apache.sling.scripting.api.ScriptCache;
 import org.apache.sling.scripting.api.resource.ScriptingResourceResolverProvider;
+import org.apache.sling.scripting.core.BundledRenderUnit;
 import org.apache.sling.scripting.core.ScriptNameAwareReader;
 import org.apache.sling.scripting.sightly.impl.engine.SightlyScriptEngineFactory;
 import org.apache.sling.scripting.sightly.impl.engine.bundled.BundledUnitManagerImpl;
@@ -112,7 +113,7 @@ public class ScriptUseProvider implements UseProvider {
             URL script = bundledUnitManager.getScript(bindings, scriptName);
             if (script != null) {
                 String scriptUrlAsString = script.toExternalForm();
-                bindings.remove("org.apache.sling.scripting.bundle.tracker.BundledRenderUnit");
+                bindings.remove(BundledRenderUnit.VARIABLE);
                 bindings.put(ScriptEngine.FILENAME, scriptUrlAsString);
                 try {
                     ScriptEngine scriptEngine = scriptEngineManager.getEngineByExtension(extension);