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 2021/07/02 15:37:29 UTC
[sling-whiteboard] branch master updated: [Feature writing] support
bundles and configs
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 472c3ae [Feature writing] support bundles and configs
472c3ae is described below
commit 472c3aef902c1247a79dbfb66e186a47e3ad7c66
Author: David Bosschaert <da...@apache.org>
AuthorDate: Fri Jul 2 16:36:55 2021 +0100
[Feature writing] support bundles and configs
---
.../feature/osgi/impl/ArtifactBuilderImpl.java | 4 +-
.../sling/feature/osgi/impl/BundleBuilderImpl.java | 4 +-
.../osgi/impl/ConfigurationBuilderImpl.java | 10 ++---
.../feature/osgi/impl/FeatureServiceImpl.java | 50 +++++++++++++++++++++-
.../feature/osgi/impl/FeatureServiceImplTest.java | 18 +++++---
5 files changed, 70 insertions(+), 16 deletions(-)
diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ArtifactBuilderImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ArtifactBuilderImpl.java
index a294e11..7b1952e 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ArtifactBuilderImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ArtifactBuilderImpl.java
@@ -17,7 +17,7 @@
package org.apache.sling.feature.osgi.impl;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@@ -28,7 +28,7 @@ import org.osgi.service.feature.ID;
class ArtifactBuilderImpl implements FeatureArtifactBuilder {
private final ID id;
- private final Map<String,Object> metadata = new HashMap<>();
+ private final Map<String,Object> metadata = new LinkedHashMap<>();
ArtifactBuilderImpl(ID id) {
this.id = id;
diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/BundleBuilderImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/BundleBuilderImpl.java
index 1d39e59..2f67d59 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/BundleBuilderImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/BundleBuilderImpl.java
@@ -17,7 +17,7 @@
package org.apache.sling.feature.osgi.impl;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
@@ -28,7 +28,7 @@ import org.osgi.service.feature.ID;
class BundleBuilderImpl implements FeatureBundleBuilder {
private final ID id;
- private final Map<String,Object> metadata = new HashMap<>();
+ private final Map<String,Object> metadata = new LinkedHashMap<>();
BundleBuilderImpl(ID id) {
this.id = id;
diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ConfigurationBuilderImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ConfigurationBuilderImpl.java
index f11d0cf..c82a137 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ConfigurationBuilderImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ConfigurationBuilderImpl.java
@@ -16,20 +16,20 @@
*/
package org.apache.sling.feature.osgi.impl;
-import org.osgi.service.feature.FeatureConfiguration;
-import org.osgi.service.feature.FeatureConfigurationBuilder;
-
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
+import org.osgi.service.feature.FeatureConfiguration;
+import org.osgi.service.feature.FeatureConfigurationBuilder;
+
class ConfigurationBuilderImpl implements FeatureConfigurationBuilder {
private final String p;
private final String name;
- private final Map<String,Object> values = new HashMap<>();
+ private final Map<String,Object> values = new LinkedHashMap<>();
ConfigurationBuilderImpl(String pid) {
this.p = pid;
diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
index 34c428b..68f72d9 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/FeatureServiceImpl.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import javax.json.Json;
import javax.json.JsonArray;
@@ -297,13 +298,21 @@ public class FeatureServiceImpl implements FeatureService {
JsonObjectBuilder json = Json.createObjectBuilder(attrs);
+ JsonArray bundles = getBundles(feature);
+ if (bundles != null) {
+ json.add("bundles", bundles);
+ }
+
+ JsonObject configs = getConfigurations(feature);
+ if (configs != null) {
+ json.add("configurations", configs);
+ }
+
JsonObject extensions = getExtensions(feature);
if (extensions != null) {
json.add("extensions", extensions);
}
- // TODO add bundles
- // TODO add configs
// TODO add variables
// TODO add frameworkproperties
@@ -315,6 +324,43 @@ public class FeatureServiceImpl implements FeatureService {
}
}
+ private JsonArray getBundles(Feature feature) {
+ List<FeatureBundle> bundles = feature.getBundles();
+ if (bundles == null || bundles.size() == 0)
+ return null;
+
+ JsonArrayBuilder ab = Json.createArrayBuilder();
+
+ for (FeatureBundle bundle : bundles) {
+ Map<String, Object> attrs = new LinkedHashMap<>();
+ attrs.put("id", bundle.getID().toString());
+ attrs.putAll(bundle.getMetadata());
+ ab.add(Json.createObjectBuilder(attrs));
+ }
+
+ return ab.build();
+ }
+
+ private JsonObject getConfigurations(Feature feature) {
+ Map<String, FeatureConfiguration> configs = feature.getConfigurations();
+ if (configs == null || configs.size() == 0)
+ return null;
+
+ JsonObjectBuilder ob = Json.createObjectBuilder();
+
+ for (Map.Entry<String,FeatureConfiguration> cfg : configs.entrySet()) {
+ JsonObjectBuilder cb = Json.createObjectBuilder();
+
+ for (Map.Entry<String,Object> prop : cfg.getValue().getValues().entrySet()) {
+ Map.Entry<String, JsonValue> je = TypeConverter.convertObjectToTypedJsonValue(prop.getValue());
+ String tk = je.getKey();
+ cb.add(TypeConverter.NO_TYPE_INFO.equals(tk) ? prop.getKey() : prop.getKey() + ":" + tk, je.getValue());
+ }
+ ob.add(cfg.getKey(), cb.build());
+ }
+ return ob.build();
+ }
+
private JsonObject getExtensions(Feature feature) {
Map<String, FeatureExtension> extensions = feature.getExtensions();
if (extensions == null || extensions.size() == 0)
diff --git a/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java b/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
index 2568081..bb97870 100644
--- a/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
+++ b/osgi-featuremodel/src/test/java/org/apache/sling/feature/osgi/impl/FeatureServiceImplTest.java
@@ -58,8 +58,10 @@ public class FeatureServiceImplTest {
BuilderFactory bf = features.getBuilderFactory();
URL res = getClass().getResource("/features/test-feature.json");
+
+ Feature f;
try (Reader r = new InputStreamReader(res.openStream())) {
- Feature f = features.readFeature(r);
+ f = features.readFeature(r);
assertTrue(f.getName().isEmpty());
assertEquals("The feature description", f.getDescription().get());
@@ -102,6 +104,8 @@ public class FeatureServiceImplTest {
assertEquals(1, values2.size());
assertArrayEquals(new String[] {"yeah", "yeah", "yeah"}, (String[]) values2.get("a.value"));
}
+
+ testWriteFeature(f, res);
}
@Test
@@ -184,13 +188,17 @@ public class FeatureServiceImplTest {
assertEquals("{\"foo\":[1,2,3]}", jsonEx.getJSON());
}
- StringWriter sw = new StringWriter();
- features.writeFeature(f, sw);
+ testWriteFeature(f, res);
+ }
+
+ private void testWriteFeature(Feature feature, URL expectedURL) throws IOException {
+ StringWriter sw = new StringWriter();
+ features.writeFeature(feature, sw);
- String expected = new String(res.openStream().readAllBytes()).replaceAll("\\s","");
+ String expected = new String(expectedURL.openStream().readAllBytes()).replaceAll("\\s","");
String actual = sw.toString().replaceAll("\\s","");
assertEquals(expected, actual);
- }
+ }
@Test
public void testCreateFeatureBundle() {