You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2008/01/03 15:40:22 UTC

svn commit: r608505 - in /felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin: om/Component.java tags/JavaClassDescription.java tags/JavaMethod.java tags/cl/ClassLoaderJavaClassDescription.java tags/qdox/QDoxJavaClassDescription.java

Author: cziegeler
Date: Thu Jan  3 06:40:17 2008
New Revision: 608505

URL: http://svn.apache.org/viewvc?rev=608505&view=rev
Log:
RESOLVED - issue FELIX-446: Search of activation/deactivation method might get wrong result 
https://issues.apache.org/jira/browse/FELIX-446

Modified:
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaMethod.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java?rev=608505&r1=608504&r2=608505&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Component.java Thu Jan  3 06:40:17 2008
@@ -18,14 +18,9 @@
  */
 package org.apache.felix.scrplugin.om;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaMethod;
-import org.apache.felix.scrplugin.tags.JavaParameter;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import java.util.*;
+
+import org.apache.felix.scrplugin.tags.*;
 import org.apache.maven.plugin.MojoExecutionException;
 
 /**
@@ -211,8 +206,8 @@
                 // no errors so far, let's continue
                 if ( issues.size() == 0 ) {
                     // check activate and deactivate methods
-                    this.checkActivationMethod(javaClass, "activate", warnings);
-                    this.checkActivationMethod(javaClass, "deactivate", warnings);
+                    this.checkLifecycleMethod(javaClass, "activate", warnings);
+                    this.checkLifecycleMethod(javaClass, "deactivate", warnings);
 
                     // ensure public default constructor
                     boolean constructorFound = true;
@@ -266,50 +261,34 @@
     }
 
     /**
-     * Check methods.
-     * @param javaClass
-     * @param methodName
+     * Check for existence of lifecycle methods.
+     * @param javaClass The java class to inspect.
+     * @param methodName The method name.
+     * @param warnings The list of warnings used to add new warnings.
      */
-    protected void checkActivationMethod(JavaClassDescription javaClass, String methodName, List warnings) {
-        JavaMethod[] methods = javaClass.getMethods();
-        JavaMethod activation = null;
-        for (int i=0; i < methods.length; i++) {
-            // ignore method not matching the name
-            if (!methodName.equals(methods[i].getName())) {
-                continue;
-            }
-
-            // if the method has the correct parameter type, check protected
-            JavaParameter[] params = methods[i].getParameters();
-            if (params == null || params.length != 1) {
-                continue;
+    protected void checkLifecycleMethod(JavaClassDescription javaClass, String methodName, List warnings)
+    throws MojoExecutionException {
+        final JavaMethod method = javaClass.getMethodBySignature(methodName, new String[] {"org.osgi.service.component.ComponentContext"});
+        if ( method != null ) {
+            // check protected
+            if (method.isPublic()) {
+                warnings.add(this.getMessage("Lifecycle method " + method.getName() + " should be declared protected"));
+            } else if (!method.isProtected()) {
+                warnings.add(this.getMessage("Lifecycle method " + method.getName() + " has wrong qualifier, public or protected required"));
             }
-
-            // this might be considered, if it is an overload, drop out of check
-            if (activation != null) {
-                return;
+        } else {
+            // if no method is found, we check for any method with that name
+            final JavaMethod[] methods = javaClass.getMethods();
+            for(int i=0; i<methods.length; i++) {
+                if ( methodName.equals(methods[i].getName()) ) {
+
+                    if ( methods[i].getParameters().length != 1 ) {
+                        warnings.add(this.getMessage("Lifecycle method " + methods[i].getName() + " has wrong number of arguments"));
+                    } else {
+                        warnings.add(this.getMessage("Lifecycle method " + methods[i].getName() + " has wrong argument " + methods[i].getParameters()[0].getType()));
+                    }
+                }
             }
-
-            // consider this method for further checks
-            activation = methods[i];
-        }
-
-        // no activation method found
-        if (activation == null) {
-            return;
-        }
-
-        // check protected
-        if (activation.isPublic()) {
-            warnings.add(this.getMessage("Activation method " + activation.getName() + " should be declared protected"));
-        } else if (!activation.isProtected()) {
-            warnings.add(this.getMessage("Activation method " + activation.getName() + " has wrong qualifier, public or protected required"));
-        }
-
-        // check paramter (we know there is exactly one)
-        JavaParameter param = activation.getParameters()[0];
-        if (!"org.osgi.service.component.ComponentContext".equals(param.getType())) {
-            warnings.add(this.getMessage("Activation method " + methodName + " has wrong argument type " + param.getType()));
         }
     }
 }

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java?rev=608505&r1=608504&r2=608505&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java Thu Jan  3 06:40:17 2008
@@ -98,6 +98,10 @@
      */
     boolean isInterface();
 
+    /**
+     * Return all methods of this class
+     * @return An array of methods or an empty array.
+     */
     JavaMethod[] getMethods();
 
     /**

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaMethod.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaMethod.java?rev=608505&r1=608504&r2=608505&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaMethod.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaMethod.java Thu Jan  3 06:40:17 2008
@@ -24,6 +24,8 @@
  */
 public interface JavaMethod {
 
+    JavaMethod[] EMPTY_RESULT = new JavaMethod[0];
+
     boolean isPublic();
 
     boolean isProtected();

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java?rev=608505&r1=608504&r2=608505&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/cl/ClassLoaderJavaClassDescription.java Thu Jan  3 06:40:17 2008
@@ -111,8 +111,7 @@
      * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getMethods()
      */
     public JavaMethod[] getMethods() {
-        // TODO Auto-generated method stub
-        return null;
+        return JavaMethod.EMPTY_RESULT;
     }
 
     /**

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java?rev=608505&r1=608504&r2=608505&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java Thu Jan  3 06:40:17 2008
@@ -167,7 +167,7 @@
     public JavaMethod[] getMethods() {
         final com.thoughtworks.qdox.model.JavaMethod[] methods = this.javaClass.getMethods();
         if ( methods == null || methods.length == 0) {
-            return new JavaMethod[0];
+            return JavaMethod.EMPTY_RESULT;
         }
         final JavaMethod[] m = new JavaMethod[methods.length];
         for(int i=0;i<methods.length;i++) {