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 2019/12/02 11:19:38 UTC

[sling-org-apache-sling-scripting-sightly] branch master updated: SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings

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

radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git


The following commit(s) were added to refs/heads/master by this push:
     new e0b2291  SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings
e0b2291 is described below

commit e0b22918e26a7df34bcbf9b1fe3c06adf81a811d
Author: Radu Cotescu <17...@users.noreply.github.com>
AuthorDate: Mon Dec 2 12:19:30 2019 +0100

    SLING-8865 - Enhance the HTL runtime and script engine to take advantage of the support for lazy bindings
    
    * made SightlyBindingsValuesProvider use a LazyBindings.Supplier when possible
    * switched to LazyBindings in BindingsUtils
---
 pom.xml                                                    |  2 +-
 .../sightly/impl/engine/SightlyBindingsValuesProvider.java | 14 ++++++++++----
 .../sling/scripting/sightly/impl/utils/BindingsUtils.java  |  3 ++-
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0a7946b..50a2ffd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -173,7 +173,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.14.0</version>
+            <version>2.21.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyBindingsValuesProvider.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyBindingsValuesProvider.java
index 33164bb..4b898f8 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyBindingsValuesProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyBindingsValuesProvider.java
@@ -21,7 +21,7 @@ package org.apache.sling.scripting.sightly.impl.engine;
 import javax.script.Bindings;
 
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ValueMap;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.scripting.api.BindingsValuesProvider;
 import org.apache.sling.scripting.sightly.impl.utils.BindingsUtils;
 import org.osgi.service.component.annotations.Component;
@@ -36,14 +36,20 @@ import org.osgi.service.component.annotations.Component;
 )
 public class SightlyBindingsValuesProvider implements BindingsValuesProvider {
 
-    public static final String PROPERTIES = "properties";
+    private static final String PROPERTIES = "properties";
 
     @Override
     public void addBindings(Bindings bindings) {
         if (!bindings.containsKey(PROPERTIES)) {
             Resource currentResource = BindingsUtils.getResource(bindings);
-            if (currentResource != null) {
-                bindings.put(PROPERTIES, currentResource.adaptTo(ValueMap.class));
+            if (bindings instanceof LazyBindings) {
+                if (currentResource != null) {
+                    bindings.put(PROPERTIES, (LazyBindings.Supplier) currentResource::getValueMap);
+                }
+            } else {
+                if (currentResource != null) {
+                    bindings.put(PROPERTIES, currentResource.getValueMap());
+                }
             }
         }
     }
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/utils/BindingsUtils.java b/src/main/java/org/apache/sling/scripting/sightly/impl/utils/BindingsUtils.java
index 7f8b03d..8de2121 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/utils/BindingsUtils.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/utils/BindingsUtils.java
@@ -22,6 +22,7 @@ import javax.script.SimpleBindings;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.api.scripting.SlingBindings;
 import org.apache.sling.api.scripting.SlingScriptHelper;
 
@@ -79,7 +80,7 @@ public class BindingsUtils {
      * @return the merging of the two maps
      */
     public static Bindings merge(Bindings former, Bindings latter) {
-        Bindings bindings = new SimpleBindings();
+        Bindings bindings = new LazyBindings();
         bindings.putAll(former);
         bindings.putAll(latter);
         return bindings;