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 2015/10/26 18:52:11 UTC

svn commit: r1710664 - in /sling/trunk/tooling/support/provisioning-model/src: main/java/org/apache/sling/provisioning/model/ test/java/org/apache/sling/provisioning/model/ test/resources/merge/

Author: cziegeler
Date: Mon Oct 26 17:52:10 2015
New Revision: 1710664

URL: http://svn.apache.org/viewvc?rev=1710664&view=rev
Log:
SLING-5189 : Improve start level handling when merging models

Added:
    sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt   (with props)
    sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt   (with props)
Modified:
    sling/trunk/tooling/support/provisioning-model/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java
    sling/trunk/tooling/support/provisioning-model/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java

Modified: sling/trunk/tooling/support/provisioning-model/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/provisioning-model/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java?rev=1710664&r1=1710663&r2=1710664&view=diff
==============================================================================
--- sling/trunk/tooling/support/provisioning-model/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java (original)
+++ sling/trunk/tooling/support/provisioning-model/src/main/java/org/apache/sling/provisioning/model/MergeUtility.java Mon Oct 26 17:52:10 2015
@@ -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);
+                            }
                         }
                     }
                 }

Modified: sling/trunk/tooling/support/provisioning-model/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/provisioning-model/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java?rev=1710664&r1=1710663&r2=1710664&view=diff
==============================================================================
--- sling/trunk/tooling/support/provisioning-model/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java (original)
+++ sling/trunk/tooling/support/provisioning-model/src/test/java/org/apache/sling/provisioning/model/MergeUtilityTest.java Mon Oct 26 17:52:10 2015
@@ -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);
+    }
 }

Added: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt?rev=1710664&view=auto
==============================================================================
--- sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt (added)
+++ sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt Mon Oct 26 17:52:10 2015
@@ -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 

Propchange: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-base.txt
------------------------------------------------------------------------------
    svn:keywords = Id

Added: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt?rev=1710664&view=auto
==============================================================================
--- sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt (added)
+++ sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt Mon Oct 26 17:52:10 2015
@@ -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

Propchange: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/tooling/support/provisioning-model/src/test/resources/merge/startlevel-merge.txt
------------------------------------------------------------------------------
    svn:keywords = Id