You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by da...@apache.org on 2018/11/21 14:15:47 UTC

[sling-org-apache-sling-feature] branch master updated: SLING-8121 Rename feature 'include' to 'prototype'

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

davidb 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 cf839d2  SLING-8121 Rename feature 'include' to 'prototype'
cf839d2 is described below

commit cf839d229091f2229b25253ba744c0824194f53b
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Wed Nov 21 10:53:13 2018 +0000

    SLING-8121 Rename feature 'include' to 'prototype'
---
 design/feature-model.json                          |  8 ++-
 .../java/org/apache/sling/feature/Feature.java     | 34 ++++++------
 .../sling/feature/{Include.java => Prototype.java} | 10 ++--
 .../sling/feature/builder/FeatureBuilder.java      | 53 +++++++++---------
 .../sling/feature/builder/FeatureBuilderTest.java  | 62 +++++++++++-----------
 5 files changed, 82 insertions(+), 85 deletions(-)

diff --git a/design/feature-model.json b/design/feature-model.json
index 4a5b49f..08152e2 100644
--- a/design/feature-model.json
+++ b/design/feature-model.json
@@ -3,8 +3,7 @@
 
     "id": "org.apache.sling:my.app:feature:optional:1.0",
 
-    "# variables used in includes, requirements, capabilities and bundles sections":
-    "# are substituted at build time. Configuration and framework properties at launch time.",
+    "# variables": "used in configuration and framework properties are substitityped at launch time.",
     "variables": {
         "cfgvar": "somedefault",
         "xyz-ver": "1.2.3",
@@ -13,7 +12,7 @@
         "provisioning.model.name": ":boot"
     },
 
