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/06/29 00:47:10 UTC

svn commit: r1140878 - in /felix/trunk/bundleplugin/src/main/java/org/apache/felix: bundleplugin/BlueprintPlugin.java bundleplugin/BundlePlugin.java bundleplugin/ManifestPlugin.java bundleplugin/PackageVersionAnalyzer.java obrplugin/ObrUtils.java

Author: mcculls
Date: Tue Jun 28 22:47:10 2011
New Revision: 1140878

URL: http://svn.apache.org/viewvc?rev=1140878&view=rev
Log:
FELIX-3011: add 'dumpInstructions' and 'dumpClasspath' parameters that let you dump the BND instructions/classpath to a file

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/PackageVersionAnalyzer.java
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUtils.java

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java?rev=1140878&r1=1140877&r2=1140878&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BlueprintPlugin.java Tue Jun 28 22:47:10 2011
@@ -26,7 +26,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.URL;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -48,6 +47,7 @@ import aQute.libg.generics.Create;
 import aQute.libg.qtokens.QuotedTokenizer;
 import aQute.libg.reporter.Reporter;
 
+
 public class BlueprintPlugin implements AnalyzerPlugin {
 
 

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java?rev=1140878&r1=1140877&r2=1140878&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java Tue Jun 28 22:47:10 2011
@@ -19,11 +19,13 @@
 package org.apache.felix.bundleplugin;
 
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -61,7 +63,7 @@ import org.apache.maven.shared.osgi.Mave
 import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.StringInputStream;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
 import aQute.lib.osgi.Analyzer;
@@ -93,6 +95,20 @@ public class BundlePlugin extends Abstra
     protected File manifestLocation;
 
     /**
+     * File where the BND instructions will be dumped
+     *
+     * @parameter expression="${dumpInstructions}"
+     */
+    protected File dumpInstructions;
+
+    /**
+     * File where the BND class-path will be dumped
+     *
+     * @parameter expression="${dumpClasspath}"
+     */
+    protected File dumpClasspath;
+
+    /**
      * When true, unpack the bundle contents to the outputDirectory
      *
      * @parameter expression="${unpackBundle}"
@@ -197,6 +213,8 @@ public class BundlePlugin extends Abstra
     private static final String[] DEFAULT_INCLUDES =
         { "**/**" };
 
+    private static final String NL = System.getProperty( "line.separator" );
+
 
     protected Maven2OsgiConverter getMaven2OsgiConverter()
     {
@@ -426,10 +444,28 @@ public class BundlePlugin extends Abstra
         Collection embeddableArtifacts = getEmbeddableArtifacts( currentProject, builder );
         new DependencyEmbedder( getLog(), embeddableArtifacts ).processHeaders( builder );
 
-        dumpInstructions( "BND Instructions:", builder.getProperties(), getLog() );
-        dumpClasspath( "BND Classpath:", builder.getClasspath(), getLog() );
+        if ( dumpInstructions != null || getLog().isDebugEnabled() )
+        {
+            StringBuilder buf = new StringBuilder();
+            getLog().debug( "BND Instructions:" + NL + dumpInstructions( builder.getProperties(), buf ) );
+            if ( dumpInstructions != null )
+            {
+                FileUtils.fileWrite( dumpInstructions, buf.toString() );
+            }
+        }
+
+        if ( dumpClasspath != null || getLog().isDebugEnabled() )
+        {
+            StringBuilder buf = new StringBuilder();
+            getLog().debug( "BND Classpath:" + NL + dumpClasspath( builder.getClasspath(), buf ) );
+            if ( dumpClasspath != null )
+            {
+                FileUtils.fileWrite( dumpClasspath, buf.toString() );
+            }
+        }
     }
 
+
     protected Builder buildOSGiBundle( MavenProject currentProject, Map originalInstructions, Properties properties,
         Jar[] classpath ) throws Exception
     {
@@ -445,51 +481,74 @@ public class BundlePlugin extends Abstra
     }
 
 
-    protected static void dumpInstructions( String title, Properties properties, Log log )
+    protected static StringBuilder dumpInstructions( Properties properties, StringBuilder buf )
     {
-        if ( log.isDebugEnabled() )
+        try
         {
-            log.debug( title );
-            log.debug( "------------------------------------------------------------------------" );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
+            Properties stringProperties = new Properties();
             for ( Enumeration e = properties.propertyNames(); e.hasMoreElements(); )
             {
+                // we can only store String properties
                 String key = ( String ) e.nextElement();
-                log.debug( key + ": " + properties.getProperty( key ) );
+                String value = properties.getProperty( key );
+                if ( value != null )
+                {
+                    stringProperties.setProperty( key, value );
+                }
             }
-            log.debug( "------------------------------------------------------------------------" );
+            StringWriter writer = new StringWriter();
+            stringProperties.store( writer, null );
+            buf.append( writer );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
         }
+        catch ( Throwable e )
+        {
+            // ignore...
+        }
+        return buf;
     }
 
 
-    protected static void dumpClasspath( String title, List classpath, Log log )
+    protected static StringBuilder dumpClasspath( List classpath, StringBuilder buf )
     {
-        if ( log.isDebugEnabled() )
+        try
         {
-            log.debug( title );
-            log.debug( "------------------------------------------------------------------------" );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
+            buf.append( "-classpath:\\" + NL );
             for ( Iterator i = classpath.iterator(); i.hasNext(); )
             {
                 File path = ( ( Jar ) i.next() ).getSource();
-                log.debug( null == path ? "null" : path.toString() );
+                if ( path != null )
+                {
+                    buf.append( ' ' + path.toString() + ( i.hasNext() ? ",\\" : "" ) + NL );
+                }
             }
-            log.debug( "------------------------------------------------------------------------" );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
+        }
+        catch ( Throwable e )
+        {
+            // ignore...
         }
+        return buf;
     }
 
 
-    protected static void dumpManifest( String title, Manifest manifest, Log log )
+    protected static StringBuilder dumpManifest( Manifest manifest, StringBuilder buf )
     {
-        if ( log.isDebugEnabled() )
+        try
         {
-            log.debug( title );
-            log.debug( "------------------------------------------------------------------------" );
-            for ( Iterator i = manifest.getMainAttributes().entrySet().iterator(); i.hasNext(); )
-            {
-                Map.Entry entry = ( Map.Entry ) i.next();
-                log.debug( entry.getKey() + ": " + entry.getValue() );
-            }
-            log.debug( "------------------------------------------------------------------------" );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            manifest.write( out ); // manifest encoding is UTF8
+            buf.append( out.toString( "UTF8" ) );
+            buf.append( "#-----------------------------------------------------------------------" + NL );
+        }
+        catch ( Throwable e )
+        {
+            // ignore...
         }
+        return buf;
     }
 
 
@@ -541,7 +600,10 @@ public class BundlePlugin extends Abstra
     {
         Jar jar = builder.getJar();
 
-        dumpManifest( "BND Manifest:", jar.getManifest(), getLog() );
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "BND Manifest:" + NL + dumpManifest( jar.getManifest(), new StringBuilder() ) );
+        }
 
         boolean addMavenDescriptor = currentProject.getBasedir() != null;
 
