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.2.0
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git

commit c2b343f53991aa3c7462c0117e2435006d1bba8b
Author: Carsten Ziegeler <cziege...@apache.org>
AuthorDate: Tue Jun 9 11:37:32 2015 +0000

    SLING-4790 : Removal of artifacts from inherited model is not possible
    
    git-svn-id: 
https://svn.apache.org/repos/asf/sling/trunk/tooling/support/provisioning-model@1684381
 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/provisioning/model/ModelUtility.java     | 93 ++++++++++++----------
 1 file changed, 53 insertions(+), 40 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java 
b/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java
index 4946cbf..8e833b2 100644
--- a/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java
+++ b/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java
@@ -43,6 +43,17 @@ public abstract class ModelUtility {
      * @param additional The additional model.
      */
     public static void merge(final Model base, final Model additional) {
+        merge(base, additional, true);
+    }
+
+    /**
+     * Merge the additional model into the base model.
+     * @param base The base model.
+     * @param additional The additional model.
+     * @param handleRemove Handle special remove run mode
+     * @since 1.2
+     */
+    public static void merge(final Model base, final Model additional, final 
boolean handleRemove) {
         // features
         for(final Feature feature : additional.getFeatures()) {
             final Feature baseFeature = 
base.getOrCreateFeature(feature.getName());
@@ -54,57 +65,59 @@ public abstract class ModelUtility {
             for(final RunMode runMode : feature.getRunModes()) {
                 // check for special remove run mode
                 String names[] = runMode.getNames();
-                if ( names != null ) {
-                    int removeIndex = -1;
-                    int index = 0;
-                    for(final String name : names) {
-                        if ( name.equals(ModelConstants.RUN_MODE_REMOVE) ) {
-                            removeIndex = index;
-                            break;
+                if ( handleRemove ) {
+                    if ( names != null ) {
+                        int removeIndex = -1;
+                        int index = 0;
+                        for(final String name : names) {
+                            if ( name.equals(ModelConstants.RUN_MODE_REMOVE) ) 
{
+                                removeIndex = index;
+                                break;
+                            }
+                            index++;
                         }
-                        index++;
-                    }
-                    if ( removeIndex != -1 ) {
-                        String[] newNames = null;
-                        if ( names.length > 1 ) {
-                            newNames = new String[names.length - 1];
-                            index = 0;
-                            for(final String name : names) {
-                                if ( 
!name.equals(ModelConstants.RUN_MODE_REMOVE) ) {
-                                    newNames[index++] = name;
+                        if ( removeIndex != -1 ) {
+                            String[] newNames = null;
+                            if ( names.length > 1 ) {
+                                newNames = new String[names.length - 1];
+                                index = 0;
+                                for(final String name : names) {
+                                    if ( 
!name.equals(ModelConstants.RUN_MODE_REMOVE) ) {
+                                        newNames[index++] = name;
+                                    }
                                 }
                             }
-                        }
-                        names = newNames;
-                        final RunMode baseRunMode = 
baseFeature.getRunMode(names);
-                        if ( baseRunMode != null ) {
-
-                            // artifact groups
-                            for(final ArtifactGroup group : 
runMode.getArtifactGroups()) {
-                                for(final Artifact artifact : group) {
-                                    for(final ArtifactGroup searchGroup : 
baseRunMode.getArtifactGroups()) {
-                                        final Artifact found = 
searchGroup.search(artifact);
-                                        if ( found != null ) {
-                                            searchGroup.remove(found);
+                            names = newNames;
+                            final RunMode baseRunMode = 
baseFeature.getRunMode(names);
+                            if ( baseRunMode != null ) {
+
+                                // artifact groups
+                                for(final ArtifactGroup group : 
runMode.getArtifactGroups()) {
+                                    for(final Artifact artifact : group) {
+                                        for(final ArtifactGroup searchGroup : 
baseRunMode.getArtifactGroups()) {
+                                            final Artifact found = 
searchGroup.search(artifact);
+                                            if ( found != null ) {
+                                                searchGroup.remove(found);
+                                            }
                                         }
                                     }
                                 }
-                            }
 
-                            // configurations
-                            for(final Configuration config : 
runMode.getConfigurations()) {
-                                final Configuration found = 
baseRunMode.getConfiguration(config.getPid(), config.getFactoryPid());
-                                if ( found != null ) {
-                                    
baseRunMode.getConfigurations().remove(found);
+                                // configurations
+                                for(final Configuration config : 
runMode.getConfigurations()) {
+                                    final Configuration found = 
baseRunMode.getConfiguration(config.getPid(), config.getFactoryPid());
+                                    if ( found != null ) {
+                                        
baseRunMode.getConfigurations().remove(found);
+                                    }
                                 }
-                            }
 
-                            // settings
-                            for(final Map.Entry<String, String> entry : 
runMode.getSettings() ) {
-                                
baseRunMode.getSettings().remove(entry.getKey());
+                                // settings
+                                for(final Map.Entry<String, String> entry : 
runMode.getSettings() ) {
+                                    
baseRunMode.getSettings().remove(entry.getKey());
+                                }
                             }
+                            continue;
                         }
-                        continue;
                     }
                 }
                 final RunMode baseRunMode = 
baseFeature.getOrCreateRunMode(names);

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Reply via email to