This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.scripting.sightly.js.provider-1.0.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly-js-provider.git
commit 104aad1c908e13ab04d7122a858f2a24aaf37367 Author: Radu Cotescu <[email protected]> AuthorDate: Mon Apr 6 20:15:05 2015 +0000 SLING-4578 - Incorrect Sightly JS Use-API script dependency resolution * explicitly check component inheritance when resolving script dependencies * provided tests for Use API dependency inheritance * made sure IT are run in the same order on all platforms git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/contrib/scripting/sightly/js-use-provider@1671688 13f79535-47bb-0310-9956-ffa450edef68 --- .../scripting/sightly/js/impl/JsEnvironment.java | 42 +++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java index 859accc..d91b764 100644 --- a/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java +++ b/src/main/java/org/apache/sling/scripting/sightly/js/impl/JsEnvironment.java @@ -30,7 +30,9 @@ import javax.script.SimpleBindings; import javax.script.SimpleScriptContext; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.resource.ResourceUtil; import org.apache.sling.api.scripting.SlingBindings; import org.apache.sling.api.scripting.SlingScriptHelper; import org.apache.sling.scripting.sightly.ResourceResolution; @@ -89,10 +91,11 @@ public class JsEnvironment { SlingScriptHelper scriptHelper = (SlingScriptHelper) globalBindings.get(SlingBindings.SLING); Resource componentCaller = ResourceResolution.getResourceForRequest(caller.getResourceResolver(), scriptHelper.getRequest()); if (scriptResource == null) { - scriptResource = ResourceResolution.getResourceFromSearchPath(componentCaller, path); - } - if (scriptResource == null) { - scriptResource = ResourceResolution.getResourceFromSearchPath(caller, path); + if (isResourceOverlay(caller, componentCaller)) { + scriptResource = ResourceResolution.getResourceFromSearchPath(componentCaller, path); + } else { + scriptResource = ResourceResolution.getResourceFromSearchPath(caller, path); + } } if (scriptResource == null) { throw new SightlyException("Required script resource could not be located: " + path); @@ -170,4 +173,35 @@ public class JsEnvironment { } }); } + + /** + * Using the inheritance chain created with the help of {@code sling:resourceSuperType} this method checks if {@code resourceB} + * inherits from {@code resourceA}. In case {@code resourceA} is a {@code nt:file}, its parent will be used for the inheritance check. + * + * @param resourceA the base resource + * @param resourceB the potentially overlaid resource + * @return {@code true} if {@code resourceB} overlays {@code resourceB}, {@code false} otherwise + */ + private boolean isResourceOverlay(Resource resourceA, Resource resourceB) { + String resourceBSuperType = resourceB.getResourceSuperType(); + if (StringUtils.isNotEmpty(resourceBSuperType)) { + String parentResourceType = resourceA.getResourceType(); + if ("nt:file".equals(parentResourceType)) { + parentResourceType = ResourceUtil.getParent(resourceA.getPath()); + } + if (resourceBSuperType.equals(parentResourceType)) { + return true; + } + Resource parentB = resourceB.getResourceResolver().getResource(resourceBSuperType); + resourceBSuperType = parentB.getResourceSuperType(); + while (!"/".equals(parentB.getPath()) && StringUtils.isNotEmpty(resourceBSuperType)) { + if (resourceBSuperType.equals(parentResourceType)) { + return true; + } + parentB = parentB.getParent(); + resourceBSuperType = parentB.getResourceSuperType(); + } + } + return false; + } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
