Author: cziegeler
Date: Wed Jul 5 12:17:56 2017
New Revision: 1800866
URL: http://svn.apache.org/viewvc?rev=1800866&view=rev
Log:
Add copy operation to feature, add assembled flag
Modified:
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Feature.java
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java
Modified:
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Feature.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Feature.java?rev=1800866&r1=1800865&r2=1800866&view=diff
==============================================================================
---
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Feature.java
(original)
+++
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/Feature.java
Wed Jul 5 12:17:56 2017
@@ -17,7 +17,9 @@
package org.apache.sling.feature;
import java.util.ArrayList;
+import java.util.Enumeration;
import java.util.List;
+import java.util.Map;
/**
* A feature consists of
@@ -50,19 +52,21 @@ public class Feature implements Comparab
private final Extensions extensions = new Extensions();
/** The optional location. */
- private String location;
+ private volatile String location;
/** The optional title. */
- private String title;
+ private volatile String title;
/** The optional description. */
- private String description;
+ private volatile String description;
/** The optional vendor. */
- private String vendor;
+ private volatile String vendor;
/** The optional license. */
- private String license;
+ private volatile String license;
+
+ private volatile boolean assembled = false;
/**
* Construct a new feature.
@@ -166,6 +170,66 @@ public class Feature implements Comparab
this.license = license;
}
+ public boolean isAssembled() {
+ return assembled;
+ }
+
+ public void setAssembled(final boolean flag) {
+ this.assembled = flag;
+ }
+
+ /**
+ * Create a copy of the feature
+ * @return A copy of the feature
+ */
+ public Feature copy() {
+ final Feature result = new Feature(this.getId());
+
+ // metadata
+ result.setLocation(this.getLocation());
+ result.setTitle(this.getTitle());
+ result.setDescription(this.getDescription());
+ result.setVendor(this.getVendor());
+ result.setLicense(this.getLicense());
+ result.setAssembled(this.isAssembled());
+
+ // bundles
+ for(final Map.Entry<Integer, Artifact> entry : this.getBundles()) {
+ final Artifact c = new Artifact(entry.getValue().getId());
+ c.getMetadata().putAll(entry.getValue().getMetadata());
+
+ result.getBundles().add(entry.getKey(), c);
+ }
+
+ // 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();
+ c.getProperties().put(key, cfg.getProperties().get(key));
+ }
+ result.getConfigurations().add(c);
+ }
+
+ // framework properties
+ result.getFrameworkProperties().putAll(this.getFrameworkProperties());
+
+ // requirements (TODO copy requirement)
+ result.getRequirements().addAll(this.getRequirements());
+
+ // capabilities (TODO copy capability)
+ result.getCapabilities().addAll(this.getCapabilities());
+
+ // includes (TODO copy include)
+ result.getIncludes().addAll(this.getIncludes());
+
+ // extensions (TODO copy extension)
+ result.getExtensions().addAll(this.getExtensions());
+
+ return result;
+ }
+
@Override
public int compareTo(final Feature o) {
return this.id.compareTo(o.id);
@@ -189,8 +253,10 @@ public class Feature implements Comparab
@Override
public String toString() {
- return "Feature [id=" + this.getId().toMvnId()
+ return (this.isAssembled() ? "Assembled Feature" : "Feature") +
+ " [id=" + this.getId().toMvnId()
+ ( this.getLocation() != null ? ", location=" +
this.getLocation() : "")
+ "]";
}
+
}
Modified:
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java?rev=1800866&r1=1800865&r2=1800866&view=diff
==============================================================================
---
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java
(original)
+++
sling/whiteboard/cziegeler/feature/src/main/java/org/apache/sling/feature/process/FeatureBuilder.java
Wed Jul 5 12:17:56 2017
@@ -63,11 +63,19 @@ public class FeatureBuilder {
throw new IllegalStateException("Recursive inclusion of " +
feature.getId().toMvnId() + " via " + processedFeatures);
}
processedFeatures.add(feature.getId().toMvnId());
- Feature result = feature;
+ // we copy the feature as we set the assembled flag on the result
+ final Feature result = feature.copy();
if ( !feature.getIncludes().isEmpty() ) {
- result = new Feature(feature.getId());
- result.setLocation(feature.getLocation());
+
+ // clear everything in the result, will be added in the process
+ feature.getBundles().clear();
+ feature.getFrameworkProperties().clear();
+ feature.getConfigurations().clear();
+ feature.getRequirements().clear();
+ feature.getCapabilities().clear();
+ feature.getIncludes().clear();
+ feature.getExtensions().clear();
for(final Include i : feature.getIncludes()) {
final Feature f = provider.provide(i.getId());
@@ -164,6 +172,7 @@ public class FeatureBuilder {
}
processedFeatures.remove(feature.getId().toMvnId());
+ result.setAssembled(true);
return result;
}