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