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/11/12 14:21:38 UTC
[sling-org-apache-sling-feature] branch master updated: SLING-9899
: Support strategy FIRST for artifact merging
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 f5cfdfb SLING-9899 : Support strategy FIRST for artifact merging
f5cfdfb is described below
commit f5cfdfb3393565ef83ab1fb873f457fcc4462556
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Thu Nov 12 15:17:20 2020 +0100
SLING-9899 : Support strategy FIRST for artifact merging
---
.../sling/feature/builder/BuilderContext.java | 4 ++++
.../apache/sling/feature/builder/BuilderUtil.java | 2 ++
.../sling/feature/builder/BuilderUtilTest.java | 24 ++++++++++++++++++++++
3 files changed, 30 insertions(+)
diff --git a/src/main/java/org/apache/sling/feature/builder/BuilderContext.java b/src/main/java/org/apache/sling/feature/builder/BuilderContext.java
index f7c919c..43f1c7d 100644
--- a/src/main/java/org/apache/sling/feature/builder/BuilderContext.java
+++ b/src/main/java/org/apache/sling/feature/builder/BuilderContext.java
@@ -41,6 +41,7 @@ import org.apache.sling.feature.ArtifactId;
* An override rule is an artifact id. As the version for the rule, one of
* {@link BuilderContext#VERSION_OVERRIDE_ALL},
* {@link BuilderContext#VERSION_OVERRIDE_LATEST} or
+ * {@link BuilderContext#VERSION_OVERRIDE_FIRST} or
* {@link BuilderContext#VERSION_OVERRIDE_HIGHEST} as well as any version can be
* specified. If the artifact id should match more than a single artifact
* {@link BuilderContext#COORDINATE_MATCH_ALL} can be specified as group id,
@@ -62,6 +63,9 @@ public class BuilderContext {
/** Used in override rule to select the last candidate applied. */
public static final String VERSION_OVERRIDE_LATEST = "LATEST";
+ /** Used in override rule to select the first candidate applied. */
+ public static final String VERSION_OVERRIDE_FIRST = "FIRST";
+
/** Used in override rule to match all coordinates */
public static final String COORDINATE_MATCH_ALL = "*";
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 efbc1ad..2dba3f0 100644
--- a/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java
+++ b/src/main/java/org/apache/sling/feature/builder/BuilderUtil.java
@@ -250,6 +250,8 @@ class BuilderUtil {
addFeatureOrigin(
selectStartOrder(fromTarget, fromSource, a1v.compareTo(a2v) > 0 ? fromTarget : fromSource),
source, fromSource, fromTarget));
+ } else if (BuilderContext.VERSION_OVERRIDE_FIRST.equalsIgnoreCase(rule)) {
+ result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromTarget), source, fromSource, fromTarget));
} else if (BuilderContext.VERSION_OVERRIDE_LATEST.equalsIgnoreCase(rule)) {
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromSource), source, fromSource, fromTarget));
} else {
diff --git a/src/test/java/org/apache/sling/feature/builder/BuilderUtilTest.java b/src/test/java/org/apache/sling/feature/builder/BuilderUtilTest.java
index c66d523..d547d59 100644
--- a/src/test/java/org/apache/sling/feature/builder/BuilderUtilTest.java
+++ b/src/test/java/org/apache/sling/feature/builder/BuilderUtilTest.java
@@ -145,6 +145,30 @@ public class BuilderUtilTest {
assertContains(result, 3, ArtifactId.parse("g/c/2.5"));
}
+ @Test public void testMergeBundlesWithAlgFirst() {
+ final Bundles target = new Bundles();
+
+ target.add(createBundle("g/a/1.0", 1));
+ target.add(createBundle("g/b/2.0", 2));
+ target.add(createBundle("g/c/2.5", 3));
+
+ final Bundles source = new Bundles();
+ source.add(createBundle("g/a/1.1", 1));
+ source.add(createBundle("g/b/1.9", 2));
+ source.add(createBundle("g/c/2.5", 3));
+
+ final Feature orgFeat = new Feature(new ArtifactId("gid", "aid", "123", null, null));
+
+ List<ArtifactId> overrides = Arrays.asList(ArtifactId.parse("g:a:FIRST"), ArtifactId.parse("g:b:FIRST"));
+ BuilderUtil.mergeArtifacts(target, source, orgFeat, overrides, null);
+
+ final List<Map.Entry<Integer, Artifact>> result = getBundles(target);
+ assertEquals(3, result.size());
+ assertContains(result, 1, ArtifactId.parse("g/a/1.0"));
+ assertContains(result, 2, ArtifactId.parse("g/b/2.0"));
+ assertContains(result, 3, ArtifactId.parse("g/c/2.5"));
+ }
+
@Test public void testMergeBundlesWithAliasNoRule() {
final Bundles target = new Bundles();
Artifact b = createBundle("g/b/2.0", 2);