felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Felix > Apache Felix Maven SCR Plugin
Date Wed, 20 Oct 2010 07:26:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=FELIX&amp;forWysiwyg=true" type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+SCR+Plugin">Apache Felix Maven SCR Plugin</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~fmeschbe">Felix Meschberger</a>
    </h4>
        <br/>
                         <h4>Changes (4)</h4>
                                 
    
<div id="page-diffs">
            <table class="diff" cellpadding="0" cellspacing="0">
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" ># The _Metatype Service_ provides a description suitable for management tools to manage configurations provided by the Configuration Admin Service. The descriptions of the data is provided in one or more XML files and associated languag binding files. <br> <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h2. Maven SCR Plugin <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h2. Where to go from here <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">* [{excerpt-include:Apache Felix Maven SCR Plugin Use|nopanel=true}|Apache Felix Maven SCR Plugin Use] <br>* [{excerpt-include:Apache Felix SCR Ant Task Use|nopanel=true}|Apache Felix SCR Ant Task Use] <br>* [{excerpt-include:SCR Annotations|nopanel=true}|SCR Annotations] <br>* [{excerpt-include:SCR JavaDoc Tags|nopanel=true}|SCR JavaDoc Tags] <br></td></tr>
            <tr><td class="diff-unchanged" > <br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">h3. Use <br> <br>Support for automatic generation of the compenent and metadata descriptors is embeded in the {{org.apache.felix:maven-scr-plugin}} plugin. To use this plugin, it has to be declared in the project descriptor as a {{&lt;plugin&gt;}} element: <br> <br>{code:xml} <br>&lt;project&gt; <br>  ... <br>  &lt;build&gt; <br>    ... <br>    &lt;plugins&gt; <br>      ... <br>      &lt;plugin&gt; <br>        &lt;groupId&gt;org.apache.felix&lt;/groupId&gt; <br>        &lt;artifactId&gt;maven-scr-plugin&lt;/artifactId&gt; <br>        &lt;executions&gt; <br>          &lt;execution&gt; <br>            &lt;id&gt;generate-scr-scrdescriptor&lt;/id&gt; <br>            &lt;goals&gt; <br>              &lt;goal&gt;scr&lt;/goal&gt; <br>            &lt;/goals&gt; <br>          &lt;/execution&gt; <br>        &lt;/executions&gt; <br>      &lt;/plugin&gt; <br>      ... <br>    &lt;/plugins&gt; <br>    ... <br>  &lt;/build&gt; <br>  ... <br>&lt;/project&gt; <br>{code} <br> <br>The {{scr}} goal is bound to the {{generate-resources}} phase and will generate a single descriptor file as well as meta type file for all components found in the project. <br> <br>The plugin may be configured with the following properties (Check the version column to make sure you use at least this version for the mentioned feature): <br>| *Property* | *Description* | *Version* | <br>| {{specVersion}} | The plugin will generate a descriptor for the Declarative Service version (either 1.0 or 1.1). If no value is specified, the plugin will detect the version and only use 1.1 if features from this version are used. | &gt;= 1.4.0 |  <br>| {{generateAccessors}} | If this switch is turned on, the bind and unbind methods for unary references are automatically generated by the plugin. By default this is set to {{true}}. | | <br>| {{parseJavadoc}} | If this switch is turned on, the java source code and its javadoc tags are scanned for the scr tags (see below). The default value is {{true}}. | | <br>| {{processAnnotations}} | If this switch is turned on, the java code is scanned for the scr annotations (see below). The default value is {{true}}. | &gt;= 1.2.0 | <br>| {{sourceExcludes}} | Comma separated list of classes to exclude when processing the source. | | <br>| {{strictMode}} | The plugin distinguishes between errors and warnings. In strict mode warnings are treated as errors and cause the plugin to fail. The default value is {{false}}. | | <br>| {{properties}} | A map of predefined properties. These properties are set to each component (if the component does not define the property already). This is a map where the property name is made up by the included element name and the value is the value of the element.| &gt;= 1.2.0 | <br>| {{finalName}} | The name of the descriptor file to create. This property defaults to the value of the {{scr.descriptor.name}} property if defined. Otherwise the default is {{serviceComponents.xml}}. | | <br>| {{metaTypeName}} | The name of the descriptor file to create. This property defauls to {{metatype.xml}}. | | <br>The meta type file is generated in the {{OSGI-INF/metatype/}} directory and the scr descriptor file in the {{OSGI-INF}} directory. <br>_Note_: The location of the meta type descriptor may not be changed as the OSGi Metatype Service Specification prescribes the location of the descriptors. <br> <br>The plugin will look for component definition tags in all Java files found in the source directories of the project. <br> <br>h3. Using the descriptor <br> <br>Currently the {{maven-scr-plugin}} only creates the component descriptor file. Adding the descriptor to the bundle and setting the {{Service-Component}} manifest header accordingly is a different task. However, if you&#39;re using the {{org.apache.felix:maven-bundle-plugin}} to construct the bundle and its manifest, then the {{maven-scr-plugin}} will add the following settings automatically for the {{org.apache.felix:maven-bundle-plugin}} (given default {{maven-scr-plugin}} configuration), so you don&#39;t have to configure this yourself: <br> <br>{code:xml} <br>... <br>&lt;Include-Resource&gt; <br>    src/main/resources, <br>    target/scr-plugin-generated <br>&lt;/Include-Resource&gt; <br>&lt;Service-Component&gt; <br>  OSGI-INF/serviceComponents.xml <br>&lt;/Service-Component&gt; <br>... <br>{code} <br> <br>h2. Annotations <br> <br>The {{maven-scr-plugin}} uses the {{SCR}} annotations from the corresponding subproject at Apache Felix. All annotations are in the {{org.apache.felix.scr.annotations}} package. If you want to use the annotations in your project, you have to use a {{maven-scr-plugin}} version &gt;= 1.2.0 and make sure that you add a dependency to the annotations to your {{POM}}: <br> <br>{code:xml} <br>&lt;dependency&gt; <br>    &lt;groupId&gt;org.apache.felix&lt;/groupId&gt; <br>    &lt;artifactId&gt;org.apache.felix.scr.annotations&lt;/artifactId&gt; <br>    &lt;version&gt;1.2.0&lt;/version&gt; <br>&lt;/dependency&gt; <br>{code} <br> <br>The following annotations are supported: <br>* {{[Component|#Component]}} <br>* {{[Activate|#scran_componentmethod]}} <br>* {{[Deactivate|#scran_componentmethod]}} <br>* {{[Modified|#scran_componentmethod]}} <br>* {{[Service|#Service]}} <br>* {{[Property|#Property]}} <br>* {{[Reference|#Reference]}} <br> <br> <br>h3. Component <br> <br>The {{Component}} annotation is the only required annotation. If this annotation is not declared for a Java class, the class is not declared as a component. <br> <br>This annotation is used to declare the {{&lt;component&gt;}} element of the component declaration. See section 112.4.3, Component Element, in the OSGi Service Platform Service Compendium Specification for more information. The required {{&lt;implementation&gt;}} element is automatically generated with the fully qualified name of the class containing the {{Component}} annotation. <br> <br>Supported attributes: <br>| *Name* | *Default Value* | *Required* | *SCR* | *Metatype* | *Description* | <br>| name | Fully qualified name of the Java class | no | {{component.name}} | {{OCD.id}} | Defines the Component name also used as the PID for the Configuration Admin Service | <br>| ds | {{true}} | no | --  | --  | Whether Declarative Services descriptor is generated or not. If this parameter is not set or set to {{true}} the Declarative Services descriptor is generated in the service descriptor file for this component. Otherwise no Declarative Services descriptor is generated for this component. | <br>| specVersion | {{1.0}} | no | -- | -- | Defines what Declarative Services specification the component is written against. Though the Maven SCR Plugin is very good at detecting whether components are written against the original or a newer specification, there are some cases, where the plugin may fail. For these cases, the {{specVersion}} attribute may be set to the correct version. Currently supported values for this attribute are {{1.0}} and {{1.1}}. Since version 1.4.1 of the Maven SCR Plugin and version 1.0.1 of the SCR Annotations. | <br>| componentAbstract | see description | no | --  | --  | This marks an abstract service description which is not added to the descriptor but intended for reuse through inheritance. This attribute defaults to {{true}} for abstract classes and {{false}} for concrete classes. | <br>| enabled | {{true}} | no | {{component.enabled}} | --  | Whether the component is enabled when the bundle starts | <br>| factory | --  | no | {{component.factory}} | --  | Whether the component is a factory component | <br>| immediate | --  | no | {{component.immediate}} | --  | Whether the component is immediately activated | <br>| inherit | {{true}} | no | --  | --  | Whether any service, property and reference declarations from base classes should be inherited by this class. | <br>| metatype | {{false}} | no | --  | --  | Whether Metatype Service data is generated or not. If this parameter is set to {{true}} Metatype Service data is generated in the {{metatype.xml}} file for this component. Otherwise no Metatype Service data is generated for this component. | <br>| label | {{%&lt;name&gt;.name}} | no | --  | {{OCD.name}} | This is generally used as a title for the object described by the meta type. This name may be localized by prepending a {{%}} sign to the name. | <br>| description | {{%&lt;name&gt;.name}} | no | --  | {{OCD.description}} | This is generally used as a description for the object described by the meta type. This name may be localized by prepending a {{%}} sign to the name. | <br>| createPid | {{true}} | no | {{service.pid}} | --  | Generate the {{service.pid}} property if non is declared. | <br>| configurationFactory | {{false}} | no | -- | {{Designate.factoryPid}} | Is this a configuration factory? (since 1.4.0) | <br> <br>The follwing attributes are supported since version 1.4.0 of the plugin and required a Declarative Service implementation 1.1: <br>| policy | {{OPTIONAL}} | no | component.policy | -- | The configuration policy for this component: {{OPTIONAL}}, {{IGNORE}}, or {{REQUIRE}} | <br> <br> <br>h4. Abstract Service Descriptions <br> <br>If the {{Component}} annotations contains the attribute {{componentAbstract}} with a value of true, the containing class is regarded as an abstract class. It is not added to the service descriptor and the tags are not validated. The information about this class is added to the bundle. Classes from other bundles (or the same) can extends this abstract class and do not need to specify the references of the abstract class if they set the {{inherit}} parameter on the {{scr.component}} tag to true. <br> <br>This allows to create abstract classes which already provide some valuable functionality without having to deal with the details like reference definitions in each and every subclass. <br> <br> <br>{anchor:componentmethod} <br>h3. {{Activate}}, {{Deactivate}}, and {{Modified}} <br> <br>The Declarative Service version 1.1 allows to specify the name for the activate, deactivate and modified method (see the spec for more information). The {{Activate}}, {{Deactivate}}, and {{Modified}} annotation can be used to mark a method to be used for the specified purpose. However, as the DS specifies a method search algorithm, there are rare cases where the marked method is not used (if there is another method with the same name, but a different signature this might happen). <br> <br> <br>h3. Service <br> <br>The {{Service}} annotation defines whether and which service interfaces are provided by the component. This is a class annotation. <br> <br>This tag is used to declare {{&lt;service&gt;}} and {{&lt;provide&gt;}} elements of the component declaration. See section 112.4.6, Service Elements, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported attributes: <br>| *Name* | *Default Value* | *Required* | *Descriptor* | *Description* | <br>| value | All implemented interfaces | no | {{provide.interface}} | The name of the service interface provided by the component. This can either be the fully qualified  name or just the interface class name if the interface is either in the same package or is imported. If this property is not set {{provide}} elements will be generated for all interfaces generated by the class | <br>| serviceFactory | {{false}} | no | {{service.servicefactory}} | Whether the component is registered as a {{ServiceFactory}} or not | <br>Omitting the {{Service}} annotation will just define (and activate if required) the component but not register it as a service. Multiple {{Service}} annotations may be declared each with its own {{value}}. These annotations need to be wrapped into a {{Services}} anotation. The component is registered as a {{ServiceFactory}} if at least on {{Service}} annotations declares the {{serviceFactory}} attribute as {{true}}. <br> <br> <br> <br>h3. Property <br> <br>The {{Property}} annotation defines properties which are made available to the component through the {{ComponentContext.getProperties()}} method. These tags are not strictly required but may be used by components to defined initial configuration. Additionally properties may be set here to identify the component if it is registered as a service, for example the {{service.description}} and {{service.vendor}} properties. <br> <br>This tag may be defined in the Java Class comment of the component or in a coment to a field defining a constant with the name of the property. <br> <br>This tag is used to declare {{&lt;property&gt;}} elements of the component declaration. See section 112.4.5, Properties and Property Elements, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *SCR* | *Metatype* | *Description* | <br>| name | The name of constant | yes | {{property.name}} | {{AD.id}} | The name of the property. If this tag is defined on a field with an initialization expression, the value of that expression is used as the name if the field is of type {{String}}. | <br>| value | --  | no | {{property.value}} | {{AD.default}} | The string value of the property. This can either be a single value or an array. | <br>| longValue | --  | no | {{property.value}} | {{AD.default}} | The long value of the property. This can either be a single value or an array. | <br>| doubleValue | --  | no | {{property.value}} | {{AD.default}} | The double value of the property. This can either be a single value or an array. | <br>| floatValue | --  | no | {{property.value}} | {{AD.default}} | The float value of the property. This can either be a single value or an array. | <br>| intValue | --  | no | {{property.value}} | {{AD.default}} | The int value of the property. This can either be a single value or an array. | <br>| byteValue | --  | no | {{property.value}} | {{AD.default}} | The byte value of the property. This can either be a single value or an array. | <br>| charValue | --  | no | {{property.value}} | {{AD.default}} | The char value of the property. This can either be a single value or an array. | <br>| boolValue | --  | no | {{property.value}} | {{AD.default}} | The boolean value of the property. This can either be a single value or an array. | <br>| shortValue | --  | no | {{property.value}} | {{AD.default}} | The short value of the property. This can either be a single value or an array. | <br>| label | {{%&lt;name&gt;.name}} | no | --  | {{AD.name}} | The label to display in a form to configure this property. This name may be localized by prepending a {{%}} sign to the name. | <br>| description | {{%&lt;name&gt;.description}} | no | --  | {{AD.description}} | A descriptive text to provide the client in a form to configure this property. This name may be localized by prepending a {{%}} sign to the name. | <br>| propertyPrivate | Depending on the name | no | --  | See description | Boolean flag defining whether a metatype descriptor entry should be generated for this property or not. By default a metatype descriptor entry, i.e. an {{AD}} element, is generated except for the properties {{service.pid}}, {{service.description}}, {{service.id}}, {{service.ranking}}, {{service.vendor}}, {{service.bundlelocation}} and {{service.factoryPid}}. If a property should not be available for display in a configuration user interface, this parameter should be set to {{true}}. | <br>| cardinality | Depends on property value(s) | no | --  | {{AD.cardinality}} | Defines the cardinality of the property and its collection type. If the cardinality is negative, the property is expected to be stored in a {{java.util.Vector}} (primitive types such as {{boolean}} are boxed in the Wrapper class), if the cardinality is positive, the property is stored in an array (primitve types are unboxed, that is {{Boolean}} type values are stored in {{boolean\[\]}}). The actual value defines the maximum number of elements in the vector or array, where {{Integer.MIN_INT}} describes an unbounded Vector and {{Integer.MAX_INT}} describes an unbounded array. If the cardinality is zero, the property is a scalar value. If the defined value of the property is set in the {{value}} attribute, the cardinality defaults to {{0}} (zero for scalar value). If the property is defined in one or more properties starting with {{values}}, the cardinality defaults to {{Integer.MAX_INT}}, that is an unbounded array. | <br>| options | --  | no | --  | See below | See below for a description of the {{options}} attribute. | <br>* Generating {{&lt;properties&gt;}} elements referring to bundle entries is not currently supported. <br>* Multiple property annotations can be embedded in the {{Properties}} annoation. <br> <br> <br>h4. Naming the Property <br> <br>It is important to carefully define the name of properties. By using a constant of the form <br> <br>{code:xml} <br>@Property(value=&quot;default value&quot;) <br>static final String CONSTANT_NAME = &quot;property.name&quot;; <br>{code} <br> <br>and defining the {{Property}} annotation on this constant, the name of the property is taken from the constant value. Thus it may easily be ensured, that both the property in the descriptor files and the property used by the implementation are actually the same. In addition the value attribute can point to another constant. <br> <br> <br>h4. The {{options}} Parameter <br> <br>Some properties may only be set to a set of possible values. To support user interfaces which provide a selection list of values or a list of checkboxes the option values and labels may be defined as parameters to the {{Property}} annotation. All parameters in the form of name-value pairs occurring _after_ the {{options}} attribute are used to build the list of available value options. The parameter name is used as the value while the parameter value is used as the label in the user interface. This label may be prepended with a {{%}} sign to localize the string. <br> <br>The options are written to the {{metatype.xml}} file as {{Option}} elements inside the {{AD}} element defining the property. The name of the parameter will be used for the {{Option.value}} attribute while the value of the parameter defines the {{Option.label}} attribute. <br> <br>Please note, that all parameters of the {{Property}} annotation occurring _after_ the {{options}} parameter are used to build the options list. Hence no non-option value parameters should actually follow the {{options}} parameter. <br> <br>h4. Multivalue Properties <br> <br>Generally the value of a property is scalar, that is a property has a single value such as {{true}}, {{5}} or {{&quot;This is a String&quot;}}. Such scalar values are defined with the different {{value}} attributes of the {{Property}} annotation. In the case of a scalar property value, the {{cardinality}} parameter value is assumed to be {{0}} (zero) unless of course set otherwise. <br> <br>There may be properties, which have a list of values, such as a list of possible URL mappings for an URL Mapper. Such multiple values are defined just by comma separate as the value of the annotation parameter. <br> <br>If the cardinality of the property is not explicilty set with the {{cardinality}} property, it defaults to {{Integer.MAX_INT}}, i.e. unbound array, if multiple values are defined. Otherwise the {{cardinality}} parameter may be set for example to a negative value to store the values in a {{java.util.Vector}} instead. <br> <br> <br> <br>h3. Reference <br> <br>The {{Reference}} annotation defines references to other services made available to the component by the Service Component Runtime. <br> <br>This annotation may be declared on a Class level or any Java field to which it might apply. Depending on where the annotation is declared, the parameters may have different default values. <br> <br>This annotation is used to declare {{&lt;reference&gt;}} elements of the component declaration. See section 112.4.7, Reference Element, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *Descriptor* | *Description* | <br>| name | Name of the field | yes | {{reference.name}} | The local name of the reference. If the {{Reference}} annotation is declared in the class comment, this parameter is required. If the annotation is declared on a field, the default value for the {{name}} parameter is the name of the field | <br>| interface | Type of the field | yes | {{reference.interface}} | The name of the service interface. This name is used by the Service Component Runtime to access the service on behalf of the component. If the {{Reference}} annotation is declared on a class level, this parameter is required. If the annoation is declared on a field, the default value for the {{interface}} parameter is the type of the field | <br>| cardinality | {{1..1}} | no | {{reference.cardinality}} | The cardinality of the service reference. This must be one of value from the enumeration {{ReferenceCardinality}} | <br>| policy | {{static}} | no | {{reference.policy}} | The dynamicity policy of the reference. If {{dynamic}} the service will be made available to the component as it comes and goes. If {{static}} the component will be deactivated and re-activated if the service comes and/or goes away. This must be one of {{static}} and {{dynamic}} | <br>| target | --  | no | {{reference.target}} | A service target filter to select specific services to be made available. In order to be able to overwrite the value of this value by a configuration property, this parameter must be declared. If the parameter is not declared, the respective declaration attribute will not be generated | <br>| bind | See description | no | {{reference.bind}} | The name of the method to be called when the service is to be bound to the component. The default value is the name created by appending the reference {{name}} to the string {{bind}}. The method must be declared {{public}} or {{protected}} and take single argument which is declared with the service interface type | <br>| unbind | See description | no | {{reference.unbind}} | The name of the method to be called when the service is to be unbound from the component. The default value is the name created by appending the reference {{name}} to the string {{unbind}}. The method must be declared {{public}} or {{protected}} and take single argument which is declared with the service interface type | <br>| strategy | {{event}} | no || {{reference.strategy}} | The strategy used for this reference, one of {{event}} or {{lookup}} | <br>_Notes_: <br>* If you define a reference on a field with a strategy of {{event}} and there is no bind or unbind method, the plugin will create the necessary methods. <br> <br>h2. JavaDoc tags <br> <br>The {{scr}} goal of the {{maven-scr-plugin}} looks for the following JavaDoc tags when building component descriptors: <br>* {{[scr.component|#scr.component]}} <br>* {{[scr.property|#{{scr.property}}]}} <br>* {{[scr.service|#scr.service]}} <br>* {{[scr.reference|#scr.reference]}} <br> <br> <br> <br>h3. scr.component <br> <br>The {{scr.component}} tag is the only required tag. If this tag is not declared in the Java class comment, the class is not declared as a component. <br> <br>This tag is used to declare the {{&lt;component&gt;}} element of the component declaration. See section 112.4.3, Component Element, in the OSGi Service Platform Service Compendium Specification for more information. The required {{&lt;implementation&gt;}} element is automatically generated with the fully qualified name of the class containing the {{scr.component}} tag. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *SCR* | *Metatype* | *Description* | <br>| name | Fully qualified name of the Java class | no | {{component.name}} | {{OCD.id}} | Defines the Component name also used as the PID for the Configuration Admin Service | <br>| ds | {{true}} | no | --  | --  | Whether Declarative Services descriptor is generated or not. If this parameter is not set or set to {{true}} the Declarative Services descriptor is generated in the service descriptor file for this component. Otherwise no Declarative Services descriptor is generated for this component. | <br>| abstract | see description | no | --  | --  | This marks an abstract service description which is not added to the descriptor but intended for reuse through inheritance. This attribute defaults to {{true}} for abstract classes and {{false}} for concrete classes. | <br>| enabled | {{true}} | no | {{component.enabled}} | --  | Whether the component is enabled when the bundle starts | <br>| factory | --  | no | {{component.factory}} | --  | Whether the component is a factory component | <br>| immediate | --  | no | {{component.immediate}} | --  | Whether the component is immediately activated | <br>| inherit | {{true}} | no | --  | --  | Whether any service, property and reference declarations from base classes should be inherited by this class. | <br>| metatype | {{true}} | no | --  | --  | Whether Metatype Service data is generated or not. If this parameter is not set or set to {{true}} Metatype Service data is generated in the {{metatype.xml}} file for this component. Otherwise no Metatype Service data is generated for this component. | <br>| label | {{%&lt;name&gt;.name}} | no | --  | {{OCD.name}} | This is generally used as a title for the object described by the meta type. This name may be localized by prepending a {{%}} sign to the name. | <br>| description | {{%&lt;name&gt;.name}} | no | --  | {{OCD.description}} | This is generally used as a description for the object described by the meta type. This name may be localized by prepending a {{%}} sign to the name. | <br>| create-pid | {{true}} | no | {{service.pid}} | --  | Generate the {{service.pid}} property if non is declared. | <br>| configurationFactory | {{false}} | no | -- | {{Designate.factoryPid}} | Is this a configuration factory? (since 1.4.0) | <br> <br>The follwing attributes are supported since version 1.4.0 of the plugin and required a Declarative Service implementation 1.1: <br>| policy | {{OPTIONAL}} | no | component.policy | -- | The configuration policy for this component: {{OPTIONAL}}, {{IGNORE}}, or {{REQUIRE}} | <br>| activate | {{activate}} | no | component.activate | -- | The name of the component activation method. | <br>| deactivate | {{deactivate}} | no | component.deactivate | -- | The name of the component deactivation method. | <br>| modified | -- | no | component.modified | -- | The name of the component modified method. | <br> <br>h4. Abstract Service Descriptions <br> <br>If the {{scr.component}} tag contains the parameter {{abstract}} with a value of true, the containing class is regarded as an abstract class. It is not added to the service descriptor and the tags are not validated. The information about this class is added to the bundle. Classes from other bundles (or the same) can extends this abstract class and do not need to specify the references of the abstract class if they set the {{inherit}} parameter on the {{scr.component}} tag to true. <br> <br>This allows to create abstract classes which already provide some valuable functionality without having to deal with the details like reference definitions in each and every subclass. <br> <br> <br>h3. scr.property <br> <br>The {{scr.property}} tag defines properties which are made available to the component through the {{ComponentContext.getProperties()}} method. These tags are not strictly required but may be used by components to defined initial configuration. Additionally properties may be set here to identify the component if it is registered as a service, for example the {{service.description}} and {{service.vendor}} properties. <br> <br>This tag may be defined in the Java Class comment of the component or in a coment to a field defining a constant with the name of the property. <br> <br>This tag is used to declare {{&lt;property&gt;}} elements of the component declaration. See section 112.4.5, Properties and Property Elements, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *SCR* | *Metatype* | *Description* | <br>| name | The name of constant | yes | {{property.name}} | {{AD.id}} | The name of the property. If this tag is defined on a field with an initialization expression, the value of that expression is used as the name if the field is of type {{String}}. | <br>| value | --  | no | {{property.value}} | {{AD.default}} | The value of the property. If the property type is not {{String}}, parsing of the value is done using the {{valueOf(String)}} method of the class defined by the property type | <br>| type | {{String}} | no | {{property.type}} | {{AD.type}} | The type of the property value. This must be one of {{String}}, {{Long}}, {{Double}}, {{Float}}, {{Integer}}, {{Byte}}, {{Char}}, {{Boolean}} and {{Short}}. | <br>| label | {{%&lt;name&gt;.name}} | no | --  | {{AD.name}} | The label to display in a form to configure this property. This name may be localized by prepending a {{%}} sign to the name. | <br>| description | {{%&lt;name&gt;.description}} | no | --  | {{AD.description}} | A descriptive text to provide the client in a form to configure this property. This name may be localized by prepending a {{%}} sign to the name. | <br>| private | Depending on the name | no | --  | See description | Boolean flag defining whether a metatype descriptor entry should be generated for this property or not. By default a metatype descriptor entry, i.e. an {{AD}} element, is generated except for the properties {{service.pid}}, {{service.description}}, {{service.id}}, {{service.ranking}}, {{service.vendor}}, {{service.bundlelocation}} and {{service.factoryPid}}. If a property should not be available for display in a configuration user interface, this parameter should be set to {{true}}. | <br>| cardinality | Depends on property value(s) | no | --  | {{AD.cardinality}} | Defines the cardinality of the property and its collection type. If the cardinality is negative, the property is expected to be stored in a {{java.util.Vector}} (primitive types such as {{boolean}} are boxed in the Wrapper class), if the cardinality is positive, the property is stored in an array (primitve types are unboxed, that is {{Boolean}} type values are stored in {{boolean\[\]}}). The actual value defines the maximum number of elements in the vector or array, where {{Integer.MIN_INT}} describes an unbounded Vector and {{Integer.MAX_INT}} describes an unbounded array. If the cardinality is zero, the property is a scalar value. If the defined value of the property is set in the {{value}} attribute, the cardinality defaults to {{0}} (zero for scalar value). If the property is defined in one or more properties starting with {{values}}, the cardinality defaults to {{Integer.MAX_INT}}, that is an unbounded array. | <br>| options | --  | no | --  | See below | See below for a description of the {{options}} parameter. | <br>| values\* | --  | no | --  | See below | See below for a description of parameters starting with {{values}}. | <br>| valueRef | --  | no | --  | {{AD.default}} | A constant containing the value for this property. The constant can either be declared in the same class as this property or in any class that is imported. The type of the property is derived from the constant. | <br>| valueRefs | --  | no | --  | See below | Same as the {{values}} attribute with the difference that it acts like the {{valueRef}} attribute and the value points to a constants defining the multi value for the property. | <br>_Notes_: <br>* Generating {{&lt;properties&gt;}} elements referring to bundle entries is not currently supported. <br> <br> <br>h4. Naming the property <br> <br>It is important to carefully define the name of properties. By using a constant of the form <br> <br>{code:xml} <br>/** @scr.property value=&quot;default value&quot; */ <br>static final String CONSTANT_NAME = &quot;property.name&quot;; <br>{code} <br> <br>and defining the {{scr.property}} tag on this constant, the name of the property is taken from the constant value. Thus it may easily be ensured, that both the property in the descriptor files and the property used by the implementation are actually the same. <br> <br> <br>h4. The {{options}} parameter <br> <br>Some properties may only be set to a set of possible values. To support user interfaces which provide a selection list of values or a list of checkboxes the option values and labels may be defined as parameters to the {{scr.property}} tag. All parameters in the form of name-value pairs occurring _after_ the {{options}} parameter are used to build the list of available value options. The parameter name is used as the value while the parameter value is used as the label in the user interface. This label may be prepended with a {{%}} sign to localize the string. <br> <br>The options are written to the {{metatype.xml}} file as {{Option}} elements inside the {{AD}} element defining the property. The name of the parameter will be used for the {{Option.value}} attribute while the value of the parameter defines the {{Option.label}} attribute. <br> <br>Please note, that all parameters of the {{scr.property}} tag occurring _after_ the {{options}} parameter are used to build the options list. Hence no non-option value parameters should actually follow the {{options}} parameter. <br> <br> <br>h4. Multivalue properties <br> <br>Generally the value of a property is scalar, that is a property has a single value such as {{true}}, {{5}} or {{&quot;This is a String&quot;}}. Such scalar values are defined with the {{value}} parameter of the {{scr.property}} tag. In the case of a scalar property value, the {{cardinality}} parameter value is assumed to be {{0}} (zero) unless of course set otherwise. <br> <br>There may be properties, which have a list of values, such as a list of possible URL mappings for an URL Mapper. Such multiple values are defined in one more parameters whose name starts with {{values}}. Each parameter must of course have a unique name which is not in any except to differentiate the parameters. <br> <br>If the cardinality of the property is not explicilty set with the {{cardinality}} property, it defaults to {{Integer.MAX_INT}}, i.e. unbound array, if multiple values with a series of {{values}} parameters are defined. Otherwise the {{cardinality}} parameter may be set for example to a negative value to store the values in a {{java.util.Vector}} instead. <br> <br> <br> <br>h3. scr.service <br> <br>The {{scr.service}} tag defines whether and which service interfaces are provided by the component. <br> <br>This tag is expected in the Java Class comment of the component. <br> <br>This tag is used to declare {{&lt;service&gt;}} and {{&lt;provide&gt;}} elements of the component declaration. See section 112.4.6, Service Elements, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *Descriptor* | *Description* | <br>| interface | All implemented interfaces | no | {{provide.interface}} | The name of the service interface provided by the component. This can either be the fully qualified  name or just the interface class name if the interface is either in the same package or is imported. If this property is not set {{provide}} elements will be generated for all interfaces generated by the class | <br>| servicefactory | {{false}} | no | {{service.servicefactory}} | Whether the component is registered as a {{ServiceFactory}} or not | <br>Omitting the {{scr.service}} tag will just define (and activate if required) the component but not register it as a service. Multiple {{scr.service}} tags may be declared each with its own {{interface}}. The component is registered as a {{ServiceFactory}} if at least on {{scr.service}} tag declares the {{servicefactory}} parameter as {{true}}. <br> <br> <br> <br>h3. scr.reference <br> <br>The {{scr.reference}} tag defines references to other services made available to the component by the Service Component Runtime. <br> <br>This tag may be declared in the java Class comment or any Java Field to which it might apply. Depending on where the tag is declared, the parameters may have different default values. <br> <br>This tag is used to declare {{&lt;reference&gt;}} elements of the component declaration. See section 112.4.7, Reference Element, in the OSGi Service Platform Service Compendium Specification for more information. <br> <br>Supported parameters: <br>| *Name* | *Default Value* | *Required* | *Descriptor* | *Description* | <br>| name | Name of the field | yes | {{reference.name}} | The local name of the reference. If the {{scr.reference}} tag is declared in the class comment, this parameter is required. If the tag is declared in the field comment, the default value for the {{name}} parameter is the name of the field | <br>| interface | Type of the field | yes | {{reference.interface}} | The name of the service interface. This name is used by the Service Component Runtime to access the service on behalf of the component. If the {{scr.reference}} tag is declared in the class comment, this parameter is required. If the tag is declared in the field comment, the default value for the {{interface}} parameter is the type of the field | <br>| cardinality | {{1..1}} | no | {{reference.cardinality}} | The cardinality of the service reference. This must be one of {{0..1}}, {{1..1}}, {{0..n}}, and {{1..n}} | <br>| policy | {{static}} | no | {{reference.policy}} | The dynamicity policy of the reference. If {{dynamic}} the service will be made available to the component as it comes and goes. If {{static}} the component will be deactivated and re-activated if the service comes and/or goes away. This must be one of {{static}} and {{dynamic}} | <br>| target | --  | no | {{reference.target}} | A service target filter to select specific services to be made available. In order to be able to overwrite the value of this value by a configuration property, this parameter must be declared. If the parameter is not declared, the respective declaration attribute will not be generated | <br>| bind | See description | no | {{reference.bind}} | The name of the method to be called when the service is to be bound to the component. The default value is the name created by appending the reference {{name}} to the string {{bind}}. The method must be declared {{public}} or {{protected}} and take single argument which is declared with the service interface type | <br>| unbind | See description | no | {{reference.unbind}} | The name of the method to be called when the service is to be unbound from the component. The default value is the name created by appending the reference {{name}} to the string {{unbind}}. The method must be declared {{public}} or {{protected}} and take single argument which is declared with the service interface type | <br>| strategy | {{event}} | no || {{reference.strategy}} | The strategy used for this reference, one of {{event}} or {{lookup}} | <br> <br>_Notes_: <br>* If you define a reference on a field with the strategy {{event}} and there is no bind or unbind method, the plugin will create the necessary methods. <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h2. Differences between JavaDoc tags and annotations <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>The Apache Felix Maven SCR Plugin is a great tool to ease the development of OSGi components and services. Components and services are defined through annotations and the plugin creates the necessary descriptors for the OSGi Declarative Services, Config Admin and Metatype services. Starting with version 1.4.0 of the plugin, OSGi Declarative Services versions 1.0 and 1.1 are supported.</p>

