FELIX-3552 : Implement new features of DS 1.2
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1350283 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
index 3c73f5e..f1cd0fa 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
@@ -36,6 +36,7 @@
import org.apache.felix.scr.annotations.Services;
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.AnnotationProcessor;
import org.apache.felix.scrplugin.annotations.ClassAnnotation;
import org.apache.felix.scrplugin.annotations.FieldAnnotation;
@@ -54,7 +55,6 @@
import org.apache.felix.scrplugin.description.ReferencePolicy;
import org.apache.felix.scrplugin.description.ReferenceStrategy;
import org.apache.felix.scrplugin.description.ServiceDescription;
-import org.apache.felix.scrplugin.description.SpecVersion;
/**
* This is the processor for the Apache Felix SCR annotations.
diff --git a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
index f32c1a2..0369498 100644
--- a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
+++ b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
@@ -25,6 +25,7 @@
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.AnnotationProcessor;
import org.apache.felix.scrplugin.annotations.ClassAnnotation;
import org.apache.felix.scrplugin.annotations.MethodAnnotation;
@@ -41,7 +42,6 @@
import org.apache.felix.scrplugin.description.ReferencePolicy;
import org.apache.felix.scrplugin.description.ReferenceStrategy;
import org.apache.felix.scrplugin.description.ServiceDescription;
-import org.apache.felix.scrplugin.description.SpecVersion;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
index d282e93..1ab9069 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
@@ -21,7 +21,6 @@
import java.util.Collections;
import java.util.Map;
-import org.apache.felix.scrplugin.description.SpecVersion;
/**
* Options for the {@link SCRDescriptorGenerator}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index 2642a2e..f877206 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -35,7 +35,6 @@
import org.apache.felix.scrplugin.description.ReferenceCardinality;
import org.apache.felix.scrplugin.description.ReferenceDescription;
import org.apache.felix.scrplugin.description.ServiceDescription;
-import org.apache.felix.scrplugin.description.SpecVersion;
import org.apache.felix.scrplugin.helper.AnnotationProcessorManager;
import org.apache.felix.scrplugin.helper.ClassModifier;
import org.apache.felix.scrplugin.helper.ClassScanner;
@@ -659,6 +658,8 @@
ref.setUnbind(rd.getUnbind().getName());
}
if ( rd.getUpdated() != null ) {
+ // updated requires 1.2
+ component.setSpecVersion(SpecVersion.VERSION_1_2);
ref.setUpdated(rd.getUpdated().getName());
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SpecVersion.java
similarity index 90%
rename from scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
rename to scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SpecVersion.java
index 21558d8..0ff3f29 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SpecVersion.java
@@ -11,14 +11,20 @@
* KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
-package org.apache.felix.scrplugin.description;
+package org.apache.felix.scrplugin;
-
+/**
+ * An enumeration for all available spec versions.
+ *
+ * The versions in the enumeration have to be ordered, higher versions must have
+ * a higher ordinal.
+ */
public enum SpecVersion {
VERSION_1_0("1.0", "http://www.osgi.org/xmlns/scr/v1.0.0"), // R4.1
VERSION_1_1("1.1", "http://www.osgi.org/xmlns/scr/v1.1.0"), // R4.2
- VERSION_1_1_FELIX("1.1_FELIX", "http://felix.apache.org/xmlns/scr/v1.1.0-felix"); // R4.2 + FELIX-1893
+ VERSION_1_1_FELIX("1.1_FELIX", "http://felix.apache.org/xmlns/scr/v1.1.0-felix"), // R4.2 + FELIX-1893
+ VERSION_1_2("1.2", "http://www.osgi.org/xmlns/scr/v1.2.0"); // R4.3
/**
* internal human readable name
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ComponentDescription.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ComponentDescription.java
index 0a5dcea..14c2b13 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ComponentDescription.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/ComponentDescription.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.scrplugin.description;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.ScannedAnnotation;
/**
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
index 909a3f1..0d31dce 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
@@ -25,10 +25,10 @@
import java.util.List;
import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.ScannedAnnotation;
import org.apache.felix.scrplugin.description.ClassDescription;
import org.apache.felix.scrplugin.description.ComponentConfigurationPolicy;
-import org.apache.felix.scrplugin.description.SpecVersion;
/**
* <code>Component</code> is a described component.
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java
index f50adee..b97059d 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Components.java
@@ -21,7 +21,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.apache.felix.scrplugin.description.SpecVersion;
+import org.apache.felix.scrplugin.SpecVersion;
/**
* <code>Components</code>...
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
index 5654978..2af92df 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Context.java
@@ -20,8 +20,8 @@
import org.apache.felix.scrplugin.Options;
import org.apache.felix.scrplugin.Project;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.description.ClassDescription;
-import org.apache.felix.scrplugin.description.SpecVersion;
import org.apache.felix.scrplugin.helper.IssueLog;
public class Context {
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java
index 022fead..c041dea 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Property.java
@@ -18,9 +18,9 @@
*/
package org.apache.felix.scrplugin.om;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.ScannedAnnotation;
import org.apache.felix.scrplugin.description.PropertyType;
-import org.apache.felix.scrplugin.description.SpecVersion;
/**
* <code>Property.java</code>...
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
index 3f175a6..ee932e3 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Reference.java
@@ -24,11 +24,11 @@
import java.util.Map;
import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.annotations.ScannedAnnotation;
import org.apache.felix.scrplugin.description.ReferenceCardinality;
import org.apache.felix.scrplugin.description.ReferencePolicy;
import org.apache.felix.scrplugin.description.ReferenceStrategy;
-import org.apache.felix.scrplugin.description.SpecVersion;
import org.apache.felix.scrplugin.helper.StringUtils;
/**
@@ -225,7 +225,7 @@
if (this.updated != null) {
if (context.getSpecVersion().ordinal() < SpecVersion.VERSION_1_1_FELIX.ordinal()) {
this.logError(context.getIssueLog(), "Updated method declaration requires version "
- + SpecVersion.VERSION_1_1_FELIX.getName() + " or newer");
+ + SpecVersion.VERSION_1_1_FELIX.getName() + ", " + SpecVersion.VERSION_1_2 + " or newer");
}
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index 7ea5bc9..48c9d94 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -28,6 +28,7 @@
import javax.xml.transform.TransformerException;
import org.apache.felix.scrplugin.SCRDescriptorException;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.felix.scrplugin.description.ClassDescription;
import org.apache.felix.scrplugin.description.ComponentConfigurationPolicy;
import org.apache.felix.scrplugin.description.ComponentDescription;
@@ -39,7 +40,6 @@
import org.apache.felix.scrplugin.description.ReferencePolicy;
import org.apache.felix.scrplugin.description.ReferenceStrategy;
import org.apache.felix.scrplugin.description.ServiceDescription;
-import org.apache.felix.scrplugin.description.SpecVersion;
import org.apache.felix.scrplugin.helper.IssueLog;
import org.apache.felix.scrplugin.om.Component;
import org.apache.felix.scrplugin.om.Components;
@@ -198,7 +198,7 @@
IOUtils.addAttribute(ai, COMPONENT_ATTR_FACTORY, component.getFactory());
// attributes new in 1.1
- if (SpecVersion.VERSION_1_1.getNamespaceUrl().equals(namespace) || SpecVersion.VERSION_1_1_FELIX.getNamespaceUrl().equals(namespace)) {
+ if (component.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1.ordinal() ) {
if ( component.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL ) {
IOUtils.addAttribute(ai, COMPONENT_ATTR_POLICY, component.getConfigurationPolicy().name());
}
@@ -212,16 +212,16 @@
IOUtils.newline(contentHandler);
generateImplementationXML(component, contentHandler);
if (component.getService() != null) {
- generateXML(component.getService(), contentHandler);
+ generateServiceXML(component.getService(), contentHandler);
}
if (component.getProperties() != null) {
for (final Property property : component.getProperties()) {
- generateXML(property, contentHandler);
+ generatePropertyXML(property, contentHandler);
}
}
if (component.getReferences() != null) {
for (final Reference reference : component.getReferences()) {
- generateXML(namespace, reference, contentHandler);
+ generateReferenceXML(component, reference, contentHandler);
}
}
IOUtils.indent(contentHandler, 1);
@@ -254,7 +254,10 @@
* @param contentHandler
* @throws SAXException
*/
- protected static void generateXML(Service service, ContentHandler contentHandler) throws SAXException {
+ protected static void generateServiceXML(
+ final Service service,
+ final ContentHandler contentHandler)
+ throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "servicefactory", String.valueOf(service.isServiceFactory()));
IOUtils.indent(contentHandler, 2);
@@ -294,7 +297,7 @@
* @param contentHandler
* @throws SAXException
*/
- protected static void generateXML(Property property, ContentHandler contentHandler) throws SAXException {
+ protected static void generatePropertyXML(Property property, ContentHandler contentHandler) throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "name", property.getName());
IOUtils.addAttribute(ai, "type", property.getType());
@@ -323,8 +326,10 @@
* @param contentHandler
* @throws SAXException
*/
- protected static void generateXML(final String namespace, Reference reference, ContentHandler contentHandler)
- throws SAXException {
+ protected static void generateReferenceXML(final Component component,
+ final Reference reference,
+ final ContentHandler contentHandler)
+ throws SAXException {
final AttributesImpl ai = new AttributesImpl();
IOUtils.addAttribute(ai, "name", reference.getName());
IOUtils.addAttribute(ai, "interface", reference.getInterfacename());
@@ -335,7 +340,7 @@
IOUtils.addAttribute(ai, "unbind", reference.getUnbind());
// attributes new in 1.1-felix (FELIX-1893)
- if (SpecVersion.VERSION_1_1_FELIX.getNamespaceUrl().equals(namespace)) {
+ if (component.getSpecVersion().ordinal() >= SpecVersion.VERSION_1_1_FELIX.ordinal() ) {
IOUtils.addAttribute(ai, "updated", reference.getUpdated());
}
@@ -444,8 +449,7 @@
desc.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
// check for version 1.1 attributes
- if (specVersion == SpecVersion.VERSION_1_1
- || specVersion == SpecVersion.VERSION_1_1_FELIX) {
+ if (specVersion.ordinal() >= SpecVersion.VERSION_1_1.ordinal()) {
final String policy = attributes.getValue(COMPONENT_ATTR_POLICY);
if ( policy != null ) {
try {
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index c22f564..5d6f14a 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -37,7 +37,7 @@
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
import org.apache.felix.scrplugin.SCRDescriptorGenerator;
-import org.apache.felix.scrplugin.description.SpecVersion;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
diff --git a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
index ea301d0..34206c4 100644
--- a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
+++ b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
@@ -26,7 +26,7 @@
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
import org.apache.felix.scrplugin.SCRDescriptorGenerator;
import org.apache.felix.scrplugin.Source;
-import org.apache.felix.scrplugin.description.SpecVersion;
+import org.apache.felix.scrplugin.SpecVersion;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.Project;