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/19 15:45:29 UTC

[sling-whiteboard] branch master updated: [feature-diff] experimental JSON diff via javax.json APIs

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 77675eb  [feature-diff] experimental JSON diff via javax.json APIs
77675eb is described below

commit 77675eb496a239124f3c7adeaccb7d26423a850f
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Wed Jun 19 17:45:10 2019 +0200

    [feature-diff] experimental JSON diff via javax.json APIs
---
 feature-diff/pom.xml                               | 68 ++++++----------------
 .../feature/diff/impl/ExtensionsComparator.java    | 26 +++++----
 2 files changed, 32 insertions(+), 62 deletions(-)

diff --git a/feature-diff/pom.xml b/feature-diff/pom.xml
index d94467e..e88bc12 100644
--- a/feature-diff/pom.xml
+++ b/feature-diff/pom.xml
@@ -29,7 +29,6 @@
 
   <artifactId>org.apache.sling.feature.diff</artifactId>
   <version>0.0.1-SNAPSHOT</version>
-  <packaging>bundle</packaging>
 
   <name>Apache Sling Feature Model diff tool</name>
   <description>Feature Model diff tool for Apache Sling</description>
@@ -41,11 +40,6 @@
   </properties>
 
   <dependencies>
-    <dependency>
-      <groupId>org.osgi</groupId>
-      <artifactId>org.osgi.annotation.versioning</artifactId>
-      <scope>provided</scope>
-    </dependency>
     <!--
      | utilities
     -->
@@ -61,12 +55,6 @@
       <version>3.8.1</version>
       <scope>provided</scope>
     </dependency>
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-collections4</artifactId>
-      <version>4.1</version>
-      <scope>provided</scope>
-    </dependency>
 
     <!--
      | Sling Feature Model libraries
@@ -77,6 +65,11 @@
       <scope>provided</scope>
     </dependency>
     <dependency>
+      <groupId>org.osgi</groupId>
+      <artifactId>org.osgi.annotation.versioning</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.feature</artifactId>
       <version>1.0.4</version>
@@ -87,27 +80,9 @@
      | JSON patch
     -->
     <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-databind</artifactId>
-      <version>${jackson.version}</version>
-      <scope>provided</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>org.apache.commons</groupId>
-          <artifactId>commons-collections4</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>com.fasterxml.jackson.core</groupId>
-      <artifactId>jackson-core</artifactId>
-      <version>${jackson.version}</version>
-      <scope>provided</scope>
-    </dependency>
-    <dependency>
-      <groupId>com.flipkart.zjsonpatch</groupId>
-      <artifactId>zjsonpatch</artifactId>
-      <version>0.4.8</version>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-json_1.0_spec</artifactId>
+      <version>1.0-alpha-1</version>
       <scope>provided</scope>
     </dependency>
 
@@ -124,26 +99,19 @@
   <build>
     <plugins>
       <plugin>
-        <groupId>org.apache.felix</groupId>
-        <artifactId>maven-bundle-plugin</artifactId>
-        <extensions>true</extensions>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
         <configuration>
-          <instructions>
-            <Export-Package>org.apache.sling.feature.diff*</Export-Package>
-            <Import-Package>
-              org.apache.sling.feature*,
-              org.apache.commons.collections4*,
-              org.apache.commons.io*
-            </Import-Package>
-            <Embed-Dependency>
-              jackson-core;inline=true,
-              jackson-databind;inline=true,
-              zjsonpatch;inline=true
-            </Embed-Dependency>
-            <Embed-Transitive>false</Embed-Transitive>
-          </instructions>
+          <archive>
+            <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
+          </archive>
         </configuration>
       </plugin>
+      <plugin>
+        <groupId>biz.aQute.bnd</groupId>
+        <artifactId>bnd-maven-plugin</artifactId>
+        <version>4.1.0</version>
+      </plugin>
     </plugins>
   </build>
 
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ExtensionsComparator.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ExtensionsComparator.java
index 33bb11b..16fa466 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ExtensionsComparator.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/impl/ExtensionsComparator.java
@@ -16,9 +16,13 @@
  */
 package org.apache.sling.feature.diff.impl;
 
-import java.io.IOException;
+import static javax.json.Json.createReader;
+
+import java.io.StringReader;
 import java.util.LinkedList;
 
+import javax.json.JsonValue;
+
 import org.apache.sling.feature.Artifact;
 import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Extension;
@@ -26,16 +30,11 @@ import org.apache.sling.feature.Extensions;
 import org.apache.sling.feature.Feature;
 import org.apache.sling.feature.diff.spi.FeatureElementComparator;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.flipkart.zjsonpatch.JsonDiff;
 import com.google.auto.service.AutoService;
 
 @AutoService(FeatureElementComparator.class)
 public final class ExtensionsComparator extends AbstractFeatureElementComparator {
 
-    private final ObjectMapper objectMapper = new ObjectMapper();
-
     public ExtensionsComparator() {
         super("extensions");
     }
@@ -111,20 +110,19 @@ public final class ExtensionsComparator extends AbstractFeatureElementComparator
                 String currentJSON = currentExtension.getJSON();
 
                 try {
-                    JsonNode previousNode = objectMapper.readTree(previousJSON);
-                    JsonNode currentNode = objectMapper.readTree(currentJSON); 
-                    JsonNode patchNode = JsonDiff.asJson(previousNode, currentNode); 
+                    JsonValue previousNode = parseJSON(previousJSON);
+                    JsonValue currentNode = parseJSON(currentJSON); 
 
-                    if (patchNode.size() != 0) {
+                    if (previousNode.equals(currentNode)) {
                         target.getExtensions().add(currentExtension);
                     }
-                } catch (IOException e) {
+                } catch (Throwable t) {
                     // should not happen
                     throw new RuntimeException("A JSON parse error occurred while parsing previous '"
                                                + previousJSON
                                                + "' and current '"
                                                + currentJSON
-                                               + "', see nested errors:", e);
+                                               + "', see nested errors:", t);
                 }
                 break;
 
@@ -134,4 +132,8 @@ public final class ExtensionsComparator extends AbstractFeatureElementComparator
         }
     }
 
+    private static JsonValue parseJSON(String json) {
+        return createReader(new StringReader(json)).read();
+    }
+
 }