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.4 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit f1b113a6925858cf757abfaf1f4e8b19d14e58de Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Mon Jun 6 13:29:39 2016 +0000 SLING-5765 : No way to remove an artifact from a special runmode git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/provisioning-model@1746993 13f79535-47bb-0310-9956-ffa450edef68 --- .../sling/provisioning/model/ModelUtility.java | 28 ++++++++++++++--- .../sling/provisioning/model/ModelUtilityTest.java | 36 ++++++++++++++++++++++ src/test/resources/merge/remove-special-base.txt | 26 ++++++++++++++++ src/test/resources/merge/remove-special-merge.txt | 25 +++++++++++++++ 4 files changed, 110 insertions(+), 5 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 376a80a..a5b6d1c 100644 --- a/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java +++ b/src/main/java/org/apache/sling/provisioning/model/ModelUtility.java @@ -171,14 +171,32 @@ public abstract class ModelUtility { for(final RunMode runMode : feature.getRunModes()) { final String[] rm = runMode.getNames(); if ( rm != null ) { - boolean hasSpecial = false; + int hasSpecial = 0; + boolean hasRemove = false; for(final String m : rm) { if ( m.startsWith(":") ) { - if ( hasSpecial ) { - errors.put(runMode, "Invalid modes " + Arrays.toString(rm)); - break; + if ( hasSpecial > 0 ) { + if ( hasSpecial == 1 ) { + if ( ModelConstants.RUN_MODE_REMOVE.equals(m) && !hasRemove) { + hasRemove = true; + hasSpecial = 2; + } else if ( hasRemove && !ModelConstants.RUN_MODE_REMOVE.equals(m) ) { + hasSpecial = 2; + } else { + hasSpecial = 2; + errors.put(runMode, "Invalid modes " + Arrays.toString(rm)); + break; + } + } else { + hasSpecial++; + errors.put(runMode, "Invalid modes " + Arrays.toString(rm)); + break; + } + + } else { + hasSpecial = 1; + hasRemove = ModelConstants.RUN_MODE_REMOVE.equals(m); } - hasSpecial = true; } } } diff --git a/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java b/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java index baf1ec7..d8c3463 100644 --- a/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java +++ b/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java @@ -216,4 +216,40 @@ public class ModelUtilityTest { assertEquals("bar", cfgB.getProperties().get("foo")); assertArrayEquals(new Integer[] {1,2,3}, (Integer[])cfgC.getProperties().get("array")); } + + @Test public void testRemoveFromSpecialRunmode() throws Exception { + final Model base = U.readTestModel("merge/remove-special-base.txt"); + final Model merge = U.readTestModel("merge/remove-special-merge.txt"); + final Model model = ModelUtility.getEffectiveModel(base); + + MergeUtility.merge(model, merge); + + final List<Artifact> group = U.assertArtifactsInGroup(model.getFeature("f").getRunMode(ModelConstants.RUN_MODE_STANDALONE).getArtifactGroup(0), 1); + U.assertArtifact(group.get(0), "g", "b", "1.0.0", "jar", null); + } + + @Test public void testValidateRunModes() throws Exception { + final Model m = new Model(); + final Feature f = m.getOrCreateFeature("f"); + + // single special run mode + final RunMode rm1 = f.getOrCreateRunMode(new String[] {ModelConstants.RUN_MODE_STANDALONE}); + assertNull(ModelUtility.validate(m)); + f.getRunModes().remove(rm1); + + // two special run modes -> error + final RunMode rmA = f.getOrCreateRunMode(new String[] {ModelConstants.RUN_MODE_STANDALONE, ModelConstants.RUN_MODE_WEBAPP}); + assertNotNull(ModelUtility.validate(m)); + f.getRunModes().remove(rmA); + + // two special run modes, one :remove -> ok + final RunMode rmB = f.getOrCreateRunMode(new String[] {ModelConstants.RUN_MODE_STANDALONE, ModelConstants.RUN_MODE_REMOVE}); + assertNull(ModelUtility.validate(m)); + f.getRunModes().remove(rmB); + + // three special run modes, one :remove -> error + final RunMode rmC = f.getOrCreateRunMode(new String[] {ModelConstants.RUN_MODE_STANDALONE, ModelConstants.RUN_MODE_WEBAPP, ModelConstants.RUN_MODE_REMOVE}); + assertNotNull(ModelUtility.validate(m)); + f.getRunModes().remove(rmC); + } } diff --git a/src/test/resources/merge/remove-special-base.txt b/src/test/resources/merge/remove-special-base.txt new file mode 100644 index 0000000..0aeb9de --- /dev/null +++ b/src/test/resources/merge/remove-special-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 runModes=:standalone] + g/a/1.0.0 + g/b/1.0.0 + + + \ No newline at end of file diff --git a/src/test/resources/merge/remove-special-merge.txt b/src/test/resources/merge/remove-special-merge.txt new file mode 100644 index 0000000..a0b7979 --- /dev/null +++ b/src/test/resources/merge/remove-special-merge.txt @@ -0,0 +1,25 @@ +# +# 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 runModes=:standalone,:remove] + g/a/1.0.0 + + + \ No newline at end of file -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.