Handle duplicate keys in Embed-Dependency

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1189463 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
index 06deee3..c3a2677 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
@@ -113,10 +113,10 @@
             // CLAUSE: REGEXP --> { ATTRIBUTE MAP }
             Map.Entry clause = ( Map.Entry ) clauseIterator.next();
 
-            String primaryKey = ( String ) clause.getKey();
+            String primaryKey = ( ( String ) clause.getKey() ).replaceFirst( "~+$", "" );
             StringBuilder tag = new StringBuilder( primaryKey );
 
-            if ( !primaryKey.matches( "\\*~*" ) )
+            if ( !"*".equals( primaryKey ) )
             {
                 filter = new DependencyFilter( primaryKey )
                 {
diff --git a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
index dd45df9..2df29ff 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
@@ -215,7 +215,7 @@
     }
 
 
-    public void testPositiveEmbedDependency() throws Exception
+    public void testEmbedDependencyPositiveClauses() throws Exception
     {
         ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true );
 
@@ -245,7 +245,36 @@
     }
 
 
-    public void testNegativeEmbedDependency() throws Exception
+    public void testEmbedDependencyDuplicateKeys() throws Exception
+    {
+        ArtifactStubFactory artifactFactory = new ArtifactStubFactory( plugin.getOutputDirectory(), true );
+
+        Set artifacts = new LinkedHashSet();
+
+        artifacts.addAll( artifactFactory.getClassifiedArtifacts() );
+        artifacts.addAll( artifactFactory.getScopedArtifacts() );
+        artifacts.addAll( artifactFactory.getTypedArtifacts() );
+
+        MavenProject project = getMavenProjectStub();
+        project.setDependencyArtifacts( artifacts );
+
+        Map instructions = new HashMap();
+        instructions.put( DependencyEmbedder.EMBED_DEPENDENCY, "c;type=jar,c;type=sources" );
+        Properties props = new Properties();
+
+        Builder builder = plugin.buildOSGiBundle( project, instructions, props, plugin.getClasspath( project ) );
+        Manifest manifest = builder.getJar().getManifest();
+
+        String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
+        assertEquals( ".,c-1.0-three.jar," + "c-1.0.sources", bcp );
+
+        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
+        assertEquals( "c-1.0-three.jar;g=\"g\";a=\"c\";v=\"1.0\";c=\"three\","
+            + "c-1.0.sources;g=\"g\";a=\"c\";v=\"1.0\"", eas );
+    }
+
+
+    public void testEmbedDependencyNegativeClauses() throws Exception
     {
     }
 }