sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject [sling-whiteboard] branch master updated: Remove resolver usage from application builder
Date Tue, 17 Apr 2018 07:42:37 GMT
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-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new ed16b16  Remove resolver usage from application builder
ed16b16 is described below

commit ed16b160ace07bd48369d63ae17ec554ab23b179
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Tue Apr 17 09:42:30 2018 +0200

    Remove resolver usage from application builder
---
 .../impl/ApplicationBuilderTest.java               | 43 ++++++++++----------
 .../apache/sling/feature/support/FeatureUtil.java  | 46 +++++++++++++++++-----
 .../support/process/ApplicationBuilder.java        | 41 ++++---------------
 3 files changed, 66 insertions(+), 64 deletions(-)

diff --git a/featuremodel/feature-applicationbuilder/src/test/java/org/apache/sling/feature/applicationbuilder/impl/ApplicationBuilderTest.java
b/featuremodel/feature-applicationbuilder/src/test/java/org/apache/sling/feature/applicationbuilder/impl/ApplicationBuilderTest.java
index 07faad6..f0532e5 100644
--- a/featuremodel/feature-applicationbuilder/src/test/java/org/apache/sling/feature/applicationbuilder/impl/ApplicationBuilderTest.java
+++ b/featuremodel/feature-applicationbuilder/src/test/java/org/apache/sling/feature/applicationbuilder/impl/ApplicationBuilderTest.java
@@ -16,24 +16,7 @@
  */
 package org.apache.sling.feature.applicationbuilder.impl;
 
-import org.apache.sling.feature.Application;
-import org.apache.sling.feature.ArtifactId;
-import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.resolver.FrameworkResolver;
-import org.apache.sling.feature.support.ArtifactHandler;
-import org.apache.sling.feature.support.ArtifactManager;
-import org.apache.sling.feature.support.ArtifactManagerConfig;
-import org.apache.sling.feature.support.json.ApplicationJSONWriter;
-import org.apache.sling.feature.support.json.FeatureJSONReader;
-import org.apache.sling.feature.support.json.FeatureJSONReader.SubstituteVariables;
-import org.apache.sling.feature.support.process.ApplicationBuilder;
-import org.apache.sling.feature.support.process.BuilderContext;
-import org.apache.sling.feature.support.process.FeatureProvider;
-import org.apache.sling.feature.support.resolver.FeatureResolver;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.osgi.framework.Constants;
+import static org.junit.Assert.assertEquals;
 
 import java.io.File;
 import java.io.FileReader;
@@ -53,7 +36,25 @@ import javax.json.JsonWriter;
 import javax.json.JsonWriterFactory;
 import javax.json.stream.JsonGenerator;
 
-import static org.junit.Assert.assertEquals;
+import org.apache.sling.feature.Application;
+import org.apache.sling.feature.ArtifactId;
+import org.apache.sling.feature.Feature;
+import org.apache.sling.feature.resolver.FrameworkResolver;
+import org.apache.sling.feature.support.ArtifactHandler;
+import org.apache.sling.feature.support.ArtifactManager;
+import org.apache.sling.feature.support.ArtifactManagerConfig;
+import org.apache.sling.feature.support.FeatureUtil;
+import org.apache.sling.feature.support.json.ApplicationJSONWriter;
+import org.apache.sling.feature.support.json.FeatureJSONReader;
+import org.apache.sling.feature.support.json.FeatureJSONReader.SubstituteVariables;
+import org.apache.sling.feature.support.process.ApplicationBuilder;
+import org.apache.sling.feature.support.process.BuilderContext;
+import org.apache.sling.feature.support.process.FeatureProvider;
+import org.apache.sling.feature.support.resolver.FeatureResolver;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.Constants;
 
 public class ApplicationBuilderTest {
     private Path tempDir;
@@ -87,7 +88,7 @@ public class ApplicationBuilderTest {
         Feature[] features = {fa, fb};
 
         try (FeatureResolver fr = new FrameworkResolver(am, getFrameworkProps())) {
-            Application app = ApplicationBuilder.assemble(null, bc, fr, features);
+            Application app = ApplicationBuilder.assemble(null, bc, FeatureUtil.sortFeatures(fr,
features));
             String actualJSON = writeApplication(app);
 
             String expectedJSON = "{\"features\":["
@@ -119,7 +120,7 @@ public class ApplicationBuilderTest {
         Feature[] features = {fd, fc};
 
         try (FeatureResolver fr = new FrameworkResolver(am, getFrameworkProps())) {
-            Application app = ApplicationBuilder.assemble(null, bc, fr, features);
+            Application app = ApplicationBuilder.assemble(null, bc, FeatureUtil.sortFeatures(fr,
features));
             String genApp = writeApplication(app);
 
             String expected = "{\"features\":["
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
index 5b7f30b..b816b9a 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/FeatureUtil.java
@@ -16,6 +16,15 @@
  */
 package org.apache.sling.feature.support;
 
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
 import org.apache.sling.feature.Application;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
@@ -25,15 +34,7 @@ import org.apache.sling.feature.support.process.ApplicationBuilder;
 import org.apache.sling.feature.support.process.BuilderContext;
 import org.apache.sling.feature.support.process.FeatureProvider;
 import org.apache.sling.feature.support.resolver.FeatureResolver;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
+import org.apache.sling.feature.support.resolver.FeatureResource;
 
 public class FeatureUtil {
     /**
@@ -230,6 +231,31 @@ public class FeatureUtil {
         return assembleApplication(app, artifactManager, fr, features.toArray(new Feature[0]));
     }
 
+    public static Feature[] sortFeatures(final FeatureResolver fr, final Feature... features)
{
+        final List<Feature> featureList = new ArrayList<>();
+        for(final Feature f : features) {
+            featureList.add(f);
+        }
+
+        final List<Feature> sortedFeatures;
+        if (fr != null) {
+            // order by dependency chain
+            final List<FeatureResource> sortedResources = fr.orderResources(featureList);
+
+            sortedFeatures = new ArrayList<>();
+            for (final FeatureResource rsrc : sortedResources) {
+                Feature f = rsrc.getFeature();
+                if (!sortedFeatures.contains(f)) {
+                    sortedFeatures.add(rsrc.getFeature());
+                }
+            }
+        } else {
+            sortedFeatures = featureList;
+            Collections.sort(sortedFeatures);
+        }
+        return sortedFeatures.toArray(new Feature[sortedFeatures.size()]);
+    }
+
     public static Application assembleApplication(
             Application app,
             final ArtifactManager artifactManager, FeatureResolver fr, final Feature... features)
@@ -254,7 +280,7 @@ public class FeatureUtil {
                 }
                 return null;
             }
-        }), fr, features);
+        }), sortFeatures(fr, features));
 
         // check framework
         if ( app.getFramework() == null ) {
diff --git a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/process/ApplicationBuilder.java
b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/process/ApplicationBuilder.java
index 1fc2325..bac2486 100644
--- a/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/process/ApplicationBuilder.java
+++ b/featuremodel/feature-support/src/main/java/org/apache/sling/feature/support/process/ApplicationBuilder.java
@@ -16,16 +16,13 @@
  */
 package org.apache.sling.feature.support.process;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.sling.feature.Application;
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.support.resolver.FeatureResolver;
-import org.apache.sling.feature.support.resolver.FeatureResource;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
 
 /**
  * Build an application based on features.
@@ -34,14 +31,10 @@ public class ApplicationBuilder {
 
     /**
      * Assemble an application based on the provided feature Ids.
-     *
-     * Upgrade features are only applied if the provided feature list
-     * contains the feature to be upgraded. Otherwise the upgrade feature
-     * is ignored.
+     * The features are processed in the order they are provided.
      *
      * @param app The optional application to use as a base.
      * @param context The builder context
-     * @param resolver The Feature Resolver to use
      * @param featureIds The feature ids
      * @return The application
      * throws IllegalArgumentException If context or featureIds is {@code null}
@@ -49,7 +42,6 @@ public class ApplicationBuilder {
      */
     public static Application assemble(final Application app,
             final BuilderContext context,
-            final FeatureResolver resolver,
             final String... featureIds) {
         if ( featureIds == null || context == null ) {
             throw new IllegalArgumentException("Features and/or context must not be null");
@@ -64,18 +56,18 @@ public class ApplicationBuilder {
             }
             index++;
         }
-        return assemble(app, context, resolver, features);
+        return assemble(app, context, features);
     }
 
     /**
      * Assemble an application based on the provided features.
      *
+     * The features are processed in the order they are provided.
      * If the same feature is included more than once only the feature with
      * the highest version is used. The others are ignored.
      *
      * @param app The optional application to use as a base.
      * @param context The builder context
-     * @param resolver The Feature Resolver to use
      * @param features The features
      * @return The application
      * throws IllegalArgumentException If context or featureIds is {@code null}
@@ -84,7 +76,7 @@ public class ApplicationBuilder {
     public static Application assemble(
             Application app,
             final BuilderContext context,
-            final FeatureResolver resolver, final Feature... features) {
+            final Feature... features) {
         if ( features == null || context == null ) {
             throw new IllegalArgumentException("Features and/or context must not be null");
         }
@@ -119,26 +111,9 @@ public class ApplicationBuilder {
             }
         }
 
-        final List<Feature> sortedFeatures;
-        if (resolver != null) {
-            // order by dependency chain
-            final List<FeatureResource> sortedResources = resolver.orderResources(featureList);
-
-            sortedFeatures = new ArrayList<>();
-            for (final FeatureResource fr : sortedResources) {
-                Feature f = fr.getFeature();
-                if (!sortedFeatures.contains(f)) {
-                    sortedFeatures.add(f);
-                }
-            }
-        } else {
-            sortedFeatures = featureList;
-            Collections.sort(sortedFeatures);
-        }
-
         // assemble
         int featureStartOrder = 5; // begin with start order a little higher than 0
-        for(final Feature f : sortedFeatures) {
+        for(final Feature f : featureList) {
             app.getFeatureIds().add(f.getId());
             final Feature assembled = FeatureBuilder.assemble(f, context.clone(new FeatureProvider()
{
 

-- 
To stop receiving notification emails like this one, please contact
cziegeler@apache.org.

Mime
View raw message