FELIX-3550 : Reimplement the SCR Generator
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1351105 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
index 42ddd91..986fc5f 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
@@ -63,6 +63,13 @@
public class SCRAnnotationProcessor implements AnnotationProcessor {
/**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getName()
+ */
+ public String getName() {
+ return "Apache Felix SCR Annotation Processor";
+ }
+
+ /**
* @throws SCRDescriptorException
* @throws SCRDescriptorFailureException
* @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
index b7614a2..fc5c721 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
@@ -41,6 +41,13 @@
public class SlingAnnotationProcessor implements AnnotationProcessor {
/**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getName()
+ */
+ public String getName() {
+ return "Apache Sling Annotation Processor";
+ }
+
+ /**
* @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
*/
public void process(final ScannedClass scannedClass,
diff --git a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
index 3dcb4f3..b67787a 100644
--- a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
+++ b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
@@ -55,6 +55,13 @@
public class DSAnnotationProcessor implements AnnotationProcessor {
/**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getName()
+ */
+ public String getName() {
+ return "DS Annotation Processor";
+ }
+
+ /**
* @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#process(org.apache.felix.scrplugin.annotations.ScannedClass, org.apache.felix.scrplugin.description.ClassDescription)
*/
public void process(final ScannedClass scannedClass,
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
index 1ab9069..8599040 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
@@ -18,6 +18,7 @@
*/
package org.apache.felix.scrplugin;
+import java.io.File;
import java.util.Collections;
import java.util.Map;
@@ -35,15 +36,11 @@
private SpecVersion specVersion;
- private String[] annotationProcessors;
+ private File outputDirectory;
- public String[] getAnnotationProcessors() {
- return annotationProcessors;
- }
+ private String scrName = "serviceComponents.xml";
- public void setAnnotationProcessors(String[] annotationProcessors) {
- this.annotationProcessors = annotationProcessors;
- }
+ private String metaTypeName = "metatype.xml";
public boolean isGenerateAccessors() {
return generateAccessors;
@@ -113,4 +110,49 @@
this.specVersion = specVersion;
}
+ /**
+ * Sets the directory where the descriptor files will be created.
+ * <p>
+ * This field has no default value and this setter <b>must</b> called prior to calling {@link #execute()}.
+ */
+ public void setOutputDirectory(final File outputDirectory) {
+ this.outputDirectory = outputDirectory;
+ }
+
+ /**
+ * Sets the name of the SCR declaration descriptor file. This file will be
+ * created in the <i>OSGI-INF</i> directory below the {@link #setOutputDirectory(File) output directory}.
+ * <p>
+ * This file will be overwritten if already existing. If no descriptors are created the file is actually removed.
+ * <p>
+ * The default value of this property is <code>serviceComponents.xml</code>.
+ */
+ public void setSCRName(final String finalName) {
+ this.scrName = finalName;
+ }
+
+ /**
+ * Sets the name of the file taking the Metatype Service descriptors. This
+ * file will be created in the <i>OSGI-INF/metatype</i> directory below the {@link #setOutputDirectory(File) output directory}
+ * .
+ * <p>
+ * This file will be overwritten if already existing. If no descriptors are created the file is actually removed.
+ * <p>
+ * The default value of this property is <code>metatype.xml</code>.
+ */
+ public void setMetaTypeName(final String metaTypeName) {
+ this.metaTypeName = metaTypeName;
+ }
+
+ public File getOutputDirectory() {
+ return this.outputDirectory;
+ }
+
+ public String getMetaTypeName() {
+ return this.metaTypeName;
+ }
+
+ public String getSCRName() {
+ return this.scrName;
+ }
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index c36c534..73e2c1a 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -72,12 +72,6 @@
private final Log logger;
- private File outputDirectory;
-
- private String finalName = "serviceComponents.xml";
-
- private String metaTypeName = "metatype.xml";
-
/** The project. */
private Project project;
@@ -113,40 +107,6 @@
}
/**
- * Sets the directory where the descriptor files will be created.
- * <p>
- * This field has no default value and this setter <b>must</b> called prior to calling {@link #execute()}.
- */
- public void setOutputDirectory(final File outputDirectory) {
- this.outputDirectory = outputDirectory;
- }
-
- /**
- * Sets the name of the SCR declaration descriptor file. This file will be
- * created in the <i>OSGI-INF</i> directory below the {@link #setOutputDirectory(File) output directory}.
- * <p>
- * This file will be overwritten if already existing. If no descriptors are created the file is actually removed.
- * <p>
- * The default value of this property is <code>serviceComponents.xml</code>.
- */
- public void setFinalName(final String finalName) {
- this.finalName = finalName;
- }
-
- /**
- * Sets the name of the file taking the Metatype Service descriptors. This
- * file will be created in the <i>OSGI-INF/metatype</i> directory below the {@link #setOutputDirectory(File) output directory}
- * .
- * <p>
- * This file will be overwritten if already existing. If no descriptors are created the file is actually removed.
- * <p>
- * The default value of this property is <code>metatype.xml</code>.
- */
- public void setMetaTypeName(final String metaTypeName) {
- this.metaTypeName = metaTypeName;
- }
-
- /**
* Actually generates the Declarative Services and Metatype descriptors
* scanning the java sources provided by the {@link #setProject(Project)}
*
@@ -179,7 +139,7 @@
this.iLog = new IssueLog(this.options.isStrictMode());
// create the annotation processor manager
- final AnnotationProcessor aProcessor = new AnnotationProcessorManager(options.getAnnotationProcessors(),
+ final AnnotationProcessor aProcessor = new AnnotationProcessorManager(this.logger,
this.project.getClassLoader());
// create the class scanner - and start scanning
@@ -300,9 +260,9 @@
final Result result = new Result();
// write meta type info if there is a file name
- if (!StringUtils.isEmpty(this.metaTypeName)) {
- final String path = "OSGI-INF" + File.separator + "metatype" + File.separator + this.metaTypeName;
- final File mtFile = new File(this.outputDirectory, path);
+ if (!StringUtils.isEmpty(this.options.getMetaTypeName())) {
+ final String path = "OSGI-INF" + File.separator + "metatype" + File.separator + this.options.getMetaTypeName();
+ final File mtFile = new File(this.options.getOutputDirectory(), path);
final int size = metaData.getOCDs().size() + metaData.getDesignates().size();
if (size > 0) {
this.logger.info("Generating " + size + " MetaType Descriptors to " + mtFile);
@@ -320,8 +280,8 @@
}
// check descriptor file
- final String descriptorPath = "OSGI-INF" + File.separator + this.finalName;
- final File descriptorFile = StringUtils.isEmpty(this.finalName) ? null : new File(this.outputDirectory, descriptorPath);
+ final String descriptorPath = "OSGI-INF" + File.separator + this.options.getSCRName();
+ final File descriptorFile = StringUtils.isEmpty(this.options.getSCRName()) ? null : new File(this.options.getOutputDirectory(), descriptorPath);
// terminate if there is nothing else to write
if (components.getComponents().isEmpty()) {
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
index 90a67dd..acf3f5c 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
@@ -46,6 +46,11 @@
throws SCRDescriptorException, SCRDescriptorFailureException;
/**
+ * A user friendly name
+ */
+ String getName();
+
+ /**
* The ranking of this processor.
*/
int getRanking();
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
index d2cfa75..1ebdbed 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
@@ -29,6 +29,7 @@
import javax.imageio.spi.ServiceRegistry;
+import org.apache.felix.scrplugin.Log;
import org.apache.felix.scrplugin.SCRDescriptorException;
import org.apache.felix.scrplugin.SCRDescriptorFailureException;
import org.apache.felix.scrplugin.annotations.AnnotationProcessor;
@@ -55,12 +56,10 @@
private final List<AnnotationProcessor> cachedProcessors = new ArrayList<AnnotationProcessor>();
/**
- * @param annotationProcessorClasses List of classes that implements
- * {@link AnnotationProcessor} interface.
+ * Create annotation processor manager.
* @throws SCRDescriptorFailureException
*/
- public AnnotationProcessorManager(
- final String[] annotationProcessorClasses,
+ public AnnotationProcessorManager(final Log log,
final ClassLoader classLoader )
throws SCRDescriptorFailureException {
// search for providers
@@ -70,11 +69,6 @@
this.addProvider(provider);
}
- // add custom processors defined in the tool (maven, ant...)
- for ( int i = 0; i < annotationProcessorClasses.length; i++ ) {
- loadProcessor( classLoader, annotationProcessorClasses[i] );
- }
-
// create ordered list
for(final AnnotationProcessor pro : this.processors.values() ) {
this.cachedProcessors.add(pro);
@@ -85,6 +79,13 @@
return Integer.valueOf(o1.getRanking()).compareTo(Integer.valueOf(o2.getRanking()));
}
});
+ if ( this.cachedProcessors.size() == 0 ) {
+ throw new SCRDescriptorFailureException("No annotation processors found in classpath.");
+ }
+ log.debug("Using annotation processors: ");
+ for(final AnnotationProcessor pro : this.cachedProcessors) {
+ log.debug("- " + pro.getName() + " - " + pro.getRanking());
+ }
}
/**
@@ -106,6 +107,13 @@
}
/**
+ * @see org.apache.felix.scrplugin.annotations.AnnotationProcessor#getName()
+ */
+ public String getName() {
+ return "Annotation Processor Manager";
+ }
+
+ /**
* Add a processor (if not already available)
*/
private void addProvider(final AnnotationProcessor processor) {
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index 5d6f14a..92f6c6e 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -151,15 +151,6 @@
private Map<String, String> properties = new HashMap<String, String>();
/**
- * Allows to define additional implementations of the interface
- * {@link org.apache.felix.scrplugin.AnnotationProcessor} that provide
- * mappings from custom annotations to descriptions.
- *
- * @parameter
- */
- private String[] annotationProcessors = {};
-
- /**
* The version of the DS spec this plugin generates a descriptor for. By
* default the version is detected by the used tags.
*
@@ -186,6 +177,9 @@
// create options
final Options options = new Options();
+ options.setOutputDirectory(outputDirectory);
+ options.setSCRName(finalName);
+ options.setMetaTypeName(metaTypeName);
options.setGenerateAccessors(generateAccessors);
options.setStrictMode(strictMode);
options.setProperties(properties);
@@ -193,18 +187,15 @@
if ( specVersion != null && options.getSpecVersion() == null ) {
throw new MojoExecutionException("Unknown spec version specified: " + specVersion);
}
- options.setAnnotationProcessors(annotationProcessors);
+
try {
final SCRDescriptorGenerator generator = new SCRDescriptorGenerator(
scrLog);
// setup from plugin configuration
- generator.setOutputDirectory(outputDirectory);
generator.setOptions(options);
generator.setProject(project);
- generator.setFinalName(finalName);
- generator.setMetaTypeName(metaTypeName);
final Result result = generator.execute();
this.setServiceComponentHeader(result.getScrFiles());
diff --git a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
index 34206c4..61bfe82 100644
--- a/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
+++ b/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
@@ -69,17 +69,6 @@
protected boolean strictMode = false;
/**
- * Allows to define additional implementations of the interface
- * {@link org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider}
- * that provide mappings from custom annotations to
- * {@link org.apache.felix.scrplugin.tags.JavaTag} implementations. List of
- * full qualified class file names.
- *
- * @parameter
- */
- private String[] annotationTagProviders = {};
-
- /**
* The version of the DS spec this plugin generates a descriptor for. By
* default the version is detected by the used tags.
*
@@ -120,6 +109,9 @@
// create options
final Options options = new Options();
+ options.setOutputDirectory(destdir);
+ options.setSCRName(finalName);
+ options.setMetaTypeName(metaTypeName);
options.setGenerateAccessors(generateAccessors);
options.setStrictMode(strictMode);
options.setProperties(new HashMap<String, String>());
@@ -127,16 +119,12 @@
if ( specVersion != null && options.getSpecVersion() == null ) {
throw new BuildException("Unknown spec version specified: " + specVersion);
}
- options.setAnnotationProcessors(annotationTagProviders);
final SCRDescriptorGenerator generator = new SCRDescriptorGenerator( scrLog );
// setup from plugin configuration
- generator.setOutputDirectory(destdir);
generator.setOptions(options);
generator.setProject(project);
- generator.setFinalName(finalName);
- generator.setMetaTypeName(metaTypeName);
generator.execute();
} catch ( final SCRDescriptorException sde ) {
@@ -255,14 +243,7 @@
this.strictMode = strictMode;
}
-
- public void setAnnotationTagProviders( String[] annotationTagProviders ) {
- this.annotationTagProviders = annotationTagProviders;
- }
-
-
public void setSpecVersion( String specVersion ) {
this.specVersion = specVersion;
}
-
}