FELIX-4126 - Discontinue creation of single XML descriptor files
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1504095 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/generator/changelog.txt b/scrplugin/generator/changelog.txt
index 4c4bd32..ed93679 100644
--- a/scrplugin/generator/changelog.txt
+++ b/scrplugin/generator/changelog.txt
@@ -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
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 ef1c893..db0def5 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
@@ -43,15 +43,6 @@
/** 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 @@
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";
/**
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 f647846..27310b3 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
@@ -123,11 +123,8 @@
}
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();
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java
index 1ea2cda..2d05001 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainerUtil.java
@@ -33,46 +33,37 @@
* 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 + '$';
-
- // 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);
+ 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);
}
- } else {
- if ( components.size() > 0 ) {
- final ComponentContainerContainer ccc = new ComponentContainerContainer();
- ccc.components = components;
- result.add(ccc);
+ 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();
+ }
}
+
+ final ComponentContainerContainer ccc = new ComponentContainerContainer();
+ ccc.components = innerList;
+ ccc.className = baseClassName;
+ result.add(ccc);
}
return result;
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index 7cf61ec..cff9823 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -51,7 +51,6 @@
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 @@
// 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());
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
index f9c0143..d726a9e 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/MetaTypeIO.java
@@ -38,7 +38,6 @@
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 @@
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();
+ // write meta type info
+ final File mtDir = options.getMetaTypeDirectory();
+ final File parentDir = mtDir.getParentFile();
- final File mtFile = new File(mtDir, options.getMetaTypeName());
+ if (components.size() > 0) {
+ mtDir.mkdirs();
- 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");
- 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");
+ 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;
}
- String metatypeLocation = MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype";
+ 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;
+ }
+ }
+ }
+ 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());
}
- 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;
- }
+ 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;
}