You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by mc...@apache.org on 2011/10/26 23:54:03 UTC

svn commit: r1189494 - in /felix/trunk/bundleplugin/src: main/java/org/apache/felix/bundleplugin/ test/java/org/apache/felix/bundleplugin/

Author: mcculls
Date: Wed Oct 26 21:54:03 2011
New Revision: 1189494

URL: http://svn.apache.org/viewvc?rev=1189494&view=rev
Log:
Handle missing key in Embed-Dependency

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
    felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java?rev=1189494&r1=1189493&r2=1189494&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/AbstractDependencyFilter.java Wed Oct 26 21:54:03 2011
@@ -23,11 +23,13 @@ import java.util.Collection;
 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 @@ import aQute.lib.osgi.Instruction;
  */
 public abstract class AbstractDependencyFilter
 {
+    private final Pattern MISSING_KEY_PATTERN = Pattern.compile( "^[a-zA-Z]+=" );
+
     /**
      * Dependency artifacts.
      */
@@ -100,8 +104,15 @@ public abstract class AbstractDependency
     }
 
 
-    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 @@ public abstract class AbstractDependency
             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 @@ public abstract class AbstractDependency
             {
                 // 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 @@ public abstract class AbstractDependency
                 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 );
 }

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java?rev=1189494&r1=1189493&r2=1189494&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyEmbedder.java Wed Oct 26 21:54:03 2011
@@ -23,7 +23,6 @@ import java.io.File;
 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.apache.maven.plugin.logging.L
 import org.codehaus.plexus.util.StringUtils;
 
 import aQute.lib.osgi.Analyzer;
-import aQute.libg.header.OSGiHeader;
 
 
 /**
@@ -98,8 +96,7 @@ public final class DependencyEmbedder ex
             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 @@ public final class DependencyEmbedder ex
 
 
     @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 );

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java?rev=1189494&r1=1189493&r2=1189494&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/DependencyExcluder.java Wed Oct 26 21:54:03 2011
@@ -24,8 +24,6 @@ import java.util.HashSet;
 
 import org.apache.maven.plugin.MojoExecutionException;
 
-import aQute.libg.header.OSGiHeader;
-
 
 /**
  * Exclude selected dependencies from the classpath passed to BND.
@@ -54,13 +52,13 @@ public final class DependencyExcluder ex
 
         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 );
     }

Modified: felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java?rev=1189494&r1=1189493&r2=1189494&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java (original)
+++ felix/trunk/bundleplugin/src/test/java/org/apache/felix/bundleplugin/BundlePluginTest.java Wed Oct 26 21:54:03 2011
@@ -237,7 +237,7 @@ public class BundlePluginTest extends Ab
         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 @@ public class BundlePluginTest extends Ab
         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 class BundlePluginTest extends Ab
     }
 
 
+    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
     {
     }