You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by jo...@apache.org on 2022/02/04 08:54:52 UTC

[sling-org-apache-sling-caconfig-impl] branch improvement/SLING-11114-use-LazySupplier created (now 09e601e)

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

joerghoh pushed a change to branch improvement/SLING-11114-use-LazySupplier
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-impl.git.


      at 09e601e  SLING-11114 Use a LazySupplier for the caconfig binding

This branch includes the following new commits:

     new 09e601e  SLING-11114 Use a LazySupplier for the caconfig binding

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-caconfig-impl] 01/01: SLING-11114 Use a LazySupplier for the caconfig binding

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

joerghoh pushed a commit to branch improvement/SLING-11114-use-LazySupplier
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-caconfig-impl.git

commit 09e601e2dca07e210a3d9f45ec5f21fe4d00cdf7
Author: Joerg Hoh <jh...@adobe.com>
AuthorDate: Fri Feb 4 09:53:21 2022 +0100

    SLING-11114 Use a LazySupplier for the caconfig binding
---
 pom.xml                                            | 14 ++++++++++++-
 .../impl/ConfigurationBindingsValueProvider.java   | 24 ++++++++++++++++------
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index 307c67c..52ff6e0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -126,7 +126,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.16.4</version>
+            <version>2.21.0</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
@@ -204,6 +204,18 @@
             <version>4.1.0</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.util.converter</artifactId>
+            <version>1.0.8</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.util.function</artifactId>
+            <version>1.2.0</version>
+            <scope>test</scope>
+        </dependency>
 
     </dependencies>
 
diff --git a/src/main/java/org/apache/sling/caconfig/impl/ConfigurationBindingsValueProvider.java b/src/main/java/org/apache/sling/caconfig/impl/ConfigurationBindingsValueProvider.java
index cf75502..5424177 100644
--- a/src/main/java/org/apache/sling/caconfig/impl/ConfigurationBindingsValueProvider.java
+++ b/src/main/java/org/apache/sling/caconfig/impl/ConfigurationBindingsValueProvider.java
@@ -28,6 +28,7 @@ import javax.script.Bindings;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.scripting.SlingBindings;
+import org.apache.sling.api.scripting.LazyBindings;
 import org.apache.sling.caconfig.ConfigurationBuilder;
 import org.apache.sling.caconfig.management.multiplexer.ConfigurationInjectResourceDetectionStrategyMultiplexer;
 import org.apache.sling.caconfig.management.multiplexer.ConfigurationMetadataProviderMultiplexer;
@@ -82,14 +83,25 @@ public class ConfigurationBindingsValueProvider implements BindingsValuesProvide
         if (!enabled) {
             return;
         }
+        if (bindings instanceof LazyBindings) {
+            // it's ok if the Supplier returns null, because Bindings.get(key) is allowed to return null
+            // both when the key is not available and when the value is null.
+            bindings.put(BINDING_VARIABLE, (LazyBindings.Supplier)() -> {
+                Resource resource = detectResourceForInjection(bindings);
+                if (resource == null) {
+                    return null;
+                }
+                return new ConfigMap(resource, configMetadataProvider);
+            });
+        } else { // resolve directly
+            Resource resource = detectResourceForInjection(bindings);
+            if (resource == null) {
+                return;
+            }
 
-        Resource resource = detectResourceForInjection(bindings);
-        if (resource == null) {
-            return;
+            Map<String,Object> configMap = new ConfigMap(resource, configMetadataProvider);
+            bindings.put(BINDING_VARIABLE, configMap);
         }
-
-        Map<String,Object> configMap = new ConfigMap(resource, configMetadataProvider);
-        bindings.put(BINDING_VARIABLE, configMap);
     }
 
     private Resource detectResourceForInjection(Bindings bindings) {