This is an automated email from the ASF dual-hosted git repository. royteeuwen pushed a commit to branch feature/SLING-13237-osgi-bsn-collision-detection in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git
commit f221d5b3d01b299deba8bdc9401c15fb23145ed5 Author: Roy Teeuwen <[email protected]> AuthorDate: Tue Jun 9 21:49:40 2026 +0200 SLING-13237: optional OSGi Bundle-SymbolicName collision detection on aggregate Add an osgiBsnCollisionDetection flag to <aggregate> which, when enabled, fails the build on duplicate Bundle-SymbolicName values unless an artifactsOverrides rule resolves the collision. Requires org.apache.sling.feature 2.0.6, so bump sling.feature.version accordingly. --- pom.xml | 2 +- .../org/apache/sling/feature/maven/mojos/Aggregate.java | 12 +++++++++++- .../sling/feature/maven/mojos/AggregateFeaturesMojo.java | 4 ++++ .../feature/maven/mojos/AggregateFeaturesMojoTest.java | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b351f6e..aa55da9 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ <maven.scm.version>1.11.2</maven.scm.version> <maven.site.path>${project.artifactId}-archives/${project.artifactId}-LATEST</maven.site.path> <project.build.outputTimestamp>1771315797</project.build.outputTimestamp> - <sling.feature.version>2.0.0</sling.feature.version> + <sling.feature.version>2.0.6</sling.feature.version> </properties> <dependencies> diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java b/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java index 1610b99..555ecfb 100644 --- a/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java +++ b/src/main/java/org/apache/sling/feature/maven/mojos/Aggregate.java @@ -74,6 +74,14 @@ public class Aggregate extends FeatureSelectionConfig { public Map<String, String> frameworkPropertiesOverrides; + /** + * When {@code true}, the aggregated feature is checked for OSGi bundles with + * duplicate {@code Bundle-SymbolicName} values and the build fails unless an + * {@code artifactsOverrides} rule resolves the collision. Requires + * {@code org.apache.sling.feature} 2.0.6 or later. + */ + public boolean osgiBsnCollisionDetection = false; + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @@ -89,6 +97,7 @@ public class Aggregate extends FeatureSelectionConfig { frameworkPropertiesOverrides, markAsComplete, markAsFinal, + osgiBsnCollisionDetection, title, variablesOverrides, vendor); @@ -111,6 +120,7 @@ public class Aggregate extends FeatureSelectionConfig { && Objects.equals(frameworkPropertiesOverrides, other.frameworkPropertiesOverrides) && markAsComplete == other.markAsComplete && markAsFinal == other.markAsFinal + && osgiBsnCollisionDetection == other.osgiBsnCollisionDetection && Objects.equals(title, other.title) && Objects.equals(variablesOverrides, other.variablesOverrides) && Objects.equals(vendor, other.vendor); @@ -123,7 +133,7 @@ public class Aggregate extends FeatureSelectionConfig { + ", markAsFinal=" + markAsFinal + ", markAsComplete=" + markAsComplete + ", title=" + title + ", description=" + description + ", vendor=" + vendor + ", artifactsOverrides=" + artifactsOverrides + ", variablesOverrides=" + variablesOverrides + ", frameworkPropertiesOverrides=" - + frameworkPropertiesOverrides + "]"; + + frameworkPropertiesOverrides + ", osgiBsnCollisionDetection=" + osgiBsnCollisionDetection + "]"; } public List<ArtifactId> getArtifactOverrideRules() { diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java index a511280..29ec2d2 100644 --- a/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java +++ b/src/main/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojo.java @@ -146,6 +146,10 @@ public class AggregateFeaturesMojo extends AbstractIncludingFeatureMojo { false) .toArray(MergeHandler[]::new)) .addPostProcessExtensions(postProcessHandlers().toArray(PostProcessHandler[]::new)); + if (aggregate.osgiBsnCollisionDetection) { + builderContext.setOsgiBsnCollisionDetection(true); + } + for (final ArtifactId rule : aggregate.getArtifactOverrideRules()) { builderContext.addArtifactsOverride(rule); } diff --git a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java index ef663b0..d6f7402 100644 --- a/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java +++ b/src/test/java/org/apache/sling/feature/maven/mojos/AggregateFeaturesMojoTest.java @@ -837,6 +837,20 @@ public class AggregateFeaturesMojoTest { } } + @Test + public void testOsgiBsnCollisionDetectionFlagPropagates() throws Exception { + TestContext ctx = prepareTestContext("/aggregate-features/dir2", new String[] {"test_w.json"}); + + ctx.getMojo().aggregates.get(0).osgiBsnCollisionDetection = true; + + // The assembly must succeed when there are no BSN collisions even with detection on. + // (Negative case — collision raises an exception — is covered in the feature-core unit tests + // for OsgiBsnDeduplicator; aggregating live OSGi bundles here would require a heavier fixture.) + ctx.getMojo().execute(); + Feature genFeat = ctx.getFeatureMap().get(":aggregate:aggregated:T"); + assertNotNull(genFeat); + } + @Test public void customAggregate() throws Exception {