<p>Make sure to see the <a href="/confluence/display/FELIX/Apache+Felix+SCR+Plugin+FAQ" title="Apache Felix SCR Plugin FAQ">FAQ</a> for known problems.</p>

<h2><a name="ApacheFelixMavenSCRPlugin-Introduction"></a>Introduction</h2>

<p>In OSGi based systems functionality is mainly provided through services. Unlike traditional systems but comparable to Spring, a service is not reqiured to implement a framework defined interface. Instead services implement one or more interfaces, which stipulate the type of service provided. It is the lifetime of the bundle, which defines the lifetime of the service: A service object may be instantiated when the bundle is started and will automatically be removed when the bundle is stopped (and the service has not already been unregistered).</p>

<p>Usually, the functionality of a bundle - be it the packages exported or be it the services provided - is made available to the rest of the system, when the bundle is started. To give the bundle a change to take action, a bundle may declare a <tt>BundleActivator</tt> class in the <tt>Bundle-Activato</tt> manifest header of the bundle. When the bundle is started, the <tt>start(BundleContext)</tt> method is called, while the <tt>stop(BundleContext)</tt> method is called when the bundle is stopped. These methods are one place to instantiate and register services with the service registry.</p>

<p>The drawback of this method of service registration is that the services have to acquire other services whose functionality is used themselves and also have to observe the presence as services may come and go at any time. Though this observation is rather easy as basically a <tt>ServiceListener</tt> is to be implemented which listens for service registration and unregistration events, this is somewhat tedious and repeating for each service using other services.</p>

