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/23 07:35:18 UTC
[sling-whiteboard] branch master updated: [feature-diff] dropped
commons-lang dependency
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
The following commit(s) were added to refs/heads/master by this push:
new 39a0ced [feature-diff] dropped commons-lang dependency
39a0ced is described below
commit 39a0cedf3e8987a65dc8c63dc30532833be0e440
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Sun Jun 23 09:35:12 2019 +0200
[feature-diff] dropped commons-lang dependency
---
feature-diff/pom.xml | 6 --
.../diff/impl/ConfigurationsComparator.java | 107 ++++++++++++++++++++-
2 files changed, 102 insertions(+), 11 deletions(-)
diff --git a/feature-diff/pom.xml b/feature-diff/pom.xml
index 787ac08..8531760 100644
--- a/feature-diff/pom.xml
+++ b/feature-diff/pom.xml
@@ -49,12 +49,6 @@
<version>1.0-rc5</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>3.8.1</version>
- <scope>provided</scope>
- </dependency>
<!--
| Sling Feature Model libraries
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
index bd046f4..e4190fc 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ConfigurationsComparator.java
@@ -16,10 +16,14 @@
*/
package org.apache.sling.feature.diff.impl;
-import static org.apache.commons.lang3.builder.EqualsBuilder.reflectionEquals;
+import static java.util.Objects.deepEquals;
+import java.util.Collection;
import java.util.Dictionary;
import java.util.Enumeration;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
import org.apache.sling.feature.Configuration;
import org.apache.sling.feature.Configurations;
@@ -70,11 +74,14 @@ public final class ConfigurationsComparator extends AbstractFeatureElementCompar
while (previousKeys.hasMoreElements()) {
String previousKey = previousKeys.nextElement();
- Object previousValue = previousProperties.get(previousKey);
- Object currentValue = currentProperties.get(previousKey);
+ // no other way to check if a key was removed in a dictionary
+ if (hasKey(previousKey, currentProperties.keys())) {
+ Object previousValue = previousProperties.get(previousKey);
+ Object currentValue = currentProperties.get(previousKey);
- if (currentValue != null && !reflectionEquals(previousValue, currentValue, true)) {
- targetProperties.put(previousKey, currentValue);
+ if (!areEquals(previousValue, currentValue)) {
+ targetProperties.put(previousKey, currentValue);
+ }
}
}
@@ -95,4 +102,94 @@ public final class ConfigurationsComparator extends AbstractFeatureElementCompar
}
}
+ private static boolean areEquals(Object lhs, Object rhs) {
+ if (lhs == rhs) {
+ return true;
+ }
+
+ if (lhs == null ^ rhs == null) {
+ return false;
+ }
+
+ // Find the leaf class since there may be transients in the leaf
+ // class or in classes between the leaf and root.
+ // If we are not testing transients or a subclass has no ivars,
+ // then a subclass can test equals to a superclass.
+ final Class<?> lhsClass = lhs.getClass();
+ final Class<?> rhsClass = rhs.getClass();
+ Class<?> testClass;
+
+ if (lhsClass.isInstance(rhs)) {
+ testClass = lhsClass;
+ if (!rhsClass.isInstance(lhs)) {
+ // rhsClass is a subclass of lhsClass
+ testClass = rhsClass;
+ }
+ } else if (rhsClass.isInstance(lhs)) {
+ testClass = rhsClass;
+ if (!lhsClass.isInstance(rhs)) {
+ // lhsClass is a subclass of rhsClass
+ testClass = lhsClass;
+ }
+ } else {
+ // The two classes are not related.
+ return false;
+ }
+
+ if (testClass.isArray()) {
+ return deepEquals(lhs, rhs);
+ } else if (Collection.class.isAssignableFrom(testClass)) {
+ return areEquals((Collection<?>) lhs, (Collection<?>) rhs);
+ } else if (Map.class.isAssignableFrom(testClass)) {
+ return areEquals((Map<?, ?>) lhs, (Map<?, ?>) rhs);
+ }
+
+ return Objects.equals(lhs, rhs);
+ }
+
+ private static boolean areEquals(Collection<?> lhs, Collection<?> rhs) {
+ if (lhs.size() != rhs.size()) {
+ return false;
+ }
+
+ return deepEquals(lhs.toArray(), rhs.toArray());
+ }
+
+ private static boolean areEquals(Map<?, ?> lhs, Map<?, ?> rhs) {
+ for (Entry<?, ?> previousEntry : lhs.entrySet()) {
+ Object previousKey = previousEntry.getKey();
+
+ if (!rhs.containsKey(previousKey)) {
+ return false;
+ } else {
+ Object previousValue = previousEntry.getValue();
+ Object currentValue = rhs.get(previousKey);
+
+ if (!areEquals(previousValue, currentValue)) {
+ return false;
+ }
+ }
+ }
+
+ for (Object currentKey : rhs.keySet()) {
+ if (!lhs.containsKey(currentKey)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private static boolean hasKey(String key, Enumeration<String> keys) {
+ while (keys.hasMoreElements()) {
+ String current = keys.nextElement();
+
+ if (key.equals(current)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
}