FELIX-2175: Improve the Blueprint component to parse / introspect blueprint configuration files and generate OBR service requirements / capabilities accordingly

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@921525 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java
index 6205e23..8b2c70a 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java
@@ -9,6 +9,7 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -48,8 +49,8 @@
 
         String bpHeader = analyzer.getProperty("Bundle-Blueprint", "OSGI-INF/blueprint");
         Map<String, Map<String,String>> map = Processor.parseHeader(bpHeader, null);
-        for (String root : map.keySet()) {
-
+        for (String root : map.keySet())
+        {
             Jar jar = analyzer.getJar();
             Map<String, Resource> dir = jar.getDirectories().get(root);
             if(dir == null || dir.isEmpty())
@@ -115,22 +116,19 @@
             {
                 Set<Attribute> orgAttr = parseHeader(analyzer.getProperty(header), null);
                 Set<Attribute> newAttr = hdrs.get(header);
-                for (Attribute a : newAttr)
+                for (Iterator<Attribute> it = newAttr.iterator(); it.hasNext();)
                 {
-                    boolean found = false;
+                    Attribute a = it.next();
                     for (Attribute b : orgAttr)
                     {
                         if (b.getName().equals(a.getName()))
                         {
-                            found = true;
+                            it.remove();
                             break;
                         }
                     }
-                    if (!found)
-                    {
-                        orgAttr.add(a);
-                    }
                 }
+                orgAttr.addAll(newAttr);
                 // Rebuild from orgAttr
                 StringBuilder sb = new StringBuilder();
                 for (Attribute a : orgAttr)
diff --git a/bundleplugin/src/main/resources/org/apache/felix/bundleplugin/blueprint.xsl b/bundleplugin/src/main/resources/org/apache/felix/bundleplugin/blueprint.xsl
index 49e0d8a..b38ac87 100644
--- a/bundleplugin/src/main/resources/org/apache/felix/bundleplugin/blueprint.xsl
+++ b/bundleplugin/src/main/resources/org/apache/felix/bundleplugin/blueprint.xsl
@@ -31,7 +31,7 @@
         <xsl:if test="not($nsh_interface = '' or $nsh_namespace = '')">
             <xsl:for-each select="descendant-or-self::node() | descendant-or-self::node()/attribute::*">
                 <xsl:if test="not(namespace-uri() = 'http://www.osgi.org/xmlns/blueprint/v1.0.0' or namespace-uri() = '')">
-                    <xsl:value-of select="concat('Import-Service:', $nsh_interface, ';', $nsh_namespace, '=', namespace-uri())" />
+                    <xsl:value-of select="concat('Import-Service:', $nsh_interface, ';', $nsh_namespace, '=&quot;', namespace-uri(), '&quot;')" />
                     <xsl:text>
                     </xsl:text>
                 </xsl:if>
@@ -80,7 +80,7 @@
                 </xsl:otherwise>
             </xsl:choose>
             <xsl:for-each select="bp:service-properties/bp:entry">
-                <xsl:value-of select="concat(';', @key, '=', @value)" />
+                <xsl:value-of select="concat(';', @key, '=&quot;', @value, '&quot;')" />
             </xsl:for-each>
             <xsl:text>
             </xsl:text>
diff --git a/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml b/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml
index fe8d4f3..882f62e 100644
--- a/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml
+++ b/bundleplugin/src/test/resources/OSGI-INF/blueprint/bp.xml
@@ -45,6 +45,12 @@
         </service-properties>
     </service>
 
+    <service interface="p6.Foo">
+        <service-properties>
+            <entry key="k" value="v2" />
+        </service-properties>
+    </service>
+
     <service>
         <interfaces>
             <value>p7.Foo</value>