From 222c1bd02dfd4b4f54882e32e3584cb26cd92b40 Mon Sep 17 00:00:00 2001 From: David Bosschaert Date: Fri, 26 Oct 2018 16:14:53 +0100 Subject: [PATCH] SLING-7752 - Deserializing and serializing a feature model file suffles the configurations Committed on behalf of @andreituicu with many thanks! Pull request closed #2. --- .../java/org/apache/sling/feature/Configuration.java | 8 ++++---- src/main/java/org/apache/sling/feature/Feature.java | 9 +++++---- .../org/apache/sling/feature/builder/BuilderUtil.java | 7 ++++--- .../org/apache/sling/feature/builder/FeatureBuilder.java | 2 +- src/main/java/org/apache/sling/feature/package-info.java | 2 +- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/sling/feature/Configuration.java b/src/main/java/org/apache/sling/feature/Configuration.java index c53c95c..4642952 100644 --- a/src/main/java/org/apache/sling/feature/Configuration.java +++ b/src/main/java/org/apache/sling/feature/Configuration.java @@ -16,8 +16,8 @@ */ package org.apache.sling.feature; -import java.util.Dictionary; -import java.util.Hashtable; +import java.util.LinkedHashMap; +import java.util.Map; /** @@ -44,7 +44,7 @@ public class Configuration private final String factoryPid; /** The properties. */ - private final Dictionary properties = new Hashtable<>(); + private final Map properties = new LinkedHashMap<>(); /** * Create a new configuration @@ -139,7 +139,7 @@ public boolean isFactoryConfiguration() { * Get all properties of the configuration. * @return The properties */ - public Dictionary getProperties() { + public Map getProperties() { return this.properties; } diff --git a/src/main/java/org/apache/sling/feature/Feature.java b/src/main/java/org/apache/sling/feature/Feature.java index a25eac7..4cdcaf1 100644 --- a/src/main/java/org/apache/sling/feature/Feature.java +++ b/src/main/java/org/apache/sling/feature/Feature.java @@ -17,7 +17,6 @@ package org.apache.sling.feature; import java.util.ArrayList; -import java.util.Enumeration; import java.util.List; import org.apache.felix.utils.resource.CapabilityImpl; @@ -25,6 +24,8 @@ import org.osgi.resource.Capability; import org.osgi.resource.Requirement; +import java.util.Iterator; + /** * A feature consists of *
    @@ -310,9 +311,9 @@ public Feature copy(final ArtifactId id) { // configurations for(final Configuration cfg : this.getConfigurations()) { final Configuration c = cfg.isFactoryConfiguration() ? new Configuration(cfg.getFactoryPid(), cfg.getName()) : new Configuration(cfg.getPid()); - final Enumeration keyEnum = cfg.getProperties().keys(); - while ( keyEnum.hasMoreElements() ) { - final String key = keyEnum.nextElement(); + final Iterator keyEnum = cfg.getProperties().keySet().iterator(); + while ( keyEnum.hasNext() ) { + final String key = keyEnum.next(); c.getProperties().put(key, cfg.getProperties().get(key)); } result.getConfigurations().add(c); diff --git a/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java b/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java index 372966f..ed7d355 100644 --- a/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java +++ b/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java @@ -30,6 +30,7 @@ import java.io.StringReader; import java.io.StringWriter; import java.util.Enumeration; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Stream; @@ -148,9 +149,9 @@ static void mergeConfigurations(final Configurations target, final Configuration if ( current.compareTo(cfg) == 0 ) { found = true; // merge / override properties - final Enumeration i = cfg.getProperties().keys(); - while ( i.hasMoreElements() ) { - final String key = i.nextElement(); + final Iterator i = cfg.getProperties().keySet().iterator(); + while ( i.hasNext() ) { + final String key = i.next(); current.getProperties().put(key, cfg.getProperties().get(key)); } break; diff --git a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java index 19a56a7..059ae29 100644 --- a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java +++ b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java @@ -214,7 +214,7 @@ public static Feature assemble( */ public static void resolveVariables(final Feature feature, final KeyValueMap additionalVariables) { for(final Configuration cfg : feature.getConfigurations()) { - final Set keys = new HashSet<>(Collections.list(cfg.getProperties().keys())); + final Set keys = new HashSet<>(cfg.getProperties().keySet()); for(final String key : keys) { final Object value = cfg.getProperties().get(key); cfg.getProperties().put(key, replaceVariables(value, additionalVariables, feature)); diff --git a/src/main/java/org/apache/sling/feature/package-info.java b/src/main/java/org/apache/sling/feature/package-info.java index 3d70902..8201ca5 100644 --- a/src/main/java/org/apache/sling/feature/package-info.java +++ b/src/main/java/org/apache/sling/feature/package-info.java @@ -17,7 +17,7 @@ * under the License. */ -@org.osgi.annotation.versioning.Version("0.1.0") +@org.osgi.annotation.versioning.Version("0.2.0") package org.apache.sling.feature;