You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:58:30 UTC
[sling-org-apache-sling-provisioning-model] 03/06: SLING-5189 :
Improve start level handling when merging models
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag org.apache.sling.provisioning.model-1.4.2
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit 2c05c45ef6962dcc61f2b89c1dcfb156d55b940f
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Oct 26 17:52:10 2015 +0000
SLING-5189 : Improve start level handling when merging models
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/provisioning-model@1710664 13f79535-47bb-0310-9956-ffa450edef68
---
.../sling/provisioning/model/MergeUtility.java | 25 ++++++++++++++++++++-
.../sling/provisioning/model/MergeUtilityTest.java | 19 ++++++++++++++++
src/test/resources/merge/startlevel-base.txt | 26 ++++++++++++++++++++++
src/test/resources/merge/startlevel-merge.txt | 26 ++++++++++++++++++++++
4 files changed, 95 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java b/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java
index 85e3ad5..0d18a05 100644
--- a/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java
+++ b/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java
@@ -84,6 +84,21 @@ public abstract class MergeUtility {
/**
* Merge the additional model into the base model.
+ * <p>
+ * Merging is performed feature by feature. Each feature is treated separately.
+ * If the base model does not have a feature from the additional model, the complete
+ * feature is added. If the base model has a feature which is not in the additional model,
+ * the feature is left as is.
+ * <p>
+ * For each feature, the following actions are performed:
+ * <ul>
+ * <li>The feature type of the base feature is set to the type of the additional feature.</li>
+ * <li>All additional sections of the additional feature are added to the base feature.</li>
+ * <li>All variables from the additional feature are set on the base feature, overriding
+ * values if already present.</li>
+ * <li>Each run mode of the additional feature is merged into the base feature.</li>
+ * </ul>
+ * <p>
* @param base The base model.
* @param additional The additional model.
* @param options The merge options
@@ -115,6 +130,8 @@ public abstract class MergeUtility {
for(final ArtifactGroup group : runMode.getArtifactGroups()) {
final ArtifactGroup baseGroup = baseRunMode.getOrCreateArtifactGroup(group.getStartLevel());
+ int foundStartLevel = 0;
+
for(final Artifact artifact : group) {
boolean addArtifact = true;
for(final ArtifactGroup searchGroup : baseRunMode.getArtifactGroups()) {
@@ -122,11 +139,13 @@ public abstract class MergeUtility {
if ( found != null ) {
if ( options.isLatestArtifactWins() ) {
searchGroup.remove(found);
+ foundStartLevel = searchGroup.getStartLevel();
} else {
final Version baseVersion = new Version(found.getVersion());
final Version mergeVersion = new Version(artifact.getVersion());
if ( baseVersion.compareTo(mergeVersion) <= 0 ) {
searchGroup.remove(found);
+ foundStartLevel = searchGroup.getStartLevel();
} else {
addArtifact = false;
}
@@ -134,7 +153,11 @@ public abstract class MergeUtility {
}
}
if ( addArtifact ) {
- baseGroup.add(artifact);
+ if ( group.getStartLevel() == 0 && foundStartLevel != 0 ) {
+ baseRunMode.getOrCreateArtifactGroup(foundStartLevel).add(artifact);
+ } else {
+ baseGroup.add(artifact);
+ }
}
}
}
diff --git a/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java b/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java
index 6f35fb0..afff784 100644
--- a/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java
+++ b/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java
@@ -272,4 +272,23 @@ public class MergeUtilityTest {
assertEquals("bar", cfgB.getProperties().get("foo"));
assertArrayEquals(new Integer[] {1,2,3}, (Integer[])cfgC.getProperties().get("array"));
}
+
+ @Test public void mergeStartlevelTest() throws Exception {
+ final Model model = U.readTestModel("merge/startlevel-base.txt");
+ final Model merge = U.readTestModel("merge/startlevel-merge.txt");
+ MergeUtility.merge(model, merge);
+
+ assertNotNull(model.getFeature("f"));
+ assertNotNull(model.getFeature("f").getRunMode());
+ assertNotNull(model.getFeature("f").getRunMode().getArtifactGroup(3));
+ assertNotNull(model.getFeature("f").getRunMode().getArtifactGroup(5));
+ final List<Artifact> list5 = U.assertArtifactsInGroup(model.getFeature("f").getRunMode().getArtifactGroup(5), 1);
+ U.assertArtifact(list5.get(0), "g", "a", "2.0.0", "jar", null);
+
+ final List<Artifact> list3 = U.assertArtifactsInGroup(model.getFeature("f").getRunMode().getArtifactGroup(3), 1);
+ U.assertArtifact(list3.get(0), "g", "b", "1.1.0", "jar", null);
+
+ final List<Artifact> list = U.assertArtifactsInGroup(model.getFeature("f").getRunMode().getArtifactGroup(0), 1);
+ U.assertArtifact(list.get(0), "g", "c", "1.6.0", "jar", null);
+ }
}
diff --git a/src/test/resources/merge/startlevel-base.txt b/src/test/resources/merge/startlevel-base.txt
new file mode 100644
index 0000000..bddadbd
--- /dev/null
+++ b/src/test/resources/merge/startlevel-base.txt
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+[feature name=f]
+
+[artifacts startLevel=5]
+ g/a/1.0.0
+
+[artifacts]
+ g/b/1.0.0
+ g/c/1.0.0
diff --git a/src/test/resources/merge/startlevel-merge.txt b/src/test/resources/merge/startlevel-merge.txt
new file mode 100644
index 0000000..ae04e2a
--- /dev/null
+++ b/src/test/resources/merge/startlevel-merge.txt
@@ -0,0 +1,26 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+[feature name=f]
+
+[artifacts]
+ g/a/2.0.0
+ g/c/1.6.0
+
+[artifacts startLevel=3]
+ g/b/1.1.0
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.