Author: mcculls
Date: Sat Feb 11 17:28:48 2012
New Revision: 1243107
URL: http://svn.apache.org/viewvc?rev=1243107&view=rev
Log:
FELIX-3300: fix calculateExportsFromContents to avoid exporting empty packages,
also only use calculateExportsFromContents when analyzing attached files
Modified:
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/ManifestPlugin.java
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=1243107&r1=1243106&r2=1243107&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
Sat Feb 11 17:28:48 2012
@@ -40,6 +40,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.TreeSet;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
@@ -1239,7 +1240,7 @@ public class BundlePlugin extends Abstra
private static void addLocalPackages( File outputDirectory, Analyzer
analyzer )
{
- Collection packages = new LinkedHashSet();
+ Collection packages = new TreeSet();
if ( outputDirectory != null && outputDirectory.isDirectory() )
{
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=1243107&r1=1243106&r2=1243107&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
Sat Feb 11 17:28:48 2012
@@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -178,11 +179,16 @@ public class ManifestPlugin extends Bund
analyzer.setJar( file );
+ // calculateExportsFromContents when we have no explicit instructions
defining
+ // the contents of the bundle *and* we are not analyzing the output
directory,
+ // otherwise fall-back to addMavenInstructions approach
+
if ( analyzer.getProperty( Analyzer.EXPORT_PACKAGE ) == null
&& analyzer.getProperty( Analyzer.EXPORT_CONTENTS ) == null
- && analyzer.getProperty( Analyzer.PRIVATE_PACKAGE ) == null )
+ && analyzer.getProperty( Analyzer.PRIVATE_PACKAGE ) == null
+ && !file.equals( getOutputDirectory() ) )
{
- String export = analyzer.calculateExportsFromContents(
analyzer.getJar() );
+ String export = calculateExportsFromContents( analyzer.getJar() );
analyzer.setProperty( Analyzer.EXPORT_PACKAGE, export );
}
@@ -219,4 +225,41 @@ public class ManifestPlugin extends Bund
}
}
}
+
+
+ /*
+ * Patched version of bnd's Analyzer.calculateExportsFromContents
+ */
+ public static String calculateExportsFromContents( Jar bundle )
+ {
+ String ddel = "";
+ StringBuffer sb = new StringBuffer();
+ Map<String, Map<String, Resource>> map = bundle.getDirectories();
+ for ( Iterator<Entry<String, Map<String, Resource>>> i =
map.entrySet().iterator(); i.hasNext(); )
+ {
+ //----------------------------------------------------
+ // should also ignore directories with no resources
+ //----------------------------------------------------
+ Entry<String, Map<String, Resource>> entry = i.next();
+ if ( entry.getValue() == null || entry.getValue().isEmpty() )
+ continue;
+ //----------------------------------------------------
+ String directory = entry.getKey();
+ if ( directory.equals( "META-INF" ) || directory.startsWith(
"META-INF/" ) )
+ continue;
+ if ( directory.equals( "OSGI-OPT" ) || directory.startsWith(
"OSGI-OPT/" ) )
+ continue;
+ if ( directory.equals( "/" ) )
+ continue;
+
+ if ( directory.endsWith( "/" ) )
+ directory = directory.substring( 0, directory.length() - 1 );
+
+ directory = directory.replace( '/', '.' );
+ sb.append( ddel );
+ sb.append( directory );
+ ddel = ",";
+ }
+ return sb.toString();
+ }
}