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/11/11 14:51:04 UTC

[sling-org-apache-sling-scripting-sightly] branch issue/SLING-8737 created (now 9c3e1ed)

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

radu pushed a change to branch issue/SLING-8737
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git.


      at 9c3e1ed  SLING-8737 - Add support for lazily-evaluated bindings

This branch includes the following new commits:

     new 9c3e1ed  SLING-8737 - Add support for lazily-evaluated bindings

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-8737 - Add support for lazily-evaluated bindings

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

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

commit 9c3e1ed2b34c039c174795418d70c8e93c3690c2
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Nov 11 15:50:38 2019 +0100

    SLING-8737 - Add support for lazily-evaluated bindings
    
    * switched from SimpleBindings to LazyBindings
---
 pom.xml                                                  |  2 +-
 .../impl/engine/SightlyBindingsValuesProvider.java       | 16 ++++++++++++++--
 .../scripting/sightly/impl/utils/BindingsUtils.java      |  3 ++-
 3 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/pom.xml b/pom.xml
index 0a7946b..d0647ef 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-SNAPSHOT</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..f5e99a5 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
@@ -18,13 +18,18 @@
  ******************************************************************************/
 package org.apache.sling.scripting.sightly.impl.engine;
 
+import java.util.function.Supplier;
+
 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;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * HTL specific {@code BindingsValuesProvider}.
@@ -37,13 +42,20 @@ import org.osgi.service.component.annotations.Component;
 public class SightlyBindingsValuesProvider implements BindingsValuesProvider {
 
     public static final String PROPERTIES = "properties";
+    private static final Logger LOGGER = LoggerFactory.getLogger(SightlyBindingsValuesProvider.class);
 
     @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, (Supplier<Object>) () -> currentResource.adaptTo(ValueMap.class));
+                }
+            } else {
+                if (currentResource != null) {
+                    bindings.put(PROPERTIES, currentResource.adaptTo(ValueMap.class));
+                }
             }
         }
     }
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;