sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [sling-org-apache-sling-feature] 13/22: Support the slinstart maven plugin by providing a model converter API
Date Fri, 27 Apr 2018 09:51:33 GMT
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-org-apache-sling-feature.git

commit 6c70fe7bca7663dd5a2cf0c523761e9a6c90f577
Author: David Bosschaert <david.bosschaert@gmail.com>
AuthorDate: Fri Mar 9 10:46:10 2018 +0000

    Support the slinstart maven plugin by providing a model converter API
---
 .../java/org/apache/sling/feature/KeyValueMap.java | 23 ++++++++++++++++++----
 .../sling/feature/process/ApplicationBuilder.java  | 21 +++++++++++++-------
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/KeyValueMap.java b/src/main/java/org/apache/sling/feature/KeyValueMap.java
index ce8c1c8..675ee21 100644
--- a/src/main/java/org/apache/sling/feature/KeyValueMap.java
+++ b/src/main/java/org/apache/sling/feature/KeyValueMap.java
@@ -28,7 +28,7 @@ public class KeyValueMap
     implements Iterable<Map.Entry<String, String>> {
 
     /** The map holding the actual key value pairs. */
-    private final Map<String, String> properties = new TreeMap<>();
+    private final Map<String, Object> properties = new TreeMap<>();
 
     /**
      * Get an item from the map.
@@ -36,6 +36,14 @@ public class KeyValueMap
      * @return The item or {@code null}.
      */
     public String get(final String key) {
+        Object val = this.properties.get(key);
+        if (val instanceof String) {
+            return (String) val;
+        }
+        return null;
+    }
+
+    public Object getObject(final String key) {
         return this.properties.get(key);
     }
 
@@ -44,7 +52,7 @@ public class KeyValueMap
      * @param key The key of the item.
      * @param value The value
      */
-    public void put(final String key, final String value) {
+    public void put(final String key, final Object value) {
         this.properties.put(key, value);
     }
 
@@ -53,7 +61,7 @@ public class KeyValueMap
      * @param key The key of the item.
      * @return The previously stored value for the key or {@code null}.
      */
-    public String remove(final String key) {
+    public Object remove(final String key) {
         return this.properties.remove(key);
     }
 
@@ -67,7 +75,14 @@ public class KeyValueMap
 
     @Override
     public Iterator<Entry<String, String>> iterator() {
-        return this.properties.entrySet().iterator();
+        // TODO hack
+        Map<String, String> copied = new TreeMap<>();
+        for (Entry<String, Object> entry : properties.entrySet()) {
+            if (entry.getValue() instanceof String) {
+                copied.put(entry.getKey(), (String) entry.getValue());
+            }
+        }
+        return copied.entrySet().iterator();
     }
 
     /**
diff --git a/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java b/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
index 2a9698a..71fc8b0 100644
--- a/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
+++ b/src/main/java/org/apache/sling/feature/process/ApplicationBuilder.java
@@ -23,6 +23,7 @@ import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.FeatureResource;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -117,15 +118,21 @@ public class ApplicationBuilder {
             }
         }
 
-        // order by dependency chain
-        final List<FeatureResource> sortedResources = resolver.orderResources(featureList);
+        final List<Feature> sortedFeatures;
+        if (resolver != null) {
+            // order by dependency chain
+            final List<FeatureResource> sortedResources = resolver.orderResources(featureList);
 
-        final List<Feature> sortedFeatures = new ArrayList<>();
-        for (final FeatureResource fr : sortedResources) {
-            Feature f = fr.getFeature();
-            if (!sortedFeatures.contains(f)) {
-                sortedFeatures.add(f);
+            sortedFeatures = new ArrayList<>();
+            for (final FeatureResource fr : sortedResources) {
+                Feature f = fr.getFeature();
+                if (!sortedFeatures.contains(f)) {
+                    sortedFeatures.add(f);
+                }
             }
+        } else {
+            sortedFeatures = featureList;
+            Collections.sort(sortedFeatures);
         }
 
         // assemble

-- 
To stop receiving notification emails like this one, please contact
davidb@apache.org.

Mime
View raw message