felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mccu...@apache.org
Subject svn commit: r744869 - /felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.java
Date Mon, 16 Feb 2009 09:44:48 GMT
Author: mcculls
Date: Mon Feb 16 09:44:47 2009
New Revision: 744869

URL: http://svn.apache.org/viewvc?rev=744869&view=rev
Log:
FELIX-912: set default Export-Package based on local source files

Modified:
    felix/trunk/bundleplugin/src/main/java/org/apache/felix/bundleplugin/BundlePlugin.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=744869&r1=744868&r2=744869&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
Mon Feb 16 09:44:47 2009
@@ -386,10 +386,7 @@
             }
             else
             {
-                String bsn = builder.getProperty( Analyzer.BUNDLE_SYMBOLICNAME );
-                String namespace = bsn.replaceAll( "\\W", "." );
-
-                builder.setProperty( Analyzer.EXPORT_PACKAGE, namespace + ".*" );
+                addLocalPackages( builder, currentProject );
             }
         }
 
@@ -915,6 +912,52 @@
     }
 
 
+    private static void addLocalPackages( Analyzer analyzer, MavenProject project )
+    {
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setBasedir( project.getBuild().getSourceDirectory() );
+        scanner.setIncludes( new String[]
+            { "**/*.java" } );
+
+        scanner.addDefaultExcludes();
+        scanner.scan();
+
+        Collection packages = new HashSet();
+
+        String[] paths = scanner.getIncludedFiles();
+        for ( int i = 0; i < paths.length; i++ )
+        {
+            packages.add( getPackageName( paths[i] ) );
+        }
+
+        StringBuffer exportPackage = new StringBuffer();
+        StringBuffer privatePackage = new StringBuffer();
+
+        for ( Iterator i = packages.iterator(); i.hasNext(); )
+        {
+            String pkg = ( String ) i.next();
+            if ( ".".equals( pkg ) || pkg.contains( ".internal" ) || pkg.contains( ".impl"
) )
+            {
+                privatePackage.append( pkg ).append( ',' );
+            }
+            else
+            {
+                exportPackage.append( pkg ).append( ',' );
+            }
+        }
+
+        analyzer.setProperty( Analyzer.EXPORT_PACKAGE, exportPackage.toString() );
+        analyzer.setProperty( Analyzer.PRIVATE_PACKAGE, privatePackage.toString() );
+    }
+
+
+    public static String getPackageName( String filename )
+    {
+        int n = filename.lastIndexOf( File.separatorChar );
+        return n < 0 ? "." : filename.substring( 0, n ).replace( File.separatorChar, '.'
);
+    }
+
+
     private static String getMavenResourcePaths( MavenProject project )
     {
         final String basePath = project.getBasedir().getAbsolutePath();



Mime
View raw message