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 2007/09/11 09:45:44 UTC
svn commit: r574499 - in
/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin:
Constants.java SCRDescriptorMojo.java om/Property.java
Author: cziegeler
Date: Tue Sep 11 00:45:43 2007
New Revision: 574499
URL: http://svn.apache.org/viewvc?rev=574499&view=rev
Log:
Provide option to generate PID (which defaults to true) for a component.
Modified:
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java?rev=574499&r1=574498&r2=574499&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/Constants.java Tue Sep 11 00:45:43 2007
@@ -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";
Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java?rev=574499&r1=574498&r2=574499&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/SCRDescriptorMojo.java Tue Sep 11 00:45:43 2007
@@ -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);
Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java?rev=574499&r1=574498&r2=574499&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java (original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/om/Property.java Tue Sep 11 00:45:43 2007
@@ -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)
}
}