You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/11/07 11:45:20 UTC

[sling-org-apache-sling-feature-apiregions] branch master created (now 54aee7c)

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

davidb pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git.


      at 54aee7c  Add .gitignore

This branch includes the following new commits:

     new f8b5908  Rename feature whitelist component to feature apiregions
     new dc20a7c  Unit tests for the apiregions runtime component.
     new b3c8e9b  Unit tests for the apiregions runtime component.
     new 2835a40  Unit tests for the apiregions runtime component.
     new 1906411  Unit tests for the apiregions runtime component.
     new 57ed829  Unit tests for the apiregions runtime component.
     new a4649e4  Unit tests for the apiregions runtime component.
     new 169ac05  Unit tests for the apiregions runtime component.
     new 9f8a91e  Unit tests for the apiregions runtime component.
     new 9e20ac1  Unit test for the extension bundle activator.
     new 379d1d8  Rename whitelisting to apiregions
     new e78543d  Add some sling boilerplate files in preparation for moving out of the whiteboard
     new df4bda4  Update README.md
     new d871433  Additional unit tests for the apiregions runtime component.
     new ce4c71f  Fix a small bug relating a capability coming from no feature.
     new c24c5a6  Reduce dependencies
     new 955105c  Enable api-regions runtime support via a framework property
     new b7e63a3  Improve diagnostics on the candidate removal log message
     new 54aee7c  Add .gitignore

The 19 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-apiregions] 07/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit a4649e4da4deba4c00daba838fff46a06b38a00b
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sun Nov 4 20:19:21 2018 +0000

    Unit tests for the apiregions runtime component.
