You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by st...@apache.org on 2021/08/26 15:56:10 UTC
[felix-dev] branch master updated: [Features] Register Feature
Service
This is an automated email from the ASF dual-hosted git repository.
stbischof pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new ee485b0 [Features] Register Feature Service
new a54097b Merge pull request #92 from bosschaert/features_reg_svc
ee485b0 is described below
commit ee485b0fd25c13bf9bff91586eafe89d159a780b
Author: David Bosschaert <da...@apache.org>
AuthorDate: Thu Aug 26 16:40:35 2021 +0100
[Features] Register Feature Service
Also make it available to ServiceLoader
---
features/pom.xml | 7 ++++-
.../org/apache/felix/feature/impl/Activator.java | 34 ++++++++++++++++++++++
.../org.osgi.service.feature.FeatureService | 1 +
.../felix/feature/impl/FeatureServiceImplTest.java | 13 ++++++---
4 files changed, 50 insertions(+), 5 deletions(-)
diff --git a/features/pom.xml b/features/pom.xml
index cd4f4d6..f86e491 100644
--- a/features/pom.xml
+++ b/features/pom.xml
@@ -28,7 +28,7 @@
<name>OSGi Feature Model API</name>
<properties>
- <felix.java.version>11</felix.java.version>
+ <felix.java.version>8</felix.java.version>
</properties>
<repositories>
@@ -50,6 +50,11 @@
<goals>
<goal>bnd-process</goal>
</goals>
+ <configuration>
+ <bnd><![CDATA[
+ Bundle-Activator: org.apache.felix.feature.impl.Activator
+ ]]></bnd>
+ </configuration>
</execution>
</executions>
</plugin>
diff --git a/features/src/main/java/org/apache/felix/feature/impl/Activator.java b/features/src/main/java/org/apache/felix/feature/impl/Activator.java
new file mode 100644
index 0000000..87beb08
--- /dev/null
+++ b/features/src/main/java/org/apache/felix/feature/impl/Activator.java
@@ -0,0 +1,34 @@
+/*
+ * 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.felix.feature.impl;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.feature.FeatureService;
+
+public class Activator implements BundleActivator {
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ context.registerService(FeatureService.class, new FeatureServiceImpl(), null);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ // Nothing to do here, service is automatically unregistered
+ }
+}
diff --git a/features/src/main/resources/META-INF/services/org.osgi.service.feature.FeatureService b/features/src/main/resources/META-INF/services/org.osgi.service.feature.FeatureService
new file mode 100644
index 0000000..c92d7aa
--- /dev/null
+++ b/features/src/main/resources/META-INF/services/org.osgi.service.feature.FeatureService
@@ -0,0 +1 @@
+org.apache.felix.feature.impl.FeatureServiceImpl
diff --git a/features/src/test/java/org/apache/felix/feature/impl/FeatureServiceImplTest.java b/features/src/test/java/org/apache/felix/feature/impl/FeatureServiceImplTest.java
index e2e2927..fb3a0a6 100644
--- a/features/src/test/java/org/apache/felix/feature/impl/FeatureServiceImplTest.java
+++ b/features/src/test/java/org/apache/felix/feature/impl/FeatureServiceImplTest.java
@@ -29,8 +29,10 @@ import java.io.StringReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.net.URL;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import java.util.Scanner;
import javax.json.Json;
import javax.json.JsonObject;
@@ -65,7 +67,7 @@ public class FeatureServiceImplTest {
try (Reader r = new InputStreamReader(res.openStream())) {
f = features.readFeature(r);
- assertTrue(f.getName().isEmpty());
+ assertTrue(!f.getName().isPresent());
assertEquals("The feature description", f.getDescription().get());
assertFalse(f.getDocURL().isPresent());
assertFalse(f.getLicense().isPresent());
@@ -132,7 +134,7 @@ public class FeatureServiceImplTest {
assertEquals("org.apache.sling:test-feature2:osgifeature:cls_abc:1.1", f.getID().toString());
assertEquals("test-feature2", f.getName().get());
assertEquals("The feature description", f.getDescription().get());
- assertEquals(List.of("foo", "bar"), f.getCategories());
+ assertEquals(Arrays.asList("foo", "bar"), f.getCategories());
assertEquals("http://foo.bar.com/abc", f.getDocURL().get());
assertEquals("Apache-2.0; link=\"http://opensource.org/licenses/apache2.0.php\"", f.getLicense().get());
assertEquals("url=https://github.com/apache/sling-aggregator, connection=scm:git:https://github.com/apache/sling-aggregator.git, developerConnection=scm:git:git@github.com:apache/sling-aggregator.git",
@@ -180,7 +182,7 @@ public class FeatureServiceImplTest {
FeatureExtension textEx = extensions.get("my-text-ex");
assertEquals(FeatureExtension.Kind.OPTIONAL, textEx.getKind());
assertEquals(FeatureExtension.Type.TEXT, textEx.getType());
- assertEquals(List.of("ABC", "DEF"), textEx.getText());
+ assertEquals(Arrays.asList("ABC", "DEF"), textEx.getText());
FeatureExtension artEx = extensions.get("my-art-ex");
assertEquals(FeatureExtension.Kind.MANDATORY, artEx.getKind());
@@ -210,7 +212,10 @@ public class FeatureServiceImplTest {
StringWriter sw = new StringWriter();
features.writeFeature(feature, sw);
- String expected = new String(expectedURL.openStream().readAllBytes()).replaceAll("\\s","");
+ Scanner s = new Scanner(expectedURL.openStream()).useDelimiter("\\A");
+ String expected = s.hasNext() ? s.next() : "";
+ expected = expected.replaceAll("\\s","");
+
String actual = sw.toString().replaceAll("\\s","");
assertEquals(expected, actual);
}