[
https://issues.apache.org/jira/browse/FELIX-4393?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13919322#comment-13919322
]
Carsten Ziegeler commented on FELIX-4393:
-----------------------------------------
Thanks for the example, at least you can leave out the intValue=8080, and the
default value will be picked up from the field.
I guess all you want to do is:
@Property(label="..", description="..")
private int port = 8080;
which would be possible. Unfortunately, we have defined the @Property in a way,
that if the name is missing in the annotation, it uses the value of the field
as the name. The main reason behind is, that it's good to have a constant for
the property name which you can also use in the activate() method to get the
value from the provided properties. So we usually do
static final int DEFAULT_PORT = 8080;
@Property(intValue=DEFAULT_PORT, label="..", description="..")
static final String PROPERTY_PORT = "port";
and in the activate method
@Activate
protected void activate(Map<String, Object> properties) {
int port = PropertiesUtil.toInteger(properties.get(PROPERTY_PORT),
DEFAULT_PORT);
where the PropertiesUtil method is checking whether the property is set and
otherwise returning the default port.
So unfortunately we can't change the semantics of the @Property method for
compatibility reasons.
> @Property should accept empty name values on fields
> -----------------------------------------------------
>
> Key: FELIX-4393
> URL: https://issues.apache.org/jira/browse/FELIX-4393
> Project: Felix
> Issue Type: Improvement
> Components: Maven SCR Plugin
> Reporter: james strachan
> Assignee: Carsten Ziegeler
> Fix For: maven-scr-plugin 1.15.2, scr ant task 1.9.2, scr
> generator 1.8.4
>
>
> it'd be nice if @Property behaved like various other annotations (e.g.
> @Inject / @Resource) so that if a name is not specified and @Property is
> specified on a field, then the name value defaults to the field name.
> It looks like name is optional with a default of "" - so its just the maven
> scr plugin which seems to barf if name is empty generating this kind of
> compile error:
> {code}
> @Property : Property name can not be empty.
> {code}
> It'd be nice if the name was optional; it makes the code more DRY and keeps
> things more refactoring safe etc
--
This message was sent by Atlassian JIRA
(v6.2#6252)