<p>To overcome this situation, the OSGi Service Platform Compendium Specification provides the <em>Declarative Services Specification</em>. This specification enables the declaration of services in configuration files, which are read by the <em>Declarative Services Runtime</em> to observe dependencies and activate (register) and deactivate (unregister) services depending on whether requirements can be met. Additionally, the dependencies may be supplied through declared methods. The specification calls a class declared this way a component. A component may or may not be a service registered with the service registry.</p>

<p>Components are declared using XML configuration files contained in the respective bundle and listed in the <tt>Service-Component</tt> bundle manifest header. These configuration files may be handwritten and registered. To support automatic generation of the component descriptors, the Maven SCR Plugin helps in the generation of these files by means of JavaDoc tags embedded in the Java source code of the components.</p>

<p>Related to declarative services is configuration support. To support configuration of services and components, OSGi provides the Configuration Admin Service Specification. This specification defines a service, which is the center of providing configuration to services and components. As such the Configuration Admin Service cares for storing configuration and deliver the configuration automatically or on-demand to clients. Configuration objects are identified by so-called Persistent Identifiers (PID) and are bound to bundles when used. For services implementing the special <tt>ManagedService</tt> or <tt>ManagedServiceFactory</tt> interfaces the PID has to be provided in the service properties as a property with the name <tt>service.pid</tt>. For Declarative Services, the name of the component is used as the PID to retrieve the configuration from the Configuration Admin Service.</p>

