You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2020/02/24 14:01:50 UTC

[sling-org-apache-sling-feature] branch master updated: SLING-8676 : Prototype does not allow to remove requirements and capabilities

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git


The following commit(s) were added to refs/heads/master by this push:
     new 4406100  SLING-8676 : Prototype does not allow to remove requirements and capabilities
4406100 is described below

commit 44061001404da96f50493e041a7be4c3dae50113
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Feb 24 15:01:41 2020 +0100

    SLING-8676 : Prototype does not allow to remove requirements and capabilities
---
 .../java/org/apache/sling/feature/Prototype.java   | 58 ++++++++++++++++++++--
 .../sling/feature/builder/FeatureBuilder.java      | 12 +++++
 2 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/Prototype.java b/src/main/java/org/apache/sling/feature/Prototype.java
index ed94793..d73a554 100644
--- a/src/main/java/org/apache/sling/feature/Prototype.java
+++ b/src/main/java/org/apache/sling/feature/Prototype.java
@@ -21,6 +21,8 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.osgi.resource.Capability;
+
 /**
  * A prototype is a blueprint of a feature with optional removals of
  * <ul>
@@ -28,12 +30,11 @@ import java.util.Map;
  * <li>Bundles
  * <li>Framework properties
  * <li>Extensions or artifacts from extensions
+ * <li>Capabilities
+ * <li>Requirements
  * </ul>
  *
  * This class is not thread-safe.
- *
- * TODO - requirement, capabilities
- *
  */
 public class Prototype implements Comparable<Prototype> {
 
@@ -49,6 +50,10 @@ public class Prototype implements Comparable<Prototype> {
 
     private final Map<String, List<ArtifactId>> artifactExtensionRemovals = new HashMap<>();
 
+    private final List<MatchingRequirement> requirementRemovals = new ArrayList<>();
+
+    private final List<Capability> capabilityRemovals = new ArrayList<>();
+
     /**
      * Construct a new Include.
      * @param id The id of the feature.
@@ -69,26 +74,73 @@ public class Prototype implements Comparable<Prototype> {
         return this.id;
     }
 
+    /**
+     * Get the list of configuration removals The returned object is modifiable.
+     * 
+     * @return List of {@code PID}s.
+     */
     public List<String> getConfigurationRemovals() {
         return configurationRemovals;
     }
 
+    /**
+     * Get the list of artifact removals The returned object is modifiable.
+     * 
+     * @return List of artifact ids.
+     */
     public List<ArtifactId> getBundleRemovals() {
         return bundleRemovals;
     }
 
+    /**
+     * Get the list of framework property removals The returned object is
+     * modifiable.
+     * 
+     * @return List of property names
+     */
     public List<String> getFrameworkPropertiesRemovals() {
         return frameworkPropertiesRemovals;
     }
 
+    /**
+     * Get the list of extension removals The returned object is modifiable.
+     * 
+     * @return List of extension names
+     */
     public List<String> getExtensionRemovals() {
         return extensionRemovals;
     }
 
+    /**
+     * Get the list of artifacts removed from extensions The returned object is
+     * modifiable.
+     * 
+     * @return Map where the extension name is the key, and the value is a list of
+     *         artifact ids
+     */
     public Map<String, List<ArtifactId>> getArtifactExtensionRemovals() {
         return artifactExtensionRemovals;
     }
 
+    /**
+     * Get the list of requirement removals. The returned object is modifiable.
+     * 
+     * @return The list of requirements
+     * @since 1.3
+     */
+    public List<MatchingRequirement> getRequirementRemovals() {
+        return requirementRemovals;
+    }
+
+    /**
+     * Get the list of capability removals. The returned object is modifiable.
+     * 
+     * @return The list of capabilities
+     */
+    public List<Capability> getCapabilityRemovals() {
+        return capabilityRemovals;
+    }
+
     @Override
     public int compareTo(final Prototype o) {
         return this.id.compareTo(o.id);
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 74e9736..ecc4f99 100644
--- a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
+++ b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
@@ -35,8 +35,10 @@ import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionState;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.MatchingRequirement;
 import org.apache.sling.feature.Prototype;
 import org.osgi.framework.Version;
+import org.osgi.resource.Capability;
 
 public abstract class FeatureBuilder {
     /** This key is used to track origins while a prototype is merged in */
@@ -485,5 +487,15 @@ public abstract class FeatureBuilder {
                 }
             }
         }
+
+        // process requirement removals
+        for (final MatchingRequirement req : prototype.getRequirementRemovals()) {
+            feature.getRequirements().remove(req);
+        }
+
+        // process capability removals
+        for (final Capability cap : prototype.getCapabilityRemovals()) {
+            feature.getCapabilities().remove(cap);
+        }
     }
 }