Michael Simacek a16fbe
From 05d71f56ce6194bc32cf65f6589e7e035af02454 Mon Sep 17 00:00:00 2001
Michael Simacek a16fbe
From: Michael Simacek <msimacek@redhat.com>
Michael Simacek a16fbe
Date: Mon, 26 Sep 2016 10:08:36 +0200
Michael Simacek a16fbe
Subject: [PATCH 3/3] Use felix annotations
Michael Simacek a16fbe
Michael Simacek a16fbe
---
Michael Simacek a16fbe
 .../src/aQute/bnd/component/AnnotationReader.java  | 27 +++++++++++-----------
Michael Simacek a16fbe
 .../src/aQute/bnd/component/ComponentDef.java      |  3 +--
Michael Simacek a16fbe
 .../src/aQute/bnd/component/DSAnnotations.java     |  9 ++++----
Michael Simacek a16fbe
 .../src/aQute/bnd/component/HeaderReader.java      | 17 +++++++-------
Michael Simacek a16fbe
 .../src/aQute/bnd/component/ReferenceDef.java      |  7 +++---
Michael Simacek a16fbe
 5 files changed, 30 insertions(+), 33 deletions(-)
Michael Simacek a16fbe
Michael Simacek a16fbe
diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/AnnotationReader.java b/biz.aQute.bndlib/src/aQute/bnd/component/AnnotationReader.java
Michael Simacek a16fbe
index 2a890fc..c1d6a3f 100644
Michael Simacek a16fbe
--- a/biz.aQute.bndlib/src/aQute/bnd/component/AnnotationReader.java
Michael Simacek a16fbe
+++ b/biz.aQute.bndlib/src/aQute/bnd/component/AnnotationReader.java
Michael Simacek a16fbe
@@ -12,14 +12,6 @@ import java.util.Map.Entry;
Michael Simacek a16fbe
 import java.util.regex.Matcher;
Michael Simacek a16fbe
 import java.util.regex.Pattern;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.Activate;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.Component;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.Deactivate;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.Modified;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.Reference;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferenceCardinality;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferencePolicy;
Michael Simacek a16fbe
-
Michael Simacek a16fbe
 import aQute.bnd.annotation.xml.XMLAttribute;
Michael Simacek a16fbe
 import aQute.bnd.component.DSAnnotations.Options;
Michael Simacek a16fbe
 import aQute.bnd.component.error.DeclarativeServicesAnnotationError;
Michael Simacek a16fbe
@@ -36,6 +28,13 @@ import aQute.bnd.osgi.Verifier;
Michael Simacek a16fbe
 import aQute.bnd.version.Version;
Michael Simacek a16fbe
 import aQute.bnd.xmlattribute.XMLAttributeFinder;
