Skip to content

Commit

Permalink
SLING-7752 - Deserializing and serializing a feature model file suffl…
Browse files Browse the repository at this point in the history
…es the configurations

Committed on behalf of @andreituicu with many thanks!
Pull request closed #2.
  • Loading branch information
bosschaert committed Oct 26, 2018
1 parent c034687 commit 222c1bd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/apache/sling/feature/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


/**
Expand All @@ -44,7 +44,7 @@ public class Configuration
private final String factoryPid;

/** The properties. */
private final Dictionary<String, Object> properties = new Hashtable<>();
private final Map<String, Object> properties = new LinkedHashMap<>();

/**
* Create a new configuration
Expand Down Expand Up @@ -139,7 +139,7 @@ public boolean isFactoryConfiguration() {
* Get all properties of the configuration.
* @return The properties
*/
public Dictionary<String, Object> getProperties() {
public Map<String, Object> getProperties() {
return this.properties;
}

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/org/apache/sling/feature/Feature.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package org.apache.sling.feature;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import org.apache.felix.utils.resource.CapabilityImpl;
import org.apache.felix.utils.resource.RequirementImpl;
import org.osgi.resource.Capability;
import org.osgi.resource.Requirement;

import java.util.Iterator;

/**
* A feature consists of
* <ul>
Expand Down Expand Up @@ -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<String> keyEnum = cfg.getProperties().keys();
while ( keyEnum.hasMoreElements() ) {
final String key = keyEnum.nextElement();
final Iterator<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,9 +149,9 @@ static void mergeConfigurations(final Configurations target, final Configuration
if ( current.compareTo(cfg) == 0 ) {
found = true;
// merge / override properties
final Enumeration<String> i = cfg.getProperties().keys();
while ( i.hasMoreElements() ) {
final String key = i.nextElement();
final Iterator<String> i = cfg.getProperties().keySet().iterator();
while ( i.hasNext() ) {
final String key = i.next();
current.getProperties().put(key, cfg.getProperties().get(key));
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> keys = new HashSet<>(Collections.list(cfg.getProperties().keys()));
final Set<String> 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));
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/sling/feature/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;


0 comments on commit 222c1bd

Please sign in to comment.