FELIX-2908 - Use same mechanism to get single annotation values as for multiple annotation values


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1132949 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/changelog.txt b/scrplugin/annotations/changelog.txt
index 5c60008..d833929 100644
--- a/scrplugin/annotations/changelog.txt
+++ b/scrplugin/annotations/changelog.txt
@@ -7,6 +7,7 @@
 
 ** Improvement
     * [FELIX-2939] - Maven SCR Plugin is not (marked as) thread-safe for parallel builds
+    * [FELIX-2908] - Use same mechanism to get single annotation values as for multiple annotation values
 
 
 Changes from 1.4.0 to 1.5.0
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
index cb400ca..fc86865 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ComponentTag.java
@@ -46,11 +46,11 @@
         this.annotation = new Component() {
 
             public boolean componentAbstract() {
-                return Util.getBooleanValue(annotation, "componentAbstract", Component.class);
+                return Util.getBooleanValue(annotation, desc, "componentAbstract", Component.class);
             }
 
             public boolean createPid() {
-                return Util.getBooleanValue(annotation, "createPid", Component.class);
+                return Util.getBooleanValue(annotation, desc, "createPid", Component.class);
             }
 
             public String description() {
@@ -58,7 +58,7 @@
             }
 
             public boolean ds() {
-                return Util.getBooleanValue(annotation, "ds", Component.class);
+                return Util.getBooleanValue(annotation, desc, "ds", Component.class);
             }
 
             public String specVersion() {
@@ -66,7 +66,7 @@
             }
 
             public boolean enabled() {
-                return Util.getBooleanValue(annotation, "enabled", Component.class);
+                return Util.getBooleanValue(annotation, desc, "enabled", Component.class);
             }
 
             public String factory() {
@@ -74,11 +74,11 @@
             }
 
             public boolean immediate() {
-                return Util.getBooleanValue(annotation, "immediate", Component.class);
+                return Util.getBooleanValue(annotation, desc, "immediate", Component.class);
             }
 
             public boolean inherit() {
-                return Util.getBooleanValue(annotation, "inherit", Component.class);
+                return Util.getBooleanValue(annotation, desc, "inherit", Component.class);
             }
 
             public String label() {
@@ -86,7 +86,7 @@
             }
 
             public boolean metatype() {
-                return Util.getBooleanValue(annotation, "metatype", Component.class);
+                return Util.getBooleanValue(annotation, desc, "metatype", Component.class);
             }
 
             public String name() {
@@ -98,7 +98,7 @@
             }
 
             public boolean getConfigurationFactory() {
-                return Util.getBooleanValue(annotation, "getConfigurationFactory", Component.class);
+                return Util.getBooleanValue(annotation, desc, "getConfigurationFactory", Component.class);
             }
 
             public boolean configurationFactory() {
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
index 9264364..5b71f01 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
@@ -44,7 +44,7 @@
         this.annotation = new Property() {
 
             public int cardinality() {
-                return Util.getIntValue(annotation, "cardinality", Property.class);
+                return Util.getIntValue(annotation, desc, "cardinality", Property.class);
             }
 
             public String description() {
@@ -84,7 +84,7 @@
             }
 
             public boolean propertyPrivate() {
-                return Util.getBooleanValue(annotation, "propertyPrivate", Property.class);
+                return Util.getBooleanValue(annotation, desc, "propertyPrivate", Property.class);
             }
 
             public String[] value() {
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
index f9429b4..5f84215 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/ServiceTag.java
@@ -73,7 +73,7 @@
         final Service tag = new Service() {
 
             public boolean serviceFactory() {
-                return Util.getBooleanValue(annotation, "serviceFactory", Service.class);
+                return Util.getBooleanValue(annotation, desc, "serviceFactory", Service.class);
             }
 
             public Class<?>[] value() {
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/sling/SlingAnnotationTagProvider.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/sling/SlingAnnotationTagProvider.java
index 1ef1fa9..13d616c 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/sling/SlingAnnotationTagProvider.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/sling/SlingAnnotationTagProvider.java
@@ -47,7 +47,7 @@
         {
 
             // generate @Component tag if required
-            boolean generateComponent = Util.getBooleanValue(annotation, "generateComponent", SlingServlet.class);
+            boolean generateComponent = Util.getBooleanValue(annotation, description, "generateComponent", SlingServlet.class);
             if (generateComponent)
             {
                 String name = Util.getStringValue(annotation, description, "name", SlingServlet.class);
@@ -62,12 +62,12 @@
                 if ( desc != null && desc.trim().length() == 0 ) {
                     desc = null;
                 }
-                final boolean createMetatype = Util.getBooleanValue(annotation, "metatype", SlingServlet.class);
+                final boolean createMetatype = Util.getBooleanValue(annotation, description, "metatype", SlingServlet.class);
                 tags.add(new SlingServletComponentTag(annotation, description, createMetatype, name, label, desc));
             }
 
             // generate @Service tag if required
-            boolean generateService = Util.getBooleanValue(annotation, "generateService", SlingServlet.class);
+            boolean generateService = Util.getBooleanValue(annotation, description, "generateService", SlingServlet.class);
             if (generateService)
             {
                 tags.add(new SlingServletServiceTag(annotation, description));
@@ -114,7 +114,7 @@
         else if ( annotationName.equals(SlingFilter.class.getName()) )
         {
             // generate @Component tag if required
-            boolean generateComponent = Util.getBooleanValue(annotation, "generateComponent", SlingFilter.class);
+            boolean generateComponent = Util.getBooleanValue(annotation, description, "generateComponent", SlingFilter.class);
             if (generateComponent)
             {
                 String name = Util.getStringValue(annotation, description, "name", SlingFilter.class);
@@ -129,19 +129,19 @@
                 if ( desc != null && desc.trim().length() == 0 ) {
                     desc = null;
                 }
-                final boolean createMetatype = Util.getBooleanValue(annotation, "metatype", SlingFilter.class);
+                final boolean createMetatype = Util.getBooleanValue(annotation, description, "metatype", SlingFilter.class);
                 tags.add(new SlingFilterComponentTag(annotation, description, createMetatype, name, label, desc));
             }
 
             // generate @Service tag if required
-            boolean generateService = Util.getBooleanValue(annotation, "generateService", SlingFilter.class);
+            boolean generateService = Util.getBooleanValue(annotation, description, "generateService", SlingFilter.class);
             if (generateService)
             {
                 tags.add(new SlingFilterServiceTag(annotation, description));
             }
 
             // property order = service.ranking
-            final int order = Util.getIntValue(annotation, "order", SlingFilter.class);
+            final int order = Util.getIntValue(annotation, description, "order", SlingFilter.class);
             tags.add(new SlingServletPropertyTag(annotation, "service.ranking", String.valueOf(order), description, "Integer", true));
 
             // property scope
diff --git a/scrplugin/generator/changelog.txt b/scrplugin/generator/changelog.txt
index 1c2f6d0..0ded2d5 100644
--- a/scrplugin/generator/changelog.txt
+++ b/scrplugin/generator/changelog.txt
@@ -12,6 +12,7 @@
 ** Improvement
     * [FELIX-2492] - scr plugin: using src annotations causes NoClassDefFoundError and other errors
     * [FELIX-2939] - Maven SCR Plugin is not (marked as) thread-safe for parallel builds
+    * [FELIX-2908] - Use same mechanism to get single annotation values as for multiple annotation values
 
 
 Changes from 1.0.0 to 1.1.0
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
index 671c616..61eef89 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/tags/annotation/Util.java
@@ -40,36 +40,36 @@
      * @param clazz The annotation class.
      * @return The boolean value.
      */
-    public static boolean getBooleanValue(Annotation annotation, String name, final Class<?> clazz) {
-        final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            return Boolean.valueOf(obj.toString());
+    public static boolean getBooleanValue(final Annotation annotation, final JavaClassDescription desc, final String name, final Class<?> clazz) {
+        final String[] sValues = getAnnotationValues(annotation, name, desc);
+        if ( sValues != null )
+        {
+            return Boolean.valueOf(sValues[0]);
         }
-        try {
+        try
+        {
             return (Boolean) clazz.getMethod(name).getDefaultValue();
-        } catch( NoSuchMethodException mnfe) {
+        }
+        catch( final NoSuchMethodException mnfe)
+        {
             // we ignore this
             return true;
         }
     }
 
-    public static int getIntValue(Annotation annotation, String name, final Class<?> clazz) {
-        final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            if ( obj instanceof Number ) {
-                return ((Number)obj).intValue();
-            }
-            final String value = obj.toString();
-            if ( value.equals("Integer.MAX_VALUE") ) {
-                return Integer.MAX_VALUE;
-            } else if ( value.equals("Integer.MIN_VALUE") ) {
-                return Integer.MIN_VALUE;
-            }
-            return Integer.valueOf(value);
+    public static int getIntValue(final Annotation annotation, final JavaClassDescription desc, final String name, final Class<?> clazz) {
+        final String[] sValues = getAnnotationValues(annotation, name, desc);
+        if ( sValues != null )
+        {
+            return Integer.valueOf(sValues[0]);
+
         }
-        try {
+        try
+        {
             return (Integer) clazz.getMethod(name).getDefaultValue();
-        } catch( NoSuchMethodException mnfe) {
+        }
+        catch(final NoSuchMethodException mnfe)
+        {
             // we ignore this
             return 0;
         }
@@ -382,11 +382,11 @@
         return getEnumValue(annotation, name, enumClass, clazz, true);
     }
 
+    @SuppressWarnings("unchecked")
     public static String[] getAnnotationValues(final Annotation annotation, final String name, final JavaClassDescription desc)
     throws IllegalArgumentException
     {
-
-        EvaluatingVisitor evaluatingVisitor = new EvaluatingVisitor() {
+        final EvaluatingVisitor evaluatingVisitor = new EvaluatingVisitor() {
 
             public Object visitAnnotationFieldRef( AnnotationFieldRef fieldRef ) {
                 // during prescan of AnnotationTagProviderManager#hasScrPluginAnnotation this method is called without desc attribute
@@ -438,9 +438,9 @@
             }
 
         };
-        @SuppressWarnings("unchecked")
         final List<Object> valueList = evaluatingVisitor.getListValue(annotation, name);
-        if (valueList==null) {
+        if (valueList == null || valueList.size() == 0)
+        {
             return null;
         }
         String[] values = new String[valueList.size()];
diff --git a/scrplugin/maven-scr-plugin/changelog.txt b/scrplugin/maven-scr-plugin/changelog.txt
index b802b36..9df175f 100644
--- a/scrplugin/maven-scr-plugin/changelog.txt
+++ b/scrplugin/maven-scr-plugin/changelog.txt
@@ -11,6 +11,7 @@
 ** Improvement
     * [FELIX-2939] - Maven SCR Plugin is not (marked as) thread-safe for parallel builds
     * [FELIX-2492] - scr plugin: using src annotations causes NoClassDefFoundError and other errors
+    * [FELIX-2908] - Use same mechanism to get single annotation values as for multiple annotation values
 
 
 Changes from 1.6.0 to 1.7.0
diff --git a/scrplugin/scrtask/changelog.txt b/scrplugin/scrtask/changelog.txt
index 87f266a..284b44d 100644
--- a/scrplugin/scrtask/changelog.txt
+++ b/scrplugin/scrtask/changelog.txt
@@ -9,6 +9,7 @@
 
 ** Improvement
     * [FELIX-2492] - scr plugin: using src annotations causes NoClassDefFoundError and other errors
+    * [FELIX-2908] - Use same mechanism to get single annotation values as for multiple annotation values
 
 
 Changes from 1.0.0 to 1.1.0