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 2013/07/17 14:32:32 UTC

svn commit: r1504095 - in /felix/trunk/scrplugin/generator: ./ src/main/java/org/apache/felix/scrplugin/ src/main/java/org/apache/felix/scrplugin/helper/ src/main/java/org/apache/felix/scrplugin/xml/

Author: cziegeler
Date: Wed Jul 17 12:32:32 2013
New Revision: 1504095

URL: http://svn.apache.org/r1504095
Log:
FELIX-4126 - Discontinue creation of single XML descriptor files

Modified:
    felix/trunk/scrplugin/generator/changelog.txt
    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/helper/ComponentContainerUtil.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
    felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java

Modified: felix/trunk/scrplugin/generator/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/changelog.txt?rev=1504095&r1=1504094&r2=1504095&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/changelog.txt (original)
+++ felix/trunk/scrplugin/generator/changelog.txt Wed Jul 17 12:32:32 2013
@@ -1,3 +1,10 @@
+Changes from 1.8.0 to 1.7.0
+---------------------------
+** Improvement
+    * [FELIX-4101] - Create metatype.properties file when description and label are inlined
+    * [FELIX-4126] - Discontinue creation of single XML descriptor files 
+
+
 Changes from 1.7.0 to 1.6.0
 ---------------------------
 ** Bug

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=1504095&r1=1504094&r2=1504095&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 Wed Jul 17 12:32:32 2013
@@ -43,15 +43,6 @@ public class Options {
     /** The output directory for the generated files. */
     private File outputDirectory;
 
-    /** The name of the scr file. */
-    private String scrName = "serviceComponents.xml";
-
-    /** The name of the metatype file. */
-    private String metaTypeName = "metatype.xml";
-
-    /** Flag for generating separate descriptor files. */
-    private boolean generateSeparateDescriptors = false;
-
     /**
      * @see #setGenerateAccessors(boolean)
      * @return Whether accessor methods should be generated.
@@ -150,62 +141,6 @@ public class Options {
         this.outputDirectory = outputDirectory;
     }
 
-    /**
-     * @see #setSCRName(String)
-     * @return The file name for the SCR file.
-     */
-    public String getSCRName() {
-        return this.scrName;
-    }
-
-    /**
-     * 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;
-    }
-
-    /**
-     * @see #setMetaTypeName(String)
-     * @return The name for the metatype file
-     */
-    public String getMetaTypeName() {
-        return this.metaTypeName;
-    }
-
-    /**
-     * 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;
-    }
-
-    /**
-     * Should separate descriptor files be generated?
-     */
-    public boolean isGenerateSeparateDescriptors() {
-        return generateSeparateDescriptors;
-    }
-
-    /**
-     * Set whether separate descriptor files should be generated.
-     * @param generateSeparateDescriptors
-     */
-    public void setGenerateSeparateDescriptors(boolean generateSeparateDescriptors) {
-        this.generateSeparateDescriptors = generateSeparateDescriptors;
-    }
-
     private static final String PARENT_NAME = "OSGI-INF";
 
     /**

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=1504095&r1=1504094&r2=1504095&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 Wed Jul 17 12:32:32 2013
@@ -123,11 +123,8 @@ public class SCRDescriptorGenerator {
         }
 
         this.logger.debug("..using output directory: " + this.options.getOutputDirectory());
-        this.logger.debug("..using scr name: " + this.options.getSCRName());
-        this.logger.debug("..using metatype name: " + this.options.getMetaTypeName());
         this.logger.debug("..strict mode: " + this.options.isStrictMode());
         this.logger.debug("..generating accessors: " + this.options.isGenerateAccessors());
-        this.logger.debug("..generating separate descs: " + this.options.isGenerateSeparateDescriptors());
 
         // check speck version configuration
         SpecVersion specVersion = options.getSpecVersion();

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java?rev=1504095&r1=1504094&r2=1504095&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java (original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java Wed Jul 17 12:32:32 2013
@@ -33,46 +33,37 @@ public abstract class ComponentContainer
      * Split the list of components into separate lists depending
      * on the configuration.
      */
-    public static List<ComponentContainerContainer> split(final List<ComponentContainer> components,
-            final boolean generateSeparateDescriptors) {
+    public static List<ComponentContainerContainer> split(final List<ComponentContainer> components) {
         final List<ComponentContainerContainer> result = new ArrayList<ComponentContainerContainer>();
 
-        if ( generateSeparateDescriptors ) {
-            while ( !components.isEmpty() ) {
-                // get the first component
-                final List<ComponentContainer> innerList = new ArrayList<ComponentContainer>();
-                final ComponentContainer component = components.remove(0);
-                innerList.add(component);
-                final int pos = component.getClassDescription().getDescribedClass().getName().indexOf('$');
-                final String baseClassName;
-                if ( pos == -1 ) {
-                    baseClassName = component.getClassDescription().getDescribedClass().getName();
-                } else {
-                    baseClassName = component.getClassDescription().getDescribedClass().getName().substring(0, pos);
-                }
-                final String baseClassPrefix = baseClassName + '$';
+        while ( !components.isEmpty() ) {
+            // get the first component
+            final List<ComponentContainer> innerList = new ArrayList<ComponentContainer>();
+            final ComponentContainer component = components.remove(0);
+            innerList.add(component);
+            final int pos = component.getClassDescription().getDescribedClass().getName().indexOf('$');
+            final String baseClassName;
+            if ( pos == -1 ) {
+                baseClassName = component.getClassDescription().getDescribedClass().getName();
+            } else {
+                baseClassName = component.getClassDescription().getDescribedClass().getName().substring(0, pos);
+            }
+            final String baseClassPrefix = baseClassName + '$';
 
-                // check for inner classes
-                final Iterator<ComponentContainer> i = components.iterator();
-                while ( i.hasNext() ) {
-                    final ComponentContainer cc = i.next();
-                    if ( cc.getClassDescription().getDescribedClass().getName().startsWith(baseClassPrefix) ) {
-                        innerList.add(cc);
-                        i.remove();
-                    }
+            // check for inner classes
+            final Iterator<ComponentContainer> i = components.iterator();
+            while ( i.hasNext() ) {
+                final ComponentContainer cc = i.next();
+                if ( cc.getClassDescription().getDescribedClass().getName().startsWith(baseClassPrefix) ) {
+                    innerList.add(cc);
+                    i.remove();
                 }
-
-                final ComponentContainerContainer ccc = new ComponentContainerContainer();
-                ccc.components = innerList;
-                ccc.className = baseClassName;
-                result.add(ccc);
-            }
-        } else {
-            if ( components.size() > 0 ) {
-                final ComponentContainerContainer ccc = new ComponentContainerContainer();
-                ccc.components = components;
-                result.add(ccc);
             }
+
+            final ComponentContainerContainer ccc = new ComponentContainerContainer();
+            ccc.components = innerList;
+            ccc.className = baseClassName;
+            result.add(ccc);
         }
 
         return result;

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java?rev=1504095&r1=1504094&r2=1504095&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java (original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java Wed Jul 17 12:32:32 2013
@@ -51,7 +51,6 @@ import org.apache.felix.scrplugin.helper
 import org.apache.felix.scrplugin.helper.ComponentContainerUtil.ComponentContainerContainer;
 import org.apache.felix.scrplugin.helper.DescriptionContainer;
 import org.apache.felix.scrplugin.helper.IssueLog;
-import org.apache.felix.scrplugin.helper.StringUtils;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -748,51 +747,47 @@ public class ComponentDescriptorIO {
 
         // check descriptor file
         final File descriptorDir = options.getComponentDescriptorDirectory();
-        final File descriptorFile = StringUtils.isEmpty(options.getSCRName()) ? null : new File(descriptorDir, options.getSCRName());
 
         // terminate if there is nothing else to write
         if (components.isEmpty()) {
             logger.debug("No Service Component Descriptors found in project.");
-            // remove file if it exists
-            if (descriptorFile != null && descriptorFile.exists()) {
-                logger.debug("Removing obsolete service descriptor " + descriptorFile);
-                descriptorFile.delete();
+            // remove files if it exists
+            if ( descriptorDir.exists() ) {
+                for(final File f : descriptorDir.listFiles()) {
+                    if ( f.isFile() ) {
+                        logger.debug("Removing obsolete service descriptor " + f);
+                        f.delete();
+                    }
+                }
             }
+
             return null;
         }
-        if ( !options.isGenerateSeparateDescriptors() && descriptorFile == null ) {
-            throw new SCRDescriptorFailureException("Descriptor file name must not be empty.");
-        }
 
         // finally the descriptors have to be written ....
         descriptorDir.mkdirs(); // ensure parent dir
 
         final List<String> fileNames = new ArrayList<String>();
-        final List<ComponentContainerContainer> containers = ComponentContainerUtil.split(components, options.isGenerateSeparateDescriptors());
+        final List<ComponentContainerContainer> containers = ComponentContainerUtil.split(components);
         for(final ComponentContainerContainer ccc : containers) {
             final SpecVersion globalVersion = module.getOptions().getSpecVersion();
 
-            final File useFile;
-            if ( ccc.className == null ) {
-                useFile = descriptorFile;
-            } else {
-                SpecVersion sv = null;
-                for(final ComponentContainer cc : ccc.components ) {
-                    if ( sv == null || sv.ordinal() < cc.getComponentDescription().getSpecVersion().ordinal() ) {
-                        sv = cc.getComponentDescription().getSpecVersion();
-                    }
+            SpecVersion sv = null;
+            for(final ComponentContainer cc : ccc.components ) {
+                if ( sv == null || sv.ordinal() < cc.getComponentDescription().getSpecVersion().ordinal() ) {
+                    sv = cc.getComponentDescription().getSpecVersion();
                 }
-                module.getOptions().setSpecVersion(sv);
-                useFile = new File(descriptorDir, ccc.className + ".xml");
             }
+            module.getOptions().setSpecVersion(sv);
+            final File useFile = new File(descriptorDir, ccc.className + ".xml");
             try {
                 ComponentDescriptorIO.generateXML(module, ccc.components, useFile, logger);
             } catch (final IOException e) {
-                throw new SCRDescriptorException("Unable to generate xml", descriptorFile.toString(), e);
+                throw new SCRDescriptorException("Unable to generate xml", useFile.toString(), e);
             } catch (final TransformerException e) {
-                throw new SCRDescriptorException("Unable to generate xml", descriptorFile.toString(), e);
+                throw new SCRDescriptorException("Unable to generate xml", useFile.toString(), e);
             } catch (final SAXException e) {
-                throw new SCRDescriptorException("Unable to generate xml", descriptorFile.toString(), e);
+                throw new SCRDescriptorException("Unable to generate xml", useFile.toString(), e);
             }
             fileNames.add(PARENT_NAME + '/' + useFile.getName());
 

Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java?rev=1504095&r1=1504094&r2=1504095&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java (original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java Wed Jul 17 12:32:32 2013
@@ -38,7 +38,6 @@ import org.apache.felix.scrplugin.helper
 import org.apache.felix.scrplugin.helper.DescriptionContainer;
 import org.apache.felix.scrplugin.helper.MetatypeAttributeDefinition;
 import org.apache.felix.scrplugin.helper.MetatypeContainer;
-import org.apache.felix.scrplugin.helper.StringUtils;
 import org.osgi.service.metatype.MetaTypeService;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.SAXException;
@@ -89,108 +88,101 @@ public class MetaTypeIO {
                 components.add(component);
             }
         }
-        // write meta type info if there is a file name
-        if (!StringUtils.isEmpty(options.getMetaTypeName())) {
-            final File mtDir = options.getMetaTypeDirectory();
-            final File parentDir = mtDir.getParentFile();
-
-            final File mtFile = new File(mtDir, options.getMetaTypeName());
-
-            if (components.size() > 0) {
-                mtDir.mkdirs();
-
-                final List<String> fileNames = new ArrayList<String>();
-                final List<ComponentContainerContainer> containers = ComponentContainerUtil.split(components, options.isGenerateSeparateDescriptors());
-                for(final ComponentContainerContainer ccc : containers) {
-                    final File useFile;
-                    if ( ccc.className == null ) {
-                        useFile = mtFile;
-                    } else {
-                        useFile = new File(mtDir, ccc.className + ".xml");
+        // write meta type info
+        final File mtDir = options.getMetaTypeDirectory();
+        final File parentDir = mtDir.getParentFile();
+
+        if (components.size() > 0) {
+            mtDir.mkdirs();
+
+            final List<String> fileNames = new ArrayList<String>();
+            final List<ComponentContainerContainer> containers = ComponentContainerUtil.split(components);
+            for(final ComponentContainerContainer ccc : containers) {
+                final File useFile = new File(mtDir, ccc.className + ".xml");
+
+                String metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype";
+
+                // check if all labels and descriptions are inlined
+                boolean allInlined = true;
+                for(final ComponentContainer cc : ccc.components) {
+                    final MetatypeContainer mc = cc.getMetatypeContainer();
+
+                    if ( mc.getName() != null && mc.getName().startsWith("%") ) {
+                        allInlined = false;
+                    }
+                    if ( mc.getDescription() != null && mc.getDescription().startsWith("%") ) {
+                        allInlined = false;
+                    }
+                    for(final MetatypeAttributeDefinition mad : mc.getProperties()) {
+                        if ( mad.getName() != null && mad.getName().startsWith("%") ) {
+                            allInlined = false;
+                        }
+                        if ( mad.getDescription() != null && mad.getDescription().startsWith("%") ) {
+                            allInlined = false;
+                        }
                     }
-                    String metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype";
+                }
+                if ( allInlined ) {
+                    final Properties metatypeProps = new Properties();
 
-                    // check if all labels and descriptions are inlined
-                    boolean allInlined = true;
+                    // externalize all labels and descriptions
                     for(final ComponentContainer cc : ccc.components) {
                         final MetatypeContainer mc = cc.getMetatypeContainer();
 
-                        if ( mc.getName() != null && mc.getName().startsWith("%") ) {
-                            allInlined = false;
+                        final String baseKey = cc.getClassDescription().getDescribedClass().getName().replace("$", ".");
+
+                        if ( mc.getName() != null ) {
+                            final String key = baseKey + ".name";
+                            metatypeProps.put(key, mc.getName());
+                            mc.setName("%" + key);
                         }
-                        if ( mc.getDescription() != null && mc.getDescription().startsWith("%") ) {
-                            allInlined = false;
+                        if ( mc.getDescription() != null ) {
+                            final String key = baseKey + ".description";
+                            metatypeProps.put(key, mc.getDescription());
+                            mc.setDescription("%" + key);
                         }
                         for(final MetatypeAttributeDefinition mad : mc.getProperties()) {
-                            if ( mad.getName() != null && mad.getName().startsWith("%") ) {
-                                allInlined = false;
+                            if ( mad.getName() != null ) {
+                                final String key = baseKey + "." + mad.getId() + ".name";
+                                metatypeProps.put(key, mad.getName());
+                                mad.setName("%" + key);
                             }
-                            if ( mad.getDescription() != null && mad.getDescription().startsWith("%") ) {
-                                allInlined = false;
+                            if ( mad.getDescription() != null ) {
+                                final String key = baseKey + "." + mad.getId() + ".description";
+                                metatypeProps.put(key, mad.getDescription());
+                                mad.setDescription("%" + key);
                             }
                         }
                     }
-                    if ( allInlined ) {
-                        final Properties metatypeProps = new Properties();
-
-                        // externalize all labels and descriptions
-                        for(final ComponentContainer cc : ccc.components) {
-                            final MetatypeContainer mc = cc.getMetatypeContainer();
-
-                            final String baseKey = cc.getClassDescription().getDescribedClass().getName().replace("$", ".");
-
-                            if ( mc.getName() != null ) {
-                                final String key = baseKey + ".name";
-                                metatypeProps.put(key, mc.getName());
-                                mc.setName("%" + key);
-                            }
-                            if ( mc.getDescription() != null ) {
-                                final String key = baseKey + ".description";
-                                metatypeProps.put(key, mc.getDescription());
-                                mc.setDescription("%" + key);
-                            }
-                            for(final MetatypeAttributeDefinition mad : mc.getProperties()) {
-                                if ( mad.getName() != null ) {
-                                    final String key = baseKey + "." + mad.getId() + ".name";
-                                    metatypeProps.put(key, mad.getName());
-                                    mad.setName("%" + key);
-                                }
-                                if ( mad.getDescription() != null ) {
-                                    final String key = baseKey + "." + mad.getId() + ".description";
-                                    metatypeProps.put(key, mad.getDescription());
-                                    mad.setDescription("%" + key);
-                                }
-                            }
-                        }
-                        if ( metatypeProps.size() > 0 ) {
-                            final int lastDot = useFile.getName().lastIndexOf(".");
-                            final String baseName = useFile.getName().substring(0, lastDot);
-                            final File propsFile = new File(useFile.getParentFile(), baseName + ".properties");
-                            try {
-                                metatypeProps.store(new FileWriter(propsFile), null);
-                            } catch (IOException e) {
-                                throw new SCRDescriptorException("Unable to get metatype.properties", propsFile.getAbsolutePath());
-                            }
-                            fileNames.add(parentDir.getName() + '/' + mtDir.getName() + '/' + propsFile.getName());
-                            metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + '/' + baseName;
+                    if ( metatypeProps.size() > 0 ) {
+                        final int lastDot = useFile.getName().lastIndexOf(".");
+                        final String baseName = useFile.getName().substring(0, lastDot);
+                        final File propsFile = new File(useFile.getParentFile(), baseName + ".properties");
+                        try {
+                            metatypeProps.store(new FileWriter(propsFile), null);
+                        } catch (IOException e) {
+                            throw new SCRDescriptorException("Unable to get metatype.properties", propsFile.getAbsolutePath());
                         }
+                        fileNames.add(parentDir.getName() + '/' + mtDir.getName() + '/' + propsFile.getName());
+                        metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + '/' + baseName;
                     }
-                    logger.info("Generating " + ccc.components.size() + " MetaType Descriptors in " + useFile);
-                    MetaTypeIO.write(module, ccc.components, useFile, metatypeLocation);
-                    fileNames.add(parentDir.getName() + '/' + mtDir.getName() + '/' + useFile.getName());
                 }
-
-                return fileNames;
-            }
-            if (mtFile.exists()) {
-                mtFile.delete();
+                logger.info("Generating " + ccc.components.size() + " MetaType Descriptors in " + useFile);
+                MetaTypeIO.write(module, ccc.components, useFile, metatypeLocation);
+                fileNames.add(parentDir.getName() + '/' + mtDir.getName() + '/' + useFile.getName());
             }
 
-        } else {
-            if (components.size() > 0) {
-                logger.info("Meta type file name is not set: meta type info is not written.");
+            return fileNames;
+        }
+        if (mtDir.exists()) {
+            for(final File f : mtDir.listFiles()) {
+                if ( f.isFile() ) {
+                    logger.debug("Removing obsolete metatype file " + f);
+                    f.delete();
+                }
             }
         }
+
         return null;
     }