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-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new ec97c38  SLING-7779 API Region support for the Sling Feature Model
ec97c38 is described below

commit ec97c38af113151067aef5c14aa63df750586117
Author: David Bosschaert <[email protected]>
AuthorDate: Fri Nov 2 16:45:21 2018 +0000

    SLING-7779 API Region support for the Sling Feature Model
    
    Refactored the feature-whitelist runtime component to be a framework
    extension. Initial commit, tests to come.
---
 featuremodel/feature-whitelist/pom.xml             |   2 -
 .../sling/feature/whitelist/WhitelistService.java  |  43 -----
 .../feature/whitelist/WhitelistServiceFactory.java |  26 ---
 .../sling/feature/whitelist/impl/Activator.java    |  25 +--
 .../feature/whitelist/impl/RegionEnforcer.java     | 134 +++++++++++++++
 .../feature/whitelist/impl/ResolverHookImpl.java   | 183 ++++++++++-----------
 .../feature/whitelist/impl/WhitelistEnforcer.java  |  46 ------
 .../impl/WhitelistServiceFactoryImpl.java          |  57 -------
 .../whitelist/impl/WhitelistServiceImpl.java       | 183 ---------------------
 .../sling/feature/whitelist/package-info.java      |  23 ---
 .../impl/WhitelistServiceFactoryImplTest.java      |  23 +--
 11 files changed, 230 insertions(+), 515 deletions(-)

diff --git a/featuremodel/feature-whitelist/pom.xml 
b/featuremodel/feature-whitelist/pom.xml
index 23c37a9..3d1daed 100644
--- a/featuremodel/feature-whitelist/pom.xml
+++ b/featuremodel/feature-whitelist/pom.xml
@@ -41,12 +41,10 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
                 <configuration>
-                    <!-- 
                     <instructions>
                         
<ExtensionBundle-Activator>org.apache.sling.feature.whitelist.impl.Activator</ExtensionBundle-Activator>
                         
<Fragment-Host>system.bundle;extension:=framework</Fragment-Host>
                     </instructions>
-                     -->
                 
                     <!--  Skip baselining for 0.x version -->
                     <skip>true</skip>
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistService.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistService.java
deleted file mode 100644
index 62e782c..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistService.java
+++ /dev/null
@@ -1,43 +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.whitelist;
-
-import java.util.Set;
-
-public interface WhitelistService {
-    final static String GLOBAL_REGION = "global";
-
-    /**
-     * List the regions that a given feature is part of
-     * @param feature The feature ID in mvn syntax.
-     * @return A set of regions or {@code null} if the feature is no known.
-     */
-    Set<String> listRegions(String feature);
-
-    Set<String> listPackages(String region);
-
-//    /**
-//     * Returns whether a package is whitelisted for the given region.
-//     * @param region The region
-//     * @param packageName The package
-//     * @return Returns whether the package is whitelisted for the region.
-//     * If the region is not known {@code null} is returned.
-//     */
-//    Boolean regionWhitelistsPackage(String region, String packageName);
-}
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistServiceFactory.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistServiceFactory.java
deleted file mode 100644
index 50f0193..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/WhitelistServiceFactory.java
+++ /dev/null
@@ -1,26 +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.whitelist;
-
-import java.util.Map;
-import java.util.Set;
-
-public interface WhitelistServiceFactory {
-    void initialize(Map<String, Map<String,Set<String>>> mappings);
-}
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/Activator.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/Activator.java
index 3767370..5fc9381 100644
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/Activator.java
+++ 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/Activator.java
@@ -18,37 +18,18 @@
  */
 package org.apache.sling.feature.whitelist.impl;
 
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.whitelist.WhitelistServiceFactory;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.hooks.resolver.ResolverHookFactory;
 
 public class Activator implements BundleActivator {
-    private ServiceTracker<Features, Features> tracker;
-    private ServiceRegistration<?> resolverHookServiceRegistration;
-
     @Override
     public synchronized void start(BundleContext context) throws Exception {
-        tracker = new ServiceTracker<>(context, Features.class, null);
-        tracker.open();
-
-        WhitelistServiceFactory wsf = new WhitelistServiceFactoryImpl(context, 
tracker);
-        context.registerService(WhitelistServiceFactory.class, wsf, null);
-        /*
-        WhitelistEnforcer enforcer = new WhitelistEnforcer(context, tracker);
-        Dictionary<String, Object> resHookProps = new Hashtable<>();
-        resHookProps.put(Constants.SERVICE_PID, 
WhitelistEnforcer.class.getName());
-        resolverHookServiceRegistration = context.registerService(
-                new String[] {ManagedService.class.getName(), 
ResolverHookFactory.class.getName()},
-                enforcer, resHookProps);
-                */
+        RegionEnforcer enforcer = new RegionEnforcer();
+        context.registerService(ResolverHookFactory.class, enforcer, null);
     }
 
     @Override
     public synchronized void stop(BundleContext context) throws Exception {
-        resolverHookServiceRegistration.unregister();
-        tracker.close();
     }
 }
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/RegionEnforcer.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/RegionEnforcer.java
new file mode 100644
index 0000000..30d5f91
--- /dev/null
+++ 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/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.whitelist.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/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
index fbc2425..a039156 100644
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
+++ 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/ResolverHookImpl.java
@@ -18,10 +18,6 @@
  */
 package org.apache.sling.feature.whitelist.impl;
 
