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-org-apache-sling-feature-diff.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e7bc10  SLING-8580 - [feature-diff] exclude 'service.pid' and 
'service.factoryPid' OSGi configurations keys from comparison, which creates 
false positive diff
3e7bc10 is described below

commit 3e7bc1089727990ece0cacad3a8fae35da957225
Author: Simo Tripodi <[email protected]>
AuthorDate: Fri Jul 12 20:00:11 2019 +0200

    SLING-8580 - [feature-diff] exclude 'service.pid' and
    'service.factoryPid' OSGi configurations keys from comparison, which
    creates false positive diff
---
 .../diff/impl/ConfigurationsComparator.java        | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
 
b/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
index 0590dc4..3210fa4 100644
--- 
a/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
+++ 
b/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
@@ -31,6 +31,10 @@ import org.apache.sling.feature.Feature;
 
 public final class ConfigurationsComparator extends 
AbstractFeatureElementComparator {
 
+    private static final String SERVICE_PID_KEY = "service.pid";
+
+    private static final String SERVICE_FACTORY_PID_KEY = "service.factoryPid";
+
     public ConfigurationsComparator() {
         super("configurations");
     }
@@ -71,8 +75,9 @@ public final class ConfigurationsComparator extends 
AbstractFeatureElementCompar
         while (previousKeys.hasMoreElements()) {
             String previousKey = previousKeys.nextElement();
 
+            // skip 'service.pid' and 'service.factoryPid' keys
             // no other way to check if a key was removed in a dictionary
-            if (hasKey(previousKey, currentProperties.keys())) {
+            if (!isReservedKey(previousKey) && hasKey(previousKey, 
currentProperties.keys())) {
                 Object previousValue = previousProperties.get(previousKey);
                 Object currentValue = currentProperties.get(previousKey);
 
@@ -86,11 +91,14 @@ public final class ConfigurationsComparator extends 
AbstractFeatureElementCompar
         while (currentKeys.hasMoreElements()) {
             String currentKey = currentKeys.nextElement();
 
-            Object previousValue = previousProperties.get(currentKey);
-            Object currentValue = currentProperties.get(currentKey);
+            // skip 'service.pid' and 'service.factoryPid' keys
+            if (!isReservedKey(currentKey)) {
+                Object previousValue = previousProperties.get(currentKey);
+                Object currentValue = currentProperties.get(currentKey);
 
-            if (previousValue == null && currentValue != null) {
-                targetProperties.put(currentKey, currentValue);
+                if (previousValue == null && currentValue != null) {
+                    targetProperties.put(currentKey, currentValue);
+                }
             }
         }
 
@@ -99,6 +107,10 @@ public final class ConfigurationsComparator extends 
AbstractFeatureElementCompar
         }
     }
 
+    private static boolean isReservedKey(String key) {
+        return SERVICE_PID_KEY.equals(key) || 
SERVICE_FACTORY_PID_KEY.equals(key);
+    }
+
     private static boolean areEquals(Object lhs, Object rhs) {
         if (lhs == rhs) {
             return true;

Reply via email to