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/15 08:56:50 UTC

[sling-slingfeature-maven-plugin] 02/02: SLING-8468 - [slingfeature-m-p] donate a new MOJO which is able to scan and detect differences between different versions of the same Feature model

This is an automated email from the ASF dual-hosted git repository.

simonetripodi pushed a commit to branch feature_diff
in repository https://gitbox.apache.org/repos/asf/sling-slingfeature-maven-plugin.git

commit 8ff761ce40ad1220a6b642434b1f3e0b2188dc21
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Sat Jun 15 10:56:42 2019 +0200

    SLING-8468 - [slingfeature-m-p] donate a new MOJO which is able to scan
    and detect differences between different versions of the same Feature
    model
    
    updated diff tool APIs
    Feature output is now a Feature with a Prototype and new settings
---
 .../feature/maven/mojos/FeaturesDiffMojo.java      | 39 ++++++++++++++--------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java b/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
index cc76ccb..600ad52 100644
--- a/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
+++ b/src/main/java/org/apache/sling/feature/maven/mojos/FeaturesDiffMojo.java
@@ -16,9 +16,12 @@
  */
 package org.apache.sling.feature.maven.mojos;
 
+import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
+import static org.apache.sling.feature.io.json.FeatureJSONWriter.write;
+
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Collection;
 import java.util.Iterator;
@@ -42,9 +45,9 @@ import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.sling.feature.ArtifactId;
 import org.apache.sling.feature.Feature;
-import org.apache.sling.feature.diff.FeatureDiff;
-import org.apache.sling.feature.diff.io.json.FeatureDiffJSONSerializer;
+import org.apache.sling.feature.diff.DefaultDiffRequest;
 import org.apache.sling.feature.io.json.FeatureJSONReader;
 
 /**
@@ -107,19 +110,29 @@ public final class FeaturesDiffMojo extends AbstractIncludingFeatureMojo {
 
         getLog().info("Comparing current " + current + " to previous " + previous);
 
-        FeatureDiff featureDiff = FeatureDiff.compareFeatures(previous, current);
-
-        if (featureDiff.isEmpty()) {
-            getLog().info("There are no differences between current " + current + " and previous " + previous + " models");
-            return;
-        }
-
-        File outputDiffFile = new File(mainOutputDir, current.getId().getClassifier() + ".diff.json");
+        StringBuilder classifier = new StringBuilder()
+                                   .append(previous.getId().getVersion())
+                                   .append("-to-")
+                                   .append(current.getId().getVersion())
+                                   .append('-')
+                                   .append(current.getId().getClassifier())
+                                   .append("-upgrade");
+
+        Feature featureDiff = compareFeatures(new DefaultDiffRequest()
+                                              .setPrevious(previous)
+                                              .setCurrent(current)
+                                              .setResultId(new ArtifactId(current.getId().getGroupId(),
+                                                                          current.getId().getArtifactId(), 
+                                                                          current.getId().getVersion(),
+                                                                          classifier.toString(),
+                                                                          current.getId().getType())));
+
+        File outputDiffFile = new File(mainOutputDir, classifier.append(".json").toString());
 
         getLog().info("Rendering differences to file " + outputDiffFile);
 
-        try (FileOutputStream output = new FileOutputStream(outputDiffFile)) {
-            FeatureDiffJSONSerializer.serializeFeatureDiff(featureDiff, output);
+        try (FileWriter writer = new FileWriter(outputDiffFile)) {
+            write(writer, featureDiff);
         } catch (IOException e) {
             throw new MojoExecutionException("An error occurred while serializing Feature diff to " + outputDiffFile, e);
         }