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 2021/01/29 10:16:17 UTC

[sling-org-apache-sling-servlets-resolver] branch master updated (1d1c6f9 -> 0d03d77)

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

radu pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git.


    from 1d1c6f9  SLING-10031 Move MediaRangeList from Servlets POST to Sling API
     new 32ffb39  SLING-9999 - Remove cyclic dependency between scripting and servlets features
     new 0d03d77  SLING-9999 - Remove cyclic dependency between scripting and servlets features

The 2 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.


Summary of changes:
 pom.xml                                            | 13 ++--
 .../internal/BundledRenderUnitCapabilityImpl.java  |  4 +-
 .../tracker/internal/BundledScriptServlet.java     |  6 +-
 .../tracker/internal/BundledScriptTracker.java     | 10 +--
 .../bundle/tracker/internal/TypeProviderImpl.java  |  4 +-
 .../tracker/internal/request/RequestWrapper.java   |  2 +-
 .../resolver/bundle/tracker/ResourceTypeTest.java  | 87 ++++++++++++++++++++++
 .../resolver/it/ServletResolverTestSupport.java    |  2 +-
 8 files changed, 107 insertions(+), 21 deletions(-)
 create mode 100644 src/test/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceTypeTest.java


[sling-org-apache-sling-servlets-resolver] 01/02: SLING-9999 - Remove cyclic dependency between scripting and servlets features

Posted by ra...@apache.org.
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-servlets-resolver.git

commit 32ffb390c6ebb66aaf4fd8aff0a75f4a15066d9c
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Jan 28 14:01:49 2021 +0100

    SLING-9999 - Remove cyclic dependency between scripting and servlets features
    
    * This reverts commit 8262ce63725b9ab93c1d3eb07ace6b02d79acc65
---
 pom.xml                                            |   8 +-
 .../resolver/bundle/tracker/BundledRenderUnit.java | 145 +++++++++++++++++++
 .../tracker/BundledRenderUnitCapability.java       |  91 ++++++++++++
 .../bundle/tracker/BundledRenderUnitFinder.java    |  62 ++++++++
 .../resolver/bundle/tracker/ResourceType.java      | 161 +++++++++++++++++++++
 .../resolver/bundle/tracker/TypeProvider.java      |  45 ++++++
 .../internal/BundledRenderUnitCapabilityImpl.java  |   4 +-
 .../tracker/internal/BundledScriptServlet.java     |   6 +-
 .../tracker/internal/BundledScriptTracker.java     |  10 +-
 .../bundle/tracker/internal/TypeProviderImpl.java  |   4 +-
 .../tracker/internal/request/RequestWrapper.java   |   2 +-
 .../resolver/bundle/tracker/package-info.java      |  22 +++
 .../resolver/bundle/tracker/ResourceTypeTest.java  |  87 +++++++++++
 .../resolver/it/ServletResolverTestSupport.java    |   1 -
 14 files changed, 627 insertions(+), 21 deletions(-)

