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/06 13:59:15 UTC

[sling-whiteboard] branch master updated: Handle extension merging with null target

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-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 484a768  Handle extension merging with null target
484a768 is described below

commit 484a768a99bf2a7a5cc8fc452169695bddeeb4b4
Author: David Bosschaert <bo...@adobe.com>
AuthorDate: Tue Nov 6 13:58:43 2018 +0000

    Handle extension merging with null target
---
 .../extension/apiregions/APIRegionMergeHandler.java      | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/featuremodel/feature-extension-apiregions/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java b/featuremodel/feature-extension-apiregions/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
index f1c0d52..fbd695f 100644
--- a/featuremodel/feature-extension-apiregions/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
+++ b/featuremodel/feature-extension-apiregions/src/main/java/org/apache/sling/feature/extension/apiregions/APIRegionMergeHandler.java
@@ -41,14 +41,24 @@ public class APIRegionMergeHandler implements MergeHandler {
 
     @Override
     public void merge(HandlerContext context, Feature target, Feature source, Extension targetEx, Extension sourceEx) {
-        if (!targetEx.getName().equals("api-regions") || !sourceEx.getName().equals("api-regions"))
+        if (!sourceEx.getName().equals("api-regions"))
+            return;
+        if (targetEx != null && !targetEx.getName().equals("api-regions"))
             return;
 
         JsonReader srcJR = Json.createReader(new StringReader(sourceEx.getJSON()));
         JsonArray srcJA = srcJR.readArray();
 
-        JsonReader tgtJR = Json.createReader(new StringReader(targetEx.getJSON()));
-        JsonArray tgtJA = tgtJR.readArray();
+        JsonArray tgtJA;
+        if (targetEx != null) {
+            JsonReader tgtJR = Json.createReader(new StringReader(targetEx.getJSON()));
+            tgtJA = tgtJR.readArray();
+        } else {
+            targetEx = new Extension(sourceEx.getType(), sourceEx.getName(), sourceEx.isRequired());
+            target.getExtensions().add(targetEx);
+
+            tgtJA = Json.createArrayBuilder().build();
+        }
 
         StringWriter sw = new StringWriter();
         JsonGenerator gen = Json.createGenerator(sw);