private static boolean handleRemoveRunMode()

in src/main/java/org/apache/sling/provisioning/model/MergeUtility.java [240:294]


    private static boolean handleRemoveRunMode(final Feature baseFeature, final RunMode runMode) {
        String names[] = runMode.getNames();
        int removeIndex = -1;
        int index = 0;
        for(final String name : names) {
            if ( name.equals(ModelConstants.RUN_MODE_REMOVE) ) {
                removeIndex = index;
                break;
            }
            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;
                    }
                }
            }
            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);
                    }
                }

                // settings
                for(final Map.Entry<String, String> entry : runMode.getSettings() ) {
                    baseRunMode.getSettings().remove(entry.getKey());
                }
            }
            return true;
        }
        return false;
    }