felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1348910 - in /felix/sandbox/cziegeler/scrplugin: annotations/src/main/java/org/apache/felix/scrplugin/ generator/src/main/java/org/apache/felix/scrplugin/ generator/src/main/java/org/apache/felix/scrplugin/description/ generator/src/main/j...
Date Mon, 11 Jun 2012 15:36:09 GMT
Author: cziegeler
Date: Mon Jun 11 15:36:08 2012
New Revision: 1348910

URL: http://svn.apache.org/viewvc?rev=1348910&view=rev
Log:
New SCR Plugin (WiP)

Modified:
    felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SCRAnnotationProcessor.java
    felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SlingAnnotationProcessor.java
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
    felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
    felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java

Modified: felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SCRAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SCRAnnotationProcessor.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SCRAnnotationProcessor.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SCRAnnotationProcessor.java
Mon Jun 11 15:36:08 2012
@@ -162,7 +162,7 @@ public class SCRAnnotationProcessor impl
 
     /**
      * Create a component description.
-     * 
+     *
      * @param cad
      *            The component annotation for the class.
      * @param scannedClass
@@ -207,7 +207,7 @@ public class SCRAnnotationProcessor impl
 
     /**
      * Create a service description
-     * 
+     *
      * @param descs
      *            The service annotations.
      * @param scannedClass
@@ -248,6 +248,7 @@ public class SCRAnnotationProcessor impl
         if (javaClass != null) {
             final Class<?>[] interfaces = javaClass.getInterfaces();
             for (final Class<?> i : interfaces) {
+                service.addInterface(i.getName());
                 // recursivly add interfaces implemented by this interface
                 this.addInterfaces(service, i);
             }
@@ -259,7 +260,7 @@ public class SCRAnnotationProcessor impl
 
     /**
      * Create a method description if a name is provided.
-     * 
+     *
      * @param methodName
      *            The name of the method or <code>null</code>
      * @return A method description if the name is not null.
@@ -273,7 +274,7 @@ public class SCRAnnotationProcessor impl
 
     /**
      * Create reference descriptions
-     * 
+     *
      * @param descs
      *            List of reference annotations.s
      * @param describedClass
@@ -316,7 +317,7 @@ public class SCRAnnotationProcessor impl
 
     /**
      * Create properties descriptions
-     * 
+     *
      * @throws SCRDescriptorException
      * @throws SCRDescriptorFailureException
      */

Modified: felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SlingAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SlingAnnotationProcessor.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SlingAnnotationProcessor.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/SlingAnnotationProcessor.java
Mon Jun 11 15:36:08 2012
@@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.sling.SlingFilterScope;
 import org.apache.felix.scr.annotations.sling.SlingServlet;
 import org.apache.felix.scrplugin.description.ClassDescription;
+import org.apache.felix.scrplugin.description.ComponentConfigurationPolicy;
 import org.apache.felix.scrplugin.description.ComponentDescription;
 import org.apache.felix.scrplugin.description.PropertyDescription;
 import org.apache.felix.scrplugin.description.PropertyType;
@@ -75,6 +76,7 @@ public class SlingAnnotationProcessor im
         if (generateComponent) {
             final ComponentDescription cd = new ComponentDescription(cad);
             cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName()));
+            cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
 
             cd.setLabel(cad.getStringValue("label", "%" + cd.getName() + ".name"));
             cd.setDescription(cad.getStringValue("description", "%" + cd.getName() + ".description"));
