You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2020/01/20 12:55:05 UTC

[sling-org-apache-sling-feature-extension-apiregions] branch SLING-8970 created (now 1f4f8f1)

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

pauls pushed a change to branch SLING-8970
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git.


      at 1f4f8f1  SLING-8970 - adding test & fixing logic to consider inherited exports in region checks

This branch includes the following new commits:

     new 1f4f8f1  SLING-8970 - adding test & fixing logic to consider inherited exports in region checks

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



[sling-org-apache-sling-feature-extension-apiregions] 01/01: SLING-8970 - adding test & fixing logic to consider inherited exports in region checks

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch SLING-8970
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-extension-apiregions.git

commit 1f4f8f1904f70fad6d3a8ee4734d46b07bce84f7
Author: Karl Pauls <kp...@adobe.com>
AuthorDate: Mon Jan 20 13:54:30 2020 +0100

    SLING-8970 - adding test & fixing logic to consider inherited exports in region checks
---
 .../CheckApiRegionsBundleExportsImports.java       | 13 ++++++++
 .../CheckApiRegionsBundleExportsImportsTest.java   | 37 ++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java b/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
index d11e2a5..3ff8334 100644
--- a/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
+++ b/src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImports.java
@@ -39,6 +39,7 @@ import org.apache.sling.feature.Extensions;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.analyser.task.AnalyserTask;
 import org.apache.sling.feature.analyser.task.AnalyserTaskContext;
+import org.apache.sling.feature.extension.apiregions.api.ApiExport;
 import org.apache.sling.feature.extension.apiregions.api.ApiRegion;
 import org.apache.sling.feature.extension.apiregions.api.ApiRegions;
 import org.apache.sling.feature.scanner.BundleDescriptor;
@@ -207,6 +208,18 @@ public class CheckApiRegionsBundleExportsImports implements AnalyserTask {
                                     Set<String> imRegions =
                                             getBundleRegions(info, apiRegions, ignoreAPIRegions);
 
+                                    // Check exports of the importing regions to consider inherited exports
+                                    for (String imRegion : imRegions)
+                                    {
+                                        ApiRegion region = apiRegions.getRegionByName(imRegion);
+                                        for (ApiExport export : region.listAllExports())
+                                        {
+                                            if (export.getName().equals(pck.getName()))
+                                            {
+                                                exRegions.add(imRegion);
+                                            }
+                                        }
+                                    }
                                     // Record the exporting and importing regions for diagnostics
                                     exportingRegions.addAll(exRegions);
                                     importingRegions.addAll(imRegions);
diff --git a/src/test/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImportsTest.java b/src/test/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImportsTest.java
index a0492fa..5c0ce68 100644
--- a/src/test/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImportsTest.java
+++ b/src/test/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsBundleExportsImportsTest.java
@@ -336,6 +336,43 @@ public class CheckApiRegionsBundleExportsImportsTest {
         Mockito.verify(ctx, Mockito.never()).reportWarning(Mockito.anyString());
     }
 
+    @Test
+    /*
+     * Bundle 2 imports org.foo.b from bundle 1. Bundle 1 exports it in region1.
+     * Regions
+     */
+    public void testImportFromInheritedRegionSucceeds() throws Exception {
+        String exJson = "[" +
+            "{\"name\": \"region1\", \"exports\": [\"org.foo.b\"],\"feature-origins\":[\"f:f:1\"]}," +
+            "{\"name\": \"region2\", \"exports\": [],\"feature-origins\":[\"f:f:2\"]}" +
+            "]";
+
+        CheckApiRegionsBundleExportsImports t = new CheckApiRegionsBundleExportsImports();
+
+        Feature f = new Feature(ArtifactId.fromMvnId("f:f:1"));
+        Extension ex = new Extension(ExtensionType.JSON, "api-regions", ExtensionState.OPTIONAL);
+        ex.setJSON(exJson);
+        f.getExtensions().add(ex);
+
+
+        FeatureDescriptor fd = new FeatureDescriptorImpl(f);
+
+        fdAddBundle(fd, "g:b1:1", "test-bundle1.jar", f.getId());
+        fdAddBundle(fd, "g:b2:1", "test-bundle2.jar", ArtifactId.fromMvnId("f:f:2"));
+
+        AnalyserTaskContext ctx = Mockito.mock(AnalyserTaskContext.class);
+        Mockito.when(ctx.getFeature()).thenReturn(f);
+        Mockito.when(ctx.getFeatureDescriptor()).thenReturn(fd);
+        Mockito.when(ctx.getConfiguration()).thenReturn(
+            Collections.singletonMap("fileStorage",
+                resourceRoot + "/origins/testImportFromInheritedRegionSucceeds"));
+        t.execute(ctx);
+
+        Mockito.verify(ctx, Mockito.never()).reportError(Mockito.anyString());
+        Mockito.verify(ctx, Mockito.never()).reportWarning(Mockito.anyString());
+
+    }
+
     private void fdAddBundle(FeatureDescriptor fd, String id, String file, ArtifactId... origins) throws IOException {
         Artifact artifact = new Artifact(ArtifactId.fromMvnId(id));
         artifact.setFeatureOrigins(origins);