diff --git a/pom.xml b/pom.xml
index 96d32db..c780bb5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -214,13 +214,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.23.1-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.scripting.api</artifactId>
-            <version>2.2.1-SNAPSHOT</version>
+            <version>2.22.0</version>
             <scope>provided</scope>
         </dependency>
         <!-- for ServiceUserMapped (SLING-4312) -->
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java
new file mode 100644
index 0000000..2c89309
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java
@@ -0,0 +1,145 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import java.io.InputStream;
+import java.util.Set;
+
+import javax.script.ScriptException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ConsumerType;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+/**
+ * <p>
+ * A {@code BundledRenderUnit} represents a pre-packaged script or precompiled script (Java class) that will be executed in order to
+ * render a {@link org.apache.sling.api.SlingHttpServletRequest}.
+ * </p>
+ * <p>
+ * The {@code BundledRenderUnit} provider module is responsible for defining how a unit is executed. However, when executing the unit in the
+ * context of a {@link javax.script.ScriptEngine}, the provider module should add the current executing unit into the {@link
+ * javax.script.ScriptEngine}'s {@link javax.script.ScriptContext} using the {@link #VARIABLE} key.
+ * </p>
+ */
+@ConsumerType
+public interface BundledRenderUnit {
+
+    /**
+     * The variable available in the {@link javax.script.Bindings} associated to a {@link org.apache.sling.api.SlingHttpServletRequest} if
+     * that request is served by a {@code BundledRenderUnit}.
+     */
+    String VARIABLE = BundledRenderUnit.class.getName();
+
+    /**
+     * In case this {@code BundledRenderUnit} wraps a precompiled script, this method will return an instance of that object.
+     *
+     * @return a precompiled unit, if {@code this} unit wraps a precompiled script; {@code null} otherwise
+     */
+    @Nullable
+    default Object getUnit() {
+        return null;
+    }
+
+    /**
+     * Returns the name of {@code this BundledRenderUnit}. This can be the name of the wrapped script or precompiled script.
+     *
+     * @return the name {@code this BundledRenderUnit}
+     */
+    @NotNull String getName();
+
+    /**
+     * Returns the {@link Bundle} the publishing bundle of this unit (not to be confused with the provider module, which is the module that
+     * instantiates a {@link BundledRenderUnit}). This method can be useful for getting an instance of the bundle's classloader, when
+     * needed to load dependencies at run-time. To do so the following code example can help:
+     *
+     * <pre>
+     * Bundle bundle = bundledRenderUnit.getBundle();
+     * Classloader bundleClassloader = bundle.adapt(BundleWiring.class).getClassLoader();
+     * </pre>
+     */
+    @NotNull Bundle getBundle();
+
+    /**
+     * Returns the {@link BundleContext} to use for this unit. This method can be useful for getting an instance of the publishing bundle's
+     * context, when needed to load dependencies at run-time.
+     *
+     * @return the bundle context of the bundle publishing this unit
+     */
+    @NotNull BundleContext getBundleContext();
+
+    /**
+     * Returns the {@code Set} of {@link TypeProvider}s which are related to this unit.
+     *
+     * @return the set of providers; if the unit doesn't have any inheritance chains, then the set will contain only one {@link
+     * TypeProvider}
+     */
+    @NotNull Set<TypeProvider> getTypeProviders();
+
+    /**
+     * Retrieves an OSGi runtime dependency of the wrapped script identified by the passed {@code className} parameter.
+     *
+     * @param className the fully qualified class name
+     * @param <T>       the expected service type
+     * @return an instance of the {@link T} or {@code null}
+     */
+    @Nullable <T> T getService(@NotNull String className);
+
+    /**
+     * Retrieves multiple instances of an OSGi runtime dependency of the wrapped script identified by the passed {@code className}
+     * parameter, filtered according to the passed {@code filter}.
+     *
+     * @param className the fully qualified class name
+     * @param filter    a filter expression or {@code null} if all the instances should be returned; for more details about the {@code
+     *                  filter}'s syntax check {@link org.osgi.framework.BundleContext#getServiceReferences(String, String)}
+     * @param <T>       the expected service type
+     * @return an instance of the {@link T} or {@code null}
+     */
+    @Nullable <T> T[] getServices(@NotNull String className, @Nullable String filter);
+
+    /**
+     * Returns the path of this executable in the resource type hierarchy. The path can be relative to the search paths or absolute.
+     *
+     * @return the path of this executable in the resource type hierarchy
+     */
+    @NotNull
+    String getPath();
+
+    /**
+     * This method will execute / evaluate the wrapped script or precompiled script with the given request.
+     *
+     * @throws ScriptException if the execution leads to an error
+     */
+    void eval(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws ScriptException;
+
+    /**
+     * This method will return an input stream if {@code this} unit is backed by a script that can be interpreted.
+     *
+     * @return an {@link InputStream} providing the source code of the backing script; if {@code this} unit is backed by a precompiled
+     * script (essentially a Java class), then this method will return {@code null}
+     */
+    @Nullable
+    default InputStream getInputStream() {
+        return null;
+    }
+}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java
new file mode 100644
index 0000000..e0693cb
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java
@@ -0,0 +1,91 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import java.util.List;
+import java.util.Set;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * A {@code BundledRenderUnitCapability} encapsulates the values of a {@code Provided-Capability}, based on which {@link BundledRenderUnit}s
+ * are generated.
+ */
+@ProviderType
+public interface BundledRenderUnitCapability {
+
+    /**
+     * Returns the resource types to which a {@link BundledRenderUnit} described by this capability will be bound to.
+     *
+     * @return the resource types to which a {@link BundledRenderUnit} described by this capability will be bound to
+     */
+    @NotNull Set<ResourceType> getResourceTypes();
+
+    /**
+     * Returns the path to which a {@link BundledRenderUnit} described by this capability will be bound to.
+     *
+     * @return the path to which a {@link BundledRenderUnit} described by this capability will be bound to; this can be {@code null} if the
+     * {@link #getResourceTypes()} doesn't return an empty set
+     */
+    @Nullable String getPath();
+
+    /**
+     * Returns the selectors to which a {@link BundledRenderUnit} described by this capability will be bound to.
+     *
+     * @return the selectors to which a {@link BundledRenderUnit} described by this capability will be bound to
+     */
+    @NotNull List<String> getSelectors();
+
+    /**
+     * Returns the extension to which a {@link BundledRenderUnit} described by this capability will be bound to.
+     *
+     * @return the extension to which a {@link BundledRenderUnit} described by this capability will be bound to
+     */
+    @Nullable String getExtension();
+
+    /**
+     * Returns the resource type extended by this capability.
+     *
+     * @return the extended resource type or {@code null}
+     */
+    @Nullable String getExtendedResourceType();
+
+    /**
+     * Returns the request method to which a {@link BundledRenderUnit} described by this capability will be bound to.
+     *
+     * @return the request method to which a {@link BundledRenderUnit} described by this capability will be bound to
+     */
+    @Nullable String getMethod();
+
+    /**
+     * Returns the script engine short name which can be used to evaluate the {@link BundledRenderUnit} described by this capability.
+     *
+     * @return the script engine short name which can be used to evaluate the {@link BundledRenderUnit} described by this capability.
+     */
+    @Nullable String getScriptEngineName();
+
+    /**
+     * Returns the original's script extension that was used to generate this capability.
+     *
+     * @return the original's script extension that was used to generate this capability.
+     */
+    @Nullable String getScriptExtension();
+}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java
new file mode 100644
index 0000000..d632ba8
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java
@@ -0,0 +1,62 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import java.util.Set;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ConsumerType;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The {@code BundledScriptFinder} finds the {@link BundledRenderUnit} corresponding to a certain chain of {@link TypeProvider}s or
+ * corresponding to a certain path-based {@link BundledRenderUnitCapability}.
+ */
+@ConsumerType
+public interface BundledRenderUnitFinder {
+
+    /**
+     * Retrieves the best matching {@link BundledRenderUnit} for the provided {@code inheritanceChain}, by scanning all {@link TypeProvider}
+     * bundles for the class or script capable of providing a rendering for resource type chain.
+     *
+     * @param context             the bundle context to use.
+     * @param inheritanceChain    the resource type chain; the set is ordered from the most specific resource type to the most generic one
+     * @param allRelatedProviders this is a super set, containing both the {@code inheritanceChain} but also all the required providers; a
+     *                            required provider is a provider that's needed by a {@link ResourceType} in order to delegate rendering to
+     *                            it, but it's not extended by the same {@link ResourceType}
+     * @return a {@link BundledRenderUnit} if one was found, {@code null} otherwise
+     */
+    @Nullable
+    BundledRenderUnit findUnit(@NotNull BundleContext context, @NotNull Set<TypeProvider> inheritanceChain, @NotNull Set<TypeProvider> allRelatedProviders);
+
+    /**
+     * Retrieves a path-based {@link BundledRenderUnit} from the passed {@code provider}.
+     *
+     * @param context             the bundle context to use.
+     * @param provider            the provider from which to retrieve the unit
+     * @param allRelatedProviders this is a super set, containing both the providers connected through an inheritance relationship but also
+     *                            all the required providers; a required provider is a provider that's needed by a {@link ResourceType} in
+     *                            order to delegate rendering to it, but it's not extended by the same {@link ResourceType}
+     * @return a {@link BundledRenderUnit} if one was found, {@code null} otherwise
+     * @see BundledRenderUnitCapability#getPath()
+     */
+    @Nullable
+    BundledRenderUnit findUnit(@NotNull BundleContext context, @NotNull TypeProvider provider, @NotNull Set<TypeProvider> allRelatedProviders);
+}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java
new file mode 100644
index 0000000..0f2929e
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java
@@ -0,0 +1,161 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import java.util.Objects;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.Version;
+
+/**
+ * The {@code ResourceType} encapsulates details about a Sling resource type and provides methods for parsing resource type strings.
+ *
+ * <p>The following patterns are supported for parsing:</p>
+ * <ol>
+ * <li><tt>a/b/c</tt> - path-based</li>
+ * <li><tt>a/b/c/1.0.0</tt> - path-based, versioned</li>
+ * <li><tt>a.b.c</tt> - Java package name</li>
+ * <li><tt>a.b.c/1.0.0</tt> - Java package name, versioned</li>
+ * <li><tt>a</tt> - flat (sub-set of path-based)</li>
+ * </ol>
+ */
+public final class ResourceType {
+
+    private static final Pattern versionPattern = Pattern.compile("[\\d\\.]+(-.*)*$");
+
+    private final String type;
+    private final String version;
+    private final String resourceLabel;
+    private final String toString;
+
+    private ResourceType(@NotNull String type, @Nullable String version) {
+        this.type = type;
+        this.version = version;
+        if (type.lastIndexOf('/') != -1) {
+            resourceLabel = type.substring(type.lastIndexOf('/') + 1);
+        } else if (type.lastIndexOf('.') != -1) {
+            resourceLabel = type.substring(type.lastIndexOf('.') + 1);
+        } else {
+            resourceLabel = type;
+        }
+        toString = type + (version == null ? "" : "/" + version);
+    }
+
+    /**
+     * Returns a resource type's label. The label is important for script selection, since it will provide the name of the main script
+     * for this resource type. For more details check the Apache Sling
+     * <a href="https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#scripts-for-get-requests">URL to
+     * Script Resolution</a> page
+     *
+     * @return the resource type label
+     */
+    @NotNull
+    public String getResourceLabel() {
+        return resourceLabel;
+    }
+
+    /**
+     * Returns the resource type string, without any version information.
+     *
+     * @return the resource type string
+     */
+    @NotNull
+    public String getType() {
+        return type;
+    }
+
+    /**
+     * Returns the version, if available.
+     *
+     * @return the version, if available; {@code null} otherwise
+     */
+    @Nullable
+    public String getVersion() {
+        return version;
+    }
+
+    @Override
+    public String toString() {
+        return toString;
+    }
+
+    /**
+     * Given a {@code resourceTypeString}, this method will extract a {@link ResourceType} object.
+     * <p>The accepted patterns are:</p>
+     * <ol>
+     * <li><tt>a/b/c</tt> - path-based</li>
+     * <li><tt>a/b/c/1.0.0</tt> - path-based, versioned</li>
+     * <li><tt>a.b.c</tt> - Java package name</li>
+     * <li><tt>a.b.c/1.0.0</tt> - Java package name, versioned</li>
+     * <li><tt>a</tt> - flat (sub-set of path-based)</li>
+     * </ol>
+     *
+     * @param resourceTypeString the resource type string to parse
+     * @return a {@link ResourceType} object
+     * @throws IllegalArgumentException if the {@code resourceTypeString} cannot be parsed
+     */
+    @NotNull
+    public static ResourceType parseResourceType(@NotNull String resourceTypeString) {
+        String type = StringUtils.EMPTY;
+        String version = null;
+        if (StringUtils.isNotEmpty(resourceTypeString)) {
+            int lastSlash = resourceTypeString.lastIndexOf('/');
+            if (lastSlash != -1 && !resourceTypeString.endsWith("/")) {
+                String versionString = resourceTypeString.substring(lastSlash + 1);
+                if (versionPattern.matcher(versionString).matches()) {
+                    try {
+                        version = Version.parseVersion(versionString).toString();
+                        type = resourceTypeString.substring(0, lastSlash);
+                    } catch (IllegalArgumentException e) {
+                        type = resourceTypeString;
+                    }
+                } else {
+                    type = resourceTypeString;
+                }
+            } else {
+                type = resourceTypeString;
+            }
+        }
+        if (StringUtils.isEmpty(type)) {
+            throw new IllegalArgumentException(String.format("Cannot extract a type for the resourceTypeString %s.", resourceTypeString));
+        }
+        return new ResourceType(type, version);
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(type, version, resourceLabel);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj instanceof ResourceType) {
+            ResourceType other = (ResourceType) obj;
+            return Objects.equals(type, other.type) && Objects.equals(version, other.version) && Objects.equals(resourceLabel,
+                    other.resourceLabel);
+        }
+        return false;
+    }
+}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java
new file mode 100644
index 0000000..7e36d7d
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java
@@ -0,0 +1,45 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import org.jetbrains.annotations.NotNull;
+import org.osgi.annotation.versioning.ProviderType;
+import org.osgi.framework.Bundle;
+
+/**
+ * A {@code TypeProvider} keeps an association between a {@link BundledRenderUnitCapability} and the bundle that provides it.
+ */
+@ProviderType
+public interface TypeProvider {
+
+    /**
+     * Returns the {@link BundledRenderUnitCapability}.
+     *
+     * @return the {@link BundledRenderUnitCapability}
+     */
+    @NotNull BundledRenderUnitCapability getBundledRenderUnitCapability();
+
+    /**
+     * Returns the providing bundle.
+     *
+     * @return the providing bundle
+     */
+    @NotNull Bundle getBundle();
+
+}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledRenderUnitCapabilityImpl.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledRenderUnitCapabilityImpl.java
index 8cf1753..1d68f8e 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledRenderUnitCapabilityImpl.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledRenderUnitCapabilityImpl.java
@@ -26,10 +26,10 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 
-import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.servlets.ServletResolverConstants;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.scripting.api.bundle.BundledRenderUnitCapability;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnitCapability;
+import org.apache.sling.servlets.resolver.bundle.tracker.ResourceType;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.osgi.framework.Version;
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptServlet.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptServlet.java
index 41fad37..f8102b1 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptServlet.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptServlet.java
@@ -33,9 +33,9 @@ import javax.servlet.ServletResponse;
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
-import org.apache.sling.api.resource.type.ResourceType;
-import org.apache.sling.scripting.api.bundle.BundledRenderUnit;
-import org.apache.sling.scripting.api.bundle.TypeProvider;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnit;
+import org.apache.sling.servlets.resolver.bundle.tracker.ResourceType;
+import org.apache.sling.servlets.resolver.bundle.tracker.TypeProvider;
 import org.apache.sling.servlets.resolver.bundle.tracker.internal.request.RequestWrapper;
 import org.jetbrains.annotations.NotNull;
 
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptTracker.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptTracker.java
index 4cd7f71..2831a23 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptTracker.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/BundledScriptTracker.java
@@ -53,14 +53,14 @@ import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.ResourceUtil;
-import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.api.servlets.ServletResolverConstants;
 import org.apache.sling.commons.osgi.PropertiesUtil;