@@ -158,6 +160,7 @@ public class SlingAnnotationProcessor im
         if (generateComponent) {
             final ComponentDescription cd = new ComponentDescription(cad);
             cd.setName(cad.getStringValue("name", classDescription.getDescribedClass().getName()));
+            cd.setConfigurationPolicy(ComponentConfigurationPolicy.OPTIONAL);
 
             cd.setLabel(cad.getStringValue("label", "%" + cd.getName() + ".name"));
             cd.setDescription(cad.getStringValue("description", "%" + cd.getName() + ".description"));

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
Mon Jun 11 15:36:08 2012
@@ -19,9 +19,20 @@
 package org.apache.felix.scrplugin;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
 
 import org.apache.felix.scrplugin.description.ClassDescription;
 import org.apache.felix.scrplugin.description.ComponentDescription;
@@ -136,12 +147,12 @@ public class SCRDescriptorGenerator {
      * Actually generates the Declarative Services and Metatype descriptors
      * scanning the java sources provided by the {@link #setProject(Project)}
      *
-     * @return <code>true</code> if descriptors have been generated.
+     * @return A list of generated file names, relative to the output directory
      *
      * @throws SCRDescriptorException
      * @throws SCRDescriptorFailureException
      */
-    public boolean execute() throws SCRDescriptorException, SCRDescriptorFailureException
{
+    public List<String> execute() throws SCRDescriptorException, SCRDescriptorFailureException
{
         if (this.project == null) {
             throw new SCRDescriptorFailureException("Project has not been set!");
         }
@@ -166,9 +177,15 @@ public class SCRDescriptorGenerator {
 
         // create the class scanner - and start scanning
         final ClassScanner scanner = new ClassScanner();
-
         final List<ClassDescription> scannedDescriptions = scanner.execute(logger,
project, aProcessor);
 
+        // scan descriptions from dependencies and add scanned descriptions
+        final Map<String, ClassDescription> allDescriptions = this.getComponentDescriptors(iLog);
+        for(final ClassDescription cd : scannedDescriptions) {
+            allDescriptions.put(cd.getDescribedClass().getName(), cd);
+        }
+
+        // setup metadata
         final MetaData metaData = new MetaData();
         metaData.setLocalization(MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype");
 
@@ -178,22 +195,22 @@ public class SCRDescriptorGenerator {
 
             // check if there is more than one component definition
             if (desc.getDescriptions(ComponentDescription.class).size() > 1) {
-                iLog.addError("Class has more than one component definition." + " Merge the
definitions to a single definition.",
+                iLog.addError("Class has more than one component definition." +
+                             " Check the annotations and merge the definitions to a single
definition.",
                                 desc.getSource());
             } else {
                 try {
                     final Component comp = this.createComponent(desc, metaData, iLog);
                     if (comp.getSpecVersion() != null) {
-                        if (specVersion == null || comp.getSpecVersion().ordinal() > specVersion.ordinal())
{
+                        if ( specVersion == null ) {
+                            specVersion = comp.getSpecVersion();
+                            logger.debug("Setting used spec version to " + specVersion);
+                        } else if (comp.getSpecVersion().ordinal() > specVersion.ordinal()
&& this.options.getSpecVersion() != null) {
                             // if a spec version has been configured and a component requires
a higher
                             // version, this is considered an error!
-                            if (this.options.getSpecVersion() != null) {
-                                iLog.addError("Component " + comp + " requires spec version
" + comp.getSpecVersion().name()
-                                                + " but plugin is configured to use version
" + this.options.getSpecVersion(),
-                                                desc.getSource());
-                            } else {
-                                specVersion = comp.getSpecVersion();
-                            }
+                            iLog.addError("Component " + comp + " requires spec version "
+ comp.getSpecVersion().name()
+                                            + " but plugin is configured to use version "
+ this.options.getSpecVersion(),
+                                            desc.getSource());
                         }
                     }
                     processedComponents.add(comp);
@@ -205,6 +222,7 @@ public class SCRDescriptorGenerator {
         // if spec version is still not set, we're using lowest available
         if ( specVersion == null ) {
             specVersion = SpecVersion.VERSION_1_0;
+            logger.debug("Using default spec version " + specVersion);
         }
         this.logger.debug("Generating descriptor for spec version: " + specVersion);
 
@@ -281,17 +299,17 @@ public class SCRDescriptorGenerator {
             throw new SCRDescriptorFailureException("SCR Descriptor parsing had failures
(see log)");
         }
 
-        boolean addResources = false;
+        final List<String> result = new ArrayList<String>();
         // write meta type info if there is a file name
         if (!StringUtils.isEmpty(this.metaTypeName)) {
-            final File mtFile = new File(this.outputDirectory, "OSGI-INF" + File.separator
+ "metatype" + File.separator
-                            + this.metaTypeName);
+            final String path = "OSGI-INF" + File.separator + "metatype" + File.separator
+ this.metaTypeName;
+            final File mtFile = new File(this.outputDirectory, path);
             final int size = metaData.getOCDs().size() + metaData.getDesignates().size();
             if (size > 0) {
                 this.logger.info("Generating " + size + " MetaType Descriptors to " + mtFile);
                 mtFile.getParentFile().mkdirs();
                 MetaTypeIO.write(metaData, mtFile);
-                addResources = true;
+                result.add(path.replace(File.separatorChar, '/'));
             } else {
                 if (mtFile.exists()) {
                     mtFile.delete();
@@ -303,12 +321,12 @@ public class SCRDescriptorGenerator {
         }
 
         // check descriptor file
-        final File descriptorFile = StringUtils.isEmpty(this.finalName) ? null : new File(new
File(this.outputDirectory,
-                        "OSGI-INF"), this.finalName);
+        final String descriptorPath = "OSGI-INF" + File.separator + this.finalName;
+        final File descriptorFile = StringUtils.isEmpty(this.finalName) ? null : new File(this.outputDirectory,
descriptorPath);
 
         // terminate if there is nothing else to write
         if (components.getComponents().isEmpty()) {
-            this.logger.debug("No SCR Descriptors found in project.");
+            this.logger.debug("No Service Component Descriptors found in project.");
             // remove file if it exists
             if (descriptorFile != null && descriptorFile.exists()) {
                 this.logger.debug("Removing obsolete service descriptor " + descriptorFile);
@@ -322,14 +340,14 @@ public class SCRDescriptorGenerator {
             // finally the descriptors have to be written ....
             descriptorFile.getParentFile().mkdirs(); // ensure parent dir
 
-            this.logger.info("Generating " + components.getComponents().size() + " Service
Component Descriptors to "
+            this.logger.info("Writing " + components.getComponents().size() + " Service Component
Descriptors to "
                             + descriptorFile);
 
             ComponentDescriptorIO.write(components, descriptorFile);
-            addResources = true;
+            result.add(descriptorPath.replace(File.separatorChar, '/'));
         }
 
-        return addResources;
+        return result;
     }
 
     /**
@@ -483,4 +501,231 @@ public class SCRDescriptorGenerator {
             }
         }
     }
+
+    /**
+     * The name of the Bundle manifest header providing the list of service
+     * component descriptor files.
+     */
+    private static final String SERVICE_COMPONENT = "Service-Component";
+
+    private static final String ABSTRACT_DESCRIPTOR_FILENAME = "scrinfo.xml";
+
+    private static final String ABSTRACT_DESCRIPTOR_ARCHIV_PATH = "OSGI-INF/scr-plugin/"
+ ABSTRACT_DESCRIPTOR_FILENAME;
+
+    /**
+     * Returns a map of component descriptors which may be extended by the java
+     * sources.
+     * <p>
+     * This method calls the {@link #getDependencies()} method and checks for
+     * any Service-Component descriptors in the returned files.
+     * <p>
+     * This method may be overwritten by extensions of this class.
+     *
+     * @throws SCRDescriptorException May be thrown if an error occurrs
+     *             gethering the component descriptors.
+     */
+    private Map<String, ClassDescription> getComponentDescriptors(final IssueLog iLog)
+    throws SCRDescriptorException {
+        final Map<String, ClassDescription> descriptions = new HashMap<String, ClassDescription>();
+
+        final Collection<File> dependencies = this.project.getDependencies();
+        for ( final File artifact : dependencies ) {
+            this.logger.debug( "Trying to get manifest from artifact " + artifact );
+            try {
+                final Manifest manifest = this.getManifest( artifact );
+                if ( manifest != null ) {
+                    // read Service-Component entry
+                    if ( manifest.getMainAttributes().getValue( SERVICE_COMPONENT ) != null
) {
+                        final String serviceComponent = manifest.getMainAttributes().getValue(SERVICE_COMPONENT
);
+                        this.logger.debug( "Found Service-Component: " + serviceComponent
+ " in artifact " + artifact );
+                        final StringTokenizer st = new StringTokenizer( serviceComponent,
"," );
+                        while ( st.hasMoreTokens() ) {
+                            final String entry = st.nextToken().trim();
+                            if ( entry.length() > 0 ) {
+                                final List<ClassDescription> c = this.readServiceComponentDescriptor(
iLog, artifact, entry );
+                                if ( c != null ) {
+                                    for(final ClassDescription cd : c) {
+                                        descriptions.put(cd.getDescribedClass().getName(),
cd);
+                                    }
+                                }
+                            }
+                        }
+                    } else {
+                        this.logger.debug( "Artifact has no service component entry in manifest
" + artifact );
+                    }
+                } else {
+                    this.logger.debug( "Unable to get manifest from artifact " + artifact
);
+                }
+            } catch ( IOException ioe ) {
+                throw new SCRDescriptorException( "Unable to get manifest from artifact",
artifact.toString(), 0,
+                    ioe );
+            }
+            this.logger.debug( "Trying to get scrinfo from artifact " + artifact );
+            // now read the scr private file - components stored there
+            // overwrite components already
+            // read from the service component section.
+            InputStream scrInfoFile = null;
+            try {
+                scrInfoFile = this.getFile( artifact, ABSTRACT_DESCRIPTOR_ARCHIV_PATH );
+                if ( scrInfoFile != null ) {
+                    final List<ClassDescription> c =  this.parseServiceComponentDescriptor(
iLog, scrInfoFile, artifact.toString() + ':' + ABSTRACT_DESCRIPTOR_ARCHIV_PATH);
+                    if ( c != null ) {
+                        for(final ClassDescription cd : c) {
+                            descriptions.put(cd.getDescribedClass().getName(), cd);
+                        }
+                    }
+                } else {
+                    this.logger.debug( "Artifact has no scrinfo file (it's optional): " +
artifact );
+                }
+            } catch ( final IOException ioe ) {
+                throw new SCRDescriptorException( "Unable to get scrinfo from artifact",
artifact.toString(), 0,
+                    ioe );
+            } finally {
+                if ( scrInfoFile != null ) {
+                    try { scrInfoFile.close(); } catch ( final IOException ignore ) {}
+                }
+            }
+
+        }
+
+        return descriptions;
+    }
+
+    /**
+     * Parses the descriptors read from the given input stream. This method may
+     * be called by the {@link #getComponentDescriptors()} method to parse the
+     * descriptors gathered in an implementation dependent way.
+     *
+     * @throws SCRDescriptorException If an error occurrs reading the
+     *             descriptors from the stream.
+     */
+    private List<ClassDescription> parseServiceComponentDescriptor(final IssueLog iLog,
+                    final InputStream file, final String location )
+    throws SCRDescriptorException {
+        return ComponentDescriptorIO.read( file, this.project.getClassLoader(), iLog, location
);
+    }
+
+    /**
+     * Read the service component description.
+     *
+     * @param artifact
+     * @param entry
+     * @throws IOException
+     * @throws SCRDescriptorException
+     */
+    private List<ClassDescription> readServiceComponentDescriptor( final IssueLog iLog,
final File artifactFile, String entry ) {
+        this.logger.debug( "Reading " + entry + " from " + artifactFile );
+        InputStream xml = null;
+        try {
+            xml = this.getFile( artifactFile, entry );
+            if ( xml == null ) {
+                throw new SCRDescriptorException( "Entry " + entry + " not contained in JAR
File ", artifactFile.toString(),
+                    0 );
+            }
+            return this.parseServiceComponentDescriptor( iLog, xml, artifactFile.toString()
+ ':' + entry );
+        } catch ( final IOException mee ) {
+            this.logger.warn( "Unable to read SCR descriptor file from JAR File " + artifactFile
+ " at " + entry );
+            this.logger.debug( "Exception occurred during reading: " + mee.getMessage(),
mee );
+        } catch ( final SCRDescriptorException mee ) {
+            this.logger.warn( "Unable to read SCR descriptor file from JAR File " + artifactFile
+ " at " + entry );
+            this.logger.debug( "Exception occurred during reading: " + mee.getMessage(),
mee );
+        } finally {
+            if ( xml != null ) {
+                try { xml.close(); } catch (final IOException ignore) {}
+            }
+        }
+
+        return null;
+    }
+
+
+    /**
+     * Get the manifest from the artifact.
+     * The artifact can either be a jar or a directory.
+     */
+    private Manifest getManifest( final File artifact ) throws IOException {
+        if ( artifact.isDirectory() ) {
+            // this is maybe a classes directory, try to read manifest file directly
+            final File dir = new File(artifact, "META-INF");
+            if ( !dir.exists() || !dir.isDirectory() ) {
+                return null;
+            }
+            final File mf = new File(dir, "MANIFEST.MF");
+            if ( !mf.exists() || !mf.isFile() ) {
+                return null;
+            }
+            final InputStream is = new FileInputStream(mf);
+            try {
+                return new Manifest(is);
+            } finally {
+                try { is.close(); } catch (final IOException ignore) { }
+            }
+        }
+        JarFile file = null;
+        try {
+            file = new JarFile( artifact );
+            return file.getManifest();
+        } finally {
+            if ( file != null ) {
+                try { file.close(); } catch ( final IOException ignore ) {}
+            }
+        }
+    }
+
+    private InputStream getFile( final File artifactFile, final String path ) throws IOException
{
+        if ( artifactFile.isDirectory() ) {
+            final String filePath = path.replace('/', File.separatorChar).replace('\\', File.separatorChar);
+            final File file = new File(artifactFile, filePath);
+            if ( file.exists() && file.isFile() ) {
+                return new FileInputStream(file);
+            }
+            return null;
+        }
+        JarFile file = null;
+        try {
+            file = new JarFile( artifactFile );
+            final JarEntry entry = file.getJarEntry( path );
+            if ( entry != null ) {
+                final InputStream stream = new ArtifactFileInputStream( file, entry );
+                file = null; // prevent file from being closed now
+                return stream;
+            }
+            return null;
+        } finally {
+            if ( file != null ) {
+                try { file.close(); } catch ( final IOException ignore ) {}
+            }
+        }
+    }
+
+    private static class ArtifactFileInputStream extends FilterInputStream {
+
+        final JarFile jarFile;
+
+        ArtifactFileInputStream( JarFile jarFile, JarEntry jarEntry ) throws IOException
{
+            super( jarFile.getInputStream( jarEntry ) );
+            this.jarFile = jarFile;
+        }
+
+
+        @Override
+        public void close() throws IOException {
+            try {
+                super.close();
+            } catch ( final IOException ioe ) {
+                // ignore
+            }
+            jarFile.close();
+        }
+
+
+        @Override
+        protected void finalize() throws Throwable {
+            try {
+                close();
+            } finally {
+                super.finalize();
+            }
+        }
+    }
 }

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/description/SpecVersion.java
Mon Jun 11 15:36:08 2012
@@ -58,7 +58,13 @@ public enum SpecVersion {
         try {
             return SpecVersion.valueOf(n.toUpperCase());
         } catch (final IllegalArgumentException e) {
-            return null;
+            // ignore
         }
+        for(final SpecVersion sv : SpecVersion.values() ) {
+            if ( sv.getName().equals(n)) {
+                return sv;
+            }
+        }
+        return null;
     }
 }

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/om/Component.java
Mon Jun 11 15:36:08 2012
@@ -275,9 +275,9 @@ public class Component extends AbstractO
             }
 
             // no errors so far, let's continue
-            /*
-             * if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) {
-             * final String activateName = this.activate == null ? "activate" : this.activate;
+            if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) {
+
+            /* final String activateName = this.activate == null ? "activate" : this.activate;
              * final String deactivateName = this.deactivate == null ? "deactivate" : this.deactivate;
              *
              * // check activate and deactivate methods
@@ -307,38 +307,36 @@ public class Component extends AbstractO
              * if (!constructorFound) {
              * this.logError(context.getIssueLog(), "Class must have public default constructor:
" + javaClass.getName());
              * }
-             *
-             * // verify properties
-             * for (final Property prop : this.getProperties()) {
-             * prop.validate(specVersion, context.getIssueLog());
-             * }
-             *
-             * // verify service
-             * boolean isServiceFactory = false;
-             * if (this.getService() != null) {
-             * if (this.getService().getInterfaces().size() == 0) {
-             * this.logError(context.getIssueLog(), "Service interface information is missing!");
-             * }
-             * this.getService().validate(context);
-             * isServiceFactory = this.getService().isServicefactory();
-             * }
-             *
-             * // serviceFactory must not be true for immediate of component
-             * // factory
-             * if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue()
-             * && this.getFactory() != null) {
-             * this.logError(context.getIssueLog(),
-             * "Component must not be a ServiceFactory, if immediate and/or component factory:
"
-             * + javaClass.getName());
-             * }
-             *
-             * // immediate must not be true for component factory
-             * if (this.isImmediate() != null && this.isImmediate().booleanValue()
&& this.getFactory() != null) {
-             * this.logError(context.getIssueLog(),
-             * "Component must not be immediate if component factory: " + javaClass.getName());
-             * }
-             * }
              */
+                // verify properties
+                for (final Property prop : this.getProperties()) {
+                    prop.validate(context);
+                }
+
+                // verify service
+                boolean isServiceFactory = false;
+                if (this.getService() != null) {
+                    if (this.getService().getInterfaces().size() == 0) {
+                        this.logError(context.getIssueLog(), "Service interface information
is missing!");
+                    }
+                    this.getService().validate(context);
+                    isServiceFactory = this.getService().isServiceFactory();
+                }
+
+                // serviceFactory must not be true for immediate of component factory
+                if (isServiceFactory && this.isImmediate() != null && this.isImmediate().booleanValue()
+                    && this.getFactory() != null) {
+                    this.logError(context.getIssueLog(),
+                        "Component must not be a ServiceFactory, if immediate and/or component
factory: "
+                        + this.getClassDescription().getDescribedClass().getName());
+                }
+
+                // immediate must not be true for component factory
+                if (this.isImmediate() != null && this.isImmediate().booleanValue()
&& this.getFactory() != null) {
+                    this.logError(context.getIssueLog(),
+                        "Component must not be immediate if component factory: " + this.getClassDescription().getDescribedClass().getName());
+                }
+            }
         }
         if (context.getIssueLog().getNumberOfErrors() == currentIssueCount) {
             // verify references

Modified: felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
Mon Jun 11 15:36:08 2012
@@ -130,9 +130,11 @@ public class ComponentDescriptorIO {
 
     private static final String INTERFACE_QNAME = INTERFACE;
 
-    public static List<ClassDescription> read(final InputStream file, final IssueLog
iLog, final String location) throws SCRDescriptorException {
+    public static List<ClassDescription> read(final InputStream file,
+                    final ClassLoader classLoader,
+                    final IssueLog iLog, final String location) throws SCRDescriptorException
{
         try {
-            final XmlHandler xmlHandler = new XmlHandler(iLog, location);
+            final XmlHandler xmlHandler = new XmlHandler(classLoader, iLog, location);
             IOUtils.parse(file, xmlHandler);
             return xmlHandler.components;
         } catch (final TransformerException e) {
@@ -365,28 +367,31 @@ public class ComponentDescriptorIO {
     protected static final class XmlHandler extends DefaultHandler {
 
         /** The components container. */
-        protected final List<ClassDescription> components = new ArrayList<ClassDescription>();
+        private final List<ClassDescription> components = new ArrayList<ClassDescription>();
 
         /** Spec version. */
-        protected SpecVersion specVersion;
+        private SpecVersion specVersion;
+
+        /** A reference to the current class. */
+        private ClassDescription currentClass;
 
         /** A reference to the current component. */
-        protected ClassDescription currentComponent;
+        private ComponentDescription currentComponent;
 
         /** The current service. */
-        protected ServiceDescription currentService;
+        private ServiceDescription currentService;
 
         /** Pending property. */
-        protected PropertyDescription pendingProperty;
+        private PropertyDescription pendingProperty;
 
         /** Flag for detecting the first element. */
-        protected boolean firstElement = true;
+        private boolean firstElement = true;
 
         /** Flag for elements inside a component element */
-        protected boolean isComponent = false;
+        private boolean isComponent = false;
 
         /** Override namespace. */
-        protected String overrideNamespace;
+        private String overrideNamespace;
 
         /** The issue log. */
         private final IssueLog iLog;
@@ -394,9 +399,13 @@ public class ComponentDescriptorIO {
         /** XML file location. */
         private final String location;
 
-        public XmlHandler(final IssueLog iLog, final String loc) {
+        /** Classloader. */
+        private final ClassLoader classLoader;
+
+        public XmlHandler(final ClassLoader classLoader, final IssueLog iLog, final String
loc) {
             this.iLog = iLog;
             this.location = loc;
+            this.classLoader = classLoader;
         }
 
         /**
@@ -439,9 +448,7 @@ public class ComponentDescriptorIO {
                 if (localName.equals(COMPONENT)) {
                     this.isComponent = true;
 
-                    this.currentComponent = new ClassDescription(null, null);
                     final ComponentDescription desc = new ComponentDescription(null);
-                    this.currentComponent.add(desc);
                     desc.setName(attributes.getValue(COMPONENT_ATTR_NAME));
 
                     // enabled attribute is optional
@@ -478,9 +485,14 @@ public class ComponentDescriptorIO {
                         }
                     }
                 } else if (localName.equals(IMPLEMENTATION)) {
+                    // now we can create the class description and attach the component description
                     // Set the implementation class name (mandatory)
-                    final ComponentDescription desc = this.currentComponent.getDescription(ComponentDescription.class);
-                    desc.setLabel(attributes.getValue("class"));
+                    try {
+                        this.currentClass = new ClassDescription(this.classLoader.loadClass(attributes.getValue("class")),
null);
+                    } catch (final ClassNotFoundException e) {
+                        iLog.addError("Unable to load class " + attributes.getValue("class")
+ " from dependencies.", this.location);
+                    }
+                    this.currentClass.add(this.currentComponent);
 
                 } else if (localName.equals(PROPERTY)) {
 
@@ -502,7 +514,7 @@ public class ComponentDescriptorIO {
 
                         if (attributes.getValue("value") != null) {
                             prop.setValue(attributes.getValue("value"));
-                            this.currentComponent.add(prop);
+                            this.currentClass.add(prop);
                         } else {
                             // hold the property pending as we have a multi value
                             this.pendingProperty = prop;
@@ -527,7 +539,7 @@ public class ComponentDescriptorIO {
                 } else if (localName.equals(SERVICE)) {
 
                     this.currentService = new ServiceDescription(null);
-                    this.currentComponent.add(this.currentService);
+                    this.currentClass.add(this.currentService);
 
                     if (attributes.getValue("servicefactory") != null) {
                         this.currentService.setServiceFactory(Boolean.valueOf(attributes.getValue("servicefactory")));
@@ -573,7 +585,7 @@ public class ComponentDescriptorIO {
                         }
                     }
 
-                    this.currentComponent.add(ref);
+                    this.currentClass.add(ref);
                 }
             }
         }
@@ -592,6 +604,7 @@ public class ComponentDescriptorIO {
 
             if (NAMESPACE_URI_1_0.equals(uri) || NAMESPACE_URI_1_1.equals(uri) || NAMESPACE_URI_1_1_FELIX.equals(uri))
{
                 if (localName.equals(COMPONENT)) {
+                    this.currentClass = null;
                     this.currentComponent = null;
                     this.isComponent = false;
                 } else if (localName.equals(PROPERTY) && this.pendingProperty !=
null) {
@@ -607,7 +620,7 @@ public class ComponentDescriptorIO {
                         }
                         this.pendingProperty.setMultiValue(values);
                     }
-                    this.currentComponent.add(this.pendingProperty);
+                    this.currentClass.add(this.pendingProperty);
                     this.pendingProperty = null;
                 }
             }

Modified: felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java?rev=1348910&r1=1348909&r2=1348910&view=diff
==============================================================================
--- felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
(original)
+++ felix/sandbox/cziegeler/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
Mon Jun 11 15:36:08 2012
@@ -186,6 +186,9 @@ public class SCRDescriptorMojo extends A
         options.setStrictMode(strictMode);
         options.setProperties(properties);
         options.setSpecVersion(SpecVersion.fromName(specVersion));
+        if ( specVersion != null && options.getSpecVersion() == null ) {
+            throw new MojoExecutionException("Unknown spec version specified: " + specVersion);
+        }
         options.setAnnotationProcessors(annotationProcessors);
         try {
 
@@ -199,7 +202,9 @@ public class SCRDescriptorMojo extends A
             generator.setFinalName(finalName);
             generator.setMetaTypeName(metaTypeName);
 
-            if (generator.execute()) {
+            final List<String> generatedResources = generator.execute();
+            if ( generatedResources.size() > 0 ) {
+                // TODO use result
                 setServiceComponentHeader();
                 addResources();
             }



Mime
View raw message