You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:58:44 UTC
[sling-org-apache-sling-provisioning-model] 03/05: SLING-6181 :
Support adding version info to Feature
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.5.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-provisioning-model.git
commit af9d553d597f187a45a3e283f8773cb919f10d46
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Sun Oct 23 08:47:59 2016 +0000
SLING-6181 : Support adding version info to Feature
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/tooling/support/provisioning-model@1766252 13f79535-47bb-0310-9956-ffa450edef68
---
pom.xml | 4 +-
.../apache/sling/provisioning/model/Feature.java | 22 ++++++++
.../sling/provisioning/model/io/ModelReader.java | 3 +-
.../sling/provisioning/model/io/ModelWriter.java | 4 ++
.../sling/provisioning/model/package-info.java | 2 +-
.../sling/provisioning/model/FeatureTest.java | 60 ++++++++++++++++++++++
.../org/apache/sling/provisioning/model/U.java | 20 ++++----
src/test/resources/feature.txt | 27 ++++++++++
8 files changed, 128 insertions(+), 14 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4205d2e..c5a3548 100644
--- a/pom.xml
+++ b/pom.xml
@@ -17,7 +17,7 @@
<parent>
<groupId>org.apache.sling</groupId>
<artifactId>sling</artifactId>
- <version>26</version>
+ <version>29</version>
<relativePath />
</parent>
@@ -57,7 +57,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.configadmin</artifactId>
- <version>1.8.6</version>
+ <version>1.8.10</version>
<scope>provided</scope>
</dependency>
<dependency>
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 0f27e84..65d5fbc 100644
--- a/src/main/java/org/apache/sling/provisioning/model/Feature.java
+++ b/src/main/java/org/apache/sling/provisioning/model/Feature.java
@@ -25,6 +25,7 @@ import java.util.List;
/**
* A feature is a collection of
* - a name
+ * - a version
* - variables
* - run modes
*/
@@ -38,6 +39,9 @@ public class Feature
/** The type of feature */
private volatile String type = FeatureTypes.PLAIN;
+ /** The version of the feature */
+ private volatile String version;
+
/** Variables. */
private final KeyValueMap<String> variables = new KeyValueMap<String>();
@@ -64,6 +68,15 @@ public class Feature
}
/**
+ * Get the version of the feature.
+ * @return The version string or {@code null}
+ * @since 1.6.0
+ */
+ public String getVersion() {
+ return this.version;
+ }
+
+ /**
* Special feature?
* @return true if the feature is special
*/
@@ -129,6 +142,15 @@ public class Feature
}
/**
+ * Set the version.
+ * @param v The new version
+ * @since 1.6.0
+ */
+ public void setVersion(final String v) {
+ this.version = v;
+ }
+
+ /**
* Set the feature type.
* @param t The new type
* @since 1.4.0
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 98619a4..a5a1779 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
@@ -40,7 +40,7 @@ public class ModelReader {
private enum CATEGORY {
NONE(null, null),
- FEATURE("feature", new String[] {"name", "type"}),
+ FEATURE("feature", new String[] {"name", "type", "version"}),
VARIABLES("variables", null),
ARTIFACTS("artifacts", new String[] {"runModes", "startLevel"}),
SETTINGS("settings", new String[] {"runModes"}),
@@ -200,6 +200,7 @@ public class ModelReader {
}
this.feature = model.getOrCreateFeature(name);
this.feature.setType(parameters.get("type"));
+ this.feature.setVersion(parameters.get("version"));
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 de004d9..d503628 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
@@ -93,6 +93,10 @@ public class ModelWriter {
pw.print(" type=");
pw.print(feature.getType());
}
+ if ( feature.getVersion() != null ) {
+ pw.print(" version=");
+ pw.print(feature.getVersion());
+ }
pw.println("]");
pw.println();
diff --git a/src/main/java/org/apache/sling/provisioning/model/package-info.java b/src/main/java/org/apache/sling/provisioning/model/package-info.java
index a8beffb..9821b30 100644
--- a/src/main/java/org/apache/sling/provisioning/model/package-info.java
+++ b/src/main/java/org/apache/sling/provisioning/model/package-info.java
@@ -17,7 +17,7 @@
* under the License.
*/
-@Version("1.5.0")
+@Version("1.6.0")
package org.apache.sling.provisioning.model;
import aQute.bnd.annotation.Version;
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 3ac3c36..879a4f4 100644
--- a/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java
+++ b/src/test/java/org/apache/sling/provisioning/model/FeatureTest.java
@@ -17,7 +17,14 @@
package org.apache.sling.provisioning.model;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.apache.sling.provisioning.model.io.ModelReader;
+import org.apache.sling.provisioning.model.io.ModelWriter;
import org.junit.Test;
public class FeatureTest {
@@ -30,4 +37,57 @@ public class FeatureTest {
f.setType(FeatureTypes.SUBSYSTEM_APPLICATION);
assertEquals(FeatureTypes.SUBSYSTEM_APPLICATION, f.getType());
}
+
+ @Test
+ public void testFeatureVersion() {
+ Feature f = new Feature("blah");
+ assertNull(f.getVersion());
+
+ f.setVersion("1.0.0");
+ assertEquals("1.0.0", f.getVersion());
+ }
+
+ @Test
+ public void testFeatureVersions() throws Exception {
+ final Model m = U.readTestModel("feature.txt");
+
+ assertEquals(3, m.getFeatures().size());
+ Feature a = m.getFeature("a");
+ assertNotNull(a);
+ assertEquals("1.0", a.getVersion());
+
+ Feature b = m.getFeature("b");
+ assertNotNull(b);
+ assertNull(b.getVersion());
+
+ Feature c = m.getFeature("c");
+ assertNotNull(c);
+ assertEquals("2.0", c.getVersion());
+
+ // Write the model
+ StringWriter writer = new StringWriter();
+ try {
+ ModelWriter.write(writer, m);
+ } finally {
+ writer.close();
+ }
+
+ // read it again
+ StringReader reader = new StringReader(writer.toString());
+ final Model readModel = ModelReader.read(reader, "memory");
+ reader.close();
+
+ assertEquals(3, readModel.getFeatures().size());
+ a = readModel.getFeature("a");
+ assertNotNull(a);
+ assertEquals("1.0", a.getVersion());
+
+ b = readModel.getFeature("b");
+ assertNotNull(b);
+ assertNull(b.getVersion());
+
+ c = readModel.getFeature("c");
+ assertNotNull(c);
+ assertEquals("2.0", c.getVersion());
+ }
}
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 064cc0e..5c7fdea 100644
--- a/src/test/java/org/apache/sling/provisioning/model/U.java
+++ b/src/test/java/org/apache/sling/provisioning/model/U.java
@@ -16,6 +16,14 @@
*/
package org.apache.sling.provisioning.model;
+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;
+import static org.junit.Assert.assertFalse;
+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;
@@ -25,14 +33,6 @@ 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;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
/** Test utilities */
public class U {
@@ -84,7 +84,7 @@ public class U {
if (errors != null ) {
throw new Exception("Invalid model at " + name + " : " + errors);
}
- ModelUtility.merge(result, current);
+ MergeUtility.merge(result, current);
} finally {
reader.close();
}
@@ -144,7 +144,7 @@ public class U {
final RunMode defaultExampleRM = exampleFeature.getRunMode();
final List<Configuration> configs = assertConfigurationsInRunMode(defaultExampleRM, 3);
assertEquals(FeatureTypes.SUBSYSTEM_COMPOSITE, exampleFeature.getType());
- final Configuration cfg = assertConfiguration(configs, "org.apache.sling.another.config");
+ assertConfiguration(configs, "org.apache.sling.another.config");
}
public static Configuration assertConfiguration(final List<Configuration> configs, final String pid) {
diff --git a/src/test/resources/feature.txt b/src/test/resources/feature.txt
new file mode 100644
index 0000000..c7b5cc6
--- /dev/null
+++ b/src/test/resources/feature.txt
@@ -0,0 +1,27 @@
+#
+# 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=a version=1.0]
+ org.apache.jackrabbit/oak-core/1.0.0/jar
+
+[feature name=b]
+ org.apache.jackrabbit/oak-core/1.0.0/jar
+
+[feature name=c version=2.0]
+ org.apache.jackrabbit/oak-core/2.0.0/jar
+
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.