-import org.apache.sling.feature.ArtifactId;
-import org.apache.sling.feature.launcher.service.Bundles;
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.whitelist.WhitelistService;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.Version;
 import org.osgi.framework.hooks.resolver.ResolverHook;
@@ -29,31 +25,33 @@ 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 org.osgi.service.component.annotations.Reference;
-import org.osgi.util.tracker.ServiceTracker;
 
+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 long SERVICE_WAIT_TIMEOUT = 60000;
-
-    private final ServiceTracker<Features, Features> featureServiceTracker;
-    private final WhitelistService whitelistService;
-
-    @Reference
-    Bundles bundleService;
-
-    @Reference
-    Features featuresService;
-
-    public ResolverHookImpl(ServiceTracker<Features, Features> tracker,
-            WhitelistService wls) {
-        featureServiceTracker = tracker;
-        whitelistService = wls;
+    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
@@ -78,105 +76,106 @@ class ResolverHookImpl implements ResolverHook {
         String reqBundleName = reqBundle.getSymbolicName();
         Version reqBundleVersion = reqBundle.getVersion();
 
-        try {
-            Features fs = 
featureServiceTracker.waitForService(SERVICE_WAIT_TIMEOUT);
+        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);
+        }
 
-            // The Feature Service could not be found, skip candidate pruning
-            if (fs == null) {
-                WhitelistEnforcer.LOG.warning("Could not obtain the feature 
service, no whitelist enforcement");
-                return;
+        Set<String> regions = new HashSet<>();
+        for (String feature : reqFeatures) {
+            Set<String> fr = featureRegionMap.get(feature);
+            if (fr != null) {
+                regions.addAll(fr);
             }
+        }
 
-            String reqBundleArtifact = 
bundleService.getBundleArtifact(reqBundleName, reqBundleVersion.toString());
-            String reqFeatureArtifact = 
featuresService.getBundleOrigin(ArtifactId.fromMvnId(reqBundleArtifact));
-            Set<String> reqFeatures = 
Collections.singleton(reqFeatureArtifact); // TODO multiple features?
-            Set<String> regions;
-            if (reqFeatures == null) {
-                regions = Collections.emptySet();
-                reqFeatures = Collections.emptySet();
-            } else {
-                regions = new HashSet<>();
-                for (String feature : reqFeatures) {
-                    regions.addAll(whitelistService.listRegions(feature));
-                }
+        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;
             }
 
-            Set<BundleCapability> coveredCaps = new HashSet<>();
+            if (capBundleID == reqBundleID) {
+                // always allow capability from same bundle
+                coveredCaps.add(bc);
+                continue nextCapability;
+            }
 
-            nextCapability:
-            for (BundleCapability bc : candidates) {
-                BundleRevision rev = bc.getRevision();
+            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);
+            }
 
-                Bundle capBundle = rev.getBundle();
-                long capBundleID = capBundle.getBundleId();
-                if (capBundleID == 0) {
-                    // always allow capability from the system bundle
+            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 (capBundleID == reqBundleID) {
-                    // always allow capability from same bundle
+                if (reqFeatures.contains(capFeat)) {
+                    // Within a single feature everything can wire to 
everything else
                     coveredCaps.add(bc);
                     continue nextCapability;
                 }
 
-                String capBundleName = capBundle.getSymbolicName();
-                Version capBundleVersion = capBundle.getVersion();
-
-                String capBundleArtifact = 
bundleService.getBundleArtifact(capBundleName, capBundleVersion.toString());
-                String capFeatureArtifact = 
featuresService.getBundleOrigin(ArtifactId.fromMvnId(capBundleArtifact));
-                Set<String> capFeatures = 
Collections.singleton(capFeatureArtifact); // TODO multiple features?
-                if (capFeatures == null || capFeatures.isEmpty())
-                    capFeatures = Collections.singleton(null);
-
-                for (String capFeat : capFeatures) {
-                    if (capFeat == null) {
-                        // always allow capability not coming from a feature
-                        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;
+                }
 
-                    if (reqFeatures.contains(capFeat)) {
-                        // Within a single feature everything can wire to 
everything else
-                        coveredCaps.add(bc);
-                        continue nextCapability;
-                    }
+                Object pkg = 
bc.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
+                if (pkg instanceof String) {
+                    String packageName = (String) pkg;
 
-                    if (whitelistService.listRegions(capFeat) == null) {
-                        // If the feature hosting the capability has no 
regions defined, everyone can access
+                    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;
                     }
 
-                    Object pkg = 
bc.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE);
-                    if (pkg instanceof String) {
-                        String packageName = (String) pkg;
-
-                        if 
(whitelistService.listPackages(WhitelistService.GLOBAL_REGION).contains(packageName))
 {
-                            // If the export is in the global region everyone 
can access
+                    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;
                         }
-
-                        for (String region : regions) {
-                            if 
(whitelistService.listPackages(region).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)) {
-                WhitelistEnforcer.LOG.log(Level.INFO,
-                        "Removed one ore more candidates for requirement {0} 
as they are not in the correct region", requirement);
-            }
-        } catch (InterruptedException e) {
-            // ignore
+        // 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);
         }
     }
 
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistEnforcer.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistEnforcer.java
deleted file mode 100644
index e12038d..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistEnforcer.java
+++ /dev/null
@@ -1,46 +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.whitelist.impl;
-
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.whitelist.WhitelistService;
-import org.osgi.framework.hooks.resolver.ResolverHook;
-import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-import org.osgi.framework.wiring.BundleRevision;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Collection;
-import java.util.logging.Logger;
-
-class WhitelistEnforcer implements ResolverHookFactory {
-    static final Logger LOG = 
Logger.getLogger(WhitelistEnforcer.class.getName());
-
-    final ServiceTracker<Features, Features> featureServiceTracker;
-    final WhitelistService whitelistService;
-
-    WhitelistEnforcer(WhitelistService wls, ServiceTracker<Features, Features> 
tracker) {
-        whitelistService = wls;
-        featureServiceTracker = tracker;
-    }
-
-    @Override
-    public ResolverHook begin(Collection<BundleRevision> triggers) {
-        return new ResolverHookImpl(featureServiceTracker, whitelistService);
-    }
-}
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImpl.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImpl.java
deleted file mode 100644
index fc9eb6e..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImpl.java
+++ /dev/null
@@ -1,57 +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.whitelist.impl;
-
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.whitelist.WhitelistService;
-import org.apache.sling.feature.whitelist.WhitelistServiceFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-public class WhitelistServiceFactoryImpl implements WhitelistServiceFactory {
-    private final BundleContext bundleContext;
-    private final ServiceTracker<Features, Features> featuresServiceTracker;
-
-    WhitelistServiceFactoryImpl(BundleContext context,
-            ServiceTracker<Features, Features> tracker) {
-        bundleContext = context;
-        featuresServiceTracker = tracker;
-    }
-
-    @Override
-    public void initialize(Map<String, Map<String, Set<String>>> mappings) {
-        Map<String, Set<String>> packages = mappings.get("packages");
-        Map<String, Set<String>> regions = mappings.get("regions");
-
-        WhitelistService wls = createWhitelistService(packages, regions);
-        WhitelistEnforcer enforcer = new WhitelistEnforcer(wls, 
featuresServiceTracker);
-        Hashtable<String, Set<String>> props = new Hashtable<>(packages);
-        props.putAll(regions);
-        bundleContext.registerService(ResolverHookFactory.class, enforcer, 
props);
-    }
-
-    WhitelistService createWhitelistService(Map<String, Set<String>> packages, 
Map<String, Set<String>> regions) {
-        return null; // new WhitelistServiceImpl(packages, regions);
-    }
-}
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceImpl.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceImpl.java
deleted file mode 100644
index 24ac5ce..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceImpl.java
+++ /dev/null
@@ -1,183 +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.whitelist.impl;
-
-import org.apache.sling.feature.Extension;
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.whitelist.WhitelistService;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-
-import java.io.StringReader;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.json.Json;
-import javax.json.JsonArray;
-import javax.json.JsonObject;
-import javax.json.JsonReader;
-import javax.json.JsonString;
-import javax.json.JsonValue;
-
-@Component(immediate=true)
-class WhitelistServiceImpl implements WhitelistService {
-
-    @Reference
-    Features featuresService;
-
-    final Map<String, Set<String>> featureRegions = new ConcurrentHashMap<>();
-    final Map<String, Set<String>> regionPackages = new ConcurrentHashMap<>();
-
-
-    @Activate
-    public void activate() {
-        Map<String, Set<String>> frMap = new HashMap<>();
-        Map<String, Set<String>> rpMap = new HashMap<>();
-
-        for (Extension ex : 
featuresService.getCurrentFeature().getExtensions()) {
-            if (!"api-region".equals(ex.getName()))
-                continue;
-
-            JsonReader reader = Json.createReader(new 
StringReader(ex.getJSON()));
-            JsonArray ja = reader.readArray();
-            for (JsonValue jv : ja) {
-                if (jv instanceof JsonObject) {
-                    JsonObject jo = (JsonObject) jv;
-                    String name = jo.getString("name");
-                    String feature = jo.getString("org-feature");
-
-                    Set<String> regions = frMap.get(feature);
-                    if (regions == null) {
-                        regions = new HashSet<>();
-                        frMap.put(feature, regions);
-                    }
-                    regions.add(name);
-
-                    Set<String> packages = rpMap.get(name);
-                    if (packages == null) {
-                        packages = new HashSet<>();
-                        rpMap.put(name, packages);
-                    }
-
-                    JsonArray xja = jo.getJsonArray("exports");
-                    for (JsonValue ev : xja) {
-                        if (ev instanceof JsonString) {
-                            JsonString js = (JsonString) ev;
-                            packages.add(js.getString());
-                        }
-                    }
-                }
-            }
-        }
-
-        // Store in fields as immutable sets
-        featureRegions.clear();
-        for (Map.Entry<String, Set<String>> entry : frMap.entrySet()) {
-            featureRegions.put(entry.getKey(), 
Collections.unmodifiableSet(entry.getValue()));
-        }
-
-        regionPackages.clear();
-        for (Map.Entry<String, Set<String>> entry : rpMap.entrySet()) {
-            regionPackages.put(entry.getKey(), 
Collections.unmodifiableSet(entry.getValue()));
-        }
-    }
-
-
-    @Override
-    public Set<String> listRegions(String feature) {
-        Set<String> regions = featureRegions.get(feature);
-        if (regions == null)
-            return Collections.emptySet();
-        else
-            return regions;
-    }
-
-
-    @Override
-    public Set<String> listPackages(String region) {
-        Map<String, Set<String>> packages = regionPackages;
-        if (packages == null)
-            return Collections.emptySet();
-        else
-            return packages.get(region);
-    }
-
-
-
-//    @Override
-//    public Boolean regionWhitelistsPackage(String region, String 
packageName) {
-//        // TODO Auto-generated method stub
-//        return null;
-//    }
-    /*
-    final Map<String, Set<String>> featureRegionMapping;
-    final Map<String, Set<String>> regionPackageMapping;
-
-    WhitelistServiceImpl(Map<String, Set<String>> regionPackages,
-            Map<String, Set<String>> featureRegions) {
-        Set<String> allRegions = new HashSet<>();
-
-        Map<String, Set<String>> frm = new HashMap<>();
-        for (Map.Entry<String, Set<String>> entry : featureRegions.entrySet()) 
{
-            Set<String> regions = Collections.unmodifiableSet(new 
HashSet<>(entry.getValue()));
-            allRegions.addAll(regions);
-            frm.put(entry.getKey(), regions);
-        }
-        featureRegionMapping = Collections.unmodifiableMap(frm);
-
-        Map<String, Set<String>> rpm = new HashMap<>();
-        for (Map.Entry<String, Set<String>> entry : regionPackages.entrySet()) 
{
-            String region = entry.getKey();
-            rpm.put(region,
-                    Collections.unmodifiableSet(new 
HashSet<>(entry.getValue())));
-            allRegions.remove(region);
-        }
-
-        // If there are more regions mentioned but these don't have any package
-        // mappings, give them an empty mapping
-        for (String region : allRegions) {
-            rpm.put(region, Collections.emptySet());
-        }
-        regionPackageMapping = Collections.unmodifiableMap(rpm);
-    }
-
-    @Override
-    public Set<String> listRegions(String featureID) {
-        if (featureID == null)
-            return null;
-
-        return featureRegionMapping.get(featureID);
-    }
-
-    @Override
-    public Boolean regionWhitelistsPackage(String region, String packageName) {
-        Set<String> packages = regionPackageMapping.get(region);
-
-        if (packages == null)
-            return null;
-
-        return packages.contains(packageName);
-    }
-    */
-}
diff --git 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/package-info.java
 
b/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/package-info.java
deleted file mode 100644
index dedd3c2..0000000
--- 
a/featuremodel/feature-whitelist/src/main/java/org/apache/sling/feature/whitelist/package-info.java
+++ /dev/null
@@ -1,23 +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.
- */
-
[email protected]("0.1.0")
-package org.apache.sling.feature.whitelist;
-
-
diff --git 
a/featuremodel/feature-whitelist/src/test/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImplTest.java
 
b/featuremodel/feature-whitelist/src/test/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImplTest.java
index e53cbc4..988f485 100644
--- 
a/featuremodel/feature-whitelist/src/test/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImplTest.java
+++ 
b/featuremodel/feature-whitelist/src/test/java/org/apache/sling/feature/whitelist/impl/WhitelistServiceFactoryImplTest.java
@@ -18,28 +18,8 @@
  */
 package org.apache.sling.feature.whitelist.impl;
 
-import org.apache.sling.feature.whitelist.WhitelistService;
-import org.apache.sling.feature.whitelist.WhitelistServiceFactory;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.hooks.resolver.ResolverHookFactory;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
 public class WhitelistServiceFactoryImplTest {
+    /*
     @SuppressWarnings({ "rawtypes", "unchecked" })
     @Test
     public void testWhitelistServiceFactory() {
@@ -80,4 +60,5 @@ public class WhitelistServiceFactoryImplTest {
         ResolverHookFactory rhf = resolverHookFactory.get(0);
         assertTrue(rhf instanceof WhitelistEnforcer);
     }
+    */
 }

Reply via email to