felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1351105 - in /felix/trunk/scrplugin: annotations/src/main/java/org/apache/felix/scrplugin/processing/ ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/ generator/src/main/java/org/apache/felix/scrplugin/ generator/src/main/java/o...
Date Sun, 17 Jun 2012 13:17:53 GMT
Author: cziegeler
Date: Sun Jun 17 13:17:53 2012
New Revision: 1351105

URL: http://svn.apache.org/viewvc?rev=1351105&view=rev
Log:
FELIX-3550 : Reimplement the SCR Generator

Modified:
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
    felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
    felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
    felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
    felix/trunk/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
(original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
Sun Jun 17 13:17:53 2012
@@ -63,6 +63,13 @@ import org.apache.felix.scrplugin.descri
 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)

Modified: felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
(original)
+++ felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SlingAnnotationProcessor.java
Sun Jun 17 13:17:53 2012
@@ -41,6 +41,13 @@ import org.apache.felix.scrplugin.descri
 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,

Modified: felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
(original)
+++ felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
Sun Jun 17 13:17:53 2012
@@ -55,6 +55,13 @@ import org.osgi.service.component.annota
 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,

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/Options.java
Sun Jun 17 13:17:53 2012
@@ -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 @@ public class Options {
 
     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 @@ public class Options {
         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;
+    }
 }

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Sun Jun 17 13:17:53 2012
@@ -72,12 +72,6 @@ public class SCRDescriptorGenerator {
 
     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 @@ public class SCRDescriptorGenerator {
     }
 
     /**
-     * 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 @@ public class SCRDescriptorGenerator {
         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 @@ public class SCRDescriptorGenerator {
 
         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 @@ public class SCRDescriptorGenerator {
         }
 
         // 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()) {

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/annotations/AnnotationProcessor.java
Sun Jun 17 13:17:53 2012
@@ -46,6 +46,11 @@ public interface AnnotationProcessor {
     throws SCRDescriptorException, SCRDescriptorFailureException;
 
     /**
+     * A user friendly name
+     */
+    String getName();
+
+    /**
      * The ranking of this processor.
      */
     int getRanking();

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
(original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/AnnotationProcessorManager.java
Sun Jun 17 13:17:53 2012
@@ -29,6 +29,7 @@ import java.util.Map;
 
 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 @@ public class AnnotationProcessorManager 
     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 @@ public class AnnotationProcessorManager 
             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 @@ public class AnnotationProcessorManager 
                 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 @@ public class AnnotationProcessorManager 
     }
 
     /**
+     * @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) {

Modified: felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
(original)
+++ felix/trunk/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
Sun Jun 17 13:17:53 2012
@@ -151,15 +151,6 @@ public class SCRDescriptorMojo extends A
     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 @@ public class SCRDescriptorMojo extends A
 
         // 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 @@ public class SCRDescriptorMojo extends A
         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());

Modified: felix/trunk/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java?rev=1351105&r1=1351104&r2=1351105&view=diff
==============================================================================
--- felix/trunk/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
(original)
+++ felix/trunk/scrplugin/scrtask/src/main/java/org/apache/felix/scrplugin/ant/SCRDescriptorTask.java
Sun Jun 17 13:17:53 2012
@@ -69,17 +69,6 @@ public class SCRDescriptorTask extends M
     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 @@ public class SCRDescriptorTask extends M
 
             // 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 @@ public class SCRDescriptorTask extends M
             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 @@ public class SCRDescriptorTask extends M
         this.strictMode = strictMode;
     }
 
-
-    public void setAnnotationTagProviders( String[] annotationTagProviders ) {
-        this.annotationTagProviders = annotationTagProviders;
-    }
-
-
     public void setSpecVersion( String specVersion ) {
         this.specVersion = specVersion;
     }
-
 }



Mime
View raw message