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 40bccf5  Reboot Features Service
40bccf5 is described below

commit 40bccf55249193b0143119941cec767a77e095cc
Author: David Bosschaert <[email protected]>
AuthorDate: Fri Oct 5 11:55:17 2018 +0100

    Reboot Features Service
    
    Also introduce a Bundles Service interface that can map bundles given
    their BSN and Version to a Feature Model Artifact ID.
---
 featuremodel/feature-service/pom.xml               | 62 +++++++++++++++++++-
 .../service/{impl/Activator.java => Bundles.java}  | 28 ++++-----
 .../sling/feature/service/FeaturesFactory.java     | 41 --------------
 .../service/impl/FeaturesServiceFactoryImpl.java   | 59 -------------------
 .../feature/service/impl/FeaturesServiceImpl.java  | 28 ++++++---
 .../service/impl/FeatureServiceImplTest.java       | 18 +-----
 .../impl/FeaturesServiceFactoryImplTest.java       | 66 ----------------------
 7 files changed, 94 insertions(+), 208 deletions(-)

diff --git a/featuremodel/feature-service/pom.xml 
b/featuremodel/feature-service/pom.xml
index 52089ef..80ca9ab 100644
--- a/featuremodel/feature-service/pom.xml
+++ b/featuremodel/feature-service/pom.xml
@@ -23,7 +23,7 @@
 
     <artifactId>org.apache.sling.feature.service</artifactId>
     <version>0.0.1-SNAPSHOT</version>
-    <packaging>bundle</packaging>
+    <packaging>jar</packaging>
 
     <name>Apache Sling Feature Runtime Service</name>
     <description>
@@ -37,6 +37,34 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+                    </archive>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>biz.aQute.bnd</groupId>
+                <artifactId>bnd-maven-plugin</artifactId>
+                <version>4.0.0</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>bnd-process</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <bnd><![CDATA[
+                        -exportcontents: ${packages;VERSIONED}
+                        -removeheaders: Private-Package,Include-Resource
+                    ]]></bnd>
+                </configuration>
+            </plugin>
+            <!-- 
+            <plugin>
                 <groupId>org.apache.felix</groupId>
                 <artifactId>maven-bundle-plugin</artifactId>
                 <extensions>true</extensions>
@@ -46,16 +74,18 @@
                         
<Fragment-Host>system.bundle;extension:=framework</Fragment-Host>
                     </instructions>
                 
-                    <!--  Skip baselining for 0.x version -->
+                    <!- -  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>
+                        
<exclude>src/main/resources/META-INF/services/*</exclude>
                     </excludes>
                 </configuration>
             </plugin>
@@ -71,7 +101,33 @@
             <groupId>org.osgi</groupId>
             <artifactId>osgi.core</artifactId>
             <scope>provided</scope>
-        </dependency>        
+        </dependency>     
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.inventory</artifactId>
+            <version>1.0.6</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>
diff --git 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/Activator.java
 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java
similarity index 59%
rename from 
featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/Activator.java
rename to 
featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java
index 46bc3ed..017b32b 100644
--- 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/Activator.java
+++ 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/Bundles.java
@@ -16,20 +16,20 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.sling.feature.service.impl;
+package org.apache.sling.feature.service;
 
-import org.apache.sling.feature.service.FeaturesFactory;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
 
-public class Activator implements BundleActivator {
-    @Override
-    public void start(BundleContext context) throws Exception {
-        FeaturesServiceFactoryImpl ff = new 
FeaturesServiceFactoryImpl(context);
-        context.registerService(FeaturesFactory.class, ff, null);
-    }
-
-    @Override
-    public void stop(BundleContext context) throws Exception {
-    }
+/**
+ * This Service can provide information about bundles in the feature model.
+ */
+public interface Bundles {
+    /**
+     * Obtain the Artifact ID for a given bundle, identified by its
+     * Symbolic Name and version.
+     * @param bsn The symbolic name of the bundle.
+     * @param ver The version of the bundle.
+     * @return The artifact ID.
+     */
+    String getBundleArtifact(String bsn, Version ver);
 }
diff --git 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeaturesFactory.java
 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeaturesFactory.java
deleted file mode 100644
index 2bd7c9d..0000000
--- 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/FeaturesFactory.java
+++ /dev/null
@@ -1,41 +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.service;
-
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Service to initialize the {@link Features} service.
- */
-public interface FeaturesFactory {
-    /**
-     * Initialize the Features service. The implementation of this
-     * factory service will register a {@link Features} service
-     * based on the mapping provided.
-     * @param bundleFeatureMapping A mapping from a bundle to the features
-     * that this bundle belongs to. If a bundle is not part of a feature
-     * this must be represented by a {@code null} value in the set.
-     * Bundles are listed using the {@code symbolic-name:version} syntax.
-     * Features are described using the maven ID syntax:
-     * {@code groupID:artifactID:type:classifier:version} where
-     * type and classifier are optional.
-     */
-    void initialize(Map<String, Set<String>> bundleFeatureMapping);
-}
diff --git 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImpl.java
 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImpl.java
