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/18 21:57:41 UTC
[sling-whiteboard] branch master updated: [feature-diff] renamed
the bundles section, according to the Feature model nomenclature,
README updated
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 a08fdaf [feature-diff] renamed the bundles section, according to the Feature model nomenclature, README updated
a08fdaf is described below
commit a08fdaf9a9f4878b3e3797d3bd28717abd13a756
Author: Simo Tripodi <st...@adobe.com>
AuthorDate: Tue Jun 18 23:57:34 2019 +0200
[feature-diff] renamed the bundles section, according to the Feature
model nomenclature, README updated
---
feature-diff/README.md | 147 ++++-----------------
...factsComparator.java => BundlesComparator.java} | 6 +-
...paratorTest.java => BundlesComparatorTest.java} | 8 +-
3 files changed, 35 insertions(+), 126 deletions(-)
diff --git a/feature-diff/README.md b/feature-diff/README.md
index e2b35d0..69b8d47 100644
--- a/feature-diff/README.md
+++ b/feature-diff/README.md
@@ -9,143 +9,52 @@ This tool aims to provide to Apache Sling users an easy-to-use tool which is abl
Given two different versions of the same `org.apache.sling.feature.Feature`, all we need to do is comparing them
```java
+import static org.apache.sling.feature.diff.FeatureDiff.compareFeatures;
+
import org.apache.sling.feature.Feature
-import org.apache.sling.feature.diff.*;
+import org.apache.sling.feature.diff.DiffRequest;
+import org.apache.sling.feature.diff.DefaultDiffRequest;
...
Feature previous = // somehow obtained
Feature current = // somehow obtained
-FeatureDiff featureDiff = FeatureDiff.compareFeatures(previous, current);
-
-// check which section(s) are detected during the comparison
-
-for (DiffSection diffSection : featureDiff.getSections()) {
- System.out.println(diffSection.getId());
-
- // Removed items from the current version, but present in the previous
- if (diffSection.hasRemoved()) {
- System.out.println(" - Removed");
- for (String value : diffSection.getRemoved()) {
- System.out.println(" * " + value);
- }
- }
+DiffRequest diffRequest = new DefaultDiffRequest()
+ .setPrevious(previous)
+ .setCurrent(current)
+ .setResultId("org.apache.sling:org.apache.sling.diff:1.0.0");
- // Added items to the current version, but not present in the previous
- if (diffSection.hasAdded()) {
- System.out.println(" - Added");
-
- for (String value : diffSection.getAdded()) {
- System.out.println(" * " + value);
- }
- }
-
- // updated items from the previous to the current version
- if (diffSection.hasUpdatedItems() || diffSection.hasUpdates()) {
- System.out.println(" - Updated");
+Feature featureDiff = compareFeatures(previous, current);
+```
- for (UpdatedItem<?> updatedItem : diffSection.getUpdatedItems()) {
- System.out.println(" * " + updatedItem.getId() + " from " + updatedItem.getPrevious() + " to " + updatedItem.getCurrent());
- }
+The resulting `featureDiff` is a new `Feature` instance which prototypes from `previous` and where necessary removals sections are populated and new elements may be added.
- for (DiffSection updatesDiffSection : diffSection.getUpdates()) {
- // there could be iteratively complex sub-sections
- }
- }
-}
-```
+###Please note
-Please note that the `FeatureDiff.compareFeatures(Feature, Feature)` rejects (aka throws an `IllegalArgumentException`) `Feature` inputs that:
+The `FeatureDiff.compareFeatures(Feature, Feature)` rejects (aka throws an `IllegalArgumentException`) `Feature` inputs that:
* are `null` (bien sûr);
- * refer to completely unrelated, different `Feature`;
* refer exactly to the same `Feature`.
-## JSON representation
+## Excluding sections
-The `feature-diff` APIs contain a JSON serializer implementation, `org.apache.sling.feature.diff.io.json.FeatureDiffJSONSerializer`, which use is extremely simple:
+The `DiffRequest` data object can be configured in order to include/exclude one ore more Feature section(s), available are:
-```java
-import org.apache.sling.feature.Feature
-import org.apache.sling.feature.diff.FeatureDiff;
-import org.apache.sling.feature.diff.io.json.FeatureDiffJSONSerializer;
+ * `bundles`
+ * `configurations`
+ * `extensions`
+ * `framework-properties`
-...
+Users can simply add via the include/exclude methods the section(s) they are interested:
-Feature previous = // somehow obtained
-Feature current = // somehow obtained
-FeatureDiff featureDiff = FeatureDiff.compareFeatures(previous, current);
-
-FeatureDiffJSONSerializer.serializeFeatureDiff(featureDiff, System.out);
```
-
-output is quiet easy to interpret, i.e. from a unit test case:
-
-```json
-{
- "vendor":"The Apache Software Foundation",
- "vendorURL":"http://www.apache.org/",
- "generator":"Apache Sling Feature Diff tool",
- "generatorURL":"https://github.com/apache/sling-org-apache-sling-feature-diff",
- "generatedOn":"2019-04-04T11:08:51 +0200",
- "id":"org.apache.sling:org.apache.sling.feature.diff:1.0.0",
- "previousVersion":"0.9.0",
- "framework-properties":{
- "removed":[
- "sling.framework.install.incremental"
- ],
- "added":[
- "sling.framework.install.startlevel"
- ],
- "updated":{
- "env":{
- "previous":"staging",
- "current":"prod"
- }
- }
- },
- "bundles":{
- "removed":[
- "org.apache.sling:org.apache.sling.feature.diff:removed:1.0.0"
- ],
- "added":[
- "org.apache.sling:org.apache.sling.feature.diff:added:1.0.0"
- ],
- "updated":{
- "org.apache.sling:org.apache.sling.feature.diff:updated:2.0.0":{
- "updated":{
- "version":{
- "previous":"1.0.0",
- "current":"2.0.0"
- }
- }
- }
- }
- },
- "configurations":{
- "removed":[
- "org.apache.sling.feature.diff.config.removed"
- ],
- "added":[
- "org.apache.sling.feature.diff.config.added"
- ],
- "updated":{
- "org.apache.sling.feature.diff.config.updated":{
- "removed":[
- "it.will.appear.in.the.removed.section"
- ],
- "added":[
- "it.will.appear.in.the.added.section"
- ],
- "updated":{
- "it.will.appear.in.the.updated.section":{
- "previous":"[{/log}]",
- "current":"[{/log,/etc}]"
- }
- }
- }
- }
- }
-}
+DiffRequest diffRequest = new DefaultDiffRequest()
+ .setPrevious(previous)
+ .setCurrent(current)
+ .addIncludeComparator("bundles")
+ .addIncludeComparator("configurations")
+ .setResultId("org.apache.sling:org.apache.sling.diff:1.0.0");
+
+Feature featureDiff = compareFeatures(previous, current);
```
diff --git a/feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/ArtifactsComparator.java b/feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/BundlesComparator.java
similarity index 93%
rename from feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/ArtifactsComparator.java
rename to feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/BundlesComparator.java
index 5a567b8..f9806ad 100644
--- a/feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/ArtifactsComparator.java
+++ b/feature-diff/src/main/java/org/apache/sling/feature/diff/comparators/BundlesComparator.java
@@ -24,10 +24,10 @@ import org.apache.sling.feature.diff.spi.FeatureElementComparator;
import com.google.auto.service.AutoService;
@AutoService(FeatureElementComparator.class)
-public final class ArtifactsComparator extends AbstractFeatureElementComparator {
+public final class BundlesComparator extends AbstractFeatureElementComparator {
- public ArtifactsComparator() {
- super("artifacts");
+ public BundlesComparator() {
+ super("bundles");
}
@Override
diff --git a/feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/ArtifactsComparatorTest.java b/feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/BundlesComparatorTest.java
similarity index 92%
rename from feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/ArtifactsComparatorTest.java
rename to feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/BundlesComparatorTest.java
index 6462165..b38edf8 100644
--- a/feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/ArtifactsComparatorTest.java
+++ b/feature-diff/src/test/java/org/apache/sling/feature/diff/comparators/BundlesComparatorTest.java
@@ -23,14 +23,14 @@ import static org.junit.Assert.assertTrue;
import org.apache.sling.feature.Artifact;
import org.apache.sling.feature.ArtifactId;
import org.apache.sling.feature.Artifacts;
-import org.apache.sling.feature.diff.comparators.ArtifactsComparator;
+import org.apache.sling.feature.diff.comparators.BundlesComparator;
import org.junit.Test;
-public class ArtifactsComparatorTest extends AbstractComparatorTest<ArtifactsComparator> {
+public class BundlesComparatorTest extends AbstractComparatorTest<BundlesComparator> {
@Override
- protected ArtifactsComparator newComparatorInstance() {
- return new ArtifactsComparator();
+ protected BundlesComparator newComparatorInstance() {
+ return new BundlesComparator();
}
@Test