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 2020/03/23 16:05:32 UTC

[sling-org-apache-sling-scripting-bundle-tracker] 02/02: SLING-9216 - Allow capabilities to provide lists of resource types

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-bundle-tracker.git

commit 55d52a8293f1238e45613f73b0923b4ac324a8f5
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Mar 23 17:05:13 2020 +0100

    SLING-9216 - Allow capabilities to provide lists of resource types
---
 .../scripting/bundle/tracker/internal/BundledScriptFinder.java   | 9 ++++++++-
 .../sling/scripting/bundle/tracker/internal/TypeProvider.java    | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/BundledScriptFinder.java b/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/BundledScriptFinder.java
index 162c89d..bbe9973 100644
--- a/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/BundledScriptFinder.java
+++ b/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/BundledScriptFinder.java
@@ -40,12 +40,15 @@ import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 @Component(
         service = BundledScriptFinder.class
 )
 public class BundledScriptFinder {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(BundledScriptFinder.class);
     private static final String NS_JAVAX_SCRIPT_CAPABILITY = "javax.script";
     private static final String SLASH = "/";
     private static final String DOT = ".";
@@ -79,14 +82,18 @@ public class BundledScriptFinder {
                             } else {
                                 bundledScriptURL =
                                         provider.getBundle()
-                                                .getEntry(NS_JAVAX_SCRIPT_CAPABILITY + SLASH + match + DOT + scriptEngineExtension);
+                                                .getEntry(NS_JAVAX_SCRIPT_CAPABILITY + (match.startsWith("/") ? "" : SLASH) + match + DOT + scriptEngineExtension);
                                 if (bundledScriptURL != null) {
                                     return new Script(provider.getBundle(), bundledScriptURL, scriptEngine);
                                 }
                             }
                         }
                     }
+                } else {
+                    LOGGER.error("Cannot find a script engine for short name {}.", scriptEngineName);
                 }
+            } else {
+                LOGGER.error("Cannot find a script engine name for {}.", provider);
             }
         }
         return null;
diff --git a/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/TypeProvider.java b/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/TypeProvider.java
index 7332102..c8cda53 100644
--- a/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/TypeProvider.java
+++ b/src/main/java/org/apache/sling/scripting/bundle/tracker/internal/TypeProvider.java
@@ -77,4 +77,9 @@ public class TypeProvider {
         }
         return false;
     }
+
+    @Override
+    public String toString() {
+        return String.format("TypeProvider{ resourceTypes=%s; bundle=%s }", resourceTypes, bundle.getSymbolicName());
+    }
 }