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/02 11:13:07 UTC
svn commit: r608072 - in /felix/trunk: commons/pom/
scrplugin/src/main/java/org/apache/felix/scrplugin/
scrplugin/src/main/java/org/apache/felix/scrplugin/om/
scrplugin/src/main/java/org/apache/felix/scrplugin/tags/
scrplugin/src/main/java/org/apache/f...
Author: cziegeler
Date: Wed Jan 2 02:13:06 2008
New Revision: 608072
URL: http://svn.apache.org/viewvc?rev=608072&view=rev
Log:
FIXED - issue FELIX-444: Improve implemented service detection
https://issues.apache.org/jira/browse/FELIX-444
Modified:
felix/trunk/commons/pom/pom.xml
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.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/cl/ClassLoaderJavaClassDescription.java
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
Modified: felix/trunk/commons/pom/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/commons/pom/pom.xml?rev=608072&r1=608071&r2=608072&view=diff
==============================================================================
--- felix/trunk/commons/pom/pom.xml (original)
+++ felix/trunk/commons/pom/pom.xml Wed Jan 2 02:13:06 2008
@@ -44,12 +44,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
- <version>2.0-beta-6</version>
+ <version>2.0-beta-7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
- <version>1.0-alpha-3</version>
+ <version>1.0-alpha-4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java?rev=608072&r1=608071&r2=608072&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java Wed Jan 2 02:13:06 2008
@@ -19,36 +19,15 @@
package org.apache.felix.scrplugin;
import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.felix.scrplugin.om.Component;
-import org.apache.felix.scrplugin.om.Components;
-import org.apache.felix.scrplugin.om.Implementation;
-import org.apache.felix.scrplugin.om.Interface;
-import org.apache.felix.scrplugin.om.Property;
-import org.apache.felix.scrplugin.om.Reference;
-import org.apache.felix.scrplugin.om.Service;
-import org.apache.felix.scrplugin.om.metatype.AttributeDefinition;
-import org.apache.felix.scrplugin.om.metatype.Designate;
-import org.apache.felix.scrplugin.om.metatype.MTObject;
-import org.apache.felix.scrplugin.om.metatype.MetaData;
-import org.apache.felix.scrplugin.om.metatype.OCD;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaClassDescriptorManager;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaTag;
-import org.apache.felix.scrplugin.tags.ModifiableJavaClassDescription;
+import java.util.*;
+
+import org.apache.felix.scrplugin.om.*;
+import org.apache.felix.scrplugin.om.metatype.*;
+import org.apache.felix.scrplugin.tags.*;
import org.apache.felix.scrplugin.xml.ComponentDescriptorIO;
import org.apache.felix.scrplugin.xml.MetaTypeIO;
import org.apache.maven.model.Resource;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.*;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.StringUtils;
import org.osgi.service.cm.ConfigurationAdmin;
@@ -420,17 +399,7 @@
String name = services[i].getNamedParameter(Constants.SERVICE_INTERFACE);
if (StringUtils.isEmpty(name)) {
- while (description != null) {
- JavaClassDescription[] interfaces = description.getImplementedInterfaces();
- for (int j=0; interfaces != null && j < interfaces.length; j++) {
- final Interface interf = new Interface(services[i]);
- interf.setInterfacename(interfaces[j].getName());
- service.addInterface(interf);
- }
-
- // try super class
- description = description.getSuperClass();
- }
+ this.addInterfaces(service, services[i], description);
} else {
final Interface interf = new Interface(services[i]);
interf.setInterfacename(name);
@@ -441,6 +410,26 @@
}
service.setServicefactory(serviceFactory);
+ }
+
+ /**
+ * Recursively add interfaces to the service.
+ */
+ protected void addInterfaces(final Service service, final JavaTag serviceTag, final JavaClassDescription description)
+ throws MojoExecutionException {
+ if ( description != null ) {
+ JavaClassDescription[] interfaces = description.getImplementedInterfaces();
+ for (int j=0; j < interfaces.length; j++) {
+ final Interface interf = new Interface(serviceTag);
+ interf.setInterfacename(interfaces[j].getName());
+ service.addInterface(interf);
+ // recursivly add interfaces implemented by this interface
+ this.addInterfaces(service, serviceTag, interfaces[j]);
+ }
+
+ // try super class
+ this.addInterfaces(service, serviceTag, description.getSuperClass());
+ }
}
/**
Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java?rev=608072&r1=608071&r2=608072&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Service.java Wed Jan 2 02:13:06 2008
@@ -18,9 +18,7 @@
*/
package org.apache.felix.scrplugin.om;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
import org.apache.maven.plugin.MojoExecutionException;
@@ -32,7 +30,8 @@
protected String servicefactory;
- protected List interfaces = new ArrayList();
+ /** The list of implemented interfaces. */
+ protected final List interfaces = new ArrayList();
/**
* Default constructor.
@@ -57,12 +56,31 @@
return this.interfaces;
}
- public void setInterfaces(List interfaces) {
- this.interfaces = interfaces;
+ /**
+ * Search for an implemented interface.
+ * @param name The name of the interface.
+ * @return The interface if it is implemented by this service or null.
+ */
+ public Interface findInterface(String name) {
+ final Iterator i = this.interfaces.iterator();
+ while ( i.hasNext() ) {
+ final Interface current = (Interface)i.next();
+ if ( current.getInterfacename().equals(name) ) {
+ return current;
+ }
+ }
+ return null;
}
+ /**
+ * Add an interface to the list of interfaces.
+ * @param interf The interface.
+ */
public void addInterface(Interface interf) {
- this.interfaces.add(interf);
+ // add interface only once
+ if ( this.findInterface(interf.getInterfacename()) == null ) {
+ this.interfaces.add(interf);
+ }
}
/**
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=608072&r1=608071&r2=608072&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 Wed Jan 2 02:13:06 2008
@@ -27,6 +27,8 @@
*/
public interface JavaClassDescription {
+ JavaClassDescription[] EMPTY_RESULT = new JavaClassDescription[0];
+
/**
* Get the java class tag with the name.
* @param name
@@ -60,6 +62,12 @@
JavaField[] getFields();
+ /**
+ * Returns an array of the implemented interfaces of this class.
+ * @return An array containing the interfaces or an empty array
+ * if this class does not implement any interface.
+ * @throws MojoExecutionException
+ */
JavaClassDescription[] getImplementedInterfaces() throws MojoExecutionException;
/**
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=608072&r1=608071&r2=608072&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 Wed Jan 2 02:13:06 2008
@@ -18,21 +18,13 @@
*/
package org.apache.felix.scrplugin.tags.cl;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.lang.reflect.*;
+import java.util.*;
import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.om.Component;
import org.apache.felix.scrplugin.om.Reference;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaClassDescriptorManager;
-import org.apache.felix.scrplugin.tags.JavaField;
-import org.apache.felix.scrplugin.tags.JavaMethod;
-import org.apache.felix.scrplugin.tags.JavaTag;
+import org.apache.felix.scrplugin.tags.*;
import org.apache.maven.plugin.MojoExecutionException;
/**
@@ -72,8 +64,8 @@
*/
public JavaClassDescription[] getImplementedInterfaces() throws MojoExecutionException {
Class[] implemented = clazz.getInterfaces();
- if (implemented == null || implemented.length == 0) {
- return null;
+ if (implemented.length == 0) {
+ return JavaClassDescription.EMPTY_RESULT;
}
JavaClassDescription[] jcd = new JavaClassDescription[implemented.length];
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=608072&r1=608071&r2=608072&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 Wed Jan 2 02:13:06 2008
@@ -18,32 +18,18 @@
*/
package org.apache.felix.scrplugin.tags.qdox;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.io.*;
+import java.util.*;
-import org.apache.felix.scrplugin.tags.JavaClassDescription;
-import org.apache.felix.scrplugin.tags.JavaClassDescriptorManager;
+import org.apache.felix.scrplugin.tags.*;
import org.apache.felix.scrplugin.tags.JavaField;
import org.apache.felix.scrplugin.tags.JavaMethod;
-import org.apache.felix.scrplugin.tags.JavaTag;
-import org.apache.felix.scrplugin.tags.ModifiableJavaClassDescription;
import org.apache.maven.plugin.MojoExecutionException;
-import org.objectweb.asm.ClassAdapter;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Label;
-import org.objectweb.asm.MethodVisitor;
-import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.*;
import org.objectweb.asm.tree.ClassNode;
-import com.thoughtworks.qdox.model.DocletTag;
-import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.*;
import com.thoughtworks.qdox.model.JavaParameter;
-import com.thoughtworks.qdox.model.JavaSource;
import com.thoughtworks.qdox.model.Type;
/**
@@ -142,7 +128,7 @@
throws MojoExecutionException {
final JavaClass[] interfaces = this.javaClass.getImplementedInterfaces();
if ( interfaces == null || interfaces.length == 0 ) {
- return new JavaClassDescription[0];
+ return JavaClassDescription.EMPTY_RESULT;
}
final JavaClassDescription[] descs = new JavaClassDescription[interfaces.length];
for(int i=0;i<interfaces.length; i++) {