You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2020/03/26 10:33:44 UTC
[sling-org-apache-sling-feature] branch master updated: SLING-9260
: Aggregation of features might modify source extension
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-feature.git
The following commit(s) were added to refs/heads/master by this push:
new 91080fa SLING-9260 : Aggregation of features might modify source extension
91080fa is described below
commit 91080fa7544dbea0a8f5b28c6cbc63cfeccf847e
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Mar 26 11:33:10 2020 +0100
SLING-9260 : Aggregation of features might modify source extension
---
.../apache/sling/feature/builder/BuilderUtil.java | 4 +--
.../sling/feature/builder/FeatureBuilderTest.java | 37 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java b/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java
index 2154cd0..c79cfd8 100644
--- a/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java
+++ b/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java
@@ -663,8 +663,8 @@ class BuilderUtil {
}
}
if ( !handled ) {
- // no merge handler, just add
- target.getExtensions().add(ext);
+ // no merge handler, just add a copy
+ target.getExtensions().add(ext.copy());
}
}
}
diff --git a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
index 4411dc7..e9da31a 100644
--- a/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
+++ b/src/test/java/org/apache/sling/feature/builder/FeatureBuilderTest.java
@@ -1073,6 +1073,43 @@ public class FeatureBuilderTest {
assertEquals(test, c);
}
+ /**
+ * Merge three features. First feature has no extension, second and third have.
+ * Make sure that the extension of the second feature is not modified.
+ * Then use the aggregated result and merge another feature into it and
+ * merge sure thet the extension of the first aggregation is not modified
+ * (see SLING-9260)
+ */
+ @Test public void testCopyOfExtensionWhenMerging() {
+ final Feature f1 = new Feature(ArtifactId.parse("g/a/1"));
+
+ final Feature f2 = new Feature(ArtifactId.parse("g/b/1"));
+ Extension e2 = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.REQUIRED);
+ e2.setText("line2");
+ f2.getExtensions().add(e2);
+
+ final Feature f3 = new Feature(ArtifactId.parse("g/c/1"));
+ Extension e3 = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.REQUIRED);
+ e3.setText("line3");
+ f3.getExtensions().add(e3);
+
+ final BuilderContext bc = new BuilderContext(provider);
+ final Feature f = FeatureBuilder.assemble(ArtifactId.parse("f/f/1"), bc, f1, f2, f3);
+ assertEquals("line2\nline3", f.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT).getText());
+
+ // e2 is not modified
+ assertEquals("line2", e2.getText());
+
+ final Feature f4 = new Feature(ArtifactId.parse("g/c/1"));
+ Extension e4 = new Extension(ExtensionType.TEXT, Extension.EXTENSION_NAME_REPOINIT, ExtensionState.REQUIRED);
+ e4.setText("line4");
+ f4.getExtensions().add(e4);
+
+ final Feature ff = FeatureBuilder.assemble(ArtifactId.parse("f/g/1"), bc, f, f4);
+ assertEquals("line2\nline3\nline4", ff.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT).getText());
+ assertEquals("line2\nline3", f.getExtensions().getByName(Extension.EXTENSION_NAME_REPOINIT).getText());
+ }
+
private static class MatchingRequirementImpl extends RequirementImpl implements MatchingRequirement {
public MatchingRequirementImpl(Resource res, String ns, Map<String, String> dirs, Map<String, Object> attrs) {