FELIX-1229 : Deactivate has more possibilites than activate; update versions as this are new major features.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@784162 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr-annotations/pom.xml b/scr-annotations/pom.xml
index 3cc038e..e050756 100644
--- a/scr-annotations/pom.xml
+++ b/scr-annotations/pom.xml
@@ -29,7 +29,7 @@
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
- <version>0.9.1-SNAPSHOT</version>
+ <version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Annotations for Maven SCR Plugin</name>
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 1402dc5..600f0e2 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -29,7 +29,7 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
- <version>1.2.1-SNAPSHOT</version>
+ <version>1.4.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven SCR Plugin</name>
@@ -109,7 +109,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
- <version>0.9.0</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
index 249d30b..dbec228 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
@@ -266,8 +266,8 @@
final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate;
// check activate and deactivate methods
- this.checkLifecycleMethod(specVersion, javaClass, activateName, iLog);
- this.checkLifecycleMethod(specVersion, javaClass, deactivateName, iLog);
+ this.checkLifecycleMethod(specVersion, javaClass, activateName, true, iLog);
+ this.checkLifecycleMethod(specVersion, javaClass, deactivateName, false, iLog);
// ensure public default constructor
boolean constructorFound = true;
@@ -338,6 +338,9 @@
private static final String TYPE_COMPONENT_CONTEXT = "org.osgi.service.component.ComponentContext";
private static final String TYPE_BUNDLE_CONTEXT = "org.osgi.framework.BundleContext";
private static final String TYPE_MAP = "java.util.Map";
+ private static final String TYPE_INT = "int";
+ private static final String TYPE_INTEGER = "java.lang.Integer";
+
/**
* Check for existence of lifecycle methods.
* @param specVersion The spec version
@@ -348,6 +351,7 @@
protected void checkLifecycleMethod(final int specVersion,
final JavaClassDescription javaClass,
final String methodName,
+ final boolean isActivate,
final IssueLog iLog)
throws MojoExecutionException {
// first candidate is (de)activate(ComponentContext)
@@ -361,11 +365,20 @@
method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_MAP});
if ( method == null ) {
+ // if this is a deactivate method, we have two additional possibilities
+ // a method with parameter of type int and one of type Integer
+ if ( !isActivate ) {
+ method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_INT});
+ if ( method == null ) {
+ method = javaClass.getMethodBySignature(methodName, new String[] {TYPE_INTEGER});
+ }
+ }
+
// fourth candidate is (de)activate with two or three arguments (type must be BundleContext, ComponentCtx and Map)
// as we have to iterate now and the fifth candidate is zero arguments
// we already store this option
JavaMethod zeroArgMethod = null;
- JavaMethod found = null;
+ JavaMethod found = method;
final JavaMethod[] methods = javaClass.getMethods();
int i = 0;
while ( i < methods.length && found == null ) {
@@ -373,14 +386,17 @@
if ( methods[i].getParameters().length == 0 ) {
zeroArgMethod = methods[i];
- } else if ( methods[i].getParameters().length == 2 || methods[i].getParameters().length == 3) {
+ } else if ( methods[i].getParameters().length >= 2 ) {
boolean valid = true;
for(int m=0; m<methods[i].getParameters().length; m++) {
final String type = methods[i].getParameters()[m].getType();
if ( !type.equals(TYPE_BUNDLE_CONTEXT)
&& !type.equals(TYPE_COMPONENT_CONTEXT)
&& !type.equals(TYPE_MAP) ) {
- valid = false;
+ // if this is deactivate, int and integer are possible as well
+ if ( isActivate || (!type.equals(TYPE_INT) && !type.equals(TYPE_INTEGER)) ) {
+ valid = false;
+ }
}
}
if ( valid ) {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
index 299f83f..c7cba6f 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
@@ -34,13 +34,13 @@
protected static final JavaTag[] EMPTY_TAGS = new JavaTag[0];
- protected final Class clazz;
+ protected final Class<?> clazz;
protected final JavaClassDescriptorManager manager;
protected final Component component;
- public ClassLoaderJavaClassDescription(Class c, Component comp, JavaClassDescriptorManager m) {
+ public ClassLoaderJavaClassDescription(Class<?> c, Component comp, JavaClassDescriptorManager m) {
this.clazz = c;
this.manager = m;
this.component = comp;
@@ -99,7 +99,7 @@
* @see org.apache.felix.scrplugin.tags.JavaClassDescription#getImplementedInterfaces()
*/
public JavaClassDescription[] getImplementedInterfaces() throws MojoExecutionException {
- Class[] implemented = clazz.getInterfaces();
+ Class<?>[] implemented = clazz.getInterfaces();
if (implemented.length == 0) {
return JavaClassDescription.EMPTY_RESULT;
}
@@ -116,7 +116,7 @@
*/
public JavaMethod getMethodBySignature(String name, String[] parameters)
throws MojoExecutionException {
- Class[] classParameters = null;
+ Class<?>[] classParameters = null;
if ( parameters != null ) {
classParameters = new Class[parameters.length];
for(int i=0; i<parameters.length; i++) {
@@ -235,8 +235,8 @@
return this.testClass(this.clazz, type);
}
- protected boolean testClass(Class c, String type) {
- final Class[] interfaces = c.getInterfaces();
+ protected boolean testClass(Class<?> c, String type) {
+ final Class<?>[] interfaces = c.getInterfaces();
for(int i=0; i<interfaces.length; i++) {
if ( interfaces[i].getName().equals(type) ) {
return true;