[ 
https://issues.apache.org/jira/browse/SLING-8077?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16676960#comment-16676960
 ] 

ASF GitHub Bot commented on SLING-8077:
---------------------------------------

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:
[email protected]


> Transform ContentOrderMergeProcessor into MergeHandler
> ------------------------------------------------------
>
>                 Key: SLING-8077
>                 URL: https://issues.apache.org/jira/browse/SLING-8077
>             Project: Sling
>          Issue Type: Improvement
>          Components: Feature Model
>            Reporter: Dominik Süß
>            Priority: Major
>
> ContentOrderMergeProcessor as implemented in "Featuremodel - Content 
> Deployment Exension" currently postprocesses features after merge to set the 
> default start-order. this only works for cases where features with same order 
> are getting merged and mandates a sequential merge of features of different 
> order. 
> To tackle this issue the extension should take over the actual merge which 
> allows to preprocess the features before merging and setting the defaults 
> according to the defaults declared in the particular features before doing 
> the merge.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to