FELIX-3550 : Reimplement the SCR Generator
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1354394 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
index 0be35b2..9adcbca 100644
--- a/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
+++ b/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
@@ -206,7 +206,7 @@
// configuration pid
component.setConfigurationPid(cad.getStringValue("configurationPid", null));
- component.setCreatePid(cad.getBooleanValue("createPid", true));
+ component.setCreatePid(false);
// no inheritance
component.setInherit(false);
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 9a621e1..a4968af 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
@@ -156,7 +156,7 @@
final MetaData metaData = new MetaData();
metaData.setLocalization(MetaTypeService.METATYPE_DOCUMENTS_LOCATION + "/metatype");
- final List<ComponentContainer> processedComponents = new ArrayList<ComponentContainer>();
+ final List<ComponentContainer> processedContainers = new ArrayList<ComponentContainer>();
for (final ClassDescription desc : scannedDescriptions) {
this.logger.debug("Processing component class " + desc.getSource());
@@ -166,24 +166,20 @@
" Check the annotations and merge the definitions to a single definition.",
desc.getSource());
} else {
- try {
- final ComponentContainer comp = this.createComponent(desc, metaData, iLog);
- if (comp.getComponentDescription().getSpecVersion() != null) {
- if ( specVersion == null ) {
- specVersion = comp.getComponentDescription().getSpecVersion();
- logger.debug("Setting used spec version to " + specVersion);
- } else if (comp.getComponentDescription().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!
- iLog.addError("Component " + comp + " requires spec version " + comp.getComponentDescription().getSpecVersion().name()
- + " but plugin is configured to use version " + this.options.getSpecVersion(),
- desc.getSource());
- }
+ final ComponentContainer container = this.createComponent(desc, metaData, iLog);
+ if (container.getComponentDescription().getSpecVersion() != null) {
+ if ( specVersion == null ) {
+ specVersion = container.getComponentDescription().getSpecVersion();
+ logger.debug("Setting used spec version to " + specVersion);
+ } else if (container.getComponentDescription().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!
+ iLog.addError("Component " + container + " requires spec version " + container.getComponentDescription().getSpecVersion().name()
+ + " but plugin is configured to use version " + this.options.getSpecVersion(),
+ desc.getSource());
}
- processedComponents.add(comp);
- } catch (final SCRDescriptorException sde) {
- iLog.addError(sde.getMessage(), sde.getSourceLocation());
}
+ processedContainers.add(container);
}
}
// if spec version is still not set, we're using lowest available
@@ -197,16 +193,16 @@
// now check for abstract components and fill components objects
final DescriptionContainer module = new DescriptionContainer(this.options);
- for (final ComponentContainer comp : processedComponents) {
+ for (final ComponentContainer container : processedContainers) {
final int errorCount = iLog.getNumberOfErrors();
- final Validator validator = new Validator(comp, project, options, iLog);
+ final Validator validator = new Validator(container, project, options, iLog);
if ( this.options.isGenerateAccessors() ) {
// before we can validate we should check the references for bind/unbind method
// in order to create them if possible
- for (final ReferenceDescription ref : comp.getReferences().values()) {
+ for (final ReferenceDescription ref : container.getReferences().values()) {
// if this is a field with a single cardinality,
// we look for the bind/unbind methods
// and create them if they are not availabe
@@ -231,7 +227,7 @@
createUnbind = true;
}
if (createBind || createUnbind) {
- ClassModifier.addMethods(comp.getClassDescription().getDescribedClass().getName(),
+ ClassModifier.addMethods(container.getClassDescription().getDescribedClass().getName(),
name,
ref.getField().getName(),
type,
@@ -246,11 +242,11 @@
// ignore component if it has errors
if (iLog.getNumberOfErrors() == errorCount) {
- if (!comp.getComponentDescription().isCreateDs()) {
- logger.debug("Ignoring descriptor for DS : " + comp);
- } else if (!comp.getComponentDescription().isAbstract()) {
- this.logger.debug("Adding descriptor for DS : " + comp);
- module.addComponent(comp);
+ if (!container.getComponentDescription().isCreateDs()) {
+ logger.debug("Ignoring descriptor for DS : " + container);
+ } else if (!container.getComponentDescription().isAbstract()) {
+ this.logger.debug("Adding descriptor for DS : " + container);
+ module.add(container);
}
}
}
@@ -319,8 +315,7 @@
*/
private ComponentContainer createComponent(final ClassDescription desc,
final MetaData metaData,
- final IssueLog iLog)
- throws SCRDescriptorException, SCRDescriptorFailureException {
+ final IssueLog iLog) {
final ComponentDescription componentDesc = desc.getDescription(ComponentDescription.class);
// configuration pid in 1.2
@@ -410,7 +405,13 @@
if ( !inherit || current.getDescribedClass().getSuperclass() == null ) {
current = null;
} else {
- current = this.scanner.getDescription(current.getDescribedClass().getSuperclass());
+ try {
+ current = this.scanner.getDescription(current.getDescribedClass().getSuperclass());
+ } catch ( final SCRDescriptorFailureException sde) {
+ iLog.addError(sde.getMessage(), current.getSource());
+ } catch ( final SCRDescriptorException sde) {
+ iLog.addError(sde.getMessage(), sde.getSourceLocation());
+ }
}
} while ( inherit && current != null);
@@ -430,8 +431,7 @@
/**
* Process service directives
*/
- private void processServices(final ClassDescription current, final ComponentContainer component)
- throws SCRDescriptorException, SCRDescriptorFailureException {
+ private void processServices(final ClassDescription current, final ComponentContainer component) {
final ServiceDescription serviceDesc = current.getDescription(ServiceDescription.class);
if ( serviceDesc != null ) {
@@ -456,8 +456,7 @@
private void processProperties(
final ClassDescription current,
final ComponentContainer component,
- final OCD ocd)
- throws SCRDescriptorException, SCRDescriptorFailureException {
+ final OCD ocd) {
for(final PropertyDescription pd : current.getDescriptions(PropertyDescription.class)) {
// metatype - is this property private?
@@ -581,8 +580,7 @@
* Process reference directives
*/
private void processReferences(final ClassDescription current,
- final ComponentContainer component)
- throws SCRDescriptorException, SCRDescriptorFailureException {
+ final ComponentContainer component) {
for(final ReferenceDescription rd : current.getDescriptions(ReferenceDescription.class)) {
if ( rd.getPolicyOption() != ReferencePolicyOption.RELUCTANT ) {
component.getComponentDescription().setSpecVersion(SpecVersion.VERSION_1_2);
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
index 4fc6976..b016a82 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/ComponentContainer.java
@@ -36,7 +36,6 @@
* - the service descriptor
* - reference descriptors
* - property descriptors
- *
*/
public class ComponentContainer {
@@ -92,15 +91,29 @@
return this.allReferences;
}
+ /**
+ * Get all properties.
+ * The properties are put into the map by name.
+ * This map can be modified by clients.
+ * @return The map of properties
+ */
public Map<String, PropertyDescription> getProperties() {
return this.allProperties;
}
+ /**
+ * Get the service description.
+ * @return The service description or <code>null</code>
+ */
public ServiceDescription getServiceDescription() {
return serviceDescription;
}
- public void setServiceDescription(ServiceDescription serviceDescription) {
+ /**
+ * Set the service description
+ * @param serviceDescription The new service description
+ */
+ public void setServiceDescription(final ServiceDescription serviceDescription) {
this.serviceDescription = serviceDescription;
}
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/DescriptionContainer.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/DescriptionContainer.java
index 9b94282..eff6797 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/DescriptionContainer.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/helper/DescriptionContainer.java
@@ -18,50 +18,54 @@
*/
package org.apache.felix.scrplugin.helper;
-import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import org.apache.felix.scrplugin.Options;
-import org.apache.felix.scrplugin.description.ComponentDescription;
/**
- * <code>DescriptionContainer</code>...
- *
- * A description container is a collection of {@link ComponentDescription}s.
+ * The description container holds all {@link ComponentContainer}s.
*/
public class DescriptionContainer {
/** The options. */
private final Options options;
- /** The list of {@link Component}s. */
- private final List<ComponentContainer> components = new ArrayList<ComponentContainer>();
+ /** The list of {@link ComponentContainer}s. */
+ private final List<ComponentContainer> containers = new ArrayList<ComponentContainer>();
+ /**
+ * Constructor
+ * @param options The options for this module
+ */
public DescriptionContainer(final Options options) {
this.options = options;
}
+ /**
+ * Get the options
+ * @return The options
+ */
public Options getOptions() {
return this.options;
}
/**
- * Return the list of {@link Component}s.
+ * Return the list of {@link ComponentContainer}s.
*/
public List<ComponentContainer> getComponents() {
- return this.components;
+ return this.containers;
}
/**
- * Add a component to the list.
+ * Add a container to the list.
*/
- public void addComponent(ComponentContainer component) {
- this.components.add(component);
+ public void add(final ComponentContainer c) {
+ this.containers.add(c);
}
@Override
public String toString() {
- return "DescriptionContainer [options=" + options + ", components=" + components + "]";
+ return "DescriptionContainer [options=" + options + ", containers=" + containers + "]";
}
}