-import org.apache.sling.scripting.api.bundle.BundledRenderUnit;
-import org.apache.sling.scripting.api.bundle.BundledRenderUnitCapability;
-import org.apache.sling.scripting.api.bundle.BundledRenderUnitFinder;
-import org.apache.sling.scripting.api.bundle.TypeProvider;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnit;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnitCapability;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnitFinder;
+import org.apache.sling.servlets.resolver.bundle.tracker.ResourceType;
+import org.apache.sling.servlets.resolver.bundle.tracker.TypeProvider;
 import org.apache.sling.servlets.resolver.internal.resource.ServletMounter;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.annotation.bundle.Capability;
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/TypeProviderImpl.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/TypeProviderImpl.java
index f61b14f..63c67cf 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/TypeProviderImpl.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/TypeProviderImpl.java
@@ -20,8 +20,8 @@ package org.apache.sling.servlets.resolver.bundle.tracker.internal;
 
 import java.util.Objects;
 
-import org.apache.sling.scripting.api.bundle.BundledRenderUnitCapability;
-import org.apache.sling.scripting.api.bundle.TypeProvider;
+import org.apache.sling.servlets.resolver.bundle.tracker.BundledRenderUnitCapability;
+import org.apache.sling.servlets.resolver.bundle.tracker.TypeProvider;
 import org.jetbrains.annotations.NotNull;
 import org.osgi.framework.Bundle;
 
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/request/RequestWrapper.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/request/RequestWrapper.java
index 7c13d40..5e20069 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/request/RequestWrapper.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/internal/request/RequestWrapper.java
@@ -26,8 +26,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.type.ResourceType;
 import org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper;