deleted file mode 100644
index 7ea17c3..0000000
--- 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImpl.java
+++ /dev/null
@@ -1,59 +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.service.impl;
-
-import org.apache.sling.feature.service.Features;
-import org.apache.sling.feature.service.FeaturesFactory;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-
-import java.util.AbstractMap;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.Set;
-
-class FeaturesServiceFactoryImpl implements FeaturesFactory {
-    private final BundleContext bundleContext;
-
-    FeaturesServiceFactoryImpl(BundleContext context) {
-        bundleContext = context;
-    }
-
-    @Override
-    public void initialize(Map<String, Set<String>> bfm) {
-        Map<Map.Entry<String, Version>, Set<String>> bundleFeatureMapping = 
new HashMap<>();
-
-        for (Map.Entry<String, Set<String>> entry : bfm.entrySet()) {
-            String[] bv = entry.getKey().split(":");
-            if (bv.length == 2) {
-                try {
-                    Map.Entry<String, Version> k = new 
AbstractMap.SimpleEntry<String, Version>(
-                            bv[0], Version.parseVersion(bv[1]));
-                    bundleFeatureMapping.put(k, entry.getValue());
-                } catch (IllegalArgumentException iae) {
-                    // TODO log
-                }
-            }
-        }
-
-        Features fs = new FeaturesServiceImpl(bundleFeatureMapping);
-        bundleContext.registerService(Features.class, fs, new 
Hashtable<>(bfm));
-    }
-}
diff --git 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java
 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java
index 5ec7146..2230f01 100644
--- 
a/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java
+++ 
b/featuremodel/feature-service/src/main/java/org/apache/sling/feature/service/impl/FeaturesServiceImpl.java
@@ -18,23 +18,33 @@
  */
 package org.apache.sling.feature.service.impl;
 
+import org.apache.felix.inventory.InventoryPrinter;
 import org.apache.sling.feature.service.Features;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.Version;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 
-import java.util.AbstractMap;
-import java.util.Collections;
-import java.util.Map;
 import java.util.Set;
 
-class FeaturesServiceImpl implements Features {
-    private final Map<Map.Entry<String, Version>, Set<String>> 
bundleFeatureMap;
+@Component(immediate = true)
+public class FeaturesServiceImpl implements Features {
 
-    FeaturesServiceImpl(Map<Map.Entry<String, Version>, Set<String>> 
bundleIDFeatures) {
-        bundleFeatureMap = Collections.unmodifiableMap(bundleIDFeatures);
+    @Reference(target="(" + InventoryPrinter.NAME + "=launch.features)")
+    InventoryPrinter printer;
+
+    public FeaturesServiceImpl() {
+        // TODO Auto-generated constructor stub
+    }
+
+    @Activate
+    public void activate(BundleContext bc) {
+        System.out.println("*** Features Service Activated: " + bc);
     }
 
     @Override
-    public Set<String> getFeaturesForBundle(String bsn, Version version) {
-        return bundleFeatureMap.get(new AbstractMap.SimpleEntry<String, 
Version>(bsn, version));
+    public Set<String> getFeaturesForBundle(String bsn, Version ver) {
+        return null; // TODO
     }
 }
diff --git 
a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
 
b/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
index ba35fcc..97dc81d 100644
--- 
a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
+++ 
b/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeatureServiceImplTest.java
@@ -18,23 +18,8 @@
  */
 package org.apache.sling.feature.service.impl;
 
-import org.apache.sling.feature.service.Features;
-import org.junit.Test;
-import org.osgi.framework.Version;
-
-import java.util.AbstractMap;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
 public class FeatureServiceImplTest {
+    /*
     @Test
     public void testFeatureService() {
         Map<Entry<String, Version>, Set<String>> bif = new HashMap<>();
@@ -57,4 +42,5 @@ public class FeatureServiceImplTest {
         assertEquals(Collections.singleton(f2), 
fs.getFeaturesForBundle("mybsn", new Version(7,8,9)));
         assertNull(fs.getFeaturesForBundle("mybsn2", new Version(1,2,3)));
     }
+    */
 }
diff --git 
a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImplTest.java
 
b/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImplTest.java
deleted file mode 100644
index e7c809b..0000000
--- 
a/featuremodel/feature-service/src/test/java/org/apache/sling/feature/service/impl/FeaturesServiceFactoryImplTest.java
+++ /dev/null
@@ -1,66 +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.service.impl;
-
-import org.apache.sling.feature.service.Features;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Version;
-
-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.assertNull;
-
-public class FeaturesServiceFactoryImplTest {
-    @SuppressWarnings("unchecked")
-    @Test
-    public void testInitialize() {
-        List<Object> featuresService = new ArrayList<Object>();
-
-        BundleContext bc = Mockito.mock(BundleContext.class);
-        Mockito.when(bc.registerService(Mockito.isA(Class.class), 
Mockito.isA(Object.class), Mockito.isA(Dictionary.class)))
-            .then(i -> { featuresService.add(i.getArgument(1)); return null; 
});
-
-        FeaturesServiceFactoryImpl fsf = new FeaturesServiceFactoryImpl(bc);
-
-        Map<String, Set<String>> bfm = new HashMap<>();
-        bfm.put("foo:123", Collections.singleton("g:a:f1"));
-        bfm.put("bar:1.2.3", Collections.singleton(null));
-        bfm.put("incomplete", Collections.singleton("g:a:f1"));
-        bfm.put("tar:0.0.0", new HashSet<>(Arrays.asList("g:a:f1", null, 
"g:a:f2")));
-        fsf.initialize(bfm);
-
-        Features features = (Features) featuresService.get(0);
-        assertEquals(Collections.singleton("g:a:f1"), 
features.getFeaturesForBundle("foo", new Version(123,0,0)));
-        assertEquals(Collections.singleton(null), 
features.getFeaturesForBundle("bar", new Version(1,2,3)));
-        assertEquals(new HashSet<>(Arrays.asList(null, "g:a:f1", "g:a:f2")),
-                features.getFeaturesForBundle("tar", new Version(0,0,0)));
-        assertNull(features.getFeaturesForBundle("incomplete", new 
Version(0,0,0)));
-    }
-}

Reply via email to