FELIX-3550 : Reimplement the SCR Generator

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1356072 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
index e9b8aac..f3a7a2b 100644
--- a/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
+++ b/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/processing/SCRAnnotationProcessor.java
@@ -370,6 +370,8 @@
                 index += 2;
             }
 
+            final boolean hasName = ad.getStringValue("name", null) != null;
+
             if (values != null) {
                 prop.setType(PropertyType.valueOf(type));
                 if (values.length == 1) {
@@ -378,40 +380,47 @@
                     prop.setMultiValue(values);
                 }
             } else if (fieldAnnotation != null) {
-
                 // Detect values from field
-                final Object value = fieldAnnotation.getAnnotatedFieldValue();
-                if (value != null) {
-                    if (value.getClass().isArray()) {
-                        values = new String[Array.getLength(value)];
-                        for (int i = 0; i < values.length; i++) {
-                            values[i] = Array.get(value, i).toString();
-                        }
-                        prop.setMultiValue(values);
-                        prop.setType(PropertyType.from(Array.get(value, 0).getClass()));
-                    } else {
-                        prop.setType(PropertyType.from(value.getClass()));
-                        prop.setValue(value.toString());
-                    }
-                }
-            }
-
-            final String defaultName;
-            if (fieldAnnotation != null) {
-                if (values == null) {
-                    defaultName = fieldAnnotation.getAnnotatedField().getName();
-                } else {
+                if ( hasName ) {
                     final Object value = fieldAnnotation.getAnnotatedFieldValue();
                     if (value != null) {
-                        defaultName = value.toString();
-                    } else {
-                        defaultName = null;
+                        if (value.getClass().isArray()) {
+                            final String[] newValues = new String[Array.getLength(value)];
+                            for (int i = 0; i < newValues.length; i++) {
+                                newValues[i] = Array.get(value, i).toString();
+                            }
+                            prop.setMultiValue(newValues);
+                            prop.setType(PropertyType.from(Array.get(value, 0).getClass()));
+                        } else {
+                            prop.setType(PropertyType.from(value.getClass()));
+                            prop.setValue(value.toString());
+                        }
                     }
+                } else {
+                    prop.setType(PropertyType.String);
+                    prop.setValue(fieldAnnotation.getAnnotatedField().getName());
+                }
+            }
+
+            final String name;
+            if ( hasName ) {
+                name = ad.getStringValue("name", null);
+            } else if (fieldAnnotation != null) {
+                if (values == null) {
+                    final Object value = fieldAnnotation.getAnnotatedFieldValue();
+                    if (value != null) {
+                        name = value.toString();
+                    } else {
+                        name = null;
+                    }
+                } else {
+                    name = fieldAnnotation.getAnnotatedField().getName();
                 }
             } else {
-                defaultName = null;
+                name = null;
             }
-            prop.setName(ad.getStringValue("name", defaultName));
+
+            prop.setName(name);
             prop.setLabel(ad.getStringValue("label", null));
             prop.setDescription(ad.getStringValue("description", null));
 
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
index 0b01981..3a14ffd 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/SCRDescriptorGenerator.java
@@ -438,6 +438,7 @@
             final PropertyDescription pid = new PropertyDescription(null);
             pid.setName( org.osgi.framework.Constants.SERVICE_PID );
             pid.setValue( componentDesc.getName() );
+            pid.setType(PropertyType.String);
 
             container.getProperties().put(org.osgi.framework.Constants.SERVICE_PID, pid);
         }
diff --git a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
index a722bea..1b1b1ad 100644
--- a/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
+++ b/scrplugin/generator/src/main/java/org/apache/felix/scrplugin/xml/ComponentDescriptorIO.java
@@ -496,7 +496,8 @@
                     try {
                         cl = this.classLoader.loadClass(className);
                     } catch (final Throwable e) {
-                        iLog.addWarning("Unable to load class " + className + " from dependencies.", this.location);
+                        // this doesn't have an effect as the classes we processed are loaded
+                        // anyway.
                     }
                     this.currentClass = new ClassDescription(cl, "classpath:" + className);
                     this.currentClass.add(this.currentComponent);
diff --git a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
index f3fd5f8..8a2c22b 100644
--- a/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
+++ b/scrplugin/maven-scr-plugin/src/main/java/org/apache/felix/scrplugin/mojo/SCRDescriptorMojo.java
@@ -24,9 +24,9 @@
 import java.net.URLClassLoader;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -149,7 +149,7 @@
      *
      * @parameter
      */
-    private Map<String, String> properties = new HashMap<String, String>();
+    private Map<String, String> properties = new LinkedHashMap<String, String>();
 
     /**
      * The version of the DS spec this plugin generates a descriptor for. By