+import org.apache.sling.servlets.resolver.bundle.tracker.ResourceType;
 
 public class RequestWrapper extends SlingHttpServletRequestWrapper {
 
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java
new file mode 100644
index 0000000..91b289b
--- /dev/null
+++ b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java
@@ -0,0 +1,22 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+@Version("0.2.0")
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceTypeTest.java b/src/test/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceTypeTest.java
new file mode 100644
index 0000000..5464bd1
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceTypeTest.java
@@ -0,0 +1,87 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.servlets.resolver.bundle.tracker;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+public class ResourceTypeTest {
+
+    @Test
+    public void testSlashNoVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a/b/c");
+        assertEquals("a/b/c", t1.getType());
+        assertEquals("c", t1.getResourceLabel());
+        assertNull(t1.getVersion());
+    }
+
+    @Test
+    public void testSlashVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a/b/c/1.0.0");
+        assertEquals("a/b/c", t1.getType());
+        assertEquals("c", t1.getResourceLabel());
+        assertEquals("1.0.0", t1.getVersion());
+    }
+
+    @Test
+    public void testOneSegmentNoVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a");
+        assertEquals("a", t1.getType());
+        assertEquals("a", t1.getResourceLabel());
+        assertNull(t1.getVersion());
+    }
+
+    @Test
+    public void testOneSegmentVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a/1.2.3");
+        assertEquals("a", t1.getType());
+        assertEquals("a", t1.getResourceLabel());
+        assertEquals("1.2.3", t1.getVersion());
+    }
+
+    @Test
+    public void testDotNoVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a.b.c");
+        assertEquals("a.b.c", t1.getType());
+        assertEquals("c", t1.getResourceLabel());
+        assertNull(t1.getVersion());
+    }
+
+    @Test
+    public void testDotVersion() {
+        ResourceType t1 = ResourceType.parseResourceType("a.b.c/42.0.0");
+        assertEquals("a.b.c", t1.getType());
+        assertEquals("c", t1.getResourceLabel());
+        assertEquals("42.0.0", t1.getVersion());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testEmptyString() {
+        ResourceType t1 = ResourceType.parseResourceType(StringUtils.EMPTY);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testNull() {
+        ResourceType t1 = ResourceType.parseResourceType(null);
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
index 8184718..c69703d 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
@@ -79,7 +79,6 @@ public class ServletResolverTestSupport extends TestSupport {
         final int httpPort = findFreePort();
         versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.api");
         versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.resourceresolver");
-        versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.scripting.api");
         versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.scripting.core");
         versionResolver.setVersionFromProject("org.apache.sling", "org.apache.sling.commons.johnzon");
         versionResolver.setVersion("org.apache.sling", "org.apache.sling.engine", "2.7.2");


[sling-org-apache-sling-servlets-resolver] 02/02: SLING-9999 - Remove cyclic dependency between scripting and servlets features

Posted by ra...@apache.org.
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-servlets-resolver.git

commit 0d03d773bcf104fbc8b9d4e247051cc254c8624c
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Fri Jan 29 11:15:25 2021 +0100

    SLING-9999 - Remove cyclic dependency between scripting and servlets features
    
    * moved the o.a.s.servlets.resolver.bundle.tracker API to a dedicated bundle
---
 pom.xml                                            |   7 +-
 .../resolver/bundle/tracker/BundledRenderUnit.java | 145 -------------------
 .../tracker/BundledRenderUnitCapability.java       |  91 ------------
 .../bundle/tracker/BundledRenderUnitFinder.java    |  62 --------
 .../resolver/bundle/tracker/ResourceType.java      | 161 ---------------------
 .../resolver/bundle/tracker/TypeProvider.java      |  45 ------
 .../resolver/bundle/tracker/package-info.java      |  22 ---
 .../resolver/it/ServletResolverTestSupport.java    |   1 +
 8 files changed, 7 insertions(+), 527 deletions(-)

diff --git a/pom.xml b/pom.xml
index c780bb5..bfb9f5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -179,6 +179,11 @@
     </build>
 
     <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.servlets.resolver.api</artifactId>
+            <version>1.0.0-SNAPSHOT</version>
+        </dependency>
 
         <dependency>
             <groupId>commons-io</groupId>
@@ -214,7 +219,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.22.0</version>
+            <version>2.23.3-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <!-- for ServiceUserMapped (SLING-4312) -->
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java
deleted file mode 100644
index 2c89309..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnit.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import java.io.InputStream;
-import java.util.Set;
-
-import javax.script.ScriptException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.annotation.versioning.ConsumerType;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-
-/**
- * <p>
- * A {@code BundledRenderUnit} represents a pre-packaged script or precompiled script (Java class) that will be executed in order to
- * render a {@link org.apache.sling.api.SlingHttpServletRequest}.
- * </p>
- * <p>
- * The {@code BundledRenderUnit} provider module is responsible for defining how a unit is executed. However, when executing the unit in the
- * context of a {@link javax.script.ScriptEngine}, the provider module should add the current executing unit into the {@link
- * javax.script.ScriptEngine}'s {@link javax.script.ScriptContext} using the {@link #VARIABLE} key.
- * </p>
- */
-@ConsumerType
-public interface BundledRenderUnit {
-
-    /**
-     * The variable available in the {@link javax.script.Bindings} associated to a {@link org.apache.sling.api.SlingHttpServletRequest} if
-     * that request is served by a {@code BundledRenderUnit}.
-     */
-    String VARIABLE = BundledRenderUnit.class.getName();
-
-    /**
-     * In case this {@code BundledRenderUnit} wraps a precompiled script, this method will return an instance of that object.
-     *
-     * @return a precompiled unit, if {@code this} unit wraps a precompiled script; {@code null} otherwise
-     */
-    @Nullable
-    default Object getUnit() {
-        return null;
-    }
-
-    /**
-     * Returns the name of {@code this BundledRenderUnit}. This can be the name of the wrapped script or precompiled script.
-     *
-     * @return the name {@code this BundledRenderUnit}
-     */
-    @NotNull String getName();
-
-    /**
-     * Returns the {@link Bundle} the publishing bundle of this unit (not to be confused with the provider module, which is the module that
-     * instantiates a {@link BundledRenderUnit}). This method can be useful for getting an instance of the bundle's classloader, when
-     * needed to load dependencies at run-time. To do so the following code example can help:
-     *
-     * <pre>
-     * Bundle bundle = bundledRenderUnit.getBundle();
-     * Classloader bundleClassloader = bundle.adapt(BundleWiring.class).getClassLoader();
-     * </pre>
-     */
-    @NotNull Bundle getBundle();
-
-    /**
-     * Returns the {@link BundleContext} to use for this unit. This method can be useful for getting an instance of the publishing bundle's
-     * context, when needed to load dependencies at run-time.
-     *
-     * @return the bundle context of the bundle publishing this unit
-     */
-    @NotNull BundleContext getBundleContext();
-
-    /**
-     * Returns the {@code Set} of {@link TypeProvider}s which are related to this unit.
-     *
-     * @return the set of providers; if the unit doesn't have any inheritance chains, then the set will contain only one {@link
-     * TypeProvider}
-     */
-    @NotNull Set<TypeProvider> getTypeProviders();
-
-    /**
-     * Retrieves an OSGi runtime dependency of the wrapped script identified by the passed {@code className} parameter.
-     *
-     * @param className the fully qualified class name
-     * @param <T>       the expected service type
-     * @return an instance of the {@link T} or {@code null}
-     */
-    @Nullable <T> T getService(@NotNull String className);
-
-    /**
-     * Retrieves multiple instances of an OSGi runtime dependency of the wrapped script identified by the passed {@code className}
-     * parameter, filtered according to the passed {@code filter}.
-     *
-     * @param className the fully qualified class name
-     * @param filter    a filter expression or {@code null} if all the instances should be returned; for more details about the {@code
-     *                  filter}'s syntax check {@link org.osgi.framework.BundleContext#getServiceReferences(String, String)}
-     * @param <T>       the expected service type
-     * @return an instance of the {@link T} or {@code null}
-     */
-    @Nullable <T> T[] getServices(@NotNull String className, @Nullable String filter);
-
-    /**
-     * Returns the path of this executable in the resource type hierarchy. The path can be relative to the search paths or absolute.
-     *
-     * @return the path of this executable in the resource type hierarchy
-     */
-    @NotNull
-    String getPath();
-
-    /**
-     * This method will execute / evaluate the wrapped script or precompiled script with the given request.
-     *
-     * @throws ScriptException if the execution leads to an error
-     */
-    void eval(@NotNull HttpServletRequest request, @NotNull HttpServletResponse response) throws ScriptException;
-
-    /**
-     * This method will return an input stream if {@code this} unit is backed by a script that can be interpreted.
-     *
-     * @return an {@link InputStream} providing the source code of the backing script; if {@code this} unit is backed by a precompiled
-     * script (essentially a Java class), then this method will return {@code null}
-     */
-    @Nullable
-    default InputStream getInputStream() {
-        return null;
-    }
-}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java
deleted file mode 100644
index e0693cb..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitCapability.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import java.util.List;
-import java.util.Set;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.annotation.versioning.ProviderType;
-
-/**
- * A {@code BundledRenderUnitCapability} encapsulates the values of a {@code Provided-Capability}, based on which {@link BundledRenderUnit}s
- * are generated.
- */
-@ProviderType
-public interface BundledRenderUnitCapability {
-
-    /**
-     * Returns the resource types to which a {@link BundledRenderUnit} described by this capability will be bound to.
-     *
-     * @return the resource types to which a {@link BundledRenderUnit} described by this capability will be bound to
-     */
-    @NotNull Set<ResourceType> getResourceTypes();
-
-    /**
-     * Returns the path to which a {@link BundledRenderUnit} described by this capability will be bound to.
-     *
-     * @return the path to which a {@link BundledRenderUnit} described by this capability will be bound to; this can be {@code null} if the
-     * {@link #getResourceTypes()} doesn't return an empty set
-     */
-    @Nullable String getPath();
-
-    /**
-     * Returns the selectors to which a {@link BundledRenderUnit} described by this capability will be bound to.
-     *
-     * @return the selectors to which a {@link BundledRenderUnit} described by this capability will be bound to
-     */
-    @NotNull List<String> getSelectors();
-
-    /**
-     * Returns the extension to which a {@link BundledRenderUnit} described by this capability will be bound to.
-     *
-     * @return the extension to which a {@link BundledRenderUnit} described by this capability will be bound to
-     */
-    @Nullable String getExtension();
-
-    /**
-     * Returns the resource type extended by this capability.
-     *
-     * @return the extended resource type or {@code null}
-     */
-    @Nullable String getExtendedResourceType();
-
-    /**
-     * Returns the request method to which a {@link BundledRenderUnit} described by this capability will be bound to.
-     *
-     * @return the request method to which a {@link BundledRenderUnit} described by this capability will be bound to
-     */
-    @Nullable String getMethod();
-
-    /**
-     * Returns the script engine short name which can be used to evaluate the {@link BundledRenderUnit} described by this capability.
-     *
-     * @return the script engine short name which can be used to evaluate the {@link BundledRenderUnit} described by this capability.
-     */
-    @Nullable String getScriptEngineName();
-
-    /**
-     * Returns the original's script extension that was used to generate this capability.
-     *
-     * @return the original's script extension that was used to generate this capability.
-     */
-    @Nullable String getScriptExtension();
-}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java
deleted file mode 100644
index d632ba8..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/BundledRenderUnitFinder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import java.util.Set;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.annotation.versioning.ConsumerType;
-import org.osgi.framework.BundleContext;
-
-/**
- * The {@code BundledScriptFinder} finds the {@link BundledRenderUnit} corresponding to a certain chain of {@link TypeProvider}s or
- * corresponding to a certain path-based {@link BundledRenderUnitCapability}.
- */
-@ConsumerType
-public interface BundledRenderUnitFinder {
-
-    /**
-     * Retrieves the best matching {@link BundledRenderUnit} for the provided {@code inheritanceChain}, by scanning all {@link TypeProvider}
-     * bundles for the class or script capable of providing a rendering for resource type chain.
-     *
-     * @param context             the bundle context to use.
-     * @param inheritanceChain    the resource type chain; the set is ordered from the most specific resource type to the most generic one
-     * @param allRelatedProviders this is a super set, containing both the {@code inheritanceChain} but also all the required providers; a
-     *                            required provider is a provider that's needed by a {@link ResourceType} in order to delegate rendering to
-     *                            it, but it's not extended by the same {@link ResourceType}
-     * @return a {@link BundledRenderUnit} if one was found, {@code null} otherwise
-     */
-    @Nullable
-    BundledRenderUnit findUnit(@NotNull BundleContext context, @NotNull Set<TypeProvider> inheritanceChain, @NotNull Set<TypeProvider> allRelatedProviders);
-
-    /**
-     * Retrieves a path-based {@link BundledRenderUnit} from the passed {@code provider}.
-     *
-     * @param context             the bundle context to use.
-     * @param provider            the provider from which to retrieve the unit
-     * @param allRelatedProviders this is a super set, containing both the providers connected through an inheritance relationship but also
-     *                            all the required providers; a required provider is a provider that's needed by a {@link ResourceType} in
-     *                            order to delegate rendering to it, but it's not extended by the same {@link ResourceType}
-     * @return a {@link BundledRenderUnit} if one was found, {@code null} otherwise
-     * @see BundledRenderUnitCapability#getPath()
-     */
-    @Nullable
-    BundledRenderUnit findUnit(@NotNull BundleContext context, @NotNull TypeProvider provider, @NotNull Set<TypeProvider> allRelatedProviders);
-}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java
deleted file mode 100644
index 0f2929e..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/ResourceType.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import java.util.Objects;
-import java.util.regex.Pattern;
-
-import org.apache.commons.lang3.StringUtils;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.osgi.framework.Version;
-
-/**
- * The {@code ResourceType} encapsulates details about a Sling resource type and provides methods for parsing resource type strings.
- *
- * <p>The following patterns are supported for parsing:</p>
- * <ol>
- * <li><tt>a/b/c</tt> - path-based</li>
- * <li><tt>a/b/c/1.0.0</tt> - path-based, versioned</li>
- * <li><tt>a.b.c</tt> - Java package name</li>
- * <li><tt>a.b.c/1.0.0</tt> - Java package name, versioned</li>
- * <li><tt>a</tt> - flat (sub-set of path-based)</li>
- * </ol>
- */
-public final class ResourceType {
-
-    private static final Pattern versionPattern = Pattern.compile("[\\d\\.]+(-.*)*$");
-
-    private final String type;
-    private final String version;
-    private final String resourceLabel;
-    private final String toString;
-
-    private ResourceType(@NotNull String type, @Nullable String version) {
-        this.type = type;
-        this.version = version;
-        if (type.lastIndexOf('/') != -1) {
-            resourceLabel = type.substring(type.lastIndexOf('/') + 1);
-        } else if (type.lastIndexOf('.') != -1) {
-            resourceLabel = type.substring(type.lastIndexOf('.') + 1);
-        } else {
-            resourceLabel = type;
-        }
-        toString = type + (version == null ? "" : "/" + version);
-    }
-
-    /**
-     * Returns a resource type's label. The label is important for script selection, since it will provide the name of the main script
-     * for this resource type. For more details check the Apache Sling
-     * <a href="https://sling.apache.org/documentation/the-sling-engine/url-to-script-resolution.html#scripts-for-get-requests">URL to
-     * Script Resolution</a> page
-     *
-     * @return the resource type label
-     */
-    @NotNull
-    public String getResourceLabel() {
-        return resourceLabel;
-    }
-
-    /**
-     * Returns the resource type string, without any version information.
-     *
-     * @return the resource type string
-     */
-    @NotNull
-    public String getType() {
-        return type;
-    }
-
-    /**
-     * Returns the version, if available.
-     *
-     * @return the version, if available; {@code null} otherwise
-     */
-    @Nullable
-    public String getVersion() {
-        return version;
-    }
-
-    @Override
-    public String toString() {
-        return toString;
-    }
-
-    /**
-     * Given a {@code resourceTypeString}, this method will extract a {@link ResourceType} object.
-     * <p>The accepted patterns are:</p>
-     * <ol>
-     * <li><tt>a/b/c</tt> - path-based</li>
-     * <li><tt>a/b/c/1.0.0</tt> - path-based, versioned</li>
-     * <li><tt>a.b.c</tt> - Java package name</li>
-     * <li><tt>a.b.c/1.0.0</tt> - Java package name, versioned</li>
-     * <li><tt>a</tt> - flat (sub-set of path-based)</li>
-     * </ol>
-     *
-     * @param resourceTypeString the resource type string to parse
-     * @return a {@link ResourceType} object
-     * @throws IllegalArgumentException if the {@code resourceTypeString} cannot be parsed
-     */
-    @NotNull
-    public static ResourceType parseResourceType(@NotNull String resourceTypeString) {
-        String type = StringUtils.EMPTY;
-        String version = null;
-        if (StringUtils.isNotEmpty(resourceTypeString)) {
-            int lastSlash = resourceTypeString.lastIndexOf('/');
-            if (lastSlash != -1 && !resourceTypeString.endsWith("/")) {
-                String versionString = resourceTypeString.substring(lastSlash + 1);
-                if (versionPattern.matcher(versionString).matches()) {
-                    try {
-                        version = Version.parseVersion(versionString).toString();
-                        type = resourceTypeString.substring(0, lastSlash);
-                    } catch (IllegalArgumentException e) {
-                        type = resourceTypeString;
-                    }
-                } else {
-                    type = resourceTypeString;
-                }
-            } else {
-                type = resourceTypeString;
-            }
-        }
-        if (StringUtils.isEmpty(type)) {
-            throw new IllegalArgumentException(String.format("Cannot extract a type for the resourceTypeString %s.", resourceTypeString));
-        }
-        return new ResourceType(type, version);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(type, version, resourceLabel);
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj instanceof ResourceType) {
-            ResourceType other = (ResourceType) obj;
-            return Objects.equals(type, other.type) && Objects.equals(version, other.version) && Objects.equals(resourceLabel,
-                    other.resourceLabel);
-        }
-        return false;
-    }
-}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java
deleted file mode 100644
index 7e36d7d..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/TypeProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import org.jetbrains.annotations.NotNull;
-import org.osgi.annotation.versioning.ProviderType;
-import org.osgi.framework.Bundle;
-
-/**
- * A {@code TypeProvider} keeps an association between a {@link BundledRenderUnitCapability} and the bundle that provides it.
- */
-@ProviderType
-public interface TypeProvider {
-
-    /**
-     * Returns the {@link BundledRenderUnitCapability}.
-     *
-     * @return the {@link BundledRenderUnitCapability}
-     */
-    @NotNull BundledRenderUnitCapability getBundledRenderUnitCapability();
-
-    /**
-     * Returns the providing bundle.
-     *
-     * @return the providing bundle
-     */
-    @NotNull Bundle getBundle();
-
-}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java b/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java
deleted file mode 100644
index 91b289b..0000000
--- a/src/main/java/org/apache/sling/servlets/resolver/bundle/tracker/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-@Version("0.2.0")
-package org.apache.sling.servlets.resolver.bundle.tracker;
-
-import org.osgi.annotation.versioning.Version;
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
index c69703d..045654c 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
@@ -91,6 +91,7 @@ public class ServletResolverTestSupport extends TestSupport {
                 slingServlets(),
                 mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.converter").version("1.0.12"), // new Sling API dependency
                 testBundle("bundle.filename"),
+                mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.servlets.resolver.api").versionAsInProject(),
                 mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.servlet-helpers").versionAsInProject(),
                 junitBundles(),
                 newConfiguration("org.apache.felix.http")