---
 .../feature/apiregions/impl/ResolverHookImpl.java  |  1 -
 .../apiregions/impl/ResolverHookImplTest.java      | 28 +++++++++++++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index 3e8e9f2..caecb76 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -70,7 +70,6 @@ class ResolverHookImpl implements ResolverHook {
         if (!PackageNamespace.PACKAGE_NAMESPACE.equals(requirement.getNamespace()))
             return;
 
-        System.out.println("*** Filter Matches: " + requirement);
         Bundle reqBundle = requirement.getRevision().getBundle();
         long reqBundleID = reqBundle.getBundleId();
         String reqBundleName = reqBundle.getSymbolicName();
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index 21e77e2..a50e6f7 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -191,6 +191,8 @@ public class ResolverHookImplTest {
                 Collections.singletonList("b8"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("some.other.bundle", new Version(9,9,9,"suffix")),
                 Collections.singletonList("b9"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a-bundle", new Version(1,0,0,"SNAPSHOT")),
+                Collections.singletonList("b10"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(1,2,3)),
                 Collections.singletonList("b17"));
 
@@ -198,10 +200,11 @@ public class ResolverHookImplTest {
         bfmap.put("b7", Collections.singleton("f"));
         bfmap.put("b8", Collections.singleton("f1"));
         bfmap.put("b9", Collections.singleton("f2"));
+        bfmap.put("b10", Collections.singleton("f2"));
         bfmap.put("b17", Collections.singleton("f3"));
 
         Map<String, Set<String>> frmap = new HashMap<>();
-        frmap.put("f", new HashSet<>(Arrays.asList("r1", "r2")));
+        frmap.put("f", new HashSet<>(Arrays.asList("r1", "r2", RegionEnforcer.GLOBAL_REGION)));
         frmap.put("f1", Collections.singleton("r1"));
         frmap.put("f2", Collections.singleton("r2"));
         frmap.put("f3", Collections.singleton("r3"));
@@ -249,6 +252,29 @@ public class ResolverHookImplTest {
         Collection<BundleCapability> c3 = new ArrayList<>(Arrays.asList(bc3));
         rh.filterMatches(req3, c3);
         assertEquals(Collections.singletonList(bc3), c3);
+
+        // Check that we can get the capability from the another bundle in the same feature
+        BundleRequirement req4 = mockRequirement("b9", bsnvermap);
+        BundleCapability bc4 = mockCapability("some.cool.package", "b10", bsnvermap);
+        Collection<BundleCapability> c4 = new ArrayList<>(Arrays.asList(bc4));
+        rh.filterMatches(req4, c4);
+        assertEquals(Collections.singletonList(bc4), c4);
+
+        // Check that we can get the capability from another bundle where the capability
+        // is globally visible b7 exposes org.bar.tar in the global region, so b17 can see it
+        BundleRequirement req5 = mockRequirement("b17", bsnvermap);
+        BundleCapability bc5 = mockCapability("org.bar.tar", "b7", bsnvermap);
+        Collection<BundleCapability> c5 = new ArrayList<>(Arrays.asList(bc5));
+        rh.filterMatches(req5, c5);
+        assertEquals(Collections.singletonList(bc5), c5);
+
+        // Check that capabilities in non-package namespaces are ignored
+        BundleRequirement req7 = Mockito.mock(BundleRequirement.class);
+        Mockito.when(req7.getNamespace()).thenReturn("some.other.namespace");
+        BundleCapability bc7 = mockCapability("org.bar", "b17", bsnvermap);
+        Collection<BundleCapability> c7 = new ArrayList<>(Arrays.asList(bc7));
+        rh.filterMatches(req7, c7);
+        assertEquals(Collections.singletonList(bc7), c7);
     }
 
     private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {


[sling-org-apache-sling-feature-apiregions] 12/19: Add some sling boilerplate files in preparation for moving out of the whiteboard

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit e78543df3d40cc6c8d516f0afe81f8ec53dc439a
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:02:00 2018 +0000

    Add some sling boilerplate files in preparation for moving out of the whiteboard
---
 CODE_OF_CONDUCT.md |  22 ++++++
 CONTRIBUTING.md    |  24 +++++++
 LICENSE            | 202 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 248 insertions(+)

diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..0fa18e5
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+Apache Software Foundation Code of Conduct
+====
+
+Being an Apache project, Apache Sling adheres to the Apache Software Foundation's [Code of Conduct](https://www.apache.org/foundation/policies/conduct.html).
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..ac82a1a
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,24 @@
+<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+  ~ 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.
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/-->
+Contributing
+====
+
+Thanks for choosing to contribute!
+
+You will find all the necessary details about how you can do this at https://sling.apache.org/contributing.html.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.


[sling-org-apache-sling-feature-apiregions] 13/19: Update README.md

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit df4bda4a35d7d0497b76b8c56aa743ac04bb499d
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 14:13:24 2018 +0000

    Update README.md
---
 README.md | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b075f8a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,17 @@
+[<img src="http://sling.apache.org/res/logos/sling.png"/>](http://sling.apache.org)
+
+[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
+
+# Apache Sling API Regions runtime component
+
+The API Regions runtime component is implemented as an OSGi Framework Extension bundle.
+This ensures that the runtime component is always present early in the startup process.
+
+This component registers an OSGi resolver hook service which enforces the API regions at runtime. The component looks for properties files that provide the configuration of the API regions. The properties files are generated by the `org.apache.sling.feature.extension.apiregions` component during the extension post-processing.
+
+As the component has no dependencies on any other component, the properties files are looked up via System Properties lookups:
+
+* `apiregions.idbsnver.properties` - provides the location of the `idbsnver.properties` file.
+* `apiregions.bundles.properties` - provides the location of the `bundles.properties` file.
+* `apiregions.features.properties` - provides the location of the `features.properties` file.
+* `apiregions.regions.properties` - provides the location of the `regions.properties` file.


[sling-org-apache-sling-feature-apiregions] 06/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 57ed82972310fb745820f764c221716863c446ac
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sun Nov 4 20:07:39 2018 +0000

    Unit tests for the apiregions runtime component.
---
 .../apiregions/impl/ResolverHookImplTest.java      | 50 ++++++++++++++++++++--
 1 file changed, 46 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index eead297..21e77e2 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -31,6 +31,7 @@ import org.osgi.framework.wiring.BundleRevision;
 import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -190,16 +191,20 @@ public class ResolverHookImplTest {
                 Collections.singletonList("b8"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("some.other.bundle", new Version(9,9,9,"suffix")),
                 Collections.singletonList("b9"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(1,2,3)),
+                Collections.singletonList("b17"));
 
         Map<String, Set<String>> bfmap = new HashMap<>();
         bfmap.put("b7", Collections.singleton("f"));
         bfmap.put("b8", Collections.singleton("f1"));
         bfmap.put("b9", Collections.singleton("f2"));
+        bfmap.put("b17", Collections.singleton("f3"));
 
         Map<String, Set<String>> frmap = new HashMap<>();
         frmap.put("f", new HashSet<>(Arrays.asList("r1", "r2")));
         frmap.put("f1", Collections.singleton("r1"));
         frmap.put("f2", Collections.singleton("r2"));
+        frmap.put("f3", Collections.singleton("r3"));
 
         Map<String, Set<String>> rpmap = new HashMap<>();
         rpmap.put("r0", Collections.singleton("org.bar"));
@@ -213,8 +218,8 @@ public class ResolverHookImplTest {
         // where that region exports the package
         // Bundle 7 is in feature f with regions r1, r2. Bundle 8 is in feature f1 with regions r1
         // r1 exports the org.foo package
-        BundleRequirement req0 = mockRequirement(7, "a.b.c", new Version(0,0,0));
-        BundleCapability bc0 = mockCapability("org.foo", 8, "a.bundle", new Version(1,0,0));
+        BundleRequirement req0 = mockRequirement("b7", bsnvermap);
+        BundleCapability bc0 = mockCapability("org.foo", "b8", bsnvermap);
         List<BundleCapability> candidates0 = new ArrayList<>(Arrays.asList(bc0));
         rh.filterMatches(req0, candidates0);
         assertEquals(Collections.singletonList(bc0), candidates0);
@@ -223,12 +228,38 @@ public class ResolverHookImplTest {
         // but that region doesn't export the pacakge.
         // Bundle 7 is in feature f with regions r1, r2. Bundle 9 is in feature f2 with regions r2
         // r2 does not export any packages
-        BundleRequirement req1 = mockRequirement(7, "a.b.c", new Version(0,0,0));
-        BundleCapability bc1 = mockCapability("org.foo", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        BundleRequirement req1 = mockRequirement("b7", bsnvermap);
+        BundleCapability bc1 = mockCapability("org.foo", "b9", bsnvermap);
         List<BundleCapability> candidates1 = new ArrayList<>(Arrays.asList(bc1));
         rh.filterMatches(req1, candidates1);
         assertEquals(Collections.emptyList(), candidates1);
 
+        // Check that we cannot get the capability from another bundle in a different region
+        // Bundle 9 is in feature f2 with region r2
+        // Bundle 17 is in feature f3 with region r3
+        BundleRequirement req2 = mockRequirement("b9", bsnvermap);
+        BundleCapability bc2 = mockCapability("org.bar", "b17", bsnvermap);
+        Collection<BundleCapability> c2 = new ArrayList<>(Arrays.asList(bc2));
+        rh.filterMatches(req2, c2);
+        assertEquals(0, c2.size());
+
+        // Check that we can get the capability from the same bundle
+        BundleRequirement req3 = mockRequirement("b9", bsnvermap);
+        BundleCapability bc3 = mockCapability("abc.xyz", "b9", bsnvermap);
+        Collection<BundleCapability> c3 = new ArrayList<>(Arrays.asList(bc3));
+        rh.filterMatches(req3, c3);
+        assertEquals(Collections.singletonList(bc3), c3);
+    }
+
+    private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {
+        for (Map.Entry<Map.Entry<String, Version>, List<String>> entry : bsnvermap.entrySet()) {
+            if (entry.getValue().contains(bid)) {
+                // Remove first letter and use rest as bundle ID
+                long id = Long.parseLong(bid.substring(1));
+                return mockCapability(pkgName, id, entry.getKey().getKey(), entry.getKey().getValue());
+            }
+        }
+        throw new IllegalStateException("Bundle not found " + bid);
     }
 
     private BundleCapability mockCapability(String pkg, long bundleID, String bsn, Version version) {
@@ -250,6 +281,17 @@ public class ResolverHookImplTest {
         return cap;
     }
 
+    private BundleRequirement mockRequirement(String bid, Map<Map.Entry<String, Version>, List<String>> bsnvermap) {
+        for (Map.Entry<Map.Entry<String, Version>, List<String>> entry : bsnvermap.entrySet()) {
+            if (entry.getValue().contains(bid)) {
+                // Remove first letter and use rest as bundle ID
+                long id = Long.parseLong(bid.substring(1));
+                return mockRequirement(id, entry.getKey().getKey(), entry.getKey().getValue());
+            }
+        }
+        throw new IllegalStateException("Bundle not found " + bid);
+    }
+
     private BundleRequirement mockRequirement(long bundleID, String bsn, Version version) {
         Bundle bundle = Mockito.mock(Bundle.class);
         Mockito.when(bundle.getBundleId()).thenReturn(bundleID);


[sling-org-apache-sling-feature-apiregions] 08/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 169ac053b8411a4376565b44ee8f80fafd9b5ae3
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sun Nov 4 20:35:55 2018 +0000

    Unit tests for the apiregions runtime component.
---
 .../apiregions/impl/ResolverHookImplTest.java      | 40 +++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index a50e6f7..a80404e 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -37,10 +37,10 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Map.Entry;
 import java.util.Set;
+import java.util.Map.Entry;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 
 public class ResolverHookImplTest {
     @Test @Ignore
@@ -149,8 +149,8 @@ public class ResolverHookImplTest {
         BundleCapability bc8 = mockCapability("xyz", 19, "x.y.z", new Version(9,9,9));
         Collection<BundleCapability> c8 = new ArrayList<>(Arrays.asList(bc8));
         rh.filterMatches(req8, c8);
-
         assertEquals(Collections.singletonList(bc8), c8);
+
         // A requirement from a bundle that has no feature cannot access one in a region
         BundleRequirement req9 = mockRequirement(11, "qqq", new Version(6,6,6));
         BundleCapability bc9 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
@@ -193,8 +193,14 @@ public class ResolverHookImplTest {
                 Collections.singletonList("b9"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a-bundle", new Version(1,0,0,"SNAPSHOT")),
                 Collections.singletonList("b10"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("not.in.a.feature", new Version(0,0,1)),
+                Collections.singletonList("b11"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(1,2,3)),
                 Collections.singletonList("b17"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("x.y.z", new Version(9,9,9)),
+                Collections.singletonList("b19"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("zzz", new Version(1,0,0)),
+                Collections.singletonList("b20"));
 
         Map<String, Set<String>> bfmap = new HashMap<>();
         bfmap.put("b7", Collections.singleton("f"));
@@ -202,12 +208,15 @@ public class ResolverHookImplTest {
         bfmap.put("b9", Collections.singleton("f2"));
         bfmap.put("b10", Collections.singleton("f2"));
         bfmap.put("b17", Collections.singleton("f3"));
+        bfmap.put("b19", Collections.singleton("f3"));
+        bfmap.put("b20", Collections.singleton("f4"));
 
         Map<String, Set<String>> frmap = new HashMap<>();
         frmap.put("f", new HashSet<>(Arrays.asList("r1", "r2", RegionEnforcer.GLOBAL_REGION)));
         frmap.put("f1", Collections.singleton("r1"));
         frmap.put("f2", Collections.singleton("r2"));
         frmap.put("f3", Collections.singleton("r3"));
+        frmap.put("f4", Collections.singleton("r3"));
 
         Map<String, Set<String>> rpmap = new HashMap<>();
         rpmap.put("r0", Collections.singleton("org.bar"));
@@ -217,7 +226,7 @@ public class ResolverHookImplTest {
 
         ResolverHookImpl rh = new ResolverHookImpl(bsnvermap, bfmap, frmap, rpmap);
 
-        // Check that we cann get the capability from another bundle in the same region
+        // Check that we can get the capability from another bundle in the same region
         // where that region exports the package
         // Bundle 7 is in feature f with regions r1, r2. Bundle 8 is in feature f1 with regions r1
         // r1 exports the org.foo package
@@ -275,6 +284,29 @@ public class ResolverHookImplTest {
         Collection<BundleCapability> c7 = new ArrayList<>(Arrays.asList(bc7));
         rh.filterMatches(req7, c7);
         assertEquals(Collections.singletonList(bc7), c7);
+
+        // Check that we can get the capability from another provider in the same region
+        BundleRequirement req8 = mockRequirement("b20", bsnvermap);
+        BundleCapability bc8 = mockCapability("xyz", "b19", bsnvermap);
+        Collection<BundleCapability> c8 = new ArrayList<>(Arrays.asList(bc8));
+        rh.filterMatches(req8, c8);
+        assertEquals(Collections.singletonList(bc8), c8);
+
+        // A requirement from a bundle that has no feature cannot access one in a region
+        // b17 provides package xyz which is in region r3, but b11 is not in any region.
+        BundleRequirement req9 = mockRequirement("b11", bsnvermap);
+        BundleCapability bc9 = mockCapability("xyz", "b17", bsnvermap);
+        Collection<BundleCapability> c9 = new ArrayList<>(Arrays.asList(bc9));
+        rh.filterMatches(req9, c9);
+        assertEquals(0, c9.size());
+
+        // A requirement from a bundle that has no feature can still access one in the global region
+        // b7 exposes org.bar.tar in the global region, so b11 can see it
+        BundleRequirement req10 = mockRequirement("b11", bsnvermap);
+        BundleCapability bc10 = mockCapability("org.bar.tar", "b7", bsnvermap);
+        Collection<BundleCapability> c10 = new ArrayList<>(Arrays.asList(bc10));
+        rh.filterMatches(req10, c10);
+        assertEquals(Collections.singletonList(bc10), c10);
     }
 
     private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {


[sling-org-apache-sling-feature-apiregions] 17/19: Enable api-regions runtime support via a framework property

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 955105cc0debde29c7b61db218aa44cd2dcf290c
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 16:21:25 2018 +0000

    Enable api-regions runtime support via a framework property
    
    Framework property org.apache.sling.feature.apiregions.regions must be
    set to enable api-regions runtime support.
---
 .../org/apache/sling/feature/apiregions/impl/Activator.java  |  8 +++++++-
 .../apache/sling/feature/apiregions/impl/RegionEnforcer.java |  7 ++++++-
 .../sling/feature/apiregions/impl/ResolverHookImpl.java      |  2 +-
 .../apache/sling/feature/apiregions/impl/ActivatorTest.java  |  1 +
 .../sling/feature/apiregions/impl/RegionEnforcerTest.java    | 12 ++++++------
 5 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
index 6ced921..95f5cc7 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
@@ -26,10 +26,16 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 
 public class Activator implements BundleActivator {
+    static final String REGIONS_PROPERTY_NAME = "org.apache.sling.feature.apiregions.regions";
+
     @Override
     public synchronized void start(BundleContext context) throws Exception {
+        String regions = context.getProperty(REGIONS_PROPERTY_NAME);
+        if (regions == null)
+            return; // Component not enabled
+
         Dictionary<String, Object> props = new Hashtable<>();
-        RegionEnforcer enforcer = new RegionEnforcer(props);
+        RegionEnforcer enforcer = new RegionEnforcer(props, regions);
         context.registerService(ResolverHookFactory.class, enforcer, props);
     }
 
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index 56a5b74..cf20e0d 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -53,8 +53,9 @@ class RegionEnforcer implements ResolverHookFactory {
     final Map<String, Set<String>> bundleFeatureMap;
     final Map<String, Set<String>> featureRegionMap;
     final Map<String, Set<String>> regionPackageMap;
+    final Set<String> enabledRegions;
 
-    public RegionEnforcer(Dictionary<String, Object> regProps) throws IOException {
+    RegionEnforcer(Dictionary<String, Object> regProps, String regionsProp) throws IOException {
         File idbsnverFile = getDataFile(IDBSNVER_FILENAME);
         bsnVerMap = populateBSNVerMap(idbsnverFile);
         if (idbsnverFile != null) {
@@ -78,6 +79,8 @@ class RegionEnforcer implements ResolverHookFactory {
         if (regionsFile != null) {
             regProps.put(REGION_PACKAGE_FILENAME, regionsFile.getAbsolutePath());
         }
+
+        enabledRegions = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(regionsProp.split(","))));
     }
 
     private Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap(File idbsnverFile) throws IOException {
@@ -151,6 +154,8 @@ class RegionEnforcer implements ResolverHookFactory {
 
     @Override
     public ResolverHook begin(Collection<BundleRevision> triggers) {
+        if (enabledRegions.size() == 0)
+            return null;
         return new ResolverHookImpl(bsnVerMap, bundleFeatureMap, featureRegionMap, regionPackageMap);
     }
 }
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index dc1d08d..e754c31 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -46,7 +46,7 @@ class ResolverHookImpl implements ResolverHook {
     final Map<String, Set<String>> featureRegionMap;
     final Map<String, Set<String>> regionPackageMap;
 
-    public ResolverHookImpl(Map<Entry<String, Version>, List<String>> bsnVerMap, Map<String, Set<String>> bundleFeatureMap,
+    ResolverHookImpl(Map<Entry<String, Version>, List<String>> bsnVerMap, Map<String, Set<String>> bundleFeatureMap,
             Map<String, Set<String>> featureRegionMap, Map<String, Set<String>> regionPackageMap) {
         this.bsnVerMap = bsnVerMap;
         this.bundleFeatureMap = bundleFeatureMap;
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
index fc19bc5..20924c9 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
@@ -56,6 +56,7 @@ public class ActivatorTest {
         expectedProps.put(FEATURE_REGION_FILENAME, f);
 
         BundleContext bc = Mockito.mock(BundleContext.class);
+        Mockito.when(bc.getProperty(Activator.REGIONS_PROPERTY_NAME)).thenReturn("*");
 
         Activator a = new Activator();
         a.start(bc);
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
index 96d33b3..5d3fa22 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
@@ -55,7 +55,7 @@ public class RegionEnforcerTest {
 
     @Test
     public void testRegionEnforcerNoConfiguration() throws Exception {
-        RegionEnforcer re = new RegionEnforcer(new Hashtable<>());
+        RegionEnforcer re = new RegionEnforcer(new Hashtable<>(), "*");
         assertEquals(0, re.bsnVerMap.size());
         assertEquals(0, re.bundleFeatureMap.size());
         assertEquals(0, re.featureRegionMap.size());
@@ -68,7 +68,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + IDBSNVER_FILENAME, f);
 
         Hashtable<String, Object> props = new Hashtable<>();
-        RegionEnforcer re = new RegionEnforcer(props);
+        RegionEnforcer re = new RegionEnforcer(props, "*");
         assertEquals(2, re.bsnVerMap.size());
         assertEquals(Collections.singletonList("g:b1:1"),
                 re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b1", new Version(1,0,0))));
@@ -83,7 +83,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + BUNDLE_FEATURE_FILENAME, f);
 
         Hashtable<String, Object> props = new Hashtable<>();
-        RegionEnforcer re = new RegionEnforcer(props);
+        RegionEnforcer re = new RegionEnforcer(props, "*");
         assertEquals(3, re.bundleFeatureMap.size());
         assertEquals(Collections.singleton("org.sling:something:1.2.3:slingosgifeature:myclassifier"),
                 re.bundleFeatureMap.get("org.sling:b1:1"));
@@ -100,7 +100,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + FEATURE_REGION_FILENAME, f);
 
         Hashtable<String, Object> props = new Hashtable<>();
-        RegionEnforcer re = new RegionEnforcer(props);
+        RegionEnforcer re = new RegionEnforcer(props, "*");
         assertEquals(2, re.featureRegionMap.size());
         assertEquals(Collections.singleton("global"),
                 re.featureRegionMap.get("an.other:feature:123"));
@@ -115,7 +115,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME, f);
 
         Hashtable<String, Object> props = new Hashtable<>();
-        RegionEnforcer re = new RegionEnforcer(props);
+        RegionEnforcer re = new RegionEnforcer(props, "*");
         assertEquals(2, re.regionPackageMap.size());
         assertEquals(Collections.singleton("xyz"),
                 re.regionPackageMap.get("internal"));
@@ -135,7 +135,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME,
                 getClass().getResource("/regions1.properties").getFile());
 
-        RegionEnforcer re = new RegionEnforcer(new Hashtable<>());
+        RegionEnforcer re = new RegionEnforcer(new Hashtable<>(), "*");
         assertTrue(re.bsnVerMap.size() > 0);
         assertTrue(re.bundleFeatureMap.size() > 0);
         assertTrue(re.featureRegionMap.size() > 0);


[sling-org-apache-sling-feature-apiregions] 01/19: Rename feature whitelist component to feature apiregions

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit f8b59082f5dc4bf4be75ba75c64b976317cb9ae8
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sat Nov 3 10:11:24 2018 +0000

    Rename feature whitelist component to feature apiregions
---
 pom.xml                                            | 125 ++++++++++++
 .../sling/feature/apiregions/impl/Activator.java   |  35 ++++
 .../feature/apiregions/impl/RegionEnforcer.java    | 134 +++++++++++++
 .../feature/apiregions/impl/ResolverHookImpl.java  | 186 ++++++++++++++++++
 .../apiregions/impl/ResolverHookImplTest.java      | 209 +++++++++++++++++++++
 .../apiregions/impl/WhitelistEnforcerTest.java     |  62 ++++++
 .../impl/WhitelistServiceFactoryImplTest.java      |  64 +++++++
 .../apiregions/impl/WhitelistServiceImplTest.java  |  52 +++++
 8 files changed, 867 insertions(+)

diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5602b63
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+    <!--
+        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.
+    -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>34</version>
+        <relativePath />
+    </parent>
+
+    <artifactId>org.apache.sling.feature.apiregions</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Feature API Regions Runtime</name>
+    <description>
+        A runtime component to enforce API Regions
+    </description>
+
+    <properties>
+        <sling.java.version>8</sling.java.version>
+    </properties>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <ExtensionBundle-Activator>org.apache.sling.feature.apiregions.impl.Activator</ExtensionBundle-Activator>
+                        <Fragment-Host>system.bundle;extension:=framework</Fragment-Host>
+                    </instructions>
+                
+                    <!--  Skip baselining for 0.x version -->
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>*.md</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature.service</artifactId>
+            <version>0.0.1-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.annotation.versioning</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>        
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-json_1.1_spec</artifactId>
+            <version>1.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature</artifactId>
+            <version>0.1.3-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.feature.launcher</artifactId>
+            <version>0.1.0-SNAPSHOT</version>
+            <scope>provided</scope>
+        </dependency>
+        
+
+        <!-- Testing -->
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>2.8.9</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.johnzon</groupId>
+            <artifactId>johnzon-core</artifactId>
+            <version>1.0.0</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
new file mode 100644
index 0000000..7d77d5e
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
@@ -0,0 +1,35 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+
+public class Activator implements BundleActivator {
+    @Override
+    public synchronized void start(BundleContext context) throws Exception {
+        RegionEnforcer enforcer = new RegionEnforcer();
+        context.registerService(ResolverHookFactory.class, enforcer, null);
+    }
+
+    @Override
+    public synchronized void stop(BundleContext context) throws Exception {
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
new file mode 100644
index 0000000..26807ef
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -0,0 +1,134 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.osgi.framework.Version;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+import org.osgi.framework.wiring.BundleRevision;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+class RegionEnforcer implements ResolverHookFactory {
+    private static final String idbsnverFileName = "idbsnver.properties";
+    private static final String bundleFeatureFileName = "bundles.properties";
+    private static final String regionPackageFileName = "regions.properties";
+    private static final String featureRegionFileName = "features.properties";
+
+    private final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
+    private final Map<String, Set<String>> bundleFeatureMap;
+    private final Map<String, Set<String>> featureRegionMap;
+    private final Map<String, Set<String>> regionPackageMap;
+
+    public RegionEnforcer() throws IOException {
+        bsnVerMap = populateBSNVerMap();
+        bundleFeatureMap = populateBundleFeatureMap();
+        featureRegionMap = populateFeatureRegionMap();
+        regionPackageMap = populateRegionPackageMap();
+    }
+
+    private Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap() throws IOException {
+        File idbsnverFile = getDataFile(idbsnverFileName);
+        if (idbsnverFile != null && idbsnverFile.exists()) {
+            Map<Map.Entry<String, Version>, List<String>> m = new HashMap<>();
+
+            Properties p = new Properties();
+            try (InputStream is = new FileInputStream(idbsnverFile)) {
+                p.load(is);
+            }
+
+            for (String n : p.stringPropertyNames()) {
+                String[] bsnver = p.getProperty(n).split("~");
+                Map.Entry<String, Version> key = new AbstractMap.SimpleEntry<String, Version>(bsnver[0], Version.valueOf(bsnver[1]));
+                List<String> l = m.get(key);
+                if (l == null) {
+                    l = new ArrayList<>();
+                    m.put(key, l);
+                }
+            }
+
+            Map<Map.Entry<String, Version>, List<String>> m2 = new HashMap<>();
+
+            for (Map.Entry<Map.Entry<String, Version>, List<String>> entry : m.entrySet()) {
+                m2.put(entry.getKey(), Collections.unmodifiableList(entry.getValue()));
+            }
+
+            return Collections.unmodifiableMap(m2);
+        } else {
+            return Collections.emptyMap();
+        }
+    }
+
+    private Map<String, Set<String>> populateBundleFeatureMap() throws IOException {
+        return loadMap(bundleFeatureFileName);
+    }
+
+    private Map<String, Set<String>> populateFeatureRegionMap() throws IOException {
+        return loadMap(featureRegionFileName);
+    }
+
+    private Map<String, Set<String>> populateRegionPackageMap() throws IOException {
+        return loadMap(regionPackageFileName);
+    }
+
+    private Map<String, Set<String>> loadMap(String fileName) throws IOException {
+        Map<String, Set<String>> m = new HashMap<>();
+
+        File propsFile = getDataFile(fileName);
+        if (propsFile != null && propsFile.exists()) {
+            Properties p = new Properties();
+            try (InputStream is = new FileInputStream(propsFile)) {
+                p.load(is);
+            }
+
+            for (String n : p.stringPropertyNames()) {
+                String[] features = p.getProperty(n).split(",");
+                m.put(n, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(features))));
+            }
+        }
+
+        return Collections.unmodifiableMap(m);
+    }
+
+    private File getDataFile(String name) throws IOException {
+        String fn = System.getProperty("whitelisting." + name);
+        if (fn == null)
+            return null;
+        return new File(fn);
+    }
+
+    @Override
+    public ResolverHook begin(Collection<BundleRevision> triggers) {
+        return new ResolverHookImpl(bsnVerMap, bundleFeatureMap, featureRegionMap, regionPackageMap);
+    }
+}
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
new file mode 100644
index 0000000..5642d47
--- /dev/null
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -0,0 +1,186 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.osgi.framework.hooks.resolver.ResolverHook;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+class ResolverHookImpl implements ResolverHook {
+    private static final Logger LOG = Logger.getLogger(ResolverHookImpl.class.getName());
+
+    private final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
+    private final Map<String, Set<String>> bundleFeatureMap;
+    private final Map<String, Set<String>> featureRegionMap;
+    private final Map<String, Set<String>> regionPackageMap;
+
+    public ResolverHookImpl(Map<Entry<String, Version>, List<String>> bsnVerMap, Map<String, Set<String>> bundleFeatureMap,
+            Map<String, Set<String>> featureRegionMap, Map<String, Set<String>> regionPackageMap) {
+        this.bsnVerMap = bsnVerMap;
+        this.bundleFeatureMap = bundleFeatureMap;
+        this.featureRegionMap = featureRegionMap;
+        this.regionPackageMap = regionPackageMap;
+    }
+
+    @Override
+    public void filterResolvable(Collection<BundleRevision> candidates) {
+        // Nothing to do
+    }
+
+    @Override
+    public void filterSingletonCollisions(BundleCapability singleton, Collection<BundleCapability> collisionCandidates) {
+        // Nothing to do
+    }
+
+    @Override
+    public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
+        // Filtering is only on package resolution. Any other kind of resolution is not limited
+        if (!PackageNamespace.PACKAGE_NAMESPACE.equals(requirement.getNamespace()))
+            return;
+
+        System.out.println("*** Filter Matches: " + requirement);
+        Bundle reqBundle = requirement.getRevision().getBundle();
+        long reqBundleID = reqBundle.getBundleId();
+        String reqBundleName = reqBundle.getSymbolicName();
+        Version reqBundleVersion = reqBundle.getVersion();
+
+        List<String> aids = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(reqBundleName, reqBundleVersion));
+        if (aids == null)
+            return; // TODO what to do?
+        List<String> reqFeatures = new ArrayList<>();
+        for (String aid : aids) {
+            Set<String> fid = bundleFeatureMap.get(aid);
+            if (fid != null)
+                reqFeatures.addAll(fid);
+        }
+
+        Set<String> regions = new HashSet<>();
+        for (String feature : reqFeatures) {
+            Set<String> fr = featureRegionMap.get(feature);
+            if (fr != null) {
+                regions.addAll(fr);
+            }
+        }
+
+        Set<BundleCapability> coveredCaps = new HashSet<>();
+
+        nextCapability:
+        for (BundleCapability bc : candidates) {
+            BundleRevision rev = bc.getRevision();
+
+            Bundle capBundle = rev.getBundle();
+            long capBundleID = capBundle.getBundleId();
+            if (capBundleID == 0) {
+                // always allow capability from the system bundle
+                coveredCaps.add(bc);
+                continue nextCapability;
+            }
+
+            if (capBundleID == reqBundleID) {
+                // always allow capability from same bundle
+                coveredCaps.add(bc);
+                continue nextCapability;
+            }
+
+            String capBundleName = capBundle.getSymbolicName();
+            Version capBundleVersion = capBundle.getVersion();
+
+            List<String> capBundleArtifacts = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(capBundleName, capBundleVersion));
+            if (capBundleArtifacts == null)
+                return; // TODO what to do?
+            List<String> capFeatures = new ArrayList<>();
+            for (String ba : capBundleArtifacts) {
+                Set<String> capfeats = bundleFeatureMap.get(ba);
+                if (capfeats != null)
+                    capFeatures.addAll(capfeats);
+            }
+
+            if (capFeatures.isEmpty())
+                capFeatures = Collections.singletonList(null);
+
+            for (String capFeat : capFeatures) {
+                if (capFeat == null) {
+                    // always allow capability not coming from a feature
+                    coveredCaps.add(bc);
+                    continue nextCapability;
+                }
+
+                if (reqFeatures.contains(capFeat)) {
+                    // Within a single feature everything can wire to everything else
+                    coveredCaps.add(bc);
+                    continue nextCapability;
+                }
+
+                if (featureRegionMap.get(capFeat) == null) {
+                    // If the feature hosting the capability has no regions defined, everyone can access
+                    coveredCaps.add(bc);
+                    continue nextCapability;
+                }
+
+                Object pkg = bc.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+                if (pkg instanceof String) {
+                    String packageName = (String) pkg;
+
+                    Set<String> globalPackages = regionPackageMap.get("global");
+                    if (globalPackages != null && globalPackages.contains(packageName)) {
+                        // If the export is in the global region everyone can access
+                        coveredCaps.add(bc);
+                        continue nextCapability;
+                    }
+
+                    for (String region : regions) {
+                        Set<String> regionPackages = regionPackageMap.get(region);
+                        if (regionPackages != null && regionPackages.contains(packageName)) {
+                            // If the export is in a region that the feature is also in, then allow
+                            coveredCaps.add(bc);
+                            continue nextCapability;
+                        }
+                    }
+                }
+            }
+        }
+
+        // Remove any capabilities that are not covered
+        if (candidates.retainAll(coveredCaps)) {
+            LOG.log(Level.INFO,
+                    "Removed one ore more candidates for requirement {0} as they are not in the correct region", requirement);
+        }
+    }
+
+    @Override
+    public void end() {
+        // Nothing to do
+    }
+}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
new file mode 100644
index 0000000..5bc60a1
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -0,0 +1,209 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+import org.osgi.framework.namespace.PackageNamespace;
+import org.osgi.framework.wiring.BundleCapability;
+import org.osgi.framework.wiring.BundleRequirement;
+import org.osgi.framework.wiring.BundleRevision;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class ResolverHookImplTest {
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test @Ignore
+    public void testFilterMatches() throws Exception {
+        String f = "gid:aid:0.0.9";
+        String f2 = "gid2:aid2:1.0.0-SNAPSHOT";
+        String f3 = "gid3:aid3:1.2.3";
+        String f4 = "gid4:aid4:1.2.3";
+        String f5 = "gid5:aid5:1.2.3";
+
+        /*
+        Features fs = Mockito.mock(Features.class);
+        Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(0,0,0)))
+            .thenReturn(Collections.singleton(f)); // b7
+        Mockito.when(fs.getFeaturesForBundle("some.other.bundle", new Version(9,9,9,"suffix")))
+            .thenReturn(Collections.singleton(f2)); // b9
+        Mockito.when(fs.getFeaturesForBundle("a-bundle", new Version(1,0,0,"SNAPSHOT")))
+            .thenReturn(Collections.singleton(f2)); // b10
+        Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(1,2,3)))
+            .thenReturn(Collections.singleton(f3)); // b17
+        Mockito.when(fs.getFeaturesForBundle("z.z.z", new Version(3,2,1)))
+            .thenReturn(new HashSet<>(Arrays.asList(f, f3))); // b18
+        Mockito.when(fs.getFeaturesForBundle("x.y.z", new Version(9,9,9)))
+            .thenReturn(Collections.singleton(f3)); // b19
+        Mockito.when(fs.getFeaturesForBundle("zzz", new Version(1,0,0)))
+            .thenReturn(Collections.singleton(f4)); // b20
+        Mockito.when(fs.getFeaturesForBundle("www", new Version(1,0,0)))
+        .thenReturn(Collections.singleton(f5)); // b20
+
+        ServiceTracker st = Mockito.mock(ServiceTracker.class);
+        Mockito.when(st.waitForService(Mockito.anyLong())).thenReturn(fs);
+
+        Map<String, Set<String>> rpm = new HashMap<>();
+        rpm.put("r0", Collections.singleton("org.bar"));
+        rpm.put("r1", new HashSet<>(Arrays.asList("org.blah", "org.foo")));
+        rpm.put(WhitelistService.GLOBAL_REGION, Collections.singleton("org.bar.tar"));
+        rpm.put("r3", Collections.singleton("xyz"));
+
+        Map<String, Set<String>> frm = new HashMap<>();
+        frm.put("gid:aid:0.0.9",
+                new HashSet<>(Arrays.asList("r1", "r2", WhitelistService.GLOBAL_REGION)));
+        frm.put("gid2:aid2:1.0.0-SNAPSHOT", Collections.singleton("r2"));
+        frm.put("gid3:aid3:1.2.3", Collections.singleton("r3"));
+        frm.put("gid4:aid4:1.2.3", Collections.singleton("r3"));
+        frm.put("gid5:aid5:1.2.3", Collections.emptySet());
+
+        WhitelistService wls = new WhitelistServiceImpl(rpm, frm);
+        ResolverHookImpl rh = new ResolverHookImpl(st, wls);
+
+        // Check that we can get the capability from another bundle in the same region
+        // Bundle 7 is in feature f with regions r1, r2. Bundle 9 is in feature f2 with regions r2
+        BundleRequirement req = mockRequirement(7, "a.b.c", new Version(0,0,0));
+        BundleCapability bc1 = mockCapability("org.foo", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        List<BundleCapability> candidates = new ArrayList<>(Arrays.asList(bc1));
+        rh.filterMatches(req, candidates);
+        assertEquals(Collections.singletonList(bc1), candidates);
+
+        // Check that we cannot get the capability from another bundle in a different region
+        // Bundle 9 is in feature f2 with region r2
+        BundleRequirement req2 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        BundleCapability bc2 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
+        Collection<BundleCapability> c2 = new ArrayList<>(Arrays.asList(bc2));
+        rh.filterMatches(req2, c2);
+        assertEquals(0, c2.size());
+
+        // Check that we can get the capability from the same bundle
+        BundleRequirement req3 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        BundleCapability bc3 = mockCapability("org.bar", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        Collection<BundleCapability> c3 = new ArrayList<>(Arrays.asList(bc3));
+        rh.filterMatches(req3, c3);
+        assertEquals(Collections.singletonList(bc3), c3);
+
+        // Check that we can get the capability from the another bundle in the same feature
+        BundleRequirement req4 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        BundleCapability bc4 = mockCapability("org.bar", 10, "a-bundle", new Version(1,0,0,"SNAPSHOT"));
+        Collection<BundleCapability> c4 = new ArrayList<>(Arrays.asList(bc4));
+        rh.filterMatches(req4, c4);
+        assertEquals(Collections.singletonList(bc4), c4);
+
+        // Check that we can get the capability from another bundle where the capability
+        // is globally visible (from bundle 9, f2)
+        BundleRequirement req5 = mockRequirement(17, "a.b.c", new Version(1,2,3));
+        BundleCapability bc5 = mockCapability("org.bar.tar", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        Collection<BundleCapability> c5 = new ArrayList<>(Arrays.asList(bc5));
+        rh.filterMatches(req5, c5);
+        assertEquals(Collections.singletonList(bc5), c5);
+
+        // Check that we can get the capability from another bundle where the capability
+        // is globally visible (from bundle 7, f)
+        BundleRequirement req6 = mockRequirement(7, "a.b.c", new Version(0,0,0));
+        BundleCapability bc6 = mockCapability("org.bar.tar", 17, "a.b.c", new Version(1,2,3));
+        Collection<BundleCapability> c6 = new ArrayList<>(Arrays.asList(bc6));
+        rh.filterMatches(req6, c6);
+        assertEquals(Collections.singletonList(bc6), c6);
+
+        // Check that capabilities in non-package namespaces are ignored
+        BundleRequirement req7 = Mockito.mock(BundleRequirement.class);
+        Mockito.when(req7.getNamespace()).thenReturn("some.other.namespace");
+        BundleCapability bc7 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
+        Collection<BundleCapability> c7 = new ArrayList<>(Arrays.asList(bc7));
+        rh.filterMatches(req7, c7);
+        assertEquals(Collections.singletonList(bc7), c7);
+
+        // Check that we can get the capability from another provider in the same region
+        BundleRequirement req8 = mockRequirement(20, "zzz", new Version(1,0,0));
+        BundleCapability bc8 = mockCapability("xyz", 19, "x.y.z", new Version(9,9,9));
+        Collection<BundleCapability> c8 = new ArrayList<>(Arrays.asList(bc8));
+        rh.filterMatches(req8, c8);
+
+        assertEquals(Collections.singletonList(bc8), c8);
+        // A requirement from a bundle that has no feature cannot access one in a region
+        BundleRequirement req9 = mockRequirement(11, "qqq", new Version(6,6,6));
+        BundleCapability bc9 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
+        ArrayList c9 = new ArrayList<>(Arrays.asList(bc9));
+        rh.filterMatches(req9, c9);
+        assertEquals(0, c9.size());
+
+        // A requirement from a bundle that has no feature can still access on in the global region
+        BundleRequirement req10 = mockRequirement(11, "qqq", new Version(6,6,6));
+        BundleCapability bc10 = mockCapability("org.bar.tar", 18, "z.z.z", new Version(3,2,1));
+        ArrayList c10 = new ArrayList<>(Arrays.asList(bc10));
+        rh.filterMatches(req10, c10);
+        assertEquals(Collections.singletonList(bc10), c10);
+
+        // A requirement from a bundle that has no feature can be satisfied by a capability
+        // from a bundle that has no feature
+        BundleRequirement req11 = mockRequirement(11, "qqq", new Version(6,6,6));
+        BundleCapability bc11 = mockCapability("org.bar.tar", 20, "www", new Version(1,0,0));
+        ArrayList c11 = new ArrayList<>(Arrays.asList(bc11));
+        rh.filterMatches(req11, c11);
+        assertEquals(Collections.singletonList(bc11), c11);
+
+        // A capability from the system bundle is always accessible
+        BundleRequirement req12 = mockRequirement(11, "qqq", new Version(6,6,6));
+        BundleCapability bc12 = mockCapability("ping.pong", 0, "system.bundle", new Version(3,2,1));
+        ArrayList c12 = new ArrayList<>(Arrays.asList(bc12));
+        rh.filterMatches(req12, c12);
+        assertEquals(Collections.singletonList(bc12), c12);
+        */
+    }
+
+    private BundleCapability mockCapability(String pkg, long bundleID, String bsn, Version version) {
+        Map<String, Object> attrs =
+                Collections.singletonMap(PackageNamespace.PACKAGE_NAMESPACE, pkg);
+
+        Bundle bundle = Mockito.mock(Bundle.class);
+        Mockito.when(bundle.getBundleId()).thenReturn(bundleID);
+        Mockito.when(bundle.getSymbolicName()).thenReturn(bsn);
+        Mockito.when(bundle.getVersion()).thenReturn(version);
+
+        BundleRevision br = Mockito.mock(BundleRevision.class);
+        Mockito.when(br.getBundle()).thenReturn(bundle);
+
+
+        BundleCapability cap = Mockito.mock(BundleCapability.class);
+        Mockito.when(cap.getAttributes()).thenReturn(attrs);
+        Mockito.when(cap.getRevision()).thenReturn(br);
+        return cap;
+    }
+
+    private BundleRequirement mockRequirement(long bundleID, String bsn, Version version) {
+        Bundle bundle = Mockito.mock(Bundle.class);
+        Mockito.when(bundle.getBundleId()).thenReturn(bundleID);
+        Mockito.when(bundle.getSymbolicName()).thenReturn(bsn);
+        Mockito.when(bundle.getVersion()).thenReturn(version);
+
+        BundleRevision br = Mockito.mock(BundleRevision.class);
+        Mockito.when(br.getBundle()).thenReturn(bundle);
+
+        BundleRequirement req = Mockito.mock(BundleRequirement.class);
+        Mockito.when(req.getNamespace()).thenReturn(PackageNamespace.PACKAGE_NAMESPACE);
+        Mockito.when(req.getRevision()).thenReturn(br);
+
+        return req;
+    }
+}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java
new file mode 100644
index 0000000..e83c27f
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.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.feature.apiregions.impl;
+
+public class WhitelistEnforcerTest {
+    /*
+    @Test
+    public void testWhitelistEnforcerConfigUpdate() throws ConfigurationException {
+        BundleContext bc = Mockito.mock(BundleContext.class);
+        WhitelistEnforcer enf = new WhitelistEnforcer(bc, null);
+
+        assertNull("Precondition", enf.whitelistService);
+
+        Dictionary<String, Object> props = new Hashtable<>();
+        props.put("ignored", "ignored-too");
+        props.put("whitelist.region.region1", "org.foo.pkg1");
+        props.put("whitelist.region.region2", new String[] {"pkga", "pkgb"});
+        props.put("whitelist.region.region.3", Arrays.asList("a.b.c", "d.e.f", "g.h.i"));
+        props.put("whitelist.feature.gid:aid:slingfeature:testfeature:1.0.0", WhitelistService.GLOBAL_REGION);
+        props.put("whitelist.feature.gid:myfeature:1.0.0", new String [] {"region1", "region2"});
+        enf.updated(props);
+
+        assertNotNull(enf.whitelistService);
+        Mockito.verify(bc, Mockito.times(1)).registerService(
+                Mockito.eq(WhitelistService.class), Mockito.isA(WhitelistService.class), Mockito.any());
+
+        // check that the configuration parsing worked
+        assertTrue(enf.whitelistService.regionWhitelistsPackage("region1", "org.foo.pkg1"));
+        assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkga"));
+        assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkgb"));
+        assertFalse(enf.whitelistService.regionWhitelistsPackage("region1", "pkg1"));
+        assertTrue(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f"));
+        assertFalse(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f.g"));
+        assertNull(enf.whitelistService.regionWhitelistsPackage("unknown", "pkga"));
+
+        Set<String> regions = enf.whitelistService.listRegions("gid:myfeature:1.0.0");
+        assertEquals(new HashSet<String>(Arrays.asList("region1", "region2")), regions);
+        assertEquals(Collections.singleton("global"), enf.whitelistService
+                .listRegions("gid:aid:slingfeature:testfeature:1.0.0"));
+        assertNull(enf.whitelistService.listRegions("unknown"));
+
+        enf.updated(null);
+        assertNull("A null configuration should put back the null whitelist service", enf.whitelistService);
+    }
+    */
+}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java
new file mode 100644
index 0000000..f9120d3
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.feature.apiregions.impl;
+
+public class WhitelistServiceFactoryImplTest {
+    /*
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testWhitelistServiceFactory() {
+        List<ResolverHookFactory> resolverHookFactory = new ArrayList<>();
+        Map<String, Map<String, Set<String>>> wlsCfg = new HashMap<>();
+
+        ServiceTracker st = Mockito.mock(ServiceTracker.class);
+        BundleContext bc = Mockito.mock(BundleContext.class);
+        Mockito.when(bc.registerService(Mockito.isA(Class.class), Mockito.isA(Object.class), Mockito.isA(Dictionary.class)))
+            .then(i -> { resolverHookFactory.add(i.getArgument(1)); return null; });
+
+        WhitelistServiceFactory wsf = new WhitelistServiceFactoryImpl(bc, st) {
+            @Override
+            WhitelistService createWhitelistService(Map<String, Set<String>> packages, Map<String, Set<String>> regions) {
+                wlsCfg.put("packages", packages);
+                wlsCfg.put("regions", regions);
+                return super.createWhitelistService(packages, regions);
+            }
+        };
+
+        Map<String, Map<String, Set<String>>> m = new HashMap<>();
+        Map<String, Set<String>> packages = new HashMap<>();
+        packages.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar")));
+        packages.put("region2", Collections.singleton("org.foo.bar"));
+        m.put("packages", packages);
+
+        Map<String, Set<String>> regions = new HashMap<>();
+        regions.put("f1", new HashSet<String>(Arrays.asList("region1", "region3")));
+        regions.put("f2", Collections.singleton("region2"));
+        regions.put("f3", Collections.singleton("region4"));
+        regions.put("f4", Collections.singleton("region2"));
+        m.put("regions", regions);
+
+        wsf.initialize(m);
+
+        assertEquals(wlsCfg, m);
+
+        ResolverHookFactory rhf = resolverHookFactory.get(0);
+        assertTrue(rhf instanceof WhitelistEnforcer);
+    }
+    */
+}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java
new file mode 100644
index 0000000..832e199
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class WhitelistServiceImplTest {
+    @Test
+    @Ignore
+    public void testListRegions() {
+        /*
+        Map<String, Set<String>> frm = new HashMap<>();
+        frm.put("myfeature", new HashSet<>(Arrays.asList("rega", "regb", "regc")));
+        frm.put("myotherfeature", Collections.emptySet());
+        WhitelistService wls = new WhitelistServiceImpl(Collections.emptyMap(), frm);
+
+        assertEquals(new HashSet<>(Arrays.asList("rega", "regb", "regc")),
+                wls.listRegions("myfeature"));
+        assertEquals(0, wls.listRegions("myotherfeature").size());
+        assertNull(wls.listRegions("nonexistent"));
+    }
+
+    @Test
+    public void testRegionContainsPackage() {
+        Map<String, Set<String>> rpm = new HashMap<>();
+        rpm.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar", "org.foo.bar")));
+        WhitelistService wls = new WhitelistServiceImpl(rpm, Collections.emptyMap());
+
+        assertTrue(wls.regionWhitelistsPackage("region1", "org.foo"));
+        assertTrue(wls.regionWhitelistsPackage("region1", "org.foo.bar"));
+        assertFalse(wls.regionWhitelistsPackage("region1", "org.bar.foo"));
+        assertNull(wls.regionWhitelistsPackage("nonexitent", "org.foo"));
+        */
+    }
+}


[sling-org-apache-sling-feature-apiregions] 14/19: Additional unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit d871433d5ef623094f997d12ee2e3d987eaef191
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 16:30:49 2018 +0000

    Additional unit tests for the apiregions runtime component.
---
 .../sling/feature/apiregions/impl/ResolverHookImpl.java    |  5 +++--
 .../feature/apiregions/impl/ResolverHookImplTest.java      | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index 4939961..ae446cd 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -75,8 +75,8 @@ class ResolverHookImpl implements ResolverHook {
         String reqBundleName = reqBundle.getSymbolicName();
         Version reqBundleVersion = reqBundle.getVersion();
 
-        List<String> reqFeatures = new ArrayList<>();
         Set<String> reqRegions = new HashSet<>();
+        List<String> reqFeatures = new ArrayList<>();
         List<String> aids = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(reqBundleName, reqBundleVersion));
         if (aids != null) {
             for (String aid : aids) {
@@ -120,7 +120,8 @@ class ResolverHookImpl implements ResolverHook {
 
             List<String> capBundleArtifacts = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(capBundleName, capBundleVersion));
             if (capBundleArtifacts == null)
-                return; // TODO what to do?
+                return; // Capability is not in any feature, everyone can access
+
             List<String> capFeatures = new ArrayList<>();
             for (String ba : capBundleArtifacts) {
                 Set<String> capfeats = bundleFeatureMap.get(ba);
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index 2127804..c27ccd4 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -141,6 +141,13 @@ public class ResolverHookImplTest {
         rh.filterMatches(req5, c5);
         assertEquals(Collections.singletonList(bc5), c5);
 
+        // Check that we cannot get at a capability in a region from a bundle not in a feature
+        BundleRequirement req6 = mockRequirement(6, "bundle.not.in.feature", new Version(2,0,0));
+        BundleCapability bc6 = mockCapability("org.foo", "b9", bsnvermap);
+        Collection<BundleCapability> c6 = new ArrayList<>(Arrays.asList(bc6));
+        rh.filterMatches(req6, c6);
+        assertEquals(0, c6.size());
+
         // Check that capabilities in non-package namespaces are ignored
         BundleRequirement req7 = Mockito.mock(BundleRequirement.class);
         Mockito.when(req7.getNamespace()).thenReturn("some.other.namespace");
@@ -186,6 +193,13 @@ public class ResolverHookImplTest {
         Collection<BundleCapability> c12 = new ArrayList<>(Arrays.asList(bc12));
         rh.filterMatches(req12, c12);
         assertEquals(Collections.singletonList(bc12), c12);
+
+        // Check that anyone can get a capability from a bundle not in a feature
+        BundleRequirement req13 = mockRequirement("b9", bsnvermap);
+        BundleCapability bc13 = mockCapability("some.package", 999, "no.in.any.feature", new Version(1,0,0));
+        Collection<BundleCapability> c13 = new ArrayList<>(Arrays.asList(bc13));
+        rh.filterMatches(req13, c13);
+        assertEquals(Collections.singletonList(bc13), c13);
     }
 
     private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {


[sling-org-apache-sling-feature-apiregions] 18/19: Improve diagnostics on the candidate removal log message

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit b7e63a3be8078e3424a63dfd6854d34b375caef7
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Nov 7 10:14:30 2018 +0000

    Improve diagnostics on the candidate removal log message
---
 .../feature/apiregions/impl/ResolverHookImpl.java  | 23 +++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index e754c31..34f4409 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -30,6 +30,7 @@ import java.util.AbstractMap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -97,6 +98,7 @@ class ResolverHookImpl implements ResolverHook {
 
         Set<BundleCapability> coveredCaps = new HashSet<>();
 
+        Map<BundleCapability, Set<String>> bcRegionMap = new HashMap<>();
         nextCapability:
         for (BundleCapability bc : candidates) {
             BundleRevision rev = bc.getRevision();
@@ -154,6 +156,7 @@ class ResolverHookImpl implements ResolverHook {
                     coveredCaps.add(bc);
                     continue nextCapability;
                 }
+                bcRegionMap.put(bc, capRegions);
 
                 HashSet<String> sharedRegions = new HashSet<String>(reqRegions);
                 sharedRegions.retainAll(capRegions);
@@ -181,10 +184,28 @@ class ResolverHookImpl implements ResolverHook {
             }
         }
 
+        List<BundleCapability> removedCandidates = new ArrayList<>(candidates);
         // Remove any capabilities that are not covered
         if (candidates.retainAll(coveredCaps)) {
+            removedCandidates.removeAll(candidates);
+
+            StringBuilder sb = new StringBuilder();
+            boolean first = true;
+            for (BundleCapability bc : removedCandidates) {
+                if (first)
+                    first = false;
+                else
+                    sb.append(", ");
+
+                sb.append(bc.toString());
+                sb.append("[Regions: ");
+                sb.append(bcRegionMap.get(bc));
+                sb.append("]");
+            }
+
             LOG.log(Level.INFO,
-                    "Removed one ore more candidates for requirement {0} as they are not in the correct region", requirement);
+                    "API-Regions removed candidates {0} for requirement {1} as the requirement is in the following regions: {2}",
+                    new Object[] {sb, requirement, reqRegions});
         }
     }
 


[sling-org-apache-sling-feature-apiregions] 04/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 2835a4001cf84d53dc7f0dde041f58e34e615d96
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sat Nov 3 11:59:12 2018 +0000

    Unit tests for the apiregions runtime component.
    
    Initial unit tests for the ResolverHookImpl.
---
 .../feature/apiregions/impl/RegionEnforcer.java    |  2 +
 .../feature/apiregions/impl/ResolverHookImpl.java  | 20 ++++---
 .../apiregions/impl/RegionEnforcerTest.java        | 25 +++++++++
 .../apiregions/impl/ResolverHookImplTest.java      | 62 +++++++++++++++++++++-
 4 files changed, 100 insertions(+), 9 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index ab56dd2..fe30277 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -40,6 +40,8 @@ import java.util.Properties;
 import java.util.Set;
 
 class RegionEnforcer implements ResolverHookFactory {
+    public static String GLOBAL_REGION = "global";
+
     static final String PROPERTIES_FILE_PREFIX = "whitelisting.";
     static final String IDBSNVER_FILENAME = "idbsnver.properties";
     static final String BUNDLE_FEATURE_FILENAME = "bundles.properties";
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index 5642d47..3e8e9f2 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -41,10 +41,10 @@ import java.util.logging.Logger;
 class ResolverHookImpl implements ResolverHook {
     private static final Logger LOG = Logger.getLogger(ResolverHookImpl.class.getName());
 
-    private final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
-    private final Map<String, Set<String>> bundleFeatureMap;
-    private final Map<String, Set<String>> featureRegionMap;
-    private final Map<String, Set<String>> regionPackageMap;
+    final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
+    final Map<String, Set<String>> bundleFeatureMap;
+    final Map<String, Set<String>> featureRegionMap;
+    final Map<String, Set<String>> regionPackageMap;
 
     public ResolverHookImpl(Map<Entry<String, Version>, List<String>> bsnVerMap, Map<String, Set<String>> bundleFeatureMap,
             Map<String, Set<String>> featureRegionMap, Map<String, Set<String>> regionPackageMap) {
@@ -86,11 +86,11 @@ class ResolverHookImpl implements ResolverHook {
                 reqFeatures.addAll(fid);
         }
 
-        Set<String> regions = new HashSet<>();
+        Set<String> reqRegions = new HashSet<>();
         for (String feature : reqFeatures) {
             Set<String> fr = featureRegionMap.get(feature);
             if (fr != null) {
-                regions.addAll(fr);
+                reqRegions.addAll(fr);
             }
         }
 
@@ -143,12 +143,16 @@ class ResolverHookImpl implements ResolverHook {
                     continue nextCapability;
                 }
 
-                if (featureRegionMap.get(capFeat) == null) {
+                Set<String> capRegions = featureRegionMap.get(capFeat);
+                if (capRegions == null) {
                     // If the feature hosting the capability has no regions defined, everyone can access
                     coveredCaps.add(bc);
                     continue nextCapability;
                 }
 
+                HashSet<String> sharedRegions = new HashSet<String>(reqRegions);
+                sharedRegions.retainAll(capRegions);
+
                 Object pkg = bc.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
                 if (pkg instanceof String) {
                     String packageName = (String) pkg;
@@ -160,7 +164,7 @@ class ResolverHookImpl implements ResolverHook {
                         continue nextCapability;
                     }
 
-                    for (String region : regions) {
+                    for (String region : sharedRegions) {
                         Set<String> regionPackages = regionPackageMap.get(region);
                         if (regionPackages != null && regionPackages.contains(packageName)) {
                             // If the export is in a region that the feature is also in, then allow
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
index 2225bab..3e33075 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
@@ -35,6 +35,7 @@ import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.IDBSNVER_F
 import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.PROPERTIES_FILE_PREFIX;
 import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.REGION_PACKAGE_FILENAME;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 public class RegionEnforcerTest {
     private Properties savedProps;
@@ -113,4 +114,28 @@ public class RegionEnforcerTest {
         assertEquals(new HashSet<>(Arrays.asList("a.b.c", "d.e.f", "test")),
                 re.regionPackageMap.get("global"));
     }
+
+    @Test
+    public void testBegin() throws Exception {
+        System.setProperty(PROPERTIES_FILE_PREFIX + IDBSNVER_FILENAME,
+                getClass().getResource("/idbsnver1.properties").getFile());
+        System.setProperty(PROPERTIES_FILE_PREFIX + BUNDLE_FEATURE_FILENAME,
+                getClass().getResource("/bundles1.properties").getFile());
+        System.setProperty(PROPERTIES_FILE_PREFIX + FEATURE_REGION_FILENAME,
+                getClass().getResource("/features1.properties").getFile());
+        System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME,
+                getClass().getResource("/regions1.properties").getFile());
+
+        RegionEnforcer re = new RegionEnforcer();
+        assertTrue(re.bsnVerMap.size() > 0);
+        assertTrue(re.bundleFeatureMap.size() > 0);
+        assertTrue(re.featureRegionMap.size() > 0);
+        assertTrue(re.regionPackageMap.size() > 0);
+
+        ResolverHookImpl hook = (ResolverHookImpl) re.begin(null);
+        assertEquals(re.bsnVerMap, hook.bsnVerMap);
+        assertEquals(re.bundleFeatureMap, hook.bundleFeatureMap);
+        assertEquals(re.featureRegionMap, hook.featureRegionMap);
+        assertEquals(re.regionPackageMap, hook.regionPackageMap);
+    }
 }
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index 5bc60a1..c5d8ef8 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -28,13 +28,23 @@ import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
 
+import java.util.AbstractMap;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
 
 public class ResolverHookImplTest {
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test @Ignore
-    public void testFilterMatches() throws Exception {
+    public void xxtestFilterMatches() throws Exception {
         String f = "gid:aid:0.0.9";
         String f2 = "gid2:aid2:1.0.0-SNAPSHOT";
         String f3 = "gid3:aid3:1.2.3";
@@ -172,6 +182,56 @@ public class ResolverHookImplTest {
         */
     }
 
+    @Test
+    public void testFilterMatches() {
+        Map<Entry<String, Version>, List<String>> bsnvermap = new HashMap<>();
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(0,0,0)),
+                Collections.singletonList("b7"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.bundle", new Version(1,0,0)),
+                Collections.singletonList("b8"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("some.other.bundle", new Version(9,9,9,"suffix")),
+                Collections.singletonList("b9"));
+
+        Map<String, Set<String>> bfmap = new HashMap<>();
+        bfmap.put("b7", Collections.singleton("f"));
+        bfmap.put("b8", Collections.singleton("f1"));
+        bfmap.put("b9", Collections.singleton("f2"));
+
+        Map<String, Set<String>> frmap = new HashMap<>();
+        frmap.put("f", new HashSet<>(Arrays.asList("r1", "r2")));
+        frmap.put("f1", Collections.singleton("r1"));
+        frmap.put("f2", Collections.singleton("r2"));
+
+        Map<String, Set<String>> rpmap = new HashMap<>();
+        rpmap.put("r0", Collections.singleton("org.bar"));
+        rpmap.put("r1", new HashSet<>(Arrays.asList("org.blah", "org.foo")));
+        rpmap.put(RegionEnforcer.GLOBAL_REGION, Collections.singleton("org.bar.tar"));
+        rpmap.put("r3", Collections.singleton("xyz"));
+
+        ResolverHookImpl rh = new ResolverHookImpl(bsnvermap, bfmap, frmap, rpmap);
+
+        // Check that we cann get the capability from another bundle in the same region
+        // where that region exports the package
+        // Bundle 7 is in feature f with regions r1, r2. Bundle 8 is in feature f1 with regions r1
+        // r1 exports the org.foo package
+        BundleRequirement req0 = mockRequirement(7, "a.b.c", new Version(0,0,0));
+        BundleCapability bc0 = mockCapability("org.foo", 8, "a.bundle", new Version(1,0,0));
+        List<BundleCapability> candidates0 = new ArrayList<>(Arrays.asList(bc0));
+        rh.filterMatches(req0, candidates0);
+        assertEquals(Collections.singletonList(bc0), candidates0);
+
+        // Check that we cannot get the capability from another bundle in the same region
+        // but that region doesn't export the pacakge.
+        // Bundle 7 is in feature f with regions r1, r2. Bundle 9 is in feature f2 with regions r2
+        // r2 does not export any packages
+        BundleRequirement req1 = mockRequirement(7, "a.b.c", new Version(0,0,0));
+        BundleCapability bc1 = mockCapability("org.foo", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
+        List<BundleCapability> candidates1 = new ArrayList<>(Arrays.asList(bc1));
+        rh.filterMatches(req1, candidates1);
+        assertEquals(Collections.emptyList(), candidates1);
+
+    }
+
     private BundleCapability mockCapability(String pkg, long bundleID, String bsn, Version version) {
         Map<String, Object> attrs =
                 Collections.singletonMap(PackageNamespace.PACKAGE_NAMESPACE, pkg);


[sling-org-apache-sling-feature-apiregions] 05/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 19064115ea2bf5ad34074709417ab56ab7f4ddbf
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sat Nov 3 12:01:14 2018 +0000

    Unit tests for the apiregions runtime component.
    
    Remove some obsolete test code that related to the previous
    implementation.
---
 .../apiregions/impl/ResolverHookImplTest.java      |  3 +-
 .../apiregions/impl/WhitelistEnforcerTest.java     | 62 ---------------------
 .../impl/WhitelistServiceFactoryImplTest.java      | 64 ----------------------
 .../apiregions/impl/WhitelistServiceImplTest.java  | 52 ------------------
 4 files changed, 1 insertion(+), 180 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index c5d8ef8..eead297 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -42,16 +42,15 @@ import java.util.Set;
 import static org.junit.Assert.assertEquals;
 
 public class ResolverHookImplTest {
-    @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test @Ignore
     public void xxtestFilterMatches() throws Exception {
+        /*
         String f = "gid:aid:0.0.9";
         String f2 = "gid2:aid2:1.0.0-SNAPSHOT";
         String f3 = "gid3:aid3:1.2.3";
         String f4 = "gid4:aid4:1.2.3";
         String f5 = "gid5:aid5:1.2.3";
 
-        /*
         Features fs = Mockito.mock(Features.class);
         Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(0,0,0)))
             .thenReturn(Collections.singleton(f)); // b7
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.java
deleted file mode 100644
index e83c27f..0000000
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistEnforcerTest.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.feature.apiregions.impl;
-
-public class WhitelistEnforcerTest {
-    /*
-    @Test
-    public void testWhitelistEnforcerConfigUpdate() throws ConfigurationException {
-        BundleContext bc = Mockito.mock(BundleContext.class);
-        WhitelistEnforcer enf = new WhitelistEnforcer(bc, null);
-
-        assertNull("Precondition", enf.whitelistService);
-
-        Dictionary<String, Object> props = new Hashtable<>();
-        props.put("ignored", "ignored-too");
-        props.put("whitelist.region.region1", "org.foo.pkg1");
-        props.put("whitelist.region.region2", new String[] {"pkga", "pkgb"});
-        props.put("whitelist.region.region.3", Arrays.asList("a.b.c", "d.e.f", "g.h.i"));
-        props.put("whitelist.feature.gid:aid:slingfeature:testfeature:1.0.0", WhitelistService.GLOBAL_REGION);
-        props.put("whitelist.feature.gid:myfeature:1.0.0", new String [] {"region1", "region2"});
-        enf.updated(props);
-
-        assertNotNull(enf.whitelistService);
-        Mockito.verify(bc, Mockito.times(1)).registerService(
-                Mockito.eq(WhitelistService.class), Mockito.isA(WhitelistService.class), Mockito.any());
-
-        // check that the configuration parsing worked
-        assertTrue(enf.whitelistService.regionWhitelistsPackage("region1", "org.foo.pkg1"));
-        assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkga"));
-        assertTrue(enf.whitelistService.regionWhitelistsPackage("region2", "pkgb"));
-        assertFalse(enf.whitelistService.regionWhitelistsPackage("region1", "pkg1"));
-        assertTrue(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f"));
-        assertFalse(enf.whitelistService.regionWhitelistsPackage("region.3", "d.e.f.g"));
-        assertNull(enf.whitelistService.regionWhitelistsPackage("unknown", "pkga"));
-
-        Set<String> regions = enf.whitelistService.listRegions("gid:myfeature:1.0.0");
-        assertEquals(new HashSet<String>(Arrays.asList("region1", "region2")), regions);
-        assertEquals(Collections.singleton("global"), enf.whitelistService
-                .listRegions("gid:aid:slingfeature:testfeature:1.0.0"));
-        assertNull(enf.whitelistService.listRegions("unknown"));
-
-        enf.updated(null);
-        assertNull("A null configuration should put back the null whitelist service", enf.whitelistService);
-    }
-    */
-}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java
deleted file mode 100644
index f9120d3..0000000
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceFactoryImplTest.java
+++ /dev/null
@@ -1,64 +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.feature.apiregions.impl;
-
-public class WhitelistServiceFactoryImplTest {
-    /*
-    @SuppressWarnings({ "rawtypes", "unchecked" })
-    @Test
-    public void testWhitelistServiceFactory() {
-        List<ResolverHookFactory> resolverHookFactory = new ArrayList<>();
-        Map<String, Map<String, Set<String>>> wlsCfg = new HashMap<>();
-
-        ServiceTracker st = Mockito.mock(ServiceTracker.class);
-        BundleContext bc = Mockito.mock(BundleContext.class);
-        Mockito.when(bc.registerService(Mockito.isA(Class.class), Mockito.isA(Object.class), Mockito.isA(Dictionary.class)))
-            .then(i -> { resolverHookFactory.add(i.getArgument(1)); return null; });
-
-        WhitelistServiceFactory wsf = new WhitelistServiceFactoryImpl(bc, st) {
-            @Override
-            WhitelistService createWhitelistService(Map<String, Set<String>> packages, Map<String, Set<String>> regions) {
-                wlsCfg.put("packages", packages);
-                wlsCfg.put("regions", regions);
-                return super.createWhitelistService(packages, regions);
-            }
-        };
-
-        Map<String, Map<String, Set<String>>> m = new HashMap<>();
-        Map<String, Set<String>> packages = new HashMap<>();
-        packages.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar")));
-        packages.put("region2", Collections.singleton("org.foo.bar"));
-        m.put("packages", packages);
-
-        Map<String, Set<String>> regions = new HashMap<>();
-        regions.put("f1", new HashSet<String>(Arrays.asList("region1", "region3")));
-        regions.put("f2", Collections.singleton("region2"));
-        regions.put("f3", Collections.singleton("region4"));
-        regions.put("f4", Collections.singleton("region2"));
-        m.put("regions", regions);
-
-        wsf.initialize(m);
-
-        assertEquals(wlsCfg, m);
-
-        ResolverHookFactory rhf = resolverHookFactory.get(0);
-        assertTrue(rhf instanceof WhitelistEnforcer);
-    }
-    */
-}
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java
deleted file mode 100644
index 832e199..0000000
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/WhitelistServiceImplTest.java
+++ /dev/null
@@ -1,52 +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.feature.apiregions.impl;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class WhitelistServiceImplTest {
-    @Test
-    @Ignore
-    public void testListRegions() {
-        /*
-        Map<String, Set<String>> frm = new HashMap<>();
-        frm.put("myfeature", new HashSet<>(Arrays.asList("rega", "regb", "regc")));
-        frm.put("myotherfeature", Collections.emptySet());
-        WhitelistService wls = new WhitelistServiceImpl(Collections.emptyMap(), frm);
-
-        assertEquals(new HashSet<>(Arrays.asList("rega", "regb", "regc")),
-                wls.listRegions("myfeature"));
-        assertEquals(0, wls.listRegions("myotherfeature").size());
-        assertNull(wls.listRegions("nonexistent"));
-    }
-
-    @Test
-    public void testRegionContainsPackage() {
-        Map<String, Set<String>> rpm = new HashMap<>();
-        rpm.put("region1", new HashSet<>(Arrays.asList("org.foo", "org.bar", "org.foo.bar")));
-        WhitelistService wls = new WhitelistServiceImpl(rpm, Collections.emptyMap());
-
-        assertTrue(wls.regionWhitelistsPackage("region1", "org.foo"));
-        assertTrue(wls.regionWhitelistsPackage("region1", "org.foo.bar"));
-        assertFalse(wls.regionWhitelistsPackage("region1", "org.bar.foo"));
-        assertNull(wls.regionWhitelistsPackage("nonexitent", "org.foo"));
-        */
-    }
-}


[sling-org-apache-sling-feature-apiregions] 03/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit b3c8e9b3e49f5d4e4fbd662ee87c70312a3fe0ef
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sat Nov 3 11:21:21 2018 +0000

    Unit tests for the apiregions runtime component.
---
 pom.xml                                            |  1 +
 .../feature/apiregions/impl/RegionEnforcer.java    |  2 +-
 .../apiregions/impl/RegionEnforcerTest.java        | 43 ++++++++++++++++++++++
 src/test/resources/bundles1.properties             |  5 +++
 src/test/resources/features1.properties            |  4 ++
 src/test/resources/regions1.properties             |  4 ++
 6 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 5602b63..6f46e29 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,7 @@
                 <configuration>
                     <excludes>
                         <exclude>*.md</exclude>
+                        <exclude>src/test/resources/*</exclude>
                     </excludes>
                 </configuration>
             </plugin>
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index 7a5c673..ab56dd2 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -43,8 +43,8 @@ class RegionEnforcer implements ResolverHookFactory {
     static final String PROPERTIES_FILE_PREFIX = "whitelisting.";
     static final String IDBSNVER_FILENAME = "idbsnver.properties";
     static final String BUNDLE_FEATURE_FILENAME = "bundles.properties";
-    static final String REGION_PACKAGE_FILENAME = "regions.properties";
     static final String FEATURE_REGION_FILENAME = "features.properties";
+    static final String REGION_PACKAGE_FILENAME = "regions.properties";
 
     final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
     final Map<String, Set<String>> bundleFeatureMap;
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
index 419c0ea..2225bab 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
@@ -29,8 +29,11 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Properties;
 
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.BUNDLE_FEATURE_FILENAME;
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.FEATURE_REGION_FILENAME;
 import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.IDBSNVER_FILENAME;
 import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.PROPERTIES_FILE_PREFIX;
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.REGION_PACKAGE_FILENAME;
 import static org.junit.Assert.assertEquals;
 
 public class RegionEnforcerTest {
@@ -68,6 +71,46 @@ public class RegionEnforcerTest {
                 re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b1", new Version(1,0,0))));
         assertEquals(new HashSet<>(Arrays.asList("g:b2:1.2.3", "g2:b2:1.2.4")),
                 new HashSet<>(re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b2", new Version(1,2,3)))));
+    }
+
+    @Test
+    public void testLoadBundleFeatureMap() throws Exception {
+        String f = getClass().getResource("/bundles1.properties").getFile();
+        System.setProperty(PROPERTIES_FILE_PREFIX + BUNDLE_FEATURE_FILENAME, f);
+
+        RegionEnforcer re = new RegionEnforcer();
+        assertEquals(3, re.bundleFeatureMap.size());
+        assertEquals(Collections.singleton("org.sling:something:1.2.3:slingosgifeature:myclassifier"),
+                re.bundleFeatureMap.get("org.sling:b1:1"));
+        assertEquals(Collections.singleton("org.sling:something:1.2.3:slingosgifeature:myclassifier"),
+                re.bundleFeatureMap.get("org.sling:b2:1"));
+        assertEquals(new HashSet<>(Arrays.asList("some.other:feature:123", "org.sling:something:1.2.3:slingosgifeature:myclassifier")),
+                re.bundleFeatureMap.get("org.sling:b3:1"));
+    }
+
+    @Test
+    public void testLoadFeatureRegionMap() throws Exception {
+        String f = getClass().getResource("/features1.properties").getFile();
+        System.setProperty(PROPERTIES_FILE_PREFIX + FEATURE_REGION_FILENAME, f);
+
+        RegionEnforcer re = new RegionEnforcer();
+        assertEquals(2, re.featureRegionMap.size());
+        assertEquals(Collections.singleton("global"),
+                re.featureRegionMap.get("an.other:feature:123"));
+        assertEquals(new HashSet<>(Arrays.asList("global", "internal")),
+                re.featureRegionMap.get("org.sling:something:1.2.3"));
+    }
 
+    @Test
+    public void testLoadRegionPackageMap() throws Exception {
+        String f = getClass().getResource("/regions1.properties").getFile();
+        System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME, f);
+
+        RegionEnforcer re = new RegionEnforcer();
+        assertEquals(2, re.regionPackageMap.size());
+        assertEquals(Collections.singleton("xyz"),
+                re.regionPackageMap.get("internal"));
+        assertEquals(new HashSet<>(Arrays.asList("a.b.c", "d.e.f", "test")),
+                re.regionPackageMap.get("global"));
     }
 }
diff --git a/src/test/resources/bundles1.properties b/src/test/resources/bundles1.properties
new file mode 100644
index 0000000..7497eaf
--- /dev/null
+++ b/src/test/resources/bundles1.properties
@@ -0,0 +1,5 @@
+#Generated at Sat Nov 03 10:58:58 GMT 2018
+#Sat Nov 03 10:58:58 GMT 2018
+org.sling\:b3\:1=some.other\:feature\:123,org.sling\:something\:1.2.3\:slingosgifeature\:myclassifier
+org.sling\:b2\:1=org.sling\:something\:1.2.3\:slingosgifeature\:myclassifier
+org.sling\:b1\:1=org.sling\:something\:1.2.3\:slingosgifeature\:myclassifier
diff --git a/src/test/resources/features1.properties b/src/test/resources/features1.properties
new file mode 100644
index 0000000..9efad8d
--- /dev/null
+++ b/src/test/resources/features1.properties
@@ -0,0 +1,4 @@
+#Generated at Sat Nov 03 11:10:29 GMT 2018
+#Sat Nov 03 11:10:29 GMT 2018
+an.other\:feature\:123=global
+org.sling\:something\:1.2.3=internal,global
diff --git a/src/test/resources/regions1.properties b/src/test/resources/regions1.properties
new file mode 100644
index 0000000..a4982d7
--- /dev/null
+++ b/src/test/resources/regions1.properties
@@ -0,0 +1,4 @@
+#Generated at Sat Nov 03 11:10:29 GMT 2018
+#Sat Nov 03 11:10:29 GMT 2018
+internal=xyz
+global=d.e.f,test,a.b.c


[sling-org-apache-sling-feature-apiregions] 11/19: Rename whitelisting to apiregions

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 379d1d8b2a6aec7114d4d1a3be89bf5701e22fd7
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 13:46:46 2018 +0000

    Rename whitelisting to apiregions
    
    Also register resolver hook service with properties that point at the
    properties files used
---
 .../sling/feature/apiregions/impl/Activator.java   |  8 +++-
 .../feature/apiregions/impl/RegionEnforcer.java    | 50 +++++++++++++++-------
 .../feature/apiregions/impl/ResolverHookImpl.java  | 28 ++++++------
 .../feature/apiregions/impl/ActivatorTest.java     | 31 +++++++++++++-
 .../apiregions/impl/RegionEnforcerTest.java        | 21 ++++++---
 5 files changed, 100 insertions(+), 38 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
index 7d77d5e..6ced921 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/Activator.java
@@ -22,11 +22,15 @@ import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.hooks.resolver.ResolverHookFactory;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+
 public class Activator implements BundleActivator {
     @Override
     public synchronized void start(BundleContext context) throws Exception {
-        RegionEnforcer enforcer = new RegionEnforcer();
-        context.registerService(ResolverHookFactory.class, enforcer, null);
+        Dictionary<String, Object> props = new Hashtable<>();
+        RegionEnforcer enforcer = new RegionEnforcer(props);
+        context.registerService(ResolverHookFactory.class, enforcer, props);
     }
 
     @Override
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index fe30277..56a5b74 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -32,6 +32,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -42,7 +43,7 @@ import java.util.Set;
 class RegionEnforcer implements ResolverHookFactory {
     public static String GLOBAL_REGION = "global";
 
-    static final String PROPERTIES_FILE_PREFIX = "whitelisting.";
+    static final String PROPERTIES_FILE_PREFIX = "apiregions.";
     static final String IDBSNVER_FILENAME = "idbsnver.properties";
     static final String BUNDLE_FEATURE_FILENAME = "bundles.properties";
     static final String FEATURE_REGION_FILENAME = "features.properties";
@@ -53,15 +54,33 @@ class RegionEnforcer implements ResolverHookFactory {
     final Map<String, Set<String>> featureRegionMap;
     final Map<String, Set<String>> regionPackageMap;
 
-    public RegionEnforcer() throws IOException {
-        bsnVerMap = populateBSNVerMap();
-        bundleFeatureMap = populateBundleFeatureMap();
-        featureRegionMap = populateFeatureRegionMap();
-        regionPackageMap = populateRegionPackageMap();
+    public RegionEnforcer(Dictionary<String, Object> regProps) throws IOException {
+        File idbsnverFile = getDataFile(IDBSNVER_FILENAME);
+        bsnVerMap = populateBSNVerMap(idbsnverFile);
+        if (idbsnverFile != null) {
+            regProps.put(IDBSNVER_FILENAME, idbsnverFile.getAbsolutePath());
+        }
+
+        File bundlesFile = getDataFile(BUNDLE_FEATURE_FILENAME);
+        bundleFeatureMap = populateBundleFeatureMap(bundlesFile);
+        if (bundlesFile != null) {
+            regProps.put(BUNDLE_FEATURE_FILENAME, bundlesFile.getAbsolutePath());
+        }
+
+        File featuresFile = getDataFile(FEATURE_REGION_FILENAME);
+        featureRegionMap = populateFeatureRegionMap(featuresFile);
+        if (featuresFile != null) {
+            regProps.put(FEATURE_REGION_FILENAME, featuresFile.getAbsolutePath());
+        }
+
+        File regionsFile = getDataFile(REGION_PACKAGE_FILENAME);
+        regionPackageMap = populateRegionPackageMap(regionsFile);
+        if (regionsFile != null) {
+            regProps.put(REGION_PACKAGE_FILENAME, regionsFile.getAbsolutePath());
+        }
     }
 
-    private Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap() throws IOException {
-        File idbsnverFile = getDataFile(IDBSNVER_FILENAME);
+    private Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap(File idbsnverFile) throws IOException {
         if (idbsnverFile != null && idbsnverFile.exists()) {
             Map<Map.Entry<String, Version>, List<String>> m = new HashMap<>();
 
@@ -93,22 +112,21 @@ class RegionEnforcer implements ResolverHookFactory {
         }
     }
 
-    private Map<String, Set<String>> populateBundleFeatureMap() throws IOException {
-        return loadMap(BUNDLE_FEATURE_FILENAME);
+    private Map<String, Set<String>> populateBundleFeatureMap(File bundlesFile) throws IOException {
+        return loadMap(bundlesFile);
     }
 
-    private Map<String, Set<String>> populateFeatureRegionMap() throws IOException {
-        return loadMap(FEATURE_REGION_FILENAME);
+    private Map<String, Set<String>> populateFeatureRegionMap(File featuresFile) throws IOException {
+        return loadMap(featuresFile);
     }
 
-    private Map<String, Set<String>> populateRegionPackageMap() throws IOException {
-        return loadMap(REGION_PACKAGE_FILENAME);
+    private Map<String, Set<String>> populateRegionPackageMap(File regionsFile) throws IOException {
+        return loadMap(regionsFile);
     }
 
-    private Map<String, Set<String>> loadMap(String fileName) throws IOException {
+    private Map<String, Set<String>> loadMap(File propsFile) throws IOException {
         Map<String, Set<String>> m = new HashMap<>();
 
-        File propsFile = getDataFile(fileName);
         if (propsFile != null && propsFile.exists()) {
             Properties p = new Properties();
             try (InputStream is = new FileInputStream(propsFile)) {
diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index caecb76..4939961 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -75,22 +75,24 @@ class ResolverHookImpl implements ResolverHook {
         String reqBundleName = reqBundle.getSymbolicName();
         Version reqBundleVersion = reqBundle.getVersion();
 
-        List<String> aids = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(reqBundleName, reqBundleVersion));
-        if (aids == null)
-            return; // TODO what to do?
         List<String> reqFeatures = new ArrayList<>();
-        for (String aid : aids) {
-            Set<String> fid = bundleFeatureMap.get(aid);
-            if (fid != null)
-                reqFeatures.addAll(fid);
-        }
-
         Set<String> reqRegions = new HashSet<>();
-        for (String feature : reqFeatures) {
-            Set<String> fr = featureRegionMap.get(feature);
-            if (fr != null) {
-                reqRegions.addAll(fr);
+        List<String> aids = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(reqBundleName, reqBundleVersion));
+        if (aids != null) {
+            for (String aid : aids) {
+                Set<String> fid = bundleFeatureMap.get(aid);
+                if (fid != null)
+                    reqFeatures.addAll(fid);
+            }
+
+            for (String feature : reqFeatures) {
+                Set<String> fr = featureRegionMap.get(feature);
+                if (fr != null) {
+                    reqRegions.addAll(fr);
+                }
             }
+        } else {
+            // Bundle is not coming from a feature
         }
 
         Set<BundleCapability> coveredCaps = new HashSet<>();
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
index 3577535..fc19bc5 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
@@ -18,14 +18,43 @@
  */
 package org.apache.sling.feature.apiregions.impl;
 
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.hooks.resolver.ResolverHookFactory;
 
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.FEATURE_REGION_FILENAME;
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.PROPERTIES_FILE_PREFIX;
+
 public class ActivatorTest {
+    private Properties savedProps;
+
+    @Before
+    public void setup() {
+        savedProps = new Properties(); // note that new Properties(props) doesn't copy
+        savedProps.putAll(System.getProperties());
+    }
+
+    @After
+    public void teardown() {
+        System.setProperties(savedProps);
+        savedProps = null;
+    }
+
     @Test
     public void testStart() throws Exception {
+        String f = getClass().getResource("/features1.properties").getFile();
+        System.setProperty(PROPERTIES_FILE_PREFIX + FEATURE_REGION_FILENAME, f);
+
+        Dictionary<String, Object> expectedProps = new Hashtable<>();
+        expectedProps.put(FEATURE_REGION_FILENAME, f);
+
         BundleContext bc = Mockito.mock(BundleContext.class);
 
         Activator a = new Activator();
@@ -34,6 +63,6 @@ public class ActivatorTest {
         Mockito.verify(bc, Mockito.times(1)).registerService(
                 Mockito.eq(ResolverHookFactory.class),
                 Mockito.isA(RegionEnforcer.class),
-                Mockito.isNull());
+                Mockito.eq(expectedProps));
     }
 }
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
index 3e33075..96d33b3 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
@@ -27,6 +27,7 @@ import java.util.AbstractMap;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Properties;
 
 import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.BUNDLE_FEATURE_FILENAME;
@@ -54,7 +55,7 @@ public class RegionEnforcerTest {
 
     @Test
     public void testRegionEnforcerNoConfiguration() throws Exception {
-        RegionEnforcer re = new RegionEnforcer();
+        RegionEnforcer re = new RegionEnforcer(new Hashtable<>());
         assertEquals(0, re.bsnVerMap.size());
         assertEquals(0, re.bundleFeatureMap.size());
         assertEquals(0, re.featureRegionMap.size());
@@ -66,12 +67,14 @@ public class RegionEnforcerTest {
         String f = getClass().getResource("/idbsnver1.properties").getFile();
         System.setProperty(PROPERTIES_FILE_PREFIX + IDBSNVER_FILENAME, f);
 
-        RegionEnforcer re = new RegionEnforcer();
+        Hashtable<String, Object> props = new Hashtable<>();
+        RegionEnforcer re = new RegionEnforcer(props);
         assertEquals(2, re.bsnVerMap.size());
         assertEquals(Collections.singletonList("g:b1:1"),
                 re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b1", new Version(1,0,0))));
         assertEquals(new HashSet<>(Arrays.asList("g:b2:1.2.3", "g2:b2:1.2.4")),
                 new HashSet<>(re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b2", new Version(1,2,3)))));
+        assertEquals(f, props.get(IDBSNVER_FILENAME));
     }
 
     @Test
@@ -79,7 +82,8 @@ public class RegionEnforcerTest {
         String f = getClass().getResource("/bundles1.properties").getFile();
         System.setProperty(PROPERTIES_FILE_PREFIX + BUNDLE_FEATURE_FILENAME, f);
 
-        RegionEnforcer re = new RegionEnforcer();
+        Hashtable<String, Object> props = new Hashtable<>();
+        RegionEnforcer re = new RegionEnforcer(props);
         assertEquals(3, re.bundleFeatureMap.size());
         assertEquals(Collections.singleton("org.sling:something:1.2.3:slingosgifeature:myclassifier"),
                 re.bundleFeatureMap.get("org.sling:b1:1"));
@@ -87,6 +91,7 @@ public class RegionEnforcerTest {
                 re.bundleFeatureMap.get("org.sling:b2:1"));
         assertEquals(new HashSet<>(Arrays.asList("some.other:feature:123", "org.sling:something:1.2.3:slingosgifeature:myclassifier")),
                 re.bundleFeatureMap.get("org.sling:b3:1"));
+        assertEquals(f, props.get(BUNDLE_FEATURE_FILENAME));
     }
 
     @Test
@@ -94,12 +99,14 @@ public class RegionEnforcerTest {
         String f = getClass().getResource("/features1.properties").getFile();
         System.setProperty(PROPERTIES_FILE_PREFIX + FEATURE_REGION_FILENAME, f);
 
-        RegionEnforcer re = new RegionEnforcer();
+        Hashtable<String, Object> props = new Hashtable<>();
+        RegionEnforcer re = new RegionEnforcer(props);
         assertEquals(2, re.featureRegionMap.size());
         assertEquals(Collections.singleton("global"),
                 re.featureRegionMap.get("an.other:feature:123"));
         assertEquals(new HashSet<>(Arrays.asList("global", "internal")),
                 re.featureRegionMap.get("org.sling:something:1.2.3"));
+        assertEquals(f, props.get(FEATURE_REGION_FILENAME));
     }
 
     @Test
@@ -107,12 +114,14 @@ public class RegionEnforcerTest {
         String f = getClass().getResource("/regions1.properties").getFile();
         System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME, f);
 
-        RegionEnforcer re = new RegionEnforcer();
+        Hashtable<String, Object> props = new Hashtable<>();
+        RegionEnforcer re = new RegionEnforcer(props);
         assertEquals(2, re.regionPackageMap.size());
         assertEquals(Collections.singleton("xyz"),
                 re.regionPackageMap.get("internal"));
         assertEquals(new HashSet<>(Arrays.asList("a.b.c", "d.e.f", "test")),
                 re.regionPackageMap.get("global"));
+        assertEquals(f, props.get(REGION_PACKAGE_FILENAME));
     }
 
     @Test
@@ -126,7 +135,7 @@ public class RegionEnforcerTest {
         System.setProperty(PROPERTIES_FILE_PREFIX + REGION_PACKAGE_FILENAME,
                 getClass().getResource("/regions1.properties").getFile());
 
-        RegionEnforcer re = new RegionEnforcer();
+        RegionEnforcer re = new RegionEnforcer(new Hashtable<>());
         assertTrue(re.bsnVerMap.size() > 0);
         assertTrue(re.bundleFeatureMap.size() > 0);
         assertTrue(re.featureRegionMap.size() > 0);


[sling-org-apache-sling-feature-apiregions] 09/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 9f8a91e69c3c7d64be267b5db72d452bc03aabad
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sun Nov 4 20:43:45 2018 +0000

    Unit tests for the apiregions runtime component.
    
    Removed old variant of the unit tests now that they are all converted.
---
 .../apiregions/impl/ResolverHookImplTest.java      | 163 +++------------------
 1 file changed, 21 insertions(+), 142 deletions(-)

diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
index a80404e..2127804 100644
--- a/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ResolverHookImplTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.sling.feature.apiregions.impl;
 
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.osgi.framework.Bundle;
@@ -37,154 +36,17 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.Map.Entry;
+import java.util.Set;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 public class ResolverHookImplTest {
-    @Test @Ignore
-    public void xxtestFilterMatches() throws Exception {
-        /*
-        String f = "gid:aid:0.0.9";
-        String f2 = "gid2:aid2:1.0.0-SNAPSHOT";
-        String f3 = "gid3:aid3:1.2.3";
-        String f4 = "gid4:aid4:1.2.3";
-        String f5 = "gid5:aid5:1.2.3";
-
-        Features fs = Mockito.mock(Features.class);
-        Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(0,0,0)))
-            .thenReturn(Collections.singleton(f)); // b7
-        Mockito.when(fs.getFeaturesForBundle("some.other.bundle", new Version(9,9,9,"suffix")))
-            .thenReturn(Collections.singleton(f2)); // b9
-        Mockito.when(fs.getFeaturesForBundle("a-bundle", new Version(1,0,0,"SNAPSHOT")))
-            .thenReturn(Collections.singleton(f2)); // b10
-        Mockito.when(fs.getFeaturesForBundle("a.b.c", new Version(1,2,3)))
-            .thenReturn(Collections.singleton(f3)); // b17
-        Mockito.when(fs.getFeaturesForBundle("z.z.z", new Version(3,2,1)))
-            .thenReturn(new HashSet<>(Arrays.asList(f, f3))); // b18
-        Mockito.when(fs.getFeaturesForBundle("x.y.z", new Version(9,9,9)))
-            .thenReturn(Collections.singleton(f3)); // b19
-        Mockito.when(fs.getFeaturesForBundle("zzz", new Version(1,0,0)))
-            .thenReturn(Collections.singleton(f4)); // b20
-        Mockito.when(fs.getFeaturesForBundle("www", new Version(1,0,0)))
-        .thenReturn(Collections.singleton(f5)); // b20
-
-        ServiceTracker st = Mockito.mock(ServiceTracker.class);
-        Mockito.when(st.waitForService(Mockito.anyLong())).thenReturn(fs);
-
-        Map<String, Set<String>> rpm = new HashMap<>();
-        rpm.put("r0", Collections.singleton("org.bar"));
-        rpm.put("r1", new HashSet<>(Arrays.asList("org.blah", "org.foo")));
-        rpm.put(WhitelistService.GLOBAL_REGION, Collections.singleton("org.bar.tar"));
-        rpm.put("r3", Collections.singleton("xyz"));
-
-        Map<String, Set<String>> frm = new HashMap<>();
-        frm.put("gid:aid:0.0.9",
-                new HashSet<>(Arrays.asList("r1", "r2", WhitelistService.GLOBAL_REGION)));
-        frm.put("gid2:aid2:1.0.0-SNAPSHOT", Collections.singleton("r2"));
-        frm.put("gid3:aid3:1.2.3", Collections.singleton("r3"));
-        frm.put("gid4:aid4:1.2.3", Collections.singleton("r3"));
-        frm.put("gid5:aid5:1.2.3", Collections.emptySet());
-
-        WhitelistService wls = new WhitelistServiceImpl(rpm, frm);
-        ResolverHookImpl rh = new ResolverHookImpl(st, wls);
-
-        // Check that we can get the capability from another bundle in the same region
-        // Bundle 7 is in feature f with regions r1, r2. Bundle 9 is in feature f2 with regions r2
-        BundleRequirement req = mockRequirement(7, "a.b.c", new Version(0,0,0));
-        BundleCapability bc1 = mockCapability("org.foo", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        List<BundleCapability> candidates = new ArrayList<>(Arrays.asList(bc1));
-        rh.filterMatches(req, candidates);
-        assertEquals(Collections.singletonList(bc1), candidates);
-
-        // Check that we cannot get the capability from another bundle in a different region
-        // Bundle 9 is in feature f2 with region r2
-        BundleRequirement req2 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        BundleCapability bc2 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
-        Collection<BundleCapability> c2 = new ArrayList<>(Arrays.asList(bc2));
-        rh.filterMatches(req2, c2);
-        assertEquals(0, c2.size());
-
-        // Check that we can get the capability from the same bundle
-        BundleRequirement req3 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        BundleCapability bc3 = mockCapability("org.bar", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        Collection<BundleCapability> c3 = new ArrayList<>(Arrays.asList(bc3));
-        rh.filterMatches(req3, c3);
-        assertEquals(Collections.singletonList(bc3), c3);
-
-        // Check that we can get the capability from the another bundle in the same feature
-        BundleRequirement req4 = mockRequirement(9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        BundleCapability bc4 = mockCapability("org.bar", 10, "a-bundle", new Version(1,0,0,"SNAPSHOT"));
-        Collection<BundleCapability> c4 = new ArrayList<>(Arrays.asList(bc4));
-        rh.filterMatches(req4, c4);
-        assertEquals(Collections.singletonList(bc4), c4);
-
-        // Check that we can get the capability from another bundle where the capability
-        // is globally visible (from bundle 9, f2)
-        BundleRequirement req5 = mockRequirement(17, "a.b.c", new Version(1,2,3));
-        BundleCapability bc5 = mockCapability("org.bar.tar", 9, "some.other.bundle", new Version(9,9,9,"suffix"));
-        Collection<BundleCapability> c5 = new ArrayList<>(Arrays.asList(bc5));
-        rh.filterMatches(req5, c5);
-        assertEquals(Collections.singletonList(bc5), c5);
-
-        // Check that we can get the capability from another bundle where the capability
-        // is globally visible (from bundle 7, f)
-        BundleRequirement req6 = mockRequirement(7, "a.b.c", new Version(0,0,0));
-        BundleCapability bc6 = mockCapability("org.bar.tar", 17, "a.b.c", new Version(1,2,3));
-        Collection<BundleCapability> c6 = new ArrayList<>(Arrays.asList(bc6));
-        rh.filterMatches(req6, c6);
-        assertEquals(Collections.singletonList(bc6), c6);
-
-        // Check that capabilities in non-package namespaces are ignored
-        BundleRequirement req7 = Mockito.mock(BundleRequirement.class);
-        Mockito.when(req7.getNamespace()).thenReturn("some.other.namespace");
-        BundleCapability bc7 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
-        Collection<BundleCapability> c7 = new ArrayList<>(Arrays.asList(bc7));
-        rh.filterMatches(req7, c7);
-        assertEquals(Collections.singletonList(bc7), c7);
-
-        // Check that we can get the capability from another provider in the same region
-        BundleRequirement req8 = mockRequirement(20, "zzz", new Version(1,0,0));
-        BundleCapability bc8 = mockCapability("xyz", 19, "x.y.z", new Version(9,9,9));
-        Collection<BundleCapability> c8 = new ArrayList<>(Arrays.asList(bc8));
-        rh.filterMatches(req8, c8);
-        assertEquals(Collections.singletonList(bc8), c8);
-
-        // A requirement from a bundle that has no feature cannot access one in a region
-        BundleRequirement req9 = mockRequirement(11, "qqq", new Version(6,6,6));
-        BundleCapability bc9 = mockCapability("org.bar", 17, "a.b.c", new Version(1,2,3));
-        ArrayList c9 = new ArrayList<>(Arrays.asList(bc9));
-        rh.filterMatches(req9, c9);
-        assertEquals(0, c9.size());
-
-        // A requirement from a bundle that has no feature can still access on in the global region
-        BundleRequirement req10 = mockRequirement(11, "qqq", new Version(6,6,6));
-        BundleCapability bc10 = mockCapability("org.bar.tar", 18, "z.z.z", new Version(3,2,1));
-        ArrayList c10 = new ArrayList<>(Arrays.asList(bc10));
-        rh.filterMatches(req10, c10);
-        assertEquals(Collections.singletonList(bc10), c10);
-
-        // A requirement from a bundle that has no feature can be satisfied by a capability
-        // from a bundle that has no feature
-        BundleRequirement req11 = mockRequirement(11, "qqq", new Version(6,6,6));
-        BundleCapability bc11 = mockCapability("org.bar.tar", 20, "www", new Version(1,0,0));
-        ArrayList c11 = new ArrayList<>(Arrays.asList(bc11));
-        rh.filterMatches(req11, c11);
-        assertEquals(Collections.singletonList(bc11), c11);
-
-        // A capability from the system bundle is always accessible
-        BundleRequirement req12 = mockRequirement(11, "qqq", new Version(6,6,6));
-        BundleCapability bc12 = mockCapability("ping.pong", 0, "system.bundle", new Version(3,2,1));
-        ArrayList c12 = new ArrayList<>(Arrays.asList(bc12));
-        rh.filterMatches(req12, c12);
-        assertEquals(Collections.singletonList(bc12), c12);
-        */
-    }
-
     @Test
     public void testFilterMatches() {
         Map<Entry<String, Version>, List<String>> bsnvermap = new HashMap<>();
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("system.bundle", new Version(3,2,1)),
+                Collections.singletonList("b0"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(0,0,0)),
                 Collections.singletonList("b7"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.bundle", new Version(1,0,0)),
@@ -195,6 +57,8 @@ public class ResolverHookImplTest {
                 Collections.singletonList("b10"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("not.in.a.feature", new Version(0,0,1)),
                 Collections.singletonList("b11"));
+        bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("also.not.in.a.feature", new Version(0,0,1)),
+                Collections.singletonList("b12"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("a.b.c", new Version(1,2,3)),
                 Collections.singletonList("b17"));
         bsnvermap.put(new AbstractMap.SimpleEntry<String,Version>("x.y.z", new Version(9,9,9)),
@@ -307,6 +171,21 @@ public class ResolverHookImplTest {
         Collection<BundleCapability> c10 = new ArrayList<>(Arrays.asList(bc10));
         rh.filterMatches(req10, c10);
         assertEquals(Collections.singletonList(bc10), c10);
+
+        // A requirement from a bundle that has no feature can be satisfied by a capability
+        // from a bundle that has no feature
+        BundleRequirement req11 = mockRequirement("b11", bsnvermap);
+        BundleCapability bc11 = mockCapability("ding.dong", "b12", bsnvermap);
+        Collection<BundleCapability> c11 = new ArrayList<>(Arrays.asList(bc11));
+        rh.filterMatches(req11, c11);
+        assertEquals(Collections.singletonList(bc11), c11);
+
+        // A capability from the system bundle is always accessible
+        BundleRequirement req12 = mockRequirement("b11", bsnvermap);
+        BundleCapability bc12 = mockCapability("ping.pong", "b0", bsnvermap);
+        Collection<BundleCapability> c12 = new ArrayList<>(Arrays.asList(bc12));
+        rh.filterMatches(req12, c12);
+        assertEquals(Collections.singletonList(bc12), c12);
     }
 
     private BundleCapability mockCapability(String pkgName, String bid, Map<Entry<String, Version>, List<String>> bsnvermap) {


[sling-org-apache-sling-feature-apiregions] 19/19: Add .gitignore

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 54aee7c2db176f64e9ba01034d8c253217f98752
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Nov 7 11:24:35 2018 +0000

    Add .gitignore
---
 .gitignore | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5b783ed
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,17 @@
+/target
+.idea
+.classpath
+.metadata
+.project
+.settings
+.externalToolBuilders
+maven-eclipse.xml
+*.swp
+*.iml
+*.ipr
+*.iws
+*.bak
+.vlt
+.DS_Store
+jcr.log
+atlassian-ide-plugin.xml


[sling-org-apache-sling-feature-apiregions] 02/19: Unit tests for the apiregions runtime component.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit dc20a7c0c476c689c51be10b2bcc76042b99cca9
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sat Nov 3 10:49:57 2018 +0000

    Unit tests for the apiregions runtime component.
---
 .../feature/apiregions/impl/RegionEnforcer.java    | 28 +++++----
 .../apiregions/impl/RegionEnforcerTest.java        | 73 ++++++++++++++++++++++
 src/test/resources/idbsnver1.properties            |  6 ++
 3 files changed, 94 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
index 26807ef..7a5c673 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/RegionEnforcer.java
@@ -40,15 +40,16 @@ import java.util.Properties;
 import java.util.Set;
 
 class RegionEnforcer implements ResolverHookFactory {
-    private static final String idbsnverFileName = "idbsnver.properties";
-    private static final String bundleFeatureFileName = "bundles.properties";
-    private static final String regionPackageFileName = "regions.properties";
-    private static final String featureRegionFileName = "features.properties";
+    static final String PROPERTIES_FILE_PREFIX = "whitelisting.";
+    static final String IDBSNVER_FILENAME = "idbsnver.properties";
+    static final String BUNDLE_FEATURE_FILENAME = "bundles.properties";
+    static final String REGION_PACKAGE_FILENAME = "regions.properties";
+    static final String FEATURE_REGION_FILENAME = "features.properties";
 
-    private final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
-    private final Map<String, Set<String>> bundleFeatureMap;
-    private final Map<String, Set<String>> featureRegionMap;
-    private final Map<String, Set<String>> regionPackageMap;
+    final Map<Map.Entry<String, Version>, List<String>> bsnVerMap;
+    final Map<String, Set<String>> bundleFeatureMap;
+    final Map<String, Set<String>> featureRegionMap;
+    final Map<String, Set<String>> regionPackageMap;
 
     public RegionEnforcer() throws IOException {
         bsnVerMap = populateBSNVerMap();
@@ -58,7 +59,7 @@ class RegionEnforcer implements ResolverHookFactory {
     }
 
     private Map<Map.Entry<String, Version>, List<String>> populateBSNVerMap() throws IOException {
-        File idbsnverFile = getDataFile(idbsnverFileName);
+        File idbsnverFile = getDataFile(IDBSNVER_FILENAME);
         if (idbsnverFile != null && idbsnverFile.exists()) {
             Map<Map.Entry<String, Version>, List<String>> m = new HashMap<>();
 
@@ -75,6 +76,7 @@ class RegionEnforcer implements ResolverHookFactory {
                     l = new ArrayList<>();
                     m.put(key, l);
                 }
+                l.add(n);
             }
 
             Map<Map.Entry<String, Version>, List<String>> m2 = new HashMap<>();
@@ -90,15 +92,15 @@ class RegionEnforcer implements ResolverHookFactory {
     }
 
     private Map<String, Set<String>> populateBundleFeatureMap() throws IOException {
-        return loadMap(bundleFeatureFileName);
+        return loadMap(BUNDLE_FEATURE_FILENAME);
     }
 
     private Map<String, Set<String>> populateFeatureRegionMap() throws IOException {
-        return loadMap(featureRegionFileName);
+        return loadMap(FEATURE_REGION_FILENAME);
     }
 
     private Map<String, Set<String>> populateRegionPackageMap() throws IOException {
-        return loadMap(regionPackageFileName);
+        return loadMap(REGION_PACKAGE_FILENAME);
     }
 
     private Map<String, Set<String>> loadMap(String fileName) throws IOException {
@@ -121,7 +123,7 @@ class RegionEnforcer implements ResolverHookFactory {
     }
 
     private File getDataFile(String name) throws IOException {
-        String fn = System.getProperty("whitelisting." + name);
+        String fn = System.getProperty(PROPERTIES_FILE_PREFIX + name);
         if (fn == null)
             return null;
         return new File(fn);
diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
new file mode 100644
index 0000000..419c0ea
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/RegionEnforcerTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Version;
+
+import java.util.AbstractMap;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Properties;
+
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.IDBSNVER_FILENAME;
+import static org.apache.sling.feature.apiregions.impl.RegionEnforcer.PROPERTIES_FILE_PREFIX;
+import static org.junit.Assert.assertEquals;
+
+public class RegionEnforcerTest {
+    private Properties savedProps;
+
+    @Before
+    public void setup() {
+        savedProps = new Properties(); // note that new Properties(props) doesn't copy
+        savedProps.putAll(System.getProperties());
+    }
+
+    @After
+    public void teardown() {
+        System.setProperties(savedProps);
+        savedProps = null;
+    }
+
+    @Test
+    public void testRegionEnforcerNoConfiguration() throws Exception {
+        RegionEnforcer re = new RegionEnforcer();
+        assertEquals(0, re.bsnVerMap.size());
+        assertEquals(0, re.bundleFeatureMap.size());
+        assertEquals(0, re.featureRegionMap.size());
+        assertEquals(0, re.regionPackageMap.size());
+    }
+
+    @Test
+    public void testLoadBSNVerMap() throws Exception {
+        String f = getClass().getResource("/idbsnver1.properties").getFile();
+        System.setProperty(PROPERTIES_FILE_PREFIX + IDBSNVER_FILENAME, f);
+
+        RegionEnforcer re = new RegionEnforcer();
+        assertEquals(2, re.bsnVerMap.size());
+        assertEquals(Collections.singletonList("g:b1:1"),
+                re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b1", new Version(1,0,0))));
+        assertEquals(new HashSet<>(Arrays.asList("g:b2:1.2.3", "g2:b2:1.2.4")),
+                new HashSet<>(re.bsnVerMap.get(new AbstractMap.SimpleEntry<String,Version>("b2", new Version(1,2,3)))));
+
+    }
+}
diff --git a/src/test/resources/idbsnver1.properties b/src/test/resources/idbsnver1.properties
new file mode 100644
index 0000000..00a740d
--- /dev/null
+++ b/src/test/resources/idbsnver1.properties
@@ -0,0 +1,6 @@
+#Generated at Sat Nov 03 10:26:37 GMT 2018
+#Sat Nov 03 10:26:37 GMT 2018
+g\:b2\:1.2.3=b2~1.2.3
+g\:b1\:1=b1~1.0.0
+g2\:b2\:1.2.4=b2~1.2.3
+


[sling-org-apache-sling-feature-apiregions] 10/19: Unit test for the extension bundle activator.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit 9e20ac1c3f374996557884c3c13956a209e7e2d9
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Sun Nov 4 20:48:45 2018 +0000

    Unit test for the extension bundle activator.
---
 .../feature/apiregions/impl/ActivatorTest.java     | 39 ++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
new file mode 100644
index 0000000..3577535
--- /dev/null
+++ b/src/test/java/org/apache/sling/feature/apiregions/impl/ActivatorTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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.feature.apiregions.impl;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
+
+public class ActivatorTest {
+    @Test
+    public void testStart() throws Exception {
+        BundleContext bc = Mockito.mock(BundleContext.class);
+
+        Activator a = new Activator();
+        a.start(bc);
+
+        Mockito.verify(bc, Mockito.times(1)).registerService(
+                Mockito.eq(ResolverHookFactory.class),
+                Mockito.isA(RegionEnforcer.class),
+                Mockito.isNull());
+    }
+}


[sling-org-apache-sling-feature-apiregions] 16/19: Reduce dependencies

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit c24c5a6150f61d9205067154c2e1a96b4596a6df
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 13:03:13 2018 +0000

    Reduce dependencies
---
 pom.xml | 41 -----------------------------------------
 1 file changed, 41 deletions(-)

diff --git a/pom.xml b/pom.xml
index 6f46e29..77f31d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,45 +64,10 @@
     </build>
     <dependencies>
         <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.feature.service</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.annotation.versioning</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>osgi.core</artifactId>
             <scope>provided</scope>
         </dependency>        
-        <dependency>
-            <groupId>org.osgi</groupId>
-            <artifactId>org.osgi.service.component.annotations</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-json_1.1_spec</artifactId>
-            <version>1.0</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.feature</artifactId>
-            <version>0.1.3-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.feature.launcher</artifactId>
-            <version>0.1.0-SNAPSHOT</version>
-            <scope>provided</scope>
-        </dependency>
-        
 
         <!-- Testing -->
         <dependency>
@@ -116,11 +81,5 @@
             <version>2.8.9</version>
             <scope>test</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.johnzon</groupId>
-            <artifactId>johnzon-core</artifactId>
-            <version>1.0.0</version>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 </project>


[sling-org-apache-sling-feature-apiregions] 15/19: Fix a small bug relating a capability coming from no feature.

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

davidb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature-apiregions.git

commit ce4c71fbf8953980dd08bc7c8a074b57509e8a46
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Mon Nov 5 16:35:38 2018 +0000

    Fix a small bug relating a capability coming from no feature.
---
 .../org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
index ae446cd..dc1d08d 100644
--- a/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
+++ b/src/main/java/org/apache/sling/feature/apiregions/impl/ResolverHookImpl.java
@@ -119,8 +119,11 @@ class ResolverHookImpl implements ResolverHook {
             Version capBundleVersion = capBundle.getVersion();
 
             List<String> capBundleArtifacts = bsnVerMap.get(new AbstractMap.SimpleEntry<String, Version>(capBundleName, capBundleVersion));
-            if (capBundleArtifacts == null)
-                return; // Capability is not in any feature, everyone can access
+            if (capBundleArtifacts == null) {
+                // Capability is not in any feature, everyone can access
+                coveredCaps.add(bc);
+                continue nextCapability;
+            }
 
             List<String> capFeatures = new ArrayList<>();
             for (String ba : capBundleArtifacts) {