Provide option to generate PID (which defaults to true) for a component.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@574499 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
index a84cc95..967f337 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
@@ -45,6 +45,8 @@
public static final String COMPONENT_ABSTRACT = "abstract";
+ public static final String COMPONENT_CREATE_PID = "create-pid";
+
public static final String PROPERTY = "scr.property";
public static final String PROPERTY_NAME = "name";
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
index c50042a..08aba82 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
@@ -123,7 +123,7 @@
final JavaTag tag = javaSources[i].getTagByName(Constants.COMPONENT);
if (tag != null) {
this.getLog().debug("Processing service class " + javaSources[i].getName());
- final Component comp = this.createComponent(javaSources[i], metaData);
+ final Component comp = this.createComponent(javaSources[i], tag, metaData);
if (comp != null) {
if ( comp.isAbstract() ) {
this.getLog().debug("Adding abstract descriptor " + comp);
@@ -219,10 +219,9 @@
* @return The generated component descriptor or null if any error occurs.
* @throws MojoExecutionException
*/
- protected Component createComponent(JavaClassDescription description, MetaData metaData)
+ protected Component createComponent(JavaClassDescription description, JavaTag componentTag, MetaData metaData)
throws MojoExecutionException {
-
- final JavaTag componentTag = description.getTagByName(Constants.COMPONENT);
+ // create a new component
final Component component = new Component(componentTag);
// set implementation
@@ -277,6 +276,23 @@
description = description.getSuperClass();
} while (inherited && description != null);
+ // pid handling
+ final boolean createPid = this.getBoolean(componentTag, Constants.COMPONENT_CREATE_PID, true);
+ if ( createPid ) {
+ // check for an existing pid first
+ boolean found = false;
+ final Iterator iter = component.getProperties().iterator();
+ while ( !found && iter.hasNext() ) {
+ final Property prop = (Property)iter.next();
+ found = org.osgi.framework.Constants.SERVICE_PID.equals( prop.getName() );
+ }
+ if ( !found ) {
+ final Property pid = new Property();
+ component.addProperty(pid);
+ pid.setName(org.osgi.framework.Constants.SERVICE_PID);
+ pid.setValue(component.getName());
+ }
+ }
final List issues = new ArrayList();
final List warnings = new ArrayList();
component.validate(issues, warnings);
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
index c4e104d..915a26b 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
@@ -87,6 +87,9 @@
* warnings can be added to the warnings list.
*/
public void validate(List issues, List warnings) {
- // might want to check name and type
+ if ( name == null || name.trim().length() == 0 ) {
+ issues.add(this.getMessage("Property name can not be empty."));
+ }
+ // might want to check type (and value)
}
}