This is an automated email from the ASF dual-hosted git repository. jsedding pushed a commit to branch jsedding/SLING-13293-support-ranking-header in repository https://gitbox.apache.org/repos/asf/sling-scriptingbundle-maven-plugin.git
commit a8a61e91b03ad2ead395d236c2c4032b32fab990 Author: Julian Sedding <[email protected]> AuthorDate: Fri Aug 7 10:09:14 2026 +0200 SLING-13293 - Support setting ranking header for bundled script bundles Co-Authored-By: Claude Opus 4.8 <[email protected]> --- README.md | 3 +++ .../plugin/bnd/BundledScriptsScannerPlugin.java | 17 +++++++++++++++++ .../scriptingbundle/plugin/maven/MetadataMojo.java | 18 ++++++++++++++++++ .../scriptingbundle/plugin/processor/Constants.java | 2 ++ src/site/markdown/usage.md.vm | 14 ++++++++++++++ src/test/resources/project-2/bnd.bnd | 3 ++- src/test/resources/project-2/pom.xml | 1 + 7 files changed, 57 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24a8ce9..128a92e 100644 --- a/README.md +++ b/README.md @@ -13,4 +13,7 @@ Sling application. When executed, the plugin will define two project properties `org.apache.sling.scriptingbundle.maven.plugin.Provide-Capability`) which can be used to populate the corresponding bundle headers. +An optional `serviceRanking` can be configured to apply a service ranking to all bundled +scripts in the bundle via the `Sling-Bundled-Scripts-Ranking` bundle header. + For more details head over to the documentation page from https://sling.apache.org/components/scriptingbundle-maven-plugin/. diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java index 5994d29..4f3744a 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/bnd/BundledScriptsScannerPlugin.java @@ -128,6 +128,11 @@ public class BundledScriptsScannerPlugin implements AnalyzerPlugin, Plugin { requiredCapabilities = requiredCapabilitiesDefinition; } analyzer.set(aQute.bnd.osgi.Constants.REQUIRE_CAPABILITY, requiredCapabilities); + + Integer serviceRanking = getConfiguredServiceRanking(); + if (serviceRanking != null) { + analyzer.set(Constants.SLING_BUNDLED_SCRIPTS_RANKING_HEADER, serviceRanking.toString()); + } return false; } @@ -222,6 +227,18 @@ public class BundledScriptsScannerPlugin implements AnalyzerPlugin, Plugin { return true; } + private Integer getConfiguredServiceRanking() { + String serviceRankingString = pluginProperties.get(Constants.BND_SERVICE_RANKING); + if (StringUtils.isNotEmpty(serviceRankingString)) { + try { + return Integer.valueOf(serviceRankingString.trim()); + } catch (NumberFormatException e) { + logger.error(String.format("Invalid service ranking: %s.", serviceRankingString)); + } + } + return null; + } + private Stream<Path> walkPath(Path path, Set<PathMatcher> includes, Set<PathMatcher> excludes) throws IOException { return Files.walk(path) .filter(file -> { diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java index e80ae8c..8f4f096 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/maven/MetadataMojo.java @@ -174,6 +174,17 @@ public class MetadataMojo extends AbstractMojo { @Parameter(property = "scriptingbundle.missingRequirementsOptional", defaultValue = "true") private boolean missingRequirementsOptional = true; + /** + * When set, the given numeric value is exposed via the {@code org.apache.sling.scriptingbundle.maven.plugin.Sling-Bundled-Scripts-Ranking} + * Maven project property, which can be used to generate the {@code Sling-Bundled-Scripts-Ranking} OSGi bundle header. That header + * applies globally to all scripts in the bundle and allows influencing the service ranking of the servlets registered for the + * bundled scripts. When not set, the property is not generated. + * + * @since 0.6.0 + */ + @Parameter(property = "scriptingbundle.serviceRanking") + private Integer serviceRanking; + private Capabilities capabilities; public void execute() { @@ -247,6 +258,13 @@ public class MetadataMojo extends AbstractMojo { "org.apache.sling.scriptingbundle.maven.plugin." + org.osgi.framework.Constants.REQUIRE_CAPABILITY, requiredCapabilitiesDefinition); + if (serviceRanking != null) { + project.getProperties() + .put( + "org.apache.sling.scriptingbundle.maven.plugin." + + Constants.SLING_BUNDLED_SCRIPTS_RANKING_HEADER, + serviceRanking.toString()); + } } catch (IOException e) { logger.error("Unable to generate working directory.", e); } diff --git a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java index 46b1a18..c76cb24 100644 --- a/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java +++ b/src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java @@ -53,7 +53,9 @@ public final class Constants { public static final String BND_SCRIPT_ENGINE_MAPPINGS = "scriptEngineMappings"; public static final String BND_SEARCH_PATHS = "searchPaths"; public static final String BND_MISSING_REQUIREMENTS_OPTIONAL = "missingRequirementsOptional"; + public static final String BND_SERVICE_RANKING = "serviceRanking"; + public static final String SLING_BUNDLED_SCRIPTS_RANKING_HEADER = "Sling-Bundled-Scripts-Ranking"; public static final String SLING_RESOURCE_SUPER_TYPE_XML_LOCAL_NAME = "resourceSuperType"; public static final String SLING_REQUIRED_RESOURCE_TYPES = "sling:requiredResourceTypes"; public static final String SLING_REQUIRED_RESOURCE_TYPES_XML_LOCAL_NAME = "requiredResourceTypes"; diff --git a/src/site/markdown/usage.md.vm b/src/site/markdown/usage.md.vm index 2cdaa10..a860951 100644 --- a/src/site/markdown/usage.md.vm +++ b/src/site/markdown/usage.md.vm @@ -111,3 +111,17 @@ writing instructions of another plugin like the `maven-bundle-plugin`: The `osgi.extender` requirement is mandatory to have the bundle wired up to the Apache Sling Servlets Resolver, but this should be manually defined by the developers, so that their bundle is correctly wired up to whatever version of the Servlets Resolver is available on the destination platform. + +$h3 Setting a service ranking for the bundled scripts + +Starting with version 0.6.0, a numeric `serviceRanking` can be configured. It is applied globally to all scripts in the bundle and +influences the service ranking of the servlets that the Apache Sling Servlets Resolver registers for the bundled scripts. When used as a +bnd plugin, the ranking is written directly into the `Sling-Bundled-Scripts-Ranking` bundle header. When used as a Maven plugin, the value +is exposed via the `org.apache.sling.scriptingbundle.maven.plugin.Sling-Bundled-Scripts-Ranking` project property, which has to be added +to the manifest writing instructions of the plugin that generates the bundle, e.g.: + +``` +<Sling-Bundled-Scripts-Ranking> + ${org.apache.sling.scriptingbundle.maven.plugin.Sling-Bundled-Scripts-Ranking} +</Sling-Bundled-Scripts-Ranking> +``` diff --git a/src/test/resources/project-2/bnd.bnd b/src/test/resources/project-2/bnd.bnd index fe12e69..d242650 100644 --- a/src/test/resources/project-2/bnd.bnd +++ b/src/test/resources/project-2/bnd.bnd @@ -16,4 +16,5 @@ # under the License. -plugin: org.apache.sling.scriptingbundle.plugin.bnd.BundledScriptsScannerPlugin; \ scriptEngineMappings="html:thymeleaf,js:rhino"; \ - searchPaths=/bin + searchPaths=/bin; \ + serviceRanking=100 diff --git a/src/test/resources/project-2/pom.xml b/src/test/resources/project-2/pom.xml index d8aa4ca..10b0254 100644 --- a/src/test/resources/project-2/pom.xml +++ b/src/test/resources/project-2/pom.xml @@ -40,6 +40,7 @@ <html>thymeleaf</html> <js>rhino</js> </scriptEngineMappings> + <serviceRanking>100</serviceRanking> </configuration> <executions> <execution>
