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 2020/04/14 12:50:14 UTC
[sling-whiteboard] branch master updated: Move to a Util structure
for OSGi Feature Model
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 e51f1c7 Move to a Util structure for OSGi Feature Model
e51f1c7 is described below
commit e51f1c763b976916e82575b0c53bad269070e81c
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Tue Apr 14 13:49:59 2020 +0100
Move to a Util structure for OSGi Feature Model
---
.../{FeatureService.java => Features.java} | 24 ++++++++++++----
.../util/features/impl/FeatureServiceImpl.java | 13 +++------
.../util/features/impl/FeatureServiceImplTest.java | 32 +++++++++-------------
3 files changed, 35 insertions(+), 34 deletions(-)
diff --git a/osgi-featuremodel/src/main/java/org/osgi/util/features/FeatureService.java b/osgi-featuremodel/src/main/java/org/osgi/util/features/Features.java
similarity index 69%
rename from osgi-featuremodel/src/main/java/org/osgi/util/features/FeatureService.java
rename to osgi-featuremodel/src/main/java/org/osgi/util/features/Features.java
index aa4baf4..7c43470 100644
--- a/osgi-featuremodel/src/main/java/org/osgi/util/features/FeatureService.java
+++ b/osgi-featuremodel/src/main/java/org/osgi/util/features/Features.java
@@ -16,20 +16,26 @@
*/
package org.osgi.util.features;
+import org.osgi.util.features.impl.FeatureServiceImpl;
+
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
/**
- * The Feature Service is the primary entry point for interacting with the feature model.
+ * The Features class is the primary entry point for interacting with the feature model.
* @ThreadSafe
*/
-public interface FeatureService {
+public class Features {
+ private static final FeatureServiceImpl IMPL = new FeatureServiceImpl();
+
/**
* Get a factory which can be used to build feature model entities.
* @return A builder factory.
*/
- BuilderFactory getBuilderFactory();
+ public static BuilderFactory getBuilderFactory() {
+ return IMPL.getBuilderFactory();
+ }
/**
* Read a Feature from JSON
@@ -37,7 +43,9 @@ public interface FeatureService {
* @return The Feature represented by the JSON
* @throws IOException When reading fails
*/
- Feature readFeature(Reader jsonReader) throws IOException;
+ public static Feature readFeature(Reader jsonReader) throws IOException {
+ return IMPL.readFeature(jsonReader);
+ }
/**
* Write a Feature Model to JSON
@@ -45,7 +53,9 @@ public interface FeatureService {
* @param jsonWriter A Writer to which the Feature should be written.
* @throws IOException When writing fails.
*/
- void writeFeature(Feature feature, Writer jsonWriter) throws IOException;
+ public static void writeFeature(Feature feature, Writer jsonWriter) throws IOException {
+ IMPL.writeFeature(feature, jsonWriter);
+ }
/**
* Merge two features into a new feature.
@@ -55,5 +65,7 @@ public interface FeatureService {
* @param ctx The merge context to use for the merge operation.
* @return The merged feature.
*/
- Feature mergeFeatures(ID targetID, Feature f1, Feature f2, MergeContext ctx);
+ public static Feature mergeFeatures(ID targetID, Feature f1, Feature f2, MergeContext ctx) {
+ return IMPL.mergeFeatures(targetID, f1, f2, ctx);
+ }
}
diff --git a/osgi-featuremodel/src/main/java/org/osgi/util/features/impl/FeatureServiceImpl.java b/osgi-featuremodel/src/main/java/org/osgi/util/features/impl/FeatureServiceImpl.java
index c93dc74..8aa6b48 100644
--- a/osgi-featuremodel/src/main/java/org/osgi/util/features/impl/FeatureServiceImpl.java
+++ b/osgi-featuremodel/src/main/java/org/osgi/util/features/impl/FeatureServiceImpl.java
@@ -16,17 +16,16 @@
*/
package org.osgi.util.features.impl;
-import org.osgi.util.features.ID;
import org.osgi.util.features.BuilderFactory;
+import org.osgi.util.features.Feature;
+import org.osgi.util.features.FeatureBuilder;
import org.osgi.util.features.FeatureBundle;
import org.osgi.util.features.FeatureBundleBuilder;
import org.osgi.util.features.FeatureConfiguration;
import org.osgi.util.features.FeatureConfigurationBuilder;
import org.osgi.util.features.FeatureExtension;
import org.osgi.util.features.FeatureExtensionBuilder;
-import org.osgi.util.features.Feature;
-import org.osgi.util.features.FeatureBuilder;
-import org.osgi.util.features.FeatureService;
+import org.osgi.util.features.ID;
import org.osgi.util.features.MergeContext;
import java.io.IOException;
@@ -45,15 +44,13 @@ import javax.json.JsonObject;
import javax.json.JsonString;
import javax.json.JsonValue;
-class FeatureServiceImpl implements FeatureService {
+public class FeatureServiceImpl { //implements FeatureService {
private final BuilderFactoryImpl builderFactory = new BuilderFactoryImpl();
- @Override
public BuilderFactory getBuilderFactory() {
return builderFactory;
}
- @Override
public Feature readFeature(Reader jsonReader) throws IOException {
JsonObject json = Json.createReader(jsonReader).readObject();
@@ -217,13 +214,11 @@ class FeatureServiceImpl implements FeatureService {
return extensions.toArray(new FeatureExtension[] {});
}
- @Override
public void writeFeature(Feature feature, Writer jsonWriter) throws IOException {
// TODO Auto-generated method stub
}
- @Override
public Feature mergeFeatures(ID targetID, Feature f1, Feature f2, MergeContext ctx) {
FeatureBuilder fb = builderFactory.newFeatureBuilder(targetID);
diff --git a/osgi-featuremodel/src/test/java/org/osgi/util/features/impl/FeatureServiceImplTest.java b/osgi-featuremodel/src/test/java/org/osgi/util/features/impl/FeatureServiceImplTest.java
index a868111..14fcf05 100644
--- a/osgi-featuremodel/src/test/java/org/osgi/util/features/impl/FeatureServiceImplTest.java
+++ b/osgi-featuremodel/src/test/java/org/osgi/util/features/impl/FeatureServiceImplTest.java
@@ -17,17 +17,14 @@
package org.osgi.util.features.impl;
import org.junit.Test;
-import org.osgi.util.features.ID;
import org.osgi.util.features.BuilderFactory;
+import org.osgi.util.features.Feature;
import org.osgi.util.features.FeatureBundle;
import org.osgi.util.features.FeatureConfiguration;
import org.osgi.util.features.FeatureExtension;
-import org.osgi.util.features.Feature;
-import org.osgi.util.features.FeatureService;
+import org.osgi.util.features.Features;
+import org.osgi.util.features.ID;
import org.osgi.util.features.MergeContext;
-import org.osgi.util.features.impl.ConfigurationBuilderImpl;
-import org.osgi.util.features.impl.ExtensionBuilderImpl;
-import org.osgi.util.features.impl.FeatureServiceImpl;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -46,12 +43,11 @@ import static org.junit.Assert.assertTrue;
public class FeatureServiceImplTest {
@Test
public void testReadFeature() throws IOException {
- FeatureService fs = new FeatureServiceImpl();
- BuilderFactory bf = fs.getBuilderFactory();
+ BuilderFactory bf = Features.getBuilderFactory();
URL res = getClass().getResource("/features/test-feature.json");
try (Reader r = new InputStreamReader(res.openStream())) {
- Feature f = fs.readFeature(r);
+ Feature f = Features.readFeature(r);
assertNull(f.getTitle());
assertEquals("The feature description", f.getDescription());
@@ -75,19 +71,18 @@ public class FeatureServiceImplTest {
@Test
public void testMergeFeatures() throws IOException {
- FeatureService fs = new FeatureServiceImpl();
- BuilderFactory bf = fs.getBuilderFactory();
+ BuilderFactory bf = Features.getBuilderFactory();
URL res1 = getClass().getResource("/features/test-feature.json");
Feature f1;
try (Reader r = new InputStreamReader(res1.openStream())) {
- f1 = fs.readFeature(r);
+ f1 = Features.readFeature(r);
}
URL res2 = getClass().getResource("/features/test-feature2.json");
Feature f2;
try (Reader r = new InputStreamReader(res2.openStream())) {
- f2 = fs.readFeature(r);
+ f2 = Features.readFeature(r);
}
MergeContext ctx = bf.newMergeContextBuilder()
@@ -98,7 +93,7 @@ public class FeatureServiceImplTest {
ID tid = new ID("foo", "bar", "1.2.3");
- Feature f3 = fs.mergeFeatures(tid, f1, f2, ctx);
+ Feature f3 = Features.mergeFeatures(tid, f1, f2, ctx);
assertEquals(tid, f3.getID());
List<FeatureBundle> bundles = f3.getBundles();
@@ -128,19 +123,18 @@ public class FeatureServiceImplTest {
@Test
public void testMergeExtensions() throws IOException {
- FeatureService fs = new FeatureServiceImpl();
- BuilderFactory bf = fs.getBuilderFactory();
+ BuilderFactory bf = Features.getBuilderFactory();
URL res1 = getClass().getResource("/features/test-exfeat1.json");
Feature f1;
try (Reader r = new InputStreamReader(res1.openStream())) {
- f1 = fs.readFeature(r);
+ f1 = Features.readFeature(r);
}
URL res2 = getClass().getResource("/features/test-exfeat2.json");
Feature f2;
try (Reader r = new InputStreamReader(res2.openStream())) {
- f2 = fs.readFeature(r);
+ f2 = Features.readFeature(r);
}
MergeContext ctx = bf.newMergeContextBuilder()
@@ -152,7 +146,7 @@ public class FeatureServiceImplTest {
.build();
ID tid = new ID("g", "a", "1.2.3");
- Feature f3 = fs.mergeFeatures(tid, f1, f2, ctx);
+ Feature f3 = Features.mergeFeatures(tid, f1, f2, ctx);
Map<String, FeatureExtension> extensions = f3.getExtensions();
assertEquals(3, extensions.size());