Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLING-7752 - Deserializing and serializing a feature model file suffles the configurations #2

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;