@@ -565,8 +627,8 @@ public class BundlePlugin extends Abstra
                 mis.close();
             }
 
-            // Then apply the customized entries from the jar plugin
-            mavenManifest.read( new StringInputStream( mavenManifestText ) );
+            // Then apply customized entries from the jar plugin; note: manifest encoding is UTF8
+            mavenManifest.read( new ByteArrayInputStream( mavenManifestText.getBytes( "UTF8" ) ) );
 
             if ( !archiveConfig.isManifestSectionsEmpty() )
             {
@@ -647,7 +709,10 @@ public class BundlePlugin extends Abstra
             doMavenMetadata( currentProject, jar );
         }
 
-        dumpManifest( "Final Manifest:", builder.getJar().getManifest(), getLog() );
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "Final Manifest:" + NL + dumpManifest( jar.getManifest(), new StringBuilder() ) );
+        }
 
         builder.setJar( jar );
     }

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java?rev=1140878&r1=1140877&r2=1140878&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java Tue Jun 28 22:47:10 2011
@@ -23,10 +23,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.jar.Manifest;

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/PackageVersionAnalyzer.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/PackageVersionAnalyzer.java?rev=1140878&r1=1140877&r2=1140878&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/PackageVersionAnalyzer.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/PackageVersionAnalyzer.java Tue Jun 28 22:47:10 2011
@@ -19,12 +19,7 @@
 package org.apache.felix.bundleplugin;
 
 
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Map;
-
 import aQute.lib.osgi.Builder;
-import aQute.lib.osgi.Jar;
 
 
 /**

Modified: felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUtils.java
URL: http://svn.apache.org/viewvc/felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUtils.java?rev=1140878&r1=1140877&r2=1140878&view=diff
==============================================================================
--- felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUtils.java (original)
+++ felix/trunk/bundleplugin/src/main/java/org/apache/felix/obrplugin/ObrUtils.java Tue Jun 28 22:47:10 2011
@@ -21,7 +21,6 @@ package org.apache.felix.obrplugin;
 
 import java.io.File;
 import java.net.URI;
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.regex.Pattern;