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.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit 7fa873664a1e1319da346236fc9ad31abc18440b Author: Carsten Ziegeler <cziege...@apache.org> AuthorDate: Wed Oct 21 05:47:52 2015 +0000 SLING-5148 : Support OSGi Subsystems in the Sling Provisioning model. git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/provisioning-model@1709720 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/sling/provisioning/model/Feature.java | 42 +++------------------- .../sling/provisioning/model/FeatureTypes.java | 30 ++++++++++++++++ .../sling/provisioning/model/io/ModelReader.java | 2 +- .../sling/provisioning/model/io/ModelWriter.java | 5 +-- .../sling/provisioning/model/FeatureTest.java | 27 +++----------- .../provisioning/model/ModelProcessorTest.java | 10 +++--- .../sling/provisioning/model/ModelUtilityTest.java | 12 +++---- .../org/apache/sling/provisioning/model/U.java | 18 +++++----- 8 files changed, 64 insertions(+), 82 deletions(-) diff --git a/src/main/java/org/apache/sling/provisioning/model/Feature.java b/src/main/java/org/apache/sling/provisioning/model/Feature.java index c78cb3e..0f27e84 100644 --- a/src/main/java/org/apache/sling/provisioning/model/Feature.java +++ b/src/main/java/org/apache/sling/provisioning/model/Feature.java @@ -32,43 +32,11 @@ public class Feature extends Commentable implements Comparable<Feature> { - /** - * The feature type - * @since 1.4.0 - */ - public enum Type { - PLAIN("plain"), - SUBSYSTEM_FEATURE("osgi.subsystem.feature"), - SUBSYSTEM_APPLICATION("osgi.subsystem.application"), - SUBSYSTEM_COMPOSITE("osgi.subsystem.composite"); - - private final String textRepresentation; - - private Type(final String textRep) { - textRepresentation = textRep; - } - - public String getTextRepresentation() { - return textRepresentation; - } - - public static Type fromTextRepresentation(final String textRep) { - if (textRep == null) - return PLAIN; - - for (final Type t : values()) { - if (t.getTextRepresentation().equals(textRep)) - return t; - } - return null; - } - } - /** All run modes. */ private final List<RunMode> runModes = new ArrayList<RunMode>(); /** The type of feature */ - private volatile Type type = Type.PLAIN; + private volatile String type = FeatureTypes.PLAIN; /** Variables. */ private final KeyValueMap<String> variables = new KeyValueMap<String>(); @@ -156,7 +124,7 @@ public class Feature * @return The feature type. * @since 1.4.0 */ - public Type getType() { + public String getType() { return type; } @@ -165,8 +133,8 @@ public class Feature * @param t The new type * @since 1.4.0 */ - public void setType(final Type t) { - type = ( t == null ? Type.PLAIN : t); + public void setType(final String t) { + type = ( t == null ? FeatureTypes.PLAIN : t); } /** @@ -213,7 +181,7 @@ public class Feature public String toString() { return "Feature [runModes=" + runModes + ", variables=" + variables + ", name=" + name - + ( type != Type.PLAIN ? ", type=" + type : "" ) + + ( FeatureTypes.PLAIN.equals(this.type) ? "" : ", type=" + type ) + ( additionalSections.isEmpty() ? "" : ", additionalSections=" + this.additionalSections) + ( this.getLocation() != null ? ", location=" + this.getLocation() : "") + "]"; diff --git a/src/main/java/org/apache/sling/provisioning/model/FeatureTypes.java b/src/main/java/org/apache/sling/provisioning/model/FeatureTypes.java new file mode 100644 index 0000000..54e27ee --- /dev/null +++ b/src/main/java/org/apache/sling/provisioning/model/FeatureTypes.java @@ -0,0 +1,30 @@ +/* + * 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. + */ +package org.apache.sling.provisioning.model; + +/** + * Constants for common feature types. + * @since 1.4.0 + */ +public abstract class FeatureTypes { + + public static final String PLAIN = "plain"; + public static final String SUBSYSTEM_FEATURE = "osgi.subsystem.feature"; + public static final String SUBSYSTEM_APPLICATION = "osgi.subsystem.application"; + public static final String SUBSYSTEM_COMPOSITE = "osgi.subsystem.composite"; + +} diff --git a/src/main/java/org/apache/sling/provisioning/model/io/ModelReader.java b/src/main/java/org/apache/sling/provisioning/model/io/ModelReader.java index 21ef564..836ff77 100644 --- a/src/main/java/org/apache/sling/provisioning/model/io/ModelReader.java +++ b/src/main/java/org/apache/sling/provisioning/model/io/ModelReader.java @@ -196,7 +196,7 @@ public class ModelReader { throw new IOException(exceptionPrefix + "Duplicate feature in line " + this.lineNumberReader.getLineNumber() + ": " + line); } this.feature = model.getOrCreateFeature(name); - this.feature.setType(Feature.Type.fromTextRepresentation(parameters.get("type"))); + this.feature.setType(parameters.get("type")); this.init(this.feature); this.runMode = null; this.artifactGroup = null; diff --git a/src/main/java/org/apache/sling/provisioning/model/io/ModelWriter.java b/src/main/java/org/apache/sling/provisioning/model/io/ModelWriter.java index e6160b3..13e4d00 100644 --- a/src/main/java/org/apache/sling/provisioning/model/io/ModelWriter.java +++ b/src/main/java/org/apache/sling/provisioning/model/io/ModelWriter.java @@ -30,6 +30,7 @@ import org.apache.sling.provisioning.model.ArtifactGroup; import org.apache.sling.provisioning.model.Commentable; import org.apache.sling.provisioning.model.Configuration; import org.apache.sling.provisioning.model.Feature; +import org.apache.sling.provisioning.model.FeatureTypes; import org.apache.sling.provisioning.model.Model; import org.apache.sling.provisioning.model.ModelConstants; import org.apache.sling.provisioning.model.RunMode; @@ -88,9 +89,9 @@ public class ModelWriter { writeComment(pw, feature); pw.print("[feature name="); pw.print(feature.getName()); - if (feature.getType() != Feature.Type.PLAIN) { + if (! FeatureTypes.PLAIN.equals(feature.getType()) ) { pw.print(" type="); - pw.print(feature.getType().getTextRepresentation()); + pw.print(feature.getType()); } pw.println("]"); pw.println(); diff --git a/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java b/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java index a1b9a54..3ac3c36 100644 --- a/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java +++ b/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java @@ -16,35 +16,18 @@ */ package org.apache.sling.provisioning.model; -import org.junit.Test; - import static org.junit.Assert.assertEquals; -public class FeatureTest { - @Test - public void testTypeEnum() { - assertEquals(Feature.Type.SUBSYSTEM_APPLICATION, - Feature.Type.fromTextRepresentation("osgi.subsystem.application")); - assertEquals(Feature.Type.SUBSYSTEM_COMPOSITE, - Feature.Type.fromTextRepresentation("osgi.subsystem.composite")); - assertEquals(Feature.Type.SUBSYSTEM_FEATURE, - Feature.Type.fromTextRepresentation("osgi.subsystem.feature")); - assertEquals(Feature.Type.PLAIN, Feature.Type.fromTextRepresentation(null)); +import org.junit.Test; - assertEquals("osgi.subsystem.application", - Feature.Type.SUBSYSTEM_APPLICATION.getTextRepresentation()); - assertEquals("osgi.subsystem.composite", - Feature.Type.SUBSYSTEM_COMPOSITE.getTextRepresentation()); - assertEquals("osgi.subsystem.feature", - Feature.Type.SUBSYSTEM_FEATURE.getTextRepresentation()); - } +public class FeatureTest { @Test public void testFeatureType() { Feature f = new Feature("blah"); - assertEquals(Feature.Type.PLAIN, f.getType()); + assertEquals(FeatureTypes.PLAIN, f.getType()); - f.setType(Feature.Type.SUBSYSTEM_APPLICATION); - assertEquals(Feature.Type.SUBSYSTEM_APPLICATION, f.getType()); + f.setType(FeatureTypes.SUBSYSTEM_APPLICATION); + assertEquals(FeatureTypes.SUBSYSTEM_APPLICATION, f.getType()); } } diff --git a/src/test/java/org/apache/sling/provisioning/model/ModelProcessorTest.java b/src/test/java/org/apache/sling/provisioning/model/ModelProcessorTest.java index 16efe69..7a9a6a2 100644 --- a/src/test/java/org/apache/sling/provisioning/model/ModelProcessorTest.java +++ b/src/test/java/org/apache/sling/provisioning/model/ModelProcessorTest.java @@ -18,15 +18,15 @@ */ package org.apache.sling.provisioning.model; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + import java.util.Enumeration; import java.util.Map.Entry; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - public class ModelProcessorTest { private Model testModel; @@ -40,7 +40,7 @@ public class ModelProcessorTest { Feature feature1 = testModel.getOrCreateFeature("feature1"); feature1.setLocation("LocF1"); feature1.setComment("ComF1"); - feature1.setType(Feature.Type.SUBSYSTEM_COMPOSITE); + feature1.setType(FeatureTypes.SUBSYSTEM_COMPOSITE); feature1.getVariables().setLocation("LocFV1"); feature1.getVariables().setComment("ComFV1"); feature1.getVariables().put("k1", "v1"); @@ -96,7 +96,7 @@ public class ModelProcessorTest { assertNotNull(feature1); assertEquals("LocF1", feature1.getLocation()); assertEquals("ComF1", feature1.getComment()); - assertEquals(Feature.Type.SUBSYSTEM_COMPOSITE, feature1.getType()); + assertEquals(FeatureTypes.SUBSYSTEM_COMPOSITE, feature1.getType()); assertEquals("LocFV1", feature1.getVariables().getLocation()); assertEquals("ComFV1", feature1.getVariables().getComment()); assertEquals("#v1", feature1.getVariables().get("k1")); 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 b902ac1..baf1ec7 100644 --- a/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java +++ b/src/test/java/org/apache/sling/provisioning/model/ModelUtilityTest.java @@ -16,16 +16,16 @@ */ package org.apache.sling.provisioning.model; -import java.util.List; - -import org.junit.Test; - import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import java.util.List; + +import org.junit.Test; + public class ModelUtilityTest { @Test public void mergeArtifactsTest() throws Exception { @@ -41,7 +41,7 @@ public class ModelUtilityTest { final List<Artifact> list = U.assertArtifactsInGroup(model.getFeature("f").getRunMode().getArtifactGroup(3), 1); U.assertArtifact(list.get(0), "g", "a", "2.0.0", "jar", null); - assertEquals(Feature.Type.SUBSYSTEM_COMPOSITE, model.getFeature("f").getType()); + assertEquals(FeatureTypes.SUBSYSTEM_COMPOSITE, model.getFeature("f").getType()); } @Test public void removeTest() throws Exception { @@ -52,7 +52,7 @@ public class ModelUtilityTest { assertNotNull(model.getFeature("f").getRunMode()); assertNotNull(model.getFeature("f").getRunMode().getArtifactGroup(5)); assertNotNull(model.getFeature("f").getRunMode().getArtifactGroup(7)); - assertEquals(Feature.Type.PLAIN, model.getFeature("f").getType()); + assertEquals(FeatureTypes.PLAIN, model.getFeature("f").getType()); final List<Artifact> group5 = U.assertArtifactsInGroup(model.getFeature("f").getRunMode().getArtifactGroup(5), 1); U.assertArtifact(group5.get(0), "g", "a", "1.0.0", "jar", null); diff --git a/src/test/java/org/apache/sling/provisioning/model/U.java b/src/test/java/org/apache/sling/provisioning/model/U.java index 7c6b2ed..de1c00f 100644 --- a/src/test/java/org/apache/sling/provisioning/model/U.java +++ b/src/test/java/org/apache/sling/provisioning/model/U.java @@ -16,14 +16,6 @@ */ package org.apache.sling.provisioning.model; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.sling.provisioning.model.io.ModelReader; - import static org.apache.sling.provisioning.model.ModelConstants.DEFAULT_RUN_MODE; import static org.apache.sling.provisioning.model.ModelConstants.DEFAULT_START_LEVEL; import static org.junit.Assert.assertEquals; @@ -32,6 +24,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.sling.provisioning.model.io.ModelReader; + /** Test utilities */ public class U { @@ -120,7 +120,7 @@ public class U { final Feature exampleFeature = m.getFeature("example"); final RunMode defaultExampleRM = exampleFeature.getRunMode(); final List<Configuration> configs = assertConfigurationsInRunMode(defaultExampleRM, 3); - assertEquals(Feature.Type.SUBSYSTEM_FEATURE, exampleFeature.getType()); + assertEquals(FeatureTypes.SUBSYSTEM_FEATURE, exampleFeature.getType()); final Configuration cfg = assertConfiguration(configs, "org.apache.sling.another.config"); } -- To stop receiving notification emails like this one, please contact "commits@sling.apache.org" <commits@sling.apache.org>.