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 2019/12/16 10:34:26 UTC

[sling-whiteboard] branch master updated: Add configuration to feature model API

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 3e211bc  Add configuration to feature model API
3e211bc is described below

commit 3e211bc40a4954e49a99503d08bafc8eaff2ad3d
Author: David Bosschaert <da...@gmail.com>
AuthorDate: Mon Dec 16 10:32:09 2019 +0000

    Add configuration to feature model API
---
 .../src/main/java/org/osgi/feature/Bundle.java     |  5 ++
 .../main/java/org/osgi/feature/Configuration.java  | 83 ++++++++++++++++++++++
 .../src/main/java/org/osgi/feature/Feature.java    | 23 ++++--
 3 files changed, 107 insertions(+), 4 deletions(-)

diff --git a/osgi-featuremodel/src/main/java/org/osgi/feature/Bundle.java b/osgi-featuremodel/src/main/java/org/osgi/feature/Bundle.java
index b045466..7657590 100644
--- a/osgi-featuremodel/src/main/java/org/osgi/feature/Bundle.java
+++ b/osgi-featuremodel/src/main/java/org/osgi/feature/Bundle.java
@@ -65,6 +65,11 @@ public class Bundle {
             this.version = version;
         }
 
+        public Builder addMetadata(String key, String value) {
+            this.metadata.put(key, value);
+            return this;
+        }
+
         public Builder addMetadata(Map<String,String> md) {
             this.metadata.putAll(md);
             return this;
diff --git a/osgi-featuremodel/src/main/java/org/osgi/feature/Configuration.java b/osgi-featuremodel/src/main/java/org/osgi/feature/Configuration.java
new file mode 100644
index 0000000..f0f749e
--- /dev/null
+++ b/osgi-featuremodel/src/main/java/org/osgi/feature/Configuration.java
@@ -0,0 +1,83 @@
+/*
+ * 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.osgi.feature;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Configuration {
+    private final String pid;
+    private final String factoryPid;
+    private final Map<String, Object> values;
+
+    private Configuration(String pid, String factoryPid,
+            Map<String, Object> values) {
+        this.pid = pid;
+        this.factoryPid = factoryPid;
+        this.values = Collections.unmodifiableMap(values);
+    }
+
+    public String getPid() {
+        return pid;
+    }
+
+    public String getFactoryPid() {
+        return factoryPid;
+    }
+
+    public Map<String, Object> getValues() {
+        return values;
+    }
+
+    public class Builder {
+        private final String p;
+        private final String name;
+
+        private final Map<String,Object> values = new HashMap<>();
+
+        public Builder(String pid) {
+            this.p = pid;
+            this.name = null;
+        }
+
+        public Builder(String factoryPid, String name) {
+            this.p = factoryPid;
+            this.name = null;
+        }
+
+        public Builder addConfiguration(String key, Object value) {
+            // TODO can do some validation on the configuration
+            this.values.put(key, value);
+            return this;
+        }
+
+        public Builder addConfiguration(Map<String, Object> cfg) {
+            // TODO can do some validation on the configuration
+            this.values.putAll(cfg);
+            return this;
+        }
+
+        public Configuration build() {
+            if (name == null) {
+                return new Configuration(p, null, values);
+            } else {
+                return new Configuration(p, p + "~" + name, values);
+            }
+        }
+    }
+}
diff --git a/osgi-featuremodel/src/main/java/org/osgi/feature/Feature.java b/osgi-featuremodel/src/main/java/org/osgi/feature/Feature.java
index 2455b2b..f0d4a2f 100644
--- a/osgi-featuremodel/src/main/java/org/osgi/feature/Feature.java
+++ b/osgi-featuremodel/src/main/java/org/osgi/feature/Feature.java
@@ -39,10 +39,11 @@ public class Feature {
     private final boolean isFinal;
 
     private final List<Bundle> bundles;
+    private final List<Configuration> configurations;
     private final Map<String, String> variables;
 
     private Feature(String gid, String aid, Version ver, String aTitle, String desc, String vnd, String lic, String loc,
-            boolean comp, boolean fin, List<Bundle> bs, Map<String,String> vars) {
+            boolean comp, boolean fin, List<Bundle> bs, List<Configuration> cs, Map<String,String> vars) {
         groupId = gid;
         artifactId = aid;
         version = ver;
@@ -55,13 +56,12 @@ public class Feature {
         isFinal = fin;
 
         bundles = Collections.unmodifiableList(bs);
+        configurations = Collections.unmodifiableList(cs);
         variables = Collections.unmodifiableMap(vars);
 
         // add prototype
         // add requirements
         // add capabilities
-        // add bundles
-        // add configurations
         // add framework properties
     }
 
@@ -109,6 +109,10 @@ public class Feature {
         return bundles;
     }
 
+    public List<Configuration> getConfigurations() {
+        return configurations;
+    }
+
     public Map<String, String> getVariables() {
         return variables;
     }
@@ -128,6 +132,7 @@ public class Feature {
         private boolean isFinal;
 
         private final List<Bundle> bundles = new ArrayList<>();
+        private final List<Configuration> configurations = new ArrayList<>();
         private final Map<String,String> variables = new HashMap<>();
 
         public Builder(String groupId, String artifactId, Version version) {
@@ -176,6 +181,16 @@ public class Feature {
             return this;
         }
 
+        public Builder addConfigurations(Configuration ... configs) {
+            this.configurations.addAll(Arrays.asList(configs));
+            return this;
+        }
+
+        public Builder addVariable(String key, String value) {
+            this.variables.put(key, value);
+            return this;
+        }
+
         public Builder addVariables(Map<String, String> variables) {
             this.variables.putAll(variables);
             return this;
@@ -184,7 +199,7 @@ public class Feature {
         public Feature build() {
             return new Feature(groupId, artifactId, version, title,
                     description, vendor, license, location, complete, isFinal,
-                    bundles, variables);
+                    bundles, configurations, variables);
         }
     }
 }