<p>The Configuration Admin Service not only allows components to get or retrieve configuration, it also provides the entry point for Management Agents to retrieve and update configuration data. To help building Management Agents the OSGi Metatype Service Specification defines a descripton model which may be used to describe data used by components and services. The configuration properties and meta type description for a given PID together are used to build the user interface to configure the service and/or component.</p>

<p>To summarize:</p>
<ol>
	<li><em>Declarative Services</em> provides a means to define components (and services) through one or more XML files. Each component may get default configuration from its own definition.</li>
	<li>The <em>Configuration Admin Service</em> provides functionality to provide configuration to components and services as well as to support management tools to update (and create) configuration data.</li>
	<li>The <em>Metatype Service</em> provides a description suitable for management tools to manage configurations provided by the Configuration Admin Service. The descriptions of the data is provided in one or more XML files and associated languag binding files.</li>
</ol>


<h2><a name="ApacheFelixMavenSCRPlugin-Wheretogofromhere"></a>Where to go from here</h2>

<ul>
	<li><a href="/confluence/display/FELIX/Apache+Felix+Maven+SCR+Plugin+Use" title="Apache Felix Maven SCR Plugin Use">Using the Apache Felix Maven SCR Plugin to generate Declarative Services and Metatype Service descriptors during a Maven Build</a></li>
	<li><a href="/confluence/pages/createpage.action?spaceKey=FELIX&amp;title=Apache+Felix+SCR+Ant+Task+Use&amp;linkCreation=true&amp;fromPageId=63098" class="createlink">The page Apache Felix SCR Ant Task Use does not exist.</a></li>
	<li><a href="/confluence/display/FELIX/SCR+Annotations" title="SCR Annotations">Using Java 5 Annotations to describe the component or service.</a></li>
	<li><a href="/confluence/display/FELIX/SCR+JavaDoc+Tags" title="SCR JavaDoc Tags">Using JavaDoc Tags to describe the component or service.</a></li>
</ul>


<h2><a name="ApacheFelixMavenSCRPlugin-DifferencesbetweenJavaDoctagsandannotations"></a>Differences between JavaDoc tags and annotations</h2>

<p>In general both mechanisms provide the same functionality. There are some subtle difference which are listed in this section:</p>
<ul>
	<li>While the <tt>metatype</tt> flag is turned on by default for the JavaDoc tags, the default for the annotations is to generate no metadata. The reason for this is, that it turned out that services with metadata are less often used.</li>
	<li>The JavaDoc support adds properties and references from super classes if the source is in the same module to a component even if the super class does not have the <tt>@scr.component</tt> tag. With the annotations the super class is required to have the <tt>Component</tt> annotation.</li>
	<li>Property values are handled differently. While the JavaDoc version has an auto detection of types together with an explicit type parameter, the annotations version has several attributes. Each type has its own attribute (like <tt>shortValue</tt>, <tt>intValue</tt> and so on). This is because of a limitation in the Java annotations which only allow typed parameters.</li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action" class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+SCR+Plugin">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=63098&revisedVersion=35&originalVersion=34">View Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/FELIX/Apache+Felix+Maven+SCR+Plugin?showComments=true&amp;showCommentArea=true#addcomment">Add Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message