sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject [sling-whiteboard] branch master updated: [featurediff] added requirements comparator
Date Fri, 31 May 2019 15:37:42 GMT
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 132b6e3  [featurediff] added requirements comparator
     new acc4c98  Merge branch 'master' of github.com:apache/sling-whiteboard
132b6e3 is described below

commit 132b6e3d6ff2e6e14011b167ec9ef2d4da7be945
Author: Simo Tripodi <stripodi@adobe.com>
AuthorDate: Fri May 31 17:37:16 2019 +0200

    [featurediff] added requirements comparator
---
 feature-diff/pom.xml                               |  7 ++-
 .../org/apache/sling/feature/diff/DiffSection.java |  4 +-
 .../org/apache/sling/feature/diff/FeatureDiff.java |  2 +
 .../sling/feature/diff/RequirementsComparator.java | 54 ++++++++++++++++++++++
 .../apache/sling/feature/diff/DiffSectionTest.java |  3 +-
 5 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/feature-diff/pom.xml b/feature-diff/pom.xml
index 6df816e..f952362 100644
--- a/feature-diff/pom.xml
+++ b/feature-diff/pom.xml
@@ -53,9 +53,14 @@
      | Sling Feature Model libraries
     -->
     <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>osgi.core</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.feature</artifactId>
-      <version>1.0.0</version>
+      <version>1.0.2</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/DiffSection.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/DiffSection.java
index a62aa51..1d282ec 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/DiffSection.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/DiffSection.java
@@ -71,7 +71,9 @@ public final class DiffSection {
 
     protected void markUpdated(DiffSection diffSection) {
         DiffSection checkedSection = requireNonNull(diffSection);
-        updates.add(checkedSection);
+        if (!diffSection.isEmpty()) {
+            updates.add(checkedSection);
+        }
     }
 
     public Iterable<DiffSection> getUpdates() {
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
index e86a6e2..76e0474 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/FeatureDiff.java
@@ -42,7 +42,9 @@ public final class FeatureDiff {
         featureDiff.addSection(new GenericMapComparator("framework-properties").compare(previous.getFrameworkProperties(),
current.getFrameworkProperties()));
         featureDiff.addSection(new ArtifactsComparator("bundles").apply(previous.getBundles(),
current.getBundles()));
         featureDiff.addSection(new ConfigurationsComparator().apply(previous.getConfigurations(),
current.getConfigurations()));
+        featureDiff.addSection(new RequirementsComparator().apply(previous.getRequirements(),
current.getRequirements()));
         featureDiff.addSection(new ExtensionsComparator().apply(previous.getExtensions(),
current.getExtensions()));
+        featureDiff.addSection(new GenericMapComparator("variables").compare(previous.getVariables(),
current.getVariables()));
 
         return featureDiff;
     }
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/RequirementsComparator.java
b/feature-diff/src/main/java/org/apache/sling/feature/diff/RequirementsComparator.java
new file mode 100644
index 0000000..12b64da
--- /dev/null
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/RequirementsComparator.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.sling.feature.diff;
+
+import java.util.List;
+
+import org.osgi.resource.Requirement;
+
+final class RequirementsComparator extends AbstractFeatureElementComparator<Requirement,
List<Requirement>> {
+
+    public RequirementsComparator() {
+        super("requirements");
+    }
+
+    @Override
+    public DiffSection compare(Requirement previous, Requirement current) {
+        DiffSection diffSection = new DiffSection(getId(current));
+
+        diffSection.markUpdated(new GenericMapComparator("directives").compare(previous.getDirectives(),
current.getDirectives()));
+        diffSection.markUpdated(new GenericMapComparator("attributes").compare(previous.getAttributes(),
current.getAttributes()));
+
+        return diffSection;
+    }
+
+    @Override
+    protected String getId(Requirement item) {
+        return item.getNamespace();
+    }
+
+    @Override
+    protected Requirement find(Requirement item, List<Requirement> requirements) {
+        for (Requirement requirement : requirements) {
+            if (getId(item).equals(getId(requirement))) {
+                return requirement;
+            }
+        }
+        return null;
+    }
+
+}
diff --git a/feature-diff/src/test/java/org/apache/sling/feature/diff/DiffSectionTest.java
b/feature-diff/src/test/java/org/apache/sling/feature/diff/DiffSectionTest.java
index 2720381..b06fd39 100644
--- a/feature-diff/src/test/java/org/apache/sling/feature/diff/DiffSectionTest.java
+++ b/feature-diff/src/test/java/org/apache/sling/feature/diff/DiffSectionTest.java
@@ -92,8 +92,7 @@ public class DiffSectionTest {
         DiffSection childDiff = new DiffSection("child");
         mainDiff.markUpdated(childDiff);
 
-        assertFalse(mainDiff.isEmpty());
-        assertEquals(mainDiff.getUpdates().iterator().next(), childDiff);
+        assertTrue(mainDiff.isEmpty());
     }
 
 }


Mime
View raw message