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/01 12:36:01 UTC
[sling-whiteboard] branch master updated: Configuration type
conversion
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 f4e9538 Configuration type conversion
f4e9538 is described below
commit f4e95389391a41308980730647ac62982ebc117a
Author: David Bosschaert <da...@apache.org>
AuthorDate: Thu Jul 1 13:35:49 2021 +0100
Configuration type conversion
---
osgi-featuremodel/pom.xml | 213 +++++++++++----------
.../feature/osgi/impl/ExtensionBuilderImpl.java | 2 +-
.../feature/osgi/impl/FeatureServiceImpl.java | 41 ++--
.../feature/osgi/impl/FeatureServiceImplTest.java | 35 +++-
.../src/test/resources/features/test-feature.json | 2 +-
5 files changed, 155 insertions(+), 138 deletions(-)
diff --git a/osgi-featuremodel/pom.xml b/osgi-featuremodel/pom.xml
index 9418ad8..f083bba 100644
--- a/osgi-featuremodel/pom.xml
+++ b/osgi-featuremodel/pom.xml
@@ -1,116 +1,119 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
- <!--
- 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
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- 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.
- -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>35</version>
+ <relativePath />
+ </parent>
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.sling</groupId>
- <artifactId>sling</artifactId>
- <version>35</version>
- <relativePath />
- </parent>
+ <artifactId>org.apache.sling.feature.osgi</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <packaging>jar</packaging>
- <artifactId>org.apache.sling.feature.osgi</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>jar</packaging>
+ <name>OSGi Feature Model API</name>
- <name>OSGi Feature Model API</name>
+ <properties>
+ <sling.java.version>11</sling.java.version>
+ </properties>
- <properties>
- <sling.java.version>11</sling.java.version>
- </properties>
-
- <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.3.1</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.rat</groupId>
- <artifactId>apache-rat-plugin</artifactId>
- <configuration>
- <excludes>
- <exclude>*.md</exclude>
- <exclude>src/main/resources/META-INF/services/*</exclude>
- </excludes>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.annotation</artifactId>
- <version>8.0.0</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
- <version>8.0.0</version>
- <scope>provided</scope>
- </dependency>
+ <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.3.1</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.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>*.md</exclude>
+ <exclude>src/main/resources/META-INF/services/*</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ <version>8.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <version>8.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.function</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-json_1.1_spec</artifactId>
+ <version>1.3</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.converter</artifactId>
+ <version>1.0.18</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
- <groupId>org.apache.geronimo.specs</groupId>
- <artifactId>geronimo-json_1.1_spec</artifactId>
- <version>1.3</version>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.cm.json</artifactId>
+ <version>1.0.6</version>
<scope>provided</scope>
</dependency>
- <!-- Testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.8.9</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.johnzon</groupId>
- <artifactId>johnzon-core</artifactId>
- <version>1.2.2</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.8.9</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-core</artifactId>
+ <version>1.2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
</project>
diff --git a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ExtensionBuilderImpl.java b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ExtensionBuilderImpl.java
index 6cd972b..b3c63a1 100644
--- a/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ExtensionBuilderImpl.java
+++ b/osgi-featuremodel/src/main/java/org/apache/sling/feature/osgi/impl/ExtensionBuilderImpl.java
@@ -154,7 +154,7 @@ class ExtensionBuilderImpl implements FeatureExtensionBuilder {
for (String s : content) {
res.add(FEATURE_SERVICE.getBuilderFactory().newArtifactBuilder(
- FEATURE_SERVICE.getIDfromMavenID(s)).build());
+ FEATURE_SERVICE.getIDfromMavenCoordinates(s)).build());
}
return res;
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 7f8b3ec..3ae3a91 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
@@ -38,6 +38,7 @@ import javax.json.JsonWriterFactory;
import javax.json.stream.JsonGenerator;
import javax.json.stream.JsonGeneratorFactory;
+import org.apache.felix.cm.json.impl.TypeConverter;
import org.osgi.service.feature.BuilderFactory;
import org.osgi.service.feature.Feature;
import org.osgi.service.feature.FeatureBuilder;
@@ -58,7 +59,7 @@ public class FeatureServiceImpl implements FeatureService {
}
@Override
- public ID getIDfromMavenID(String mavenID) {
+ public ID getIDfromMavenCoordinates(String mavenID) {
return IDImpl.fromMavenID(mavenID);
}
@@ -81,10 +82,9 @@ public class FeatureServiceImpl implements FeatureService {
JsonObject json = Json.createReader(jsonReader).readObject();
String id = json.getString("id");
- FeatureBuilder builder = builderFactory.newFeatureBuilder(getIDfromMavenID(id));
+ FeatureBuilder builder = builderFactory.newFeatureBuilder(getIDfromMavenCoordinates(id));
builder.setName(json.getString("name", null));
-// builder.setCopyright(json.getString("copyright", null));
builder.setDescription(json.getString("description", null));
builder.setDocURL(json.getString("docURL", null));
builder.setLicense(json.getString("license", null));
@@ -112,7 +112,7 @@ public class FeatureServiceImpl implements FeatureService {
if (val.getValueType() == JsonValue.ValueType.OBJECT) {
JsonObject jo = val.asJsonObject();
String bid = jo.getString("id");
- FeatureBundleBuilder builder = builderFactory.newBundleBuilder(getIDfromMavenID(bid));
+ FeatureBundleBuilder builder = builderFactory.newBundleBuilder(getIDfromMavenCoordinates(bid));
for (Map.Entry<String, JsonValue> entry : jo.entrySet()) {
if (entry.getKey().equals("id"))
@@ -175,28 +175,17 @@ public class FeatureServiceImpl implements FeatureService {
JsonObject values = entry.getValue().asJsonObject();
for (Map.Entry<String, JsonValue> value : values.entrySet()) {
+ String key = value.getKey();
+ String typeInfo = null;
+ int cidx = key.indexOf(':');
+ if (cidx > 0) {
+ typeInfo = key.substring(cidx + 1);
+ key = key.substring(0, cidx);
+ }
+
JsonValue val = value.getValue();
-
- Object v;
- switch (val.getValueType()) {
- case TRUE:
- v = true;
- break;
- case FALSE:
- v = false;
- break;
- case NUMBER:
- v = ((JsonNumber) val).longValueExact();
- break;
- case STRING:
- v = ((JsonString) val).getString();
- break;
- default:
- v = val.toString();
-
- // TODO object types, arrays, and requested type conversions
- }
- builder.addValue(value.getKey(), v);
+ Object v = TypeConverter.convertObjectToType(val, typeInfo);
+ builder.addValue(key, v);
}
configs.add(builder.build());
}
@@ -237,7 +226,7 @@ public class FeatureServiceImpl implements FeatureService {
for (JsonValue jv : ja2) {
if (jv.getValueType() == JsonValue.ValueType.STRING) {
String id = ((JsonString) jv).getString();
- builder.addArtifact(getIDfromMavenID(id));
+ builder.addArtifact(getIDfromMavenCoordinates(id));
}
}
break;
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 3fd4174..28b59f3 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
@@ -17,7 +17,7 @@
package org.apache.sling.feature.osgi.impl;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
@@ -26,7 +26,9 @@ import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URL;
+import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import javax.json.Json;
import javax.json.JsonObject;
@@ -38,6 +40,7 @@ import org.osgi.service.feature.BuilderFactory;
import org.osgi.service.feature.Feature;
import org.osgi.service.feature.FeatureBuilder;
import org.osgi.service.feature.FeatureBundle;
+import org.osgi.service.feature.FeatureConfiguration;
public class FeatureServiceImplTest {
FeatureServiceImpl features;
@@ -72,6 +75,25 @@ public class FeatureServiceImplTest {
assertTrue(bundles.contains(bundle));
assertTrue(bundles.contains(bf.newBundleBuilder(features.getID("org.slf4j", "slf4j-api", "1.7.29")).build()));
assertTrue(bundles.contains(bf.newBundleBuilder(features.getID("org.slf4j", "slf4j-simple", "1.7.29")).build()));
+
+ Map<String, FeatureConfiguration> configs = f.getConfigurations();
+ assertEquals(2, configs.size());
+
+ FeatureConfiguration cfg1 = configs.get("my.pid");
+ assertEquals("my.pid", cfg1.getPid());
+ assertFalse(cfg1.getFactoryPid().isPresent());
+ Map<String, Object> values1 = cfg1.getValues();
+ assertEquals(3, values1.size());
+ assertEquals(Long.valueOf(5), values1.get("foo"));
+ assertEquals("test", values1.get("bar"));
+ assertEquals(Integer.valueOf(7), values1.get("number"));
+
+ FeatureConfiguration cfg2 = configs.get("my.factory.pid~name");
+ assertEquals("my.factory.pid~name", cfg2.getPid());
+ assertEquals("my.factory.pid", cfg2.getFactoryPid().get());
+ Map<String, Object> values2 = cfg2.getValues();
+ assertEquals(1, values2.size());
+ assertArrayEquals(new String[] {"yeah", "yeah", "yeah"}, (String[]) values2.get("a.value"));
}
}
@@ -97,6 +119,9 @@ public class FeatureServiceImplTest {
assertEquals("The ACME app", fo.getString("name"));
assertEquals(desc, fo.getString("description"));
assertFalse(fo.containsKey("docURL"));
+ assertFalse(fo.containsKey("license"));
+ assertFalse(fo.containsKey("scm"));
+ assertFalse(fo.containsKey("vendor"));
}
@Test
@@ -110,20 +135,20 @@ public class FeatureServiceImplTest {
builder.setComplete(true);
FeatureBundle b1 = factory.newBundleBuilder(
- features.getIDfromMavenID("org.osgi:org.osgi.util.function:1.1.0"))
+ features.getIDfromMavenCoordinates("org.osgi:org.osgi.util.function:1.1.0"))
.build();
FeatureBundle b2 = factory.newBundleBuilder(
- features.getIDfromMavenID("org.osgi:org.osgi.util.promise:1.1.1"))
+ features.getIDfromMavenCoordinates("org.osgi:org.osgi.util.promise:1.1.1"))
.build();
FeatureBundle b3 = factory.newBundleBuilder(
- features.getIDfromMavenID("org.apache.commons:commons-email:1.1.5"))
+ features.getIDfromMavenCoordinates("org.apache.commons:commons-email:1.1.5"))
.addMetadata("org.acme.javadoc.link",
"https://commons.apache.org/proper/commons-email/javadocs/api-1.5")
.build();
FeatureBundle b4 = factory.newBundleBuilder(
- features.getIDfromMavenID("com.acme:acmelib:1.7.2"))
+ features.getIDfromMavenCoordinates("com.acme:acmelib:1.7.2"))
.build();
builder.addBundles(b1, b2, b3, b4);
diff --git a/osgi-featuremodel/src/test/resources/features/test-feature.json b/osgi-featuremodel/src/test/resources/features/test-feature.json
index 378b3ca..323fb79 100644
--- a/osgi-featuremodel/src/test/resources/features/test-feature.json
+++ b/osgi-featuremodel/src/test/resources/features/test-feature.json
@@ -22,7 +22,7 @@
"number:Integer" : 7
},
"my.factory.pid~name" : {
- "a.value" : "yeah"
+ "a.value" : ["yeah", "yeah", "yeah"]
}
}
}
\ No newline at end of file