Michael Simacek a16fbe
 import aQute.lib.collections.MultiMap;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.Activate;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.Component;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.Deactivate;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.Modified;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.Reference;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferenceCardinality;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferencePolicy;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 /**
Michael Simacek a16fbe
  * Processes spec DS annotations into xml.
Michael Simacek a16fbe
@@ -621,11 +620,11 @@ public class AnnotationReader extends ClassDataCollector {
Michael Simacek a16fbe
 				}
Michael Simacek a16fbe
 				if (isCollection) {
Michael Simacek a16fbe
 					if (def.cardinality == null)
Michael Simacek a16fbe
-						def.cardinality = ReferenceCardinality.MULTIPLE;
Michael Simacek a16fbe
+						def.cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE;
Michael Simacek a16fbe
 					def.fieldCollectionType = fieldCollectionType;
Michael Simacek a16fbe
 				}
Michael Simacek a16fbe
-				if (def.policy == ReferencePolicy.DYNAMIC && (def.cardinality == ReferenceCardinality.MULTIPLE
Michael Simacek a16fbe
-						|| def.cardinality == ReferenceCardinality.AT_LEAST_ONE) && member.isFinal()) {
Michael Simacek a16fbe
+				if (def.policy == ReferencePolicy.DYNAMIC && (def.cardinality == ReferenceCardinality.MANDATORY_MULTIPLE
Michael Simacek a16fbe
+						|| def.cardinality == ReferenceCardinality.MANDATORY_UNARY) && member.isFinal()) {
Michael Simacek a16fbe
 					if (def.fieldOption == FieldOption.REPLACE)
Michael Simacek a16fbe
 						analyzer.error(
Michael Simacek a16fbe
 								"In component %s, collection type field: %s is final and dynamic but marked with 'replace' fieldOption. Changing this to 'update'.",
Michael Simacek a16fbe
@@ -838,7 +837,7 @@ public class AnnotationReader extends ClassDataCollector {
Michael Simacek a16fbe
 		component.implementation = clazz.getClassName();
Michael Simacek a16fbe
 		component.name = comp.name();
Michael Simacek a16fbe
 		component.factory = comp.factory();
Michael Simacek a16fbe
-		component.configurationPolicy = comp.configurationPolicy();
Michael Simacek a16fbe
+		component.configurationPolicy = comp.policy();
Michael Simacek a16fbe
 		if (annotation.get("enabled") != null)
Michael Simacek a16fbe
 			component.enabled = comp.enabled();
Michael Simacek a16fbe
 		if (annotation.get("factory") != null)
Michael Simacek a16fbe
@@ -861,8 +860,9 @@ public class AnnotationReader extends ClassDataCollector {
Michael Simacek a16fbe
 			} else {
Michael Simacek a16fbe
 				component.updateVersion(V1_2);
Michael Simacek a16fbe
 			}
Michael Simacek a16fbe
-		}
Michael Simacek a16fbe
+                }
Michael Simacek a16fbe
 
Michael Simacek a16fbe
+                /*
Michael Simacek a16fbe
 		if (annotation.get("xmlns") != null)
Michael Simacek a16fbe
 			component.xmlns = comp.xmlns();
Michael Simacek a16fbe
 
Michael Simacek a16fbe
@@ -882,6 +882,7 @@ public class AnnotationReader extends ClassDataCollector {
Michael Simacek a16fbe
 			}
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 		doProperty(comp.property());
Michael Simacek a16fbe
+                */
Michael Simacek a16fbe
 		Object[] x = annotation.get("service");
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 		if (x == null) {
Michael Simacek a16fbe
diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/ComponentDef.java b/biz.aQute.bndlib/src/aQute/bnd/component/ComponentDef.java
Michael Simacek a16fbe
index ba53142..2cdc58d 100644
Michael Simacek a16fbe
--- a/biz.aQute.bndlib/src/aQute/bnd/component/ComponentDef.java
Michael Simacek a16fbe
+++ b/biz.aQute.bndlib/src/aQute/bnd/component/ComponentDef.java
Michael Simacek a16fbe
@@ -8,8 +8,6 @@ import java.util.List;
Michael Simacek a16fbe
 import java.util.Map;
Michael Simacek a16fbe
 import java.util.TreeMap;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ConfigurationPolicy;
Michael Simacek a16fbe
-
Michael Simacek a16fbe
 import aQute.bnd.osgi.Analyzer;
Michael Simacek a16fbe
 import aQute.bnd.osgi.Descriptors.TypeRef;
Michael Simacek a16fbe
 import aQute.bnd.version.Version;
Michael Simacek a16fbe
@@ -18,6 +16,7 @@ import aQute.bnd.xmlattribute.Namespaces;
Michael Simacek a16fbe
 import aQute.bnd.xmlattribute.XMLAttributeFinder;
Michael Simacek a16fbe
 import aQute.lib.collections.MultiMap;
Michael Simacek a16fbe
 import aQute.lib.tag.Tag;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 /**
Michael Simacek a16fbe
  * This class just holds the information for the component, implementation, and
Michael Simacek a16fbe
diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java b/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java
Michael Simacek a16fbe
index b48f5b9..74e3426 100644
Michael Simacek a16fbe
--- a/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java
Michael Simacek a16fbe
+++ b/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java
Michael Simacek a16fbe
@@ -9,8 +9,6 @@ import java.util.Map;
Michael Simacek a16fbe
 import java.util.Set;
Michael Simacek a16fbe
 import java.util.TreeSet;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferenceCardinality;
Michael Simacek a16fbe
-
Michael Simacek a16fbe
 import aQute.bnd.header.Attrs;
Michael Simacek a16fbe
 import aQute.bnd.header.OSGiHeader;
Michael Simacek a16fbe
 import aQute.bnd.header.Parameters;
Michael Simacek a16fbe
@@ -25,6 +23,7 @@ import aQute.bnd.service.AnalyzerPlugin;
Michael Simacek a16fbe
 import aQute.bnd.version.Version;
Michael Simacek a16fbe
 import aQute.bnd.xmlattribute.XMLAttributeFinder;
Michael Simacek a16fbe
 import aQute.lib.strings.Strings;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferenceCardinality;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 /**
Michael Simacek a16fbe
  * Analyze the class space for any classes that have an OSGi annotation for DS.
Michael Simacek a16fbe
@@ -138,9 +137,9 @@ public class DSAnnotations implements AnalyzerPlugin {
Michael Simacek a16fbe
 	private void addServiceRequirement(ReferenceDef ref, MergedRequirement requires) {
Michael Simacek a16fbe
 		String objectClass = ref.service;
Michael Simacek a16fbe
 		ReferenceCardinality cardinality = ref.cardinality;
Michael Simacek a16fbe
-		boolean optional = cardinality == ReferenceCardinality.OPTIONAL || cardinality == ReferenceCardinality.MULTIPLE;
Michael Simacek a16fbe
-		boolean multiple = cardinality == ReferenceCardinality.MULTIPLE
Michael Simacek a16fbe
-				|| cardinality == ReferenceCardinality.AT_LEAST_ONE;
Michael Simacek a16fbe
+		boolean optional = cardinality == ReferenceCardinality.OPTIONAL_MULTIPLE || cardinality == ReferenceCardinality.OPTIONAL_UNARY;
Michael Simacek a16fbe
+		boolean multiple = cardinality == ReferenceCardinality.MANDATORY_MULTIPLE
Michael Simacek a16fbe
+				|| cardinality == ReferenceCardinality.OPTIONAL_MULTIPLE;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 		String filter = "(objectClass=" + objectClass + ")";
Michael Simacek a16fbe
 		requires.put(filter, "active", optional, multiple);
Michael Simacek a16fbe
diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/HeaderReader.java b/biz.aQute.bndlib/src/aQute/bnd/component/HeaderReader.java
Michael Simacek a16fbe
index b070fbd..e1079b8 100644
Michael Simacek a16fbe
--- a/biz.aQute.bndlib/src/aQute/bnd/component/HeaderReader.java
Michael Simacek a16fbe
+++ b/biz.aQute.bndlib/src/aQute/bnd/component/HeaderReader.java
Michael Simacek a16fbe
@@ -12,11 +12,6 @@ import java.util.StringTokenizer;
Michael Simacek a16fbe
 import java.util.regex.Matcher;
Michael Simacek a16fbe
 import java.util.regex.Pattern;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ConfigurationPolicy;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferenceCardinality;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferencePolicy;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferencePolicyOption;
Michael Simacek a16fbe
-
Michael Simacek a16fbe
 import aQute.bnd.component.error.DeclarativeServicesAnnotationError;
Michael Simacek a16fbe
 import aQute.bnd.component.error.DeclarativeServicesAnnotationError.ErrorType;
Michael Simacek a16fbe
 import aQute.bnd.osgi.Analyzer;
Michael Simacek a16fbe
@@ -29,6 +24,10 @@ import aQute.bnd.osgi.Processor;
Michael Simacek a16fbe
 import aQute.bnd.osgi.Verifier;
Michael Simacek a16fbe
 import aQute.bnd.version.Version;
Michael Simacek a16fbe
 import aQute.lib.tag.Tag;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ConfigurationPolicy;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferenceCardinality;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferencePolicy;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferencePolicyOption;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 public class HeaderReader extends Processor {
Michael Simacek a16fbe
 	final static Pattern				PROPERTY_PATTERN	= Pattern
Michael Simacek a16fbe
@@ -475,15 +474,15 @@ public class HeaderReader extends Processor {
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 			if (optional.contains(referenceName)) {
Michael Simacek a16fbe
 				if (multiple.contains(referenceName)) {
Michael Simacek a16fbe
-					rd.cardinality = ReferenceCardinality.MULTIPLE;
Michael Simacek a16fbe
+					rd.cardinality = ReferenceCardinality.OPTIONAL_MULTIPLE;
Michael Simacek a16fbe
 				} else {
Michael Simacek a16fbe
-					rd.cardinality = ReferenceCardinality.OPTIONAL;
Michael Simacek a16fbe
+					rd.cardinality = ReferenceCardinality.OPTIONAL_UNARY;
Michael Simacek a16fbe
 				}
Michael Simacek a16fbe
 			} else {
Michael Simacek a16fbe
 				if (multiple.contains(referenceName)) {
Michael Simacek a16fbe
-					rd.cardinality = ReferenceCardinality.AT_LEAST_ONE;
Michael Simacek a16fbe
+					rd.cardinality = ReferenceCardinality.MANDATORY_MULTIPLE;
Michael Simacek a16fbe
 				} else {
Michael Simacek a16fbe
-					rd.cardinality = ReferenceCardinality.MANDATORY;
Michael Simacek a16fbe
+					rd.cardinality = ReferenceCardinality.MANDATORY_UNARY;
Michael Simacek a16fbe
 				}
Michael Simacek a16fbe
 			}
Michael Simacek a16fbe
 			if (bind != null) {
Michael Simacek a16fbe
diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/ReferenceDef.java b/biz.aQute.bndlib/src/aQute/bnd/component/ReferenceDef.java
Michael Simacek a16fbe
index d21d63b..679ff45 100644
Michael Simacek a16fbe
--- a/biz.aQute.bndlib/src/aQute/bnd/component/ReferenceDef.java
Michael Simacek a16fbe
+++ b/biz.aQute.bndlib/src/aQute/bnd/component/ReferenceDef.java
Michael Simacek a16fbe
@@ -1,9 +1,5 @@
Michael Simacek a16fbe
 package aQute.bnd.component;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferenceCardinality;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferencePolicy;
Michael Simacek a16fbe
-import org.osgi.service.component.annotations.ReferencePolicyOption;
Michael Simacek a16fbe
-
Michael Simacek a16fbe
 import aQute.bnd.osgi.Analyzer;
Michael Simacek a16fbe
 import aQute.bnd.osgi.Verifier;
Michael Simacek a16fbe
 import aQute.bnd.version.Version;
Michael Simacek a16fbe
@@ -11,6 +7,9 @@ import aQute.bnd.xmlattribute.ExtensionDef;
Michael Simacek a16fbe
 import aQute.bnd.xmlattribute.Namespaces;
Michael Simacek a16fbe
 import aQute.bnd.xmlattribute.XMLAttributeFinder;
Michael Simacek a16fbe
 import aQute.lib.tag.Tag;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferenceCardinality;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferencePolicy;
Michael Simacek a16fbe
+import org.apache.felix.scr.annotations.ReferencePolicyOption;
Michael Simacek a16fbe
 
Michael Simacek a16fbe
 /**
Michael Simacek a16fbe
  * Holds the information in the reference element.
Michael Simacek a16fbe
-- 
Michael Simacek a16fbe
2.7.4
Michael Simacek a16fbe