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 2013/04/24 15:11:51 UTC
svn commit: r1471395 - in /felix/trunk/scrplugin: generator/changelog.txt
generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
maven-scr-plugin/changelog.txt scrtask/changelog.txt
Author: cziegeler
Date: Wed Apr 24 13:11:51 2013
New Revision: 1471395
URL: http://svn.apache.org/r1471395
Log:
FELIX-4033 - Issue warning messages for redundant SCR annotation combinations
Modified:
felix/trunk/scrplugin/generator/changelog.txt
felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
felix/trunk/scrplugin/maven-scr-plugin/changelog.txt
felix/trunk/scrplugin/scrtask/changelog.txt
Modified: felix/trunk/scrplugin/generator/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/changelog.txt?rev=1471395&r1=1471394&r2=1471395&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/changelog.txt (original)
+++ felix/trunk/scrplugin/generator/changelog.txt Wed Apr 24 13:11:51 2013
@@ -1,5 +1,7 @@
Changes from 1.6.0 to 1.5.0
---------------------------
+** Improvement
+ * [FELIX-4033] - Issue warning messages for redundant SCR annotation combinations
** Bug
* [FELIX-4030] - Generated metatype file contains all metatype infos
* [FELIX-3542] - Escape property values used as Metatype default values
Modified: felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java?rev=1471395&r1=1471394&r2=1471395&view=diff
==============================================================================
--- felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java (original)
+++ felix/trunk/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java Wed Apr 24 13:11:51 2013
@@ -328,6 +328,17 @@ public class SCRDescriptorGenerator {
} else {
ocd = null;
}
+ // metatype checks if metatype is not generated (FELIX-4033)
+ if ( !componentDesc.isAbstract() && !componentDesc.isCreateMetatype() ) {
+ if ( componentDesc.getLabel() != null && componentDesc.getLabel().trim().length() > 0 ) {
+ iLog.addWarning(" Component " + componentDesc.getName() + " has set a label. However metatype is set to false. This label is ignored.",
+ desc.getSource());
+ }
+ if ( componentDesc.getDescription() != null && componentDesc.getDescription().trim().length() > 0 ) {
+ iLog.addWarning(" Component " + componentDesc.getName() + " has set a description. However metatype is set to false. This description is ignored.",
+ desc.getSource());
+ }
+ }
ClassDescription current = desc;
boolean inherit;
@@ -451,6 +462,22 @@ public class SCRDescriptorGenerator {
}
}
+ private boolean isPrivateProperty(final String name) {
+ final boolean isPrivate;
+ if (org.osgi.framework.Constants.SERVICE_RANKING.equals(name)
+ || org.osgi.framework.Constants.SERVICE_PID.equals(name)
+ || org.osgi.framework.Constants.SERVICE_DESCRIPTION.equals(name)
+ || org.osgi.framework.Constants.SERVICE_ID.equals(name)
+ || org.osgi.framework.Constants.SERVICE_VENDOR.equals(name)
+ || ConfigurationAdmin.SERVICE_BUNDLELOCATION.equals(name)
+ || ConfigurationAdmin.SERVICE_FACTORYPID.equals(name) ) {
+ isPrivate = true;
+ } else {
+ isPrivate = false;
+ }
+ return isPrivate;
+ }
+
/**
* Process property directives
*/
@@ -460,70 +487,78 @@ public class SCRDescriptorGenerator {
final MetatypeContainer ocd) {
for(final PropertyDescription pd : current.getDescriptions(PropertyDescription.class)) {
- if ( this.testProperty(current, component.getProperties(), pd, current == component.getClassDescription()) && ocd != null) {
-
- // metatype - is this property private?
- final boolean isPrivate;
- if ( pd.isPrivate() != null ) {
- isPrivate = pd.isPrivate();
- } else {
- final String name = pd.getName();
- if (org.osgi.framework.Constants.SERVICE_RANKING.equals(name)
- || org.osgi.framework.Constants.SERVICE_PID.equals(name)
- || org.osgi.framework.Constants.SERVICE_DESCRIPTION.equals(name)
- || org.osgi.framework.Constants.SERVICE_ID.equals(name)
- || org.osgi.framework.Constants.SERVICE_VENDOR.equals(name)
- || ConfigurationAdmin.SERVICE_BUNDLELOCATION.equals(name)
- || ConfigurationAdmin.SERVICE_FACTORYPID.equals(name) ) {
- isPrivate = true;
- } else {
- isPrivate = false;
- }
- }
- if ( !isPrivate ) {
- final MetatypeAttributeDefinition ad = new MetatypeAttributeDefinition();
- ocd.getProperties().add(ad);
- ad.setId(pd.getName());
- ad.setType(pd.getType().name());
+ if ( this.testProperty(current, component.getProperties(), pd, current == component.getClassDescription()) ) {
+ if ( ocd != null) {
- if (pd.getLabel() != null ) {
- ad.setName(pd.getLabel());
- } else {
- ad.setName("%" + pd.getName() + ".name");
- }
- if (pd.getDescription() != null ) {
- ad.setDescription(pd.getDescription());
+ // metatype - is this property private?
+ final boolean isPrivate;
+ if ( pd.isPrivate() != null ) {
+ isPrivate = pd.isPrivate();
+ if ( isPrivate && this.isPrivateProperty(pd.getName()) ) { // additional check (FELIX-4033)
+ iLog.addWarning("Property " + pd.getName() + " in class "
+ + current.getDescribedClass().getName() + " has redundant setting" +
+ " for private (true). This property is private by default.", current.getSource() );
+ }
} else {
- ad.setDescription("%" + pd.getName() + ".description");
+ final String name = pd.getName();
+ if (isPrivateProperty(name) ) {
+ isPrivate = true;
+ } else {
+ isPrivate = false;
+ }
}
+ if ( !isPrivate ) {
+ final MetatypeAttributeDefinition ad = new MetatypeAttributeDefinition();
+ ocd.getProperties().add(ad);
+ ad.setId(pd.getName());
+ ad.setType(pd.getType().name());
+
+ if (pd.getLabel() != null ) {
+ ad.setName(pd.getLabel());
+ } else {
+ ad.setName("%" + pd.getName() + ".name");
+ }
+ if (pd.getDescription() != null ) {
+ ad.setDescription(pd.getDescription());
+ } else {
+ ad.setDescription("%" + pd.getName() + ".description");
+ }
- if ( pd.getUnbounded() == PropertyUnbounded.DEFAULT ) {
- if ( pd.getCardinality() != 0 ) {
- ad.setCardinality(pd.getCardinality());
+ if ( pd.getUnbounded() == PropertyUnbounded.DEFAULT ) {
+ if ( pd.getCardinality() != 0 ) {
+ ad.setCardinality(pd.getCardinality());
+ }
+ } else if ( pd.getUnbounded() == PropertyUnbounded.ARRAY ) {
+ // unlimited array
+ ad.setCardinality(new Integer(Integer.MAX_VALUE));
+ } else {
+ // unlimited vector
+ ad.setCardinality(new Integer(Integer.MIN_VALUE));
}
- } else if ( pd.getUnbounded() == PropertyUnbounded.ARRAY ) {
- // unlimited array
- ad.setCardinality(new Integer(Integer.MAX_VALUE));
- } else {
- // unlimited vector
- ad.setCardinality(new Integer(Integer.MIN_VALUE));
- }
- ad.setDefaultValue(pd.getValue());
- ad.setDefaultMultiValue(pd.getMultiValue());
+ ad.setDefaultValue(pd.getValue());
+ ad.setDefaultMultiValue(pd.getMultiValue());
- // check options
- final String[] parameters = pd.getOptions();
- if ( parameters != null && parameters.length > 0 ) {
- final Map<String, String> options = new LinkedHashMap<String, String>();
- for (int j=0; j < parameters.length; j=j+2) {
- final String optionLabel = parameters[j];
- final String optionValue = (j < parameters.length-1) ? parameters[j+1] : null;
- if (optionValue != null) {
- options.put(optionLabel, optionValue);
+ // check options
+ final String[] parameters = pd.getOptions();
+ if ( parameters != null && parameters.length > 0 ) {
+ final Map<String, String> options = new LinkedHashMap<String, String>();
+ for (int j=0; j < parameters.length; j=j+2) {
+ final String optionLabel = parameters[j];
+ final String optionValue = (j < parameters.length-1) ? parameters[j+1] : null;
+ if (optionValue != null) {
+ options.put(optionLabel, optionValue);
+ }
}
+ ad.setOptions(options);
}
- ad.setOptions(options);
+ }
+ } else {
+ // additional metatype checks (FELIX-4033)
+ if ( pd.isPrivate() != null && pd.isPrivate() ) {
+ iLog.addWarning("Property " + pd.getName() + " in class "
+ + current.getDescribedClass().getName() + " is set as private. " +
+ "This is redundant as no metatype will be generated.", current.getSource() );
}
}
}
Modified: felix/trunk/scrplugin/maven-scr-plugin/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/maven-scr-plugin/changelog.txt?rev=1471395&r1=1471394&r2=1471395&view=diff
==============================================================================
--- felix/trunk/scrplugin/maven-scr-plugin/changelog.txt (original)
+++ felix/trunk/scrplugin/maven-scr-plugin/changelog.txt Wed Apr 24 13:11:51 2013
@@ -1,5 +1,7 @@
Changes from 1.12.0 to 1.11.0
-----------------------------
+** Improvement
+ * [FELIX-4033] - Issue warning messages for redundant SCR annotation combinations
** Bug
* [FELIX-4030] - Generated metatype file contains all metatype infos
* [FELIX-4023] - SCR-Plugin not working reliably in m2e 1.3.1
Modified: felix/trunk/scrplugin/scrtask/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/scrtask/changelog.txt?rev=1471395&r1=1471394&r2=1471395&view=diff
==============================================================================
--- felix/trunk/scrplugin/scrtask/changelog.txt (original)
+++ felix/trunk/scrplugin/scrtask/changelog.txt Wed Apr 24 13:11:51 2013
@@ -1,5 +1,7 @@
Changes from 1.6.0 to 1.5.0
---------------------------
+** Improvement
+ * [FELIX-4033] - Issue warning messages for redundant SCR annotation combinations
** Bug
* [FELIX-4030] - Generated metatype file contains all metatype infos
* [FELIX-3542] - Escape property values used as Metatype default values