-    "includes": [
+    "prototype": 
         {
             "id": "org.apache.sling:sling:9",
             "removals": {
@@ -21,8 +20,7 @@
                 "bundles": [],
                 "framework-properties": []
             }
-        }
-    ],
+        },
     "requirements": [
         {
             "namespace": "osgi.contract",
diff --git a/src/main/java/org/apache/sling/feature/Feature.java b/src/main/java/org/apache/sling/feature/Feature.java
index f4420c8..20371c6 100644
--- a/src/main/java/org/apache/sling/feature/Feature.java
+++ b/src/main/java/org/apache/sling/feature/Feature.java
@@ -34,7 +34,7 @@ import org.osgi.resource.Requirement;
  * <li>Configurations
  * <li>Framework properties
  * <li>Requirements and capabilities
- * <li>Includes
+ * <li>Prototype
  * <li>Extensions
  * </ul>
  *
@@ -82,8 +82,8 @@ public class Feature implements Comparable<Feature> {
     /** Flag indicating whether this is a complete feature */
     private volatile boolean completeFlag = false;
 
-    /** The optional include. */
-    private volatile Include include;
+    /** The optional prototype. */
+    private volatile Prototype prototype;
 
     /**
      * Construct a new feature.
@@ -168,19 +168,19 @@ public class Feature implements Comparable<Feature> {
     }
 
     /**
-     * Get the optionally included feature.
-     * @return The included feature or {@code null} if none.
+     * Get the optional prototype feature.
+     * @return The prototype feature or {@code null} if none.
      */
-    public Include getInclude() {
-        return include;
+    public Prototype getPrototype() {
+        return prototype;
     }
 
     /**
-     * Set the optionally included feature.
-     * @param include The included feature or {@code null} if none.
+     * Set the optional prototype feature.
+     * @param prototype The prototype feature or {@code null} if none.
      */
-    public void setInclude(Include include) {
-        this.include = include;
+    public void setPrototype(Prototype prototype) {
+        this.prototype = prototype;
     }
 
     /**
@@ -265,8 +265,8 @@ public class Feature implements Comparable<Feature> {
     }
 
     /**
-     * Check whether the feature is final. A final feature can't be included by
-     * other features.
+     * Check whether the feature is final. A final feature can't be a prototype
+     * for other features.
      *
      * @return {@code true} if it is final, {@code false} otherwise
      */
@@ -376,10 +376,10 @@ public class Feature implements Comparable<Feature> {
             result.getCapabilities().add(c);
         }
 
-        // include
-        final Include i = this.getInclude();
+        // prototype
+        final Prototype i = this.getPrototype();
         if (i != null) {
-            final Include c = new Include(i.getId());
+            final Prototype c = new Prototype(i.getId());
 
             c.getBundleRemovals().addAll(i.getBundleRemovals());
             c.getConfigurationRemovals().addAll(i.getConfigurationRemovals());
@@ -387,7 +387,7 @@ public class Feature implements Comparable<Feature> {
             c.getFrameworkPropertiesRemovals().addAll(i.getFrameworkPropertiesRemovals());
             c.getArtifactExtensionRemovals().putAll(i.getArtifactExtensionRemovals());
 
-            result.setInclude(c);
+            result.setPrototype(c);
         }
 
         // extensions
diff --git a/src/main/java/org/apache/sling/feature/Include.java b/src/main/java/org/apache/sling/feature/Prototype.java
similarity index 91%
rename from src/main/java/org/apache/sling/feature/Include.java
rename to src/main/java/org/apache/sling/feature/Prototype.java
index dad1a56..ed94793 100644
--- a/src/main/java/org/apache/sling/feature/Include.java
+++ b/src/main/java/org/apache/sling/feature/Prototype.java
@@ -22,7 +22,7 @@ import java.util.List;
 import java.util.Map;
 
 /**
- * A include is an inclusion of a feature with optional removals of
+ * A prototype is a blueprint of a feature with optional removals of
  * <ul>
  * <li>Configurations / configuration properties
  * <li>Bundles
@@ -35,7 +35,7 @@ import java.util.Map;
  * TODO - requirement, capabilities
  *
  */
-public class Include implements Comparable<Include> {
+public class Prototype implements Comparable<Prototype> {
 
     private final ArtifactId id;
 
@@ -54,7 +54,7 @@ public class Include implements Comparable<Include> {
      * @param id The id of the feature.
      * @throws IllegalArgumentException If id is {@code null}.
      */
-    public Include(final ArtifactId id) {
+    public Prototype(final ArtifactId id) {
         if ( id == null ) {
             throw new IllegalArgumentException("id must not be null.");
         }
@@ -90,7 +90,7 @@ public class Include implements Comparable<Include> {
     }
 
     @Override
-    public int compareTo(final Include o) {
+    public int compareTo(final Prototype o) {
         return this.id.compareTo(o.id);
     }
 
@@ -107,7 +107,7 @@ public class Include implements Comparable<Include> {
         if (obj == null || getClass() != obj.getClass()) {
             return false;
         }
-        return this.id.equals(((Include)obj).id);
+        return this.id.equals(((Prototype)obj).id);
     }
 
     @Override
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 beb4173..e64d0c1 100644
--- a/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
+++ b/src/main/java/org/apache/sling/feature/builder/FeatureBuilder.java
@@ -32,24 +32,24 @@ import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.Include;
+import org.apache.sling.feature.Prototype;
 import org.osgi.framework.Version;
 
 public abstract class FeatureBuilder {
-    /** This key is used to track origins while includes are merged in */
+    /** This key is used to track origins while a prototype is merged in */
     private static final String TRACKING_KEY = "tracking-key";
 
     /** Pattern for using variables. */
     private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\{[a-zA-Z0-9.-_]+\\}");
 
     /**
-     * Assemble the full feature by processing all includes.
+     * Assemble the full feature by processing its prototype.
      *
      * @param feature The feature to start
      * @param context The builder context
      * @return The assembled feature.
      * @throws IllegalArgumentException If feature or context is {@code null}
-     * @throws IllegalStateException If an included feature can't be provided or merged.
+     * @throws IllegalStateException If a prototype feature can't be provided or merged.
      */
     public static Feature assemble(final Feature feature,
             final BuilderContext context) {
@@ -79,7 +79,7 @@ public abstract class FeatureBuilder {
         for(final String id : featureIds) {
             features[index] = context.getFeatureProvider().provide(ArtifactId.parse(id));
             if ( features[index] == null ) {
-                throw new IllegalStateException("Unable to find included feature " + id);
+                throw new IllegalStateException("Unable to find prototype feature " + id);
             }
             index++;
         }
@@ -87,10 +87,10 @@ public abstract class FeatureBuilder {
     }
 
     /**
-     * Remove duplicate and included features.
+     * Remove duplicate and prototype features.
      * If a feature with the same id but different version is contained several times,
      * only the one with the highest version is kept in the result list.
-     * If a feature includes another feature from the provided set, the included feature
+     * If a feature has another feature as prototype from the provided set, the prototype feature
      * is removed from the set.
      *
      * @param context The builder context
@@ -299,7 +299,7 @@ public abstract class FeatureBuilder {
         // we copy the feature as we set the assembled flag on the result
         final Feature result = feature.copy();
 
-        if ( result.getInclude() != null) {
+        if ( result.getPrototype() != null) {
             // clear everything in the result, will be added in the process
             result.getVariables().clear();
             result.getBundles().clear();
@@ -307,28 +307,28 @@ public abstract class FeatureBuilder {
             result.getConfigurations().clear();
             result.getRequirements().clear();
             result.getCapabilities().clear();
-            result.setInclude(null);
+            result.setPrototype(null);
             result.getExtensions().clear();
 
-            final Include i = feature.getInclude();
+            final Prototype i = feature.getPrototype();
 
             final Feature f = context.getFeatureProvider().provide(i.getId());
             if ( f == null ) {
-                throw new IllegalStateException("Unable to find included feature " + i.getId());
+                throw new IllegalStateException("Unable to find prototype feature " + i.getId());
             }
             if (f.isFinal()) {
                 throw new IllegalStateException(
-                        "Included feature " + i.getId() + " is marked as final and can't be used in an include.");
+                        "Prototype feature " + i.getId() + " is marked as final and can't be used in a prototype.");
             }
-            final Feature includedFeature = internalAssemble(processedFeatures, f, context);
+            final Feature prototypeFeature = internalAssemble(processedFeatures, f, context);
 
-            // process include instructions
-            processInclude(includedFeature, i);
+            // process prototype instructions
+            processPrototype(prototypeFeature, i);
 
-            // and now merge the included feature into the result. No overrides should be needed since the result is empty before
-            merge(result, includedFeature, context, Collections.emptyList(), TRACKING_KEY);
+            // and now merge the prototype feature into the result. No overrides should be needed since the result is empty before
+            merge(result, prototypeFeature, context, Collections.emptyList(), TRACKING_KEY);
 
-            // and merge the current feature over the included feature into the result
+            // and merge the current feature over the prototype feature into the result
             merge(result, feature, context, Collections.singletonList(
                     BuilderUtil.CATCHALL_OVERRIDE + BuilderUtil.OVERRIDE_SELECT_LATEST), TRACKING_KEY);
 
@@ -366,15 +366,14 @@ public abstract class FeatureBuilder {
     }
 
     /**
-     * Process the include statement Process all the removals contained in the
-     * include
+     * Process all the removals contained in the prototype
      *
      * @param feature The feature
-     * @param include The include
+     * @param prototype The prototype
      */
-    private static void processInclude(final Feature feature, final Include include) {
+    private static void processPrototype(final Feature feature, final Prototype prototype) {
         // process bundles removals
-        for (final ArtifactId a : include.getBundleRemovals()) {
+        for (final ArtifactId a : prototype.getBundleRemovals()) {
             boolean removed = false;
             final boolean ignoreVersion = a.getOSGiVersion().equals(Version.emptyVersion);
             if ( ignoreVersion ) {
@@ -409,7 +408,7 @@ public abstract class FeatureBuilder {
         }
 
         // process configuration removals
-        for (final String c : include.getConfigurationRemovals()) {
+        for (final String c : prototype.getConfigurationRemovals()) {
             final int attrPos = c.indexOf('@');
             final String pid = (attrPos == -1 ? c : c.substring(0, attrPos));
             final String attr = (attrPos == -1 ? null : c.substring(attrPos + 1));
@@ -425,12 +424,12 @@ public abstract class FeatureBuilder {
         }
 
         // process framework properties removals
-        for (final String p : include.getFrameworkPropertiesRemovals()) {
+        for (final String p : prototype.getFrameworkPropertiesRemovals()) {
             feature.getFrameworkProperties().remove(p);
         }
 
         // process extensions removals
-        for (final String name : include.getExtensionRemovals()) {
+        for (final String name : prototype.getExtensionRemovals()) {
             for (final Extension ext : feature.getExtensions()) {
                 if ( ext.getName().equals(name) ) {
                     feature.getExtensions().remove(ext);
@@ -439,7 +438,7 @@ public abstract class FeatureBuilder {
             }
         }
         // process artifact extensions removals
-        for (final Map.Entry<String, List<ArtifactId>> entry : include.getArtifactExtensionRemovals().entrySet()) {
+        for (final Map.Entry<String, List<ArtifactId>> entry : prototype.getArtifactExtensionRemovals().entrySet()) {
             for (final Extension ext : feature.getExtensions()) {
                 if ( ext.getName().equals(entry.getKey()) ) {
                     for(final ArtifactId toRemove : entry.getValue() ) {
diff --git a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
index 0526266..5de408b 100644
--- a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
+++ b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
@@ -40,7 +40,7 @@ import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Extension;
 import org.apache.sling.feature.ExtensionType;
 import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.Include;
+import org.apache.sling.feature.Prototype;
 import org.junit.Test;
 import org.osgi.resource.Capability;
 import org.osgi.resource.Requirement;
@@ -217,7 +217,7 @@ public class FeatureBuilderTest {
         }
 
         // includes should always be empty
-        assertNull(actuals.getInclude());
+        assertNull(actuals.getPrototype());
     }
 
     @Test public void testNoIncludesNoUpgrade() throws Exception {
@@ -270,8 +270,8 @@ public class FeatureBuilderTest {
 
     @Test public void testSingleInclude() throws Exception {
         final Feature base = new Feature(ArtifactId.parse("org.apache.sling/test-feature/1.1"));
-        final Include i1 = new Include(ArtifactId.parse("g/a/1"));
-        base.setInclude(i1);
+        final Prototype i1 = new Prototype(ArtifactId.parse("g/a/1"));
+        base.setPrototype(i1);
 
         final Requirement r1 = new RequirementImpl(null, "osgi.contract",
                 Collections.singletonMap("filter", "(&(osgi.contract=JavaServlet)(version=3.1))"), null);
@@ -317,7 +317,7 @@ public class FeatureBuilderTest {
         // create the expected result
         final Feature result = base.copy();
         result.getVariables().put("varx", "myvalx");
-        result.setInclude(null);
+        result.setPrototype(null);
         result.getFrameworkProperties().put("bar", "X");
         result.getBundles().add(BuilderUtilTest.createBundle("org.apache.sling/foo-bar/4.5.6", 3));
         final Configuration co3 = new Configuration("org.apache.sling.foo");
@@ -333,8 +333,8 @@ public class FeatureBuilderTest {
 
     @Test public void testSingleIncludeMultiVersion() {
         Feature base = new Feature(ArtifactId.fromMvnId("g:tgtart:1"));
-        Include i1 = new Include(ArtifactId.fromMvnId("g:a:3"));
-        base.setInclude(i1);
+        Prototype i1 = new Prototype(ArtifactId.fromMvnId("g:a:3"));
+        base.setPrototype(i1);
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("g:myart:1")));
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("group:testmulti:1")));
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("group:testmulti:3")));
@@ -358,8 +358,8 @@ public class FeatureBuilderTest {
 
     @Test public void testSingleIncludeMultiVersion2() {
         Feature base = new Feature(ArtifactId.fromMvnId("g:tgtart:1"));
-        Include i1 = new Include(ArtifactId.fromMvnId("g:a:2"));
-        base.setInclude(i1);
+        Prototype i1 = new Prototype(ArtifactId.fromMvnId("g:a:2"));
+        base.setPrototype(i1);
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("g:myart:1")));
 
         BuilderContext builderContext = new BuilderContext(provider);
@@ -383,8 +383,8 @@ public class FeatureBuilderTest {
 
     @Test public void testSingleIncludeMultiVersion3() {
         Feature base = new Feature(ArtifactId.fromMvnId("g:tgtart:1"));
-        Include i1 = new Include(ArtifactId.fromMvnId("g:a:2"));
-        base.setInclude(i1);
+        Prototype i1 = new Prototype(ArtifactId.fromMvnId("g:a:2"));
+        base.setPrototype(i1);
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("g:myart:1")));
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("group:testmulti:1")));
 
@@ -405,8 +405,8 @@ public class FeatureBuilderTest {
 
     @Test public void testSingleIncludeMultiVersion4() {
         Feature base = new Feature(ArtifactId.fromMvnId("g:tgtart:1"));
-        Include i1 = new Include(ArtifactId.fromMvnId("g:a:2"));
-        base.setInclude(i1);
+        Prototype i1 = new Prototype(ArtifactId.fromMvnId("g:a:2"));
+        base.setPrototype(i1);
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("g:myart:1")));
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("group:testmulti:1")));
         base.getBundles().add(new Artifact(ArtifactId.fromMvnId("group:testmulti:3")));
@@ -435,8 +435,8 @@ public class FeatureBuilderTest {
         final Feature a = new Feature(idA);
         final Feature b = new Feature(idB);
         // feature b includes feature a
-        final Include inc = new Include(idA);
-        b.setInclude(inc);
+        final Prototype inc = new Prototype(idA);
+        b.setPrototype(inc);
 
         // assemble application, it should only contain feature b as a is included by b
         Feature[] features = FeatureBuilder.deduplicate(new BuilderContext(new FeatureProvider() {
@@ -478,9 +478,9 @@ public class FeatureBuilderTest {
         a.getBundles().add(new Artifact(bundleA2));
         a.getBundles().add(new Artifact(bundleB));
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getBundleRemovals().add(bundleA2);
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         // assemble feature include
         Feature feature = FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -512,9 +512,9 @@ public class FeatureBuilderTest {
         a.getBundles().add(new Artifact(bundleA2));
         a.getBundles().add(new Artifact(bundleB));
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getBundleRemovals().add(ArtifactId.fromMvnId("g:a:0.0.0"));
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         // assemble feature include
         Feature feature = FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -544,9 +544,9 @@ public class FeatureBuilderTest {
         a.getBundles().add(new Artifact(bundleA1));
         a.getBundles().add(new Artifact(bundleB));
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getBundleRemovals().add(bundleA2);
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         try {
             FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -577,9 +577,9 @@ public class FeatureBuilderTest {
         e.getArtifacts().add(new Artifact(bundleB));
         a.getExtensions().add(e);
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getArtifactExtensionRemovals().put("foo", Arrays.asList(bundleA2));
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         // assemble feature include
         Feature feature = FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -613,9 +613,9 @@ public class FeatureBuilderTest {
         e.getArtifacts().add(new Artifact(bundleB));
         a.getExtensions().add(e);
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getArtifactExtensionRemovals().put("foo", Arrays.asList(ArtifactId.fromMvnId("g:a:0.0.0")));
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         // assemble feature include
         Feature feature = FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -647,9 +647,9 @@ public class FeatureBuilderTest {
         e.getArtifacts().add(new Artifact(bundleB));
         a.getExtensions().add(e);
         final Feature b = new Feature(ArtifactId.fromMvnId("g:a-include:1"));
-        final Include inc = new Include(a.getId());
+        final Prototype inc = new Prototype(a.getId());
         inc.getArtifactExtensionRemovals().put("foo", Arrays.asList(bundleA2));
-        b.setInclude(inc);
+        b.setPrototype(inc);
 
         try {
             FeatureBuilder.assemble(b, new BuilderContext(new FeatureProvider() {
@@ -675,8 +675,8 @@ public class FeatureBuilderTest {
         final Feature a = new Feature(idA);
         final Feature b = new Feature(idB);
         // feature b includes feature a
-        final Include inc = new Include(idA);
-        b.setInclude(inc);
+        final Prototype inc = new Prototype(idA);
+        b.setPrototype(inc);
 
         // assemble feature, it should only contain feature b as a is included by b
         final Feature target = FeatureBuilder.assemble(ArtifactId.fromMvnId("g:F:1.0.0"), new BuilderContext(new FeatureProvider() {
@@ -804,8 +804,8 @@ public class FeatureBuilderTest {
         a.setFinal(true);
         final Feature b = new Feature(idB);
         // feature b includes feature a
-        final Include inc = new Include(idA);
-        b.setInclude(inc);
+        final Prototype inc = new Prototype(idA);
+        b.setPrototype(inc);
 
         // assemble feature, this should throw an exception
         try {