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

cziegeler pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit 75876eeea943fb0c03d92dadd471fdfe3c2d514a
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Fri Nov 13 14:42:21 2026 +0100

    SLING-13431 : Support excluding API region exports from generated API JARs
---
 .../feature/maven/mojos/apis/RegionSupport.java    |  7 +-
 src/site/markdown/index.md                         |  9 +++
 .../maven/mojos/apis/RegionSupportTest.java        | 84 ++++++++++++++++++++++
 3 files changed, 99 insertions(+), 1 deletion(-)

diff --git 
a/src/main/java/org/apache/sling/feature/maven/mojos/apis/RegionSupport.java 
b/src/main/java/org/apache/sling/feature/maven/mojos/apis/RegionSupport.java
index 31c49ea..20227f3 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/apis/RegionSupport.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/apis/RegionSupport.java
@@ -43,6 +43,8 @@ import org.osgi.framework.Constants;
 
 public class RegionSupport {
 
+    private static final String API_JAR_EXCLUDE = "api-jar-exclude";
+
     private final Log log;
 
     private final boolean incrementalApis;
@@ -160,6 +162,9 @@ public class RegionSupport {
     }
 
     private boolean include(final ApiExport exp, final Set<String> 
enabledToggles) {
+        if (exp.getProperties().containsKey(API_JAR_EXCLUDE)) {
+            return false;
+        }
         boolean include = !toggleApiOnly;
         if (toggleApiOnly) {
             include = exp.getToggle() != null && 
enabledToggles.contains(exp.getToggle());
@@ -233,7 +238,7 @@ public class RegionSupport {
 
             if (allPackages.contains(packageName)) {
                 final ApiExport exp = apiRegion.getExportByName(packageName);
-                if (exp != null) {
+                if (exp != null && 
!exp.getProperties().containsKey(API_JAR_EXCLUDE)) {
                     result.add(exportedPackage);
                 }
             }
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index 159af25..aada872 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -20,6 +20,15 @@ As this Maven plugin comes with [Maven 
extensions](https://maven.apache.org/guid
 
 Additional Documentation can be found in the 
[README](https://github.com/apache/sling-slingfeature-maven-plugin/blob/master/README.md)
 page.
 
+## API package exclusions
+
+The `apis-jar` goal excludes an API region export if its properties contain
+`api-jar-exclude`, regardless of the property's value. The package remains in 
the
+API region definition, but is omitted from the generated API, source and 
Javadoc
+JARs and is not reported as missing. This also applies when its toggle is 
enabled.
+
+The existing per-bundle `apis-ignore` metadata remains supported.
+
 ## Plugin bindings for `slingosgifeature` packaging
 
 ```
diff --git 
a/src/test/java/org/apache/sling/feature/maven/mojos/apis/RegionSupportTest.java
 
b/src/test/java/org/apache/sling/feature/maven/mojos/apis/RegionSupportTest.java
index f7a3834..82881da 100644
--- 
a/src/test/java/org/apache/sling/feature/maven/mojos/apis/RegionSupportTest.java
+++ 
b/src/test/java/org/apache/sling/feature/maven/mojos/apis/RegionSupportTest.java
@@ -120,6 +120,90 @@ public class RegionSupportTest {
         assertTrue(usedPerRegion.contains(exportedPackages[1]));
     }
 
+    @Test
+    public void testApiJarExcludeProperty() throws MojoExecutionException {
+        final ApiRegions regions = new ApiRegions();
+        final ApiRegion region = new ApiRegion("global");
+        regions.add(region);
+        final ApiExport included = new ApiExport("included");
+        region.add(included);
+        final ApiExport excluded = new ApiExport("excluded");
+        region.add(excluded);
+        final Artifact bundle = new Artifact(ArtifactId.parse("g:b:1"));
+        final Clause[] exportedPackages = {new Clause("included", null, null), 
new Clause("excluded", null, null)};
+        final Set<String> enabledToggles = Collections.singleton("feature");
+
+        for (final boolean toggleApiOnly : new boolean[] {false, true}) {
+            final RegionSupport support = new RegionSupport(
+                    Mockito.mock(Log.class), true, toggleApiOnly, 
Collections.singleton("*"), Collections.emptySet());
+            included.setToggle(toggleApiOnly ? "feature" : null);
+            excluded.setToggle(toggleApiOnly ? "feature" : null);
+
+            for (final String value : new String[] {"true", "false", ""}) {
+                excluded.getProperties().put("api-jar-exclude", value);
+
+                final Set<String> used =
+                        support.computeAllUsedExportPackages(regions, 
enabledToggles, exportedPackages, bundle);
+                assertEquals(Collections.singleton("included"), used);
+                assertEquals(
+                        Collections.singleton(exportedPackages[0]),
+                        support.computeUsedExportPackagesPerRegion(region, 
exportedPackages, used));
+                assertEquals(Collections.singletonList(included), 
support.getAllExports(region, enabledToggles));
+                assertEquals(excluded, region.getExportByName("excluded"));
+            }
+        }
+    }
+
+    @Test
+    public void testApiJarExcludeWithIgnoredPackages() throws 
MojoExecutionException {
+        final ApiRegions regions = new ApiRegions();
+        final ApiRegion region = new ApiRegion("global");
+        regions.add(region);
+        region.add(new ApiExport("included"));
+        region.add(new ApiExport("ignored"));
+        final ApiExport excluded = new ApiExport("excluded");
+        excluded.getProperties().put("api-jar-exclude", "true");
+        region.add(excluded);
+        final Artifact bundle = new Artifact(ArtifactId.parse("g:b:1"));
+        bundle.getMetadata().put(ApisUtil.IGNORE_PACKAGES, "ignored");
+        final RegionSupport support = new RegionSupport(
+                Mockito.mock(Log.class), true, false, 
Collections.singleton("*"), Collections.emptySet());
+        final Clause[] exportedPackages = {
+            new Clause("included", null, null), new Clause("ignored", null, 
null), new Clause("excluded", null, null)
+        };
+
+        assertEquals(
+                Collections.singleton("included"),
+                support.computeAllUsedExportPackages(regions, 
Collections.emptySet(), exportedPackages, bundle));
+    }
+
+    @Test
+    public void testApiJarExcludePerRegion() throws MojoExecutionException {
+        final ApiRegions regions = new ApiRegions();
+        final ApiRegion includedRegion = new ApiRegion("included");
+        includedRegion.add(new ApiExport("p1"));
+        regions.add(includedRegion);
+        final ApiRegion excludedRegion = new ApiRegion("excluded");
+        final ApiExport excluded = new ApiExport("p1");
+        excluded.getProperties().put("api-jar-exclude", "true");
+        excludedRegion.add(excluded);
+        regions.add(excludedRegion);
+        final Artifact bundle = new Artifact(ArtifactId.parse("g:b:1"));
+        final RegionSupport support = new RegionSupport(
+                Mockito.mock(Log.class), true, false, 
Collections.singleton("*"), Collections.emptySet());
+        final Clause[] exportedPackages = {new Clause("p1", null, null)};
+
+        final Set<String> used =
+                support.computeAllUsedExportPackages(regions, 
Collections.emptySet(), exportedPackages, bundle);
+        assertEquals(Collections.singleton("p1"), used);
+        assertEquals(
+                Collections.singleton(exportedPackages[0]),
+                support.computeUsedExportPackagesPerRegion(includedRegion, 
exportedPackages, used));
+        assertTrue(support.computeUsedExportPackagesPerRegion(excludedRegion, 
exportedPackages, used)
+                .isEmpty());
+        assertTrue(support.getAllExports(excludedRegion, 
Collections.emptySet()).isEmpty());
+    }
+
     @Test
     public void testApiExportWithToggles() throws MojoExecutionException {
         final ApiRegions regions = new ApiRegions();

Reply via email to