You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by si...@apache.org on 2019/06/15 07:24:01 UTC

[sling-whiteboard] 01/03: [feature-diff] configuration comparator has to add the Configuration delta only

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

simonetripodi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-whiteboard.git

commit ede2b7e214a1f711ccea54ed24b45279248fd031
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Sat Jun 15 07:24:52 2019 +0200

    [feature-diff] configuration comparator has to add the Configuration
    delta only
---
 .../feature/diff/ConfigurationsComparator.java     | 46 ++++++++++++++++++++--
 .../diff/FrameworkPropertiesComparator.java        |  5 +--
 .../feature/diff/ConfigurationsComparatorTest.java |  2 +-
 3 files changed, 45 insertions(+), 8 deletions(-)

diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/ConfigurationsComparator.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/ConfigurationsComparator.java
index 6f3e529..996525d 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/ConfigurationsComparator.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/ConfigurationsComparator.java
@@ -17,6 +17,10 @@
 package org.apache.sling.feature.diff;
 
 import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
 import org.apache.sling.feature.Configuration;
 import org.apache.sling.feature.Configurations;
 import org.apache.sling.feature.Feature;
@@ -40,10 +44,8 @@ final class ConfigurationsComparator implements FeatureElementComparator {
 
             if (currentConfiguration == null) {
                 target.getPrototype().getConfigurationRemovals().add(previousConfiguration.getPid());
-            } else if (!reflectionEquals(previousConfiguration.getConfigurationProperties(),
-                                         currentConfiguration.getConfigurationProperties(),
-                                         true)) {
-                target.getConfigurations().add(currentConfiguration);
+            } else {
+                computeDiff(previousConfiguration, currentConfiguration, target);
             }
         }
 
@@ -56,4 +58,40 @@ final class ConfigurationsComparator implements FeatureElementComparator {
         }
     }
 
+    protected void computeDiff(Configuration previous, Configuration current, Feature target) {
+        Dictionary<String, Object> previousProperties = previous.getProperties();
+        Dictionary<String, Object> currentProperties = current.getProperties();
+
+        Configuration targetConfiguration = new Configuration(previous.getPid());
+        Dictionary<String, Object> targetProperties = targetConfiguration.getProperties();
+
+        Enumeration<String> previousKeys = previousProperties.keys();
+        while (previousKeys.hasMoreElements()) {
+            String previousKey = previousKeys.nextElement();
+
+            Object previousValue = previousProperties.get(previousKey);
+            Object currentValue = currentProperties.get(previousKey);
+
+            if (currentValue != null && !reflectionEquals(previousValue, currentValue, true)) {
+                targetProperties.put(previousKey, currentValue);
+            }
+        }
+
+        Enumeration<String> currentKeys = currentProperties.keys();
+        while (currentKeys.hasMoreElements()) {
+            String currentKey = currentKeys.nextElement();
+
+            Object previousValue = previousProperties.get(currentKey);
+            Object currentValue = currentProperties.get(currentKey);
+
+            if (previousValue == null && currentValue != null) {
+                targetProperties.put(currentKey, currentValue);
+            }
+        }
+
+        if (!targetProperties.isEmpty()) {
+            target.getConfigurations().add(targetConfiguration);
+        }
+    }
+
 }
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/FrameworkPropertiesComparator.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/FrameworkPropertiesComparator.java
index 7308805..2f3acb0 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/FrameworkPropertiesComparator.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/FrameworkPropertiesComparator.java
@@ -16,10 +16,9 @@
  */
 package org.apache.sling.feature.diff;
 
-import static java.util.Objects.deepEquals;
-
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Objects;
 
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.diff.spi.FeatureElementComparator;
@@ -47,7 +46,7 @@ final class FrameworkPropertiesComparator implements FeatureElementComparator {
                 String currentValue = current.get(previousKey);
 
                 // override the previous set value
-                if (!deepEquals(previousValue, currentValue)) {
+                if (!Objects.equals(previousValue, currentValue)) {
                     target.getFrameworkProperties().put(previousKey, currentValue);
                 }
             }
diff --git a/feature-diff/src/test/java/org/apache/sling/feature/diff/ConfigurationsComparatorTest.java b/feature-diff/src/test/java/org/apache/sling/feature/diff/ConfigurationsComparatorTest.java
index 8e68926..15be0a8 100644
--- a/feature-diff/src/test/java/org/apache/sling/feature/diff/ConfigurationsComparatorTest.java
+++ b/feature-diff/src/test/java/org/apache/sling/feature/diff/ConfigurationsComparatorTest.java
@@ -87,7 +87,7 @@ public class ConfigurationsComparatorTest extends AbstractComparatorTest<Configu
         assertFalse(targetFeature.getConfigurations().isEmpty());
 
         assertEquals(currentConfiguration.getPid(), targetFeature.getConfigurations().iterator().next().getPid());
-        Dictionary<String, Object> properties = targetFeature.getConfigurations().iterator().next().getConfigurationProperties();
+        Dictionary<String, Object> properties = targetFeature.getConfigurations().iterator().next().getProperties();
 
         assertTrue((boolean) properties.get("added"));
         assertArrayEquals(new String[] { "/log", "/etc" }, (String[]) properties.get("updated"));