FELIX-1841 Prevent updating the service registration if service properties did not change as of the configuration update (this may be the case if the configuration update only contains modified private properties not propagated to service registration properties) (Thanks Pierre de Rop for providing the patch)

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@883652 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
index 976f9a4..36d74e4 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/manager/ImmediateComponentManager.java
@@ -20,6 +20,7 @@
 
 
 import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
 
@@ -468,8 +469,12 @@
         {
             try
             {
+                // Don't propagate if service properties did not change.
                 final Dictionary regProps = getServiceProperties();
-                sr.setProperties( regProps );
+                if ( !servicePropertiesMatches( sr, regProps ) )
+                {
+                    sr.setProperties( regProps );
+                }
             }
             catch ( IllegalStateException ise )
             {
@@ -491,4 +496,31 @@
         // 7. everything set and done, the component has been udpated
         return true;
     }
+
+
+    /**
+     * Checks if the given service registration properties matches another set
+     * of properties.
+     *
+     * @param reg the service registration whose service properties will be
+     *      compared to the props parameter
+     * @param props the properties to be compared with the registration
+     *      service properties.
+     * @return <code>true</code> if the registration service properties equals
+     *      the prop properties, false if not.
+     */
+    private boolean servicePropertiesMatches( ServiceRegistration reg, Dictionary props )
+    {
+        Dictionary regProps = new Hashtable();
+        String[] keys = reg.getReference().getPropertyKeys();
+        for ( int i = 0; keys != null && i < keys.length; i++ )
+        {
+            if ( !keys[i].equals( org.osgi.framework.Constants.OBJECTCLASS )
+                && !keys[i].equals( org.osgi.framework.Constants.SERVICE_ID ) )
+            {
+                regProps.put( keys[i], reg.getReference().getProperty( keys[i] ) );
+            }
+        }
+        return regProps.equals( props );
+    }
 }