FELIX-618 - Search the import list for a service and test if the class in question implements the interface.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@673333 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index d6277f5..37b6678 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -346,7 +346,7 @@
component.setEnabled(Boolean.valueOf(getBoolean(tag, Constants.COMPONENT_ENABLED, true)));
component.setFactory(tag.getNamedParameter(Constants.COMPONENT_FACTORY));
-
+
// FELIX-593: immediate attribute does not default to true all the
// times hence we only set it if declared in the tag
if (tag.getNamedParameter(Constants.COMPONENT_IMMEDIATE) != null) {
@@ -404,13 +404,19 @@
component.setService(service);
boolean serviceFactory = false;
for (int i=0; i < services.length; i++) {
- String name = services[i].getNamedParameter(Constants.SERVICE_INTERFACE);
+ final String name = services[i].getNamedParameter(Constants.SERVICE_INTERFACE);
if (StringUtils.isEmpty(name)) {
this.addInterfaces(service, services[i], description);
} else {
+ // check if the value points to a class/interface
+ // and search through the imports
+ final JavaClassDescription serviceClass = description.getReferencedClass(name);
+ if ( serviceClass == null ) {
+ throw new MojoExecutionException("Interface '"+ name + "' in class " + description.getName() + " does not point to a valid class/interface.");
+ }
final Interface interf = new Interface(services[i]);
- interf.setInterfacename(name);
+ interf.setInterfacename(serviceClass.getName());
service.addInterface(interf);
}
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
index 724a395..af008e4 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/JavaClassDescription.java
@@ -125,4 +125,15 @@
* @throws MojoExecutionException
*/
boolean isA(String type) throws MojoExecutionException;
+
+ /**
+ * Search for the class.
+ * If the referenced name is not fully qualified, the imports
+ * of the class are searched.
+ * @param referencedName
+ * @return The java class description or null
+ * @throws MojoExecutionException
+ */
+ JavaClassDescription getReferencedClass(String referencedName)
+ throws MojoExecutionException;
}
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 cb69ee2..576c08a 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
@@ -88,6 +88,14 @@
}
/**
+ * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getReferencedClass(java.lang.String)
+ */
+ public JavaClassDescription getReferencedClass(String referencedName)
+ throws MojoExecutionException {
+ throw new MojoExecutionException("getDescription not support for this class.");
+ }
+
+ /**
* @see org.apache.felix.scrplugin.tags.JavaClassDescription#getImplementedInterfaces()
*/
public JavaClassDescription[] getImplementedInterfaces() throws MojoExecutionException {
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
index db58728..e87c2ae 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/qdox/QDoxJavaClassDescription.java
@@ -203,6 +203,28 @@
}
/**
+ * @see org.apache.felix.scrplugin.tags.JavaClassDescription#getReferencedClass(java.lang.String)
+ */
+ public JavaClassDescription getReferencedClass(final String referencedName) {
+ String className = referencedName;
+ int pos = className.indexOf('.');
+ if ( pos == -1 ) {
+ className = this.searchImport('.' + referencedName);
+ }
+ if ( className == null ) {
+ if ( pos != -1 ) {
+ return null;
+ }
+ className = this.javaClass.getSource().getPackage() + '.' + referencedName;
+ }
+ try {
+ return this.manager.getJavaClassDescription(className);
+ } catch (MojoExecutionException mee) {
+ return null;
+ }
+ }
+
+ /**
* @see org.apache.felix.scrplugin.tags.JavaClassDescription#getImplementedInterfaces()
*/
public JavaClassDescription[] getImplementedInterfaces()