You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2018/11/06 16:24:12 UTC

[GitHub] bosschaert closed pull request #2: SLING-8077 - refactor ContentorderMergeProcessor to MergeHandler adju…

bosschaert closed pull request #2: SLING-8077 - refactor ContentorderMergeProcessor to MergeHandler adju…
URL: https://github.com/apache/sling-org-apache-sling-feature-extension-content/pull/2
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java b/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
index f85f18a..05b1133 100644
--- a/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
+++ b/src/main/java/org/apache/sling/feature/extension/content/ContentOrderMergeProcessor.java
@@ -23,25 +23,50 @@
 import org.apache.sling.feature.FeatureConstants;
 import org.apache.sling.feature.KeyValueMap;
 import org.apache.sling.feature.builder.HandlerContext;
+import org.apache.sling.feature.builder.MergeHandler;
 import org.apache.sling.feature.builder.PostProcessHandler;
 
-public class ContentOrderMergeProcessor implements PostProcessHandler {
+public class ContentOrderMergeProcessor implements MergeHandler {
 
     private static final String DEFAULT_CONTENT_START_ORDER = "default.content.startorder";
 
-    @Override
-    public void postProcess(HandlerContext context, Feature feature, Extension extension) {
-        if (extension.getType() == ExtensionType.ARTIFACTS
-                && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES)) {
-            String defaultOrder = feature.getVariables().get(DEFAULT_CONTENT_START_ORDER);
-            if (defaultOrder != null) {
-                for (Artifact a : extension.getArtifacts()) {
-                    KeyValueMap kvm = a.getMetadata();
-                    if(kvm.get(Artifact.KEY_START_ORDER) == null) {
-                        kvm.put(Artifact.KEY_START_ORDER, defaultOrder);
-                    }
+    private void processFeature(HandlerContext context, Feature feature, Extension extension) {
+        String defaultOrder = feature.getVariables().get(DEFAULT_CONTENT_START_ORDER);
+        if (defaultOrder != null) {
+            for (Artifact a : extension.getArtifacts()) {
+                KeyValueMap kvm = a.getMetadata();
+                if(kvm.get(Artifact.KEY_START_ORDER) == null) {
+                    kvm.put(Artifact.KEY_START_ORDER, defaultOrder);
                 }
-                feature.getVariables().remove(DEFAULT_CONTENT_START_ORDER);
+            }
+            feature.getVariables().remove(DEFAULT_CONTENT_START_ORDER);
+        }
+    }
+
+    @Override
+    public boolean canMerge(Extension extension) {
+        return extension.getType() == ExtensionType.ARTIFACTS
+                && extension.getName().equals(FeatureConstants.EXTENSION_NAME_CONTENT_PACKAGES);
+    }
+
+    @Override
+    public void merge(HandlerContext context, Feature target, Feature source, Extension targetEx, Extension sourceEx) {
+        if (targetEx == null) {
+            target.getExtensions().add(sourceEx);
+            return;
+        }
+        processFeature(context, target, targetEx);
+        processFeature(context, source, sourceEx);
+        for (final Artifact a : sourceEx.getArtifacts()) {
+            boolean replace = true;
+            final Artifact existing = targetEx.getArtifacts().getSame(a.getId());
+            if (existing != null && existing.getId().getOSGiVersion().compareTo(a.getId().getOSGiVersion()) > 0) {
+                replace = false;
+            }
+
+            if (replace) {
+                targetEx.getArtifacts().removeSame(a.getId());
+                targetEx.getArtifacts().add(a);
             }
         }
     }
diff --git a/src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler b/src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler
similarity index 100%
rename from src/main/resources/META-INF/services/org.apache.sling.feature.builder.PostProcessHandler
rename to src/main/resources/META-INF/services/org.apache.sling.feature.builder.MergeHandler


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services