Handle missing key in Embed-Dependency

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1189494 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 c3a2677..9a1d6f3 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
@@ -23,11 +23,13 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.regex.Pattern;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
 
 import aQute.lib.osgi.Instruction;
+import aQute.libg.header.OSGiHeader;
 
 
 /**
@@ -37,6 +39,8 @@
  */
 public abstract class AbstractDependencyFilter
 {
+    private final Pattern MISSING_KEY_PATTERN = Pattern.compile( "^[a-zA-Z]+=" );
+
     /**
      * Dependency artifacts.
      */
@@ -100,8 +104,15 @@
     }
 
 
-    protected final void processInstructions( Map instructions ) throws MojoExecutionException
+    protected final void processInstructions( String header ) throws MojoExecutionException
     {
+        if ( MISSING_KEY_PATTERN.matcher( header ).lookingAt() )
+        {
+            header = "*;" + header;
+        }
+
+        Map instructions = OSGiHeader.parseHeader( header );
+
         DependencyFilter filter;
         for ( Iterator clauseIterator = instructions.entrySet().iterator(); clauseIterator.hasNext(); )
         {
@@ -114,8 +125,6 @@
             Map.Entry clause = ( Map.Entry ) clauseIterator.next();
 
             String primaryKey = ( ( String ) clause.getKey() ).replaceFirst( "~+$", "" );
-            StringBuilder tag = new StringBuilder( primaryKey );
-
             if ( !"*".equals( primaryKey ) )
             {
                 filter = new DependencyFilter( primaryKey )
@@ -133,8 +142,6 @@
             {
                 // ATTRIBUTE: KEY --> REGEXP
                 Map.Entry attr = ( Map.Entry ) attrIterator.next();
-                tag.append( ';' ).append( attr );
-
                 if ( "groupId".equals( attr.getKey() ) )
                 {
                     filter = new DependencyFilter( ( String ) attr.getValue() )
@@ -227,10 +234,10 @@
                 filter.filter( filteredDependencies );
             }
 
-            processDependencies( tag.toString(), inline, filteredDependencies );
+            processDependencies( filteredDependencies, inline );
         }
     }
 
 
-    protected abstract void processDependencies( String clause, String inline, Collection dependencies );
+    protected abstract void processDependencies( Collection dependencies, String inline );
 }
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
index 8ef8c93..1ab4ccf 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
@@ -23,7 +23,6 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
-import java.util.Map;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -31,7 +30,6 @@
 import org.codehaus.plexus.util.StringUtils;
 
 import aQute.lib.osgi.Analyzer;
-import aQute.libg.header.OSGiHeader;
 
 
 /**
@@ -98,8 +96,7 @@
             m_embedStripGroup = analyzer.getProperty( EMBED_STRIP_GROUP, "true" );
             m_embedStripVersion = analyzer.getProperty( EMBED_STRIP_VERSION );
 
-            Map embedInstructions = OSGiHeader.parseHeader( embedDependencyHeader );
-            processInstructions( embedInstructions );
+            processInstructions( embedDependencyHeader );
 
             for ( Iterator i = m_inlinedPaths.iterator(); i.hasNext(); )
             {
@@ -127,13 +124,8 @@
 
 
     @Override
-    protected void processDependencies( String tag, String inline, Collection dependencies )
+    protected void processDependencies( Collection dependencies, String inline )
     {
-        if ( dependencies.isEmpty() )
-        {
-            m_log.warn( EMBED_DEPENDENCY + ": clause \"" + tag + "\" did not match any dependencies" );
-        }
-
         if ( null == inline || "false".equalsIgnoreCase( inline ) )
         {
             m_embeddedArtifacts.addAll( dependencies );
diff --git a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
index e301426..dedd93d 100644
--- a/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
+++ b/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
@@ -24,8 +24,6 @@
 
 import org.apache.maven.plugin.MojoExecutionException;
 
-import aQute.libg.header.OSGiHeader;
-
 
 /**
  * Exclude selected dependencies from the classpath passed to BND.
@@ -54,13 +52,13 @@
 
         if ( null != excludeDependencies && excludeDependencies.length() > 0 )
         {
-            processInstructions( OSGiHeader.parseHeader( excludeDependencies ) );
+            processInstructions( excludeDependencies );
         }
     }
 
 
     @Override
-    protected void processDependencies( String tag, String inline, Collection dependencies )
+    protected void processDependencies( Collection dependencies, String inline )
     {
         m_excludedArtifacts.addAll( dependencies );
     }
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 2df29ff..428fbf4 100644
--- a/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
+++ b/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
@@ -237,7 +237,7 @@
         Manifest manifest = builder.getJar().getManifest();
 
         String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
-        assertEquals( ".,compile-1.0.jar,b-1.0.jar,runtime-1.0.jar", bcp );
+        assertEquals( ".," + "compile-1.0.jar,b-1.0.jar,runtime-1.0.jar", bcp );
 
         String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
         assertEquals( "compile-1.0.jar;g=\"g\";a=\"compile\";v=\"1.0\"," + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\","
@@ -266,7 +266,7 @@
         Manifest manifest = builder.getJar().getManifest();
 
         String bcp = manifest.getMainAttributes().getValue( Constants.BUNDLE_CLASSPATH );
-        assertEquals( ".,c-1.0-three.jar," + "c-1.0.sources", bcp );
+        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\","
@@ -274,6 +274,35 @@
     }
 
 
+    public void testEmbedDependencyMissingKey() 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, "artifactId=a|b" );
+        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( ".," + "a-1.0.war," + "a-1.0-one.jar," + "b-1.0.jar," + "b-1.0-two.jar", bcp );
+
+        String eas = manifest.getMainAttributes().getValue( "Embedded-Artifacts" );
+        assertEquals( "a-1.0.war;g=\"g\";a=\"a\";v=\"1.0\"," + "a-1.0-one.jar;g=\"g\";a=\"a\";v=\"1.0\";c=\"one\","
+            + "b-1.0.jar;g=\"g\";a=\"b\";v=\"1.0\"," + "b-1.0-two.jar;g=\"g\";a=\"b\";v=\"1.0\";c=\"two\"", eas );
+    }
+
+
     public void testEmbedDependencyNegativeClauses() throws Exception
     {
     }