You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2007/02/10 02:18:39 UTC

svn commit: r505600 - in /maven/sandbox/plugins/maven-bundle-plugin/src: main/java/aQute/lib/osgi/ main/java/org/apache/felix/tools/maven2/bundleplugin/ test/java/org/apache/felix/tools/maven2/bundleplugin/

Author: carlos
Date: Fri Feb  9 17:18:38 2007
New Revision: 505600

URL: http://svn.apache.org/viewvc?view=rev&rev=505600
Log:
Move customizations to PatchedAnalyzer

Added:
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedAnalyzer.java
      - copied, changed from r505535, maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedBuilder.java
Removed:
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/Analyzer.java
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedBuilder.java
Modified:
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
    maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java
    maven/sandbox/plugins/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java

Copied: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedAnalyzer.java (from r505535, maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedBuilder.java)
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedAnalyzer.java?view=diff&rev=505600&p1=maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedBuilder.java&r1=505535&p2=maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedAnalyzer.java&r2=505600
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedBuilder.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/aQute/lib/osgi/PatchedAnalyzer.java Fri Feb  9 17:18:38 2007
@@ -21,6 +21,9 @@
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+import java.util.jar.Attributes.Name;
 
 /**
  * Extension of {@link aQute.lib.osgi.Analyzer} for some patches
@@ -28,9 +31,54 @@
  * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
  * @version $Id$
  */
-public class PatchedBuilder
-    extends Builder
+public class PatchedAnalyzer
+    extends Analyzer
 {
+
+    public String calculateExportsFromContents() {
+        String ddel = ",";
+        StringBuffer sb = new StringBuffer();
+        Map map = dot.getDirectories();
+        for (Iterator i = map.keySet().iterator(); i.hasNext();) {
+            String directory = (String) i.next();
+            if (directory.startsWith("META-INF/"))
+                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();
+    }
+
+    /**
+     * @param analyzer
+     * @param dot
+     * @throws IOException
+     */
+    public void mergeManifest() throws IOException {
+        Manifest manifest = dot.getManifest();
+        if (manifest != null) {
+            Attributes attributes = manifest.getMainAttributes();
+            for (Iterator i = attributes.keySet().iterator(); i.hasNext();) {
+                Name name = (Name) i.next();
+                String key = name.toString();
+                // Dont want instructions
+                if (key.startsWith("-"))
+                    continue;
+
+                if (getProperty(key) == null)
+                    setProperty(key, (String) attributes.get(name));
+            }
+        }
+    }
 
     /**
      * This method should be in {@link Analyzer}

Modified: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java?view=diff&rev=505600&r1=505599&r2=505600
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundlePlugin.java Fri Feb  9 17:18:38 2007
@@ -120,7 +120,7 @@
 
    properties.putAll(instructions);
  
-   PatchedBuilder builder = new PatchedBuilder();
+   Builder builder = new Builder();
    builder.setBase(baseDir);
    builder.setProperties(properties);
    builder.setClasspath(classpath);

Modified: maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java?view=diff&rev=505600&r1=505599&r2=505600
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/ManifestPlugin.java Fri Feb  9 17:18:38 2007
@@ -30,6 +30,7 @@
 
 import aQute.lib.osgi.Analyzer;
 import aQute.lib.osgi.Jar;
+import aQute.lib.osgi.PatchedAnalyzer;
 
 /**
  * Generate an OSGi manifest for this project
@@ -83,7 +84,7 @@
     public Manifest getManifest( MavenProject project, Properties properties, Jar[] classpath )
         throws IOException
     {
-        Analyzer analyzer = new Analyzer();
+        PatchedAnalyzer analyzer = new PatchedAnalyzer();
 
         analyzer.setProperties( getDefaultProperties( project ) );
         if ( properties != null )

Modified: maven/sandbox/plugins/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/plugins/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java?view=diff&rev=505600&r1=505599&r2=505600
==============================================================================
--- maven/sandbox/plugins/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java (original)
+++ maven/sandbox/plugins/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundlePluginTest.java Fri Feb  9 17:18:38 2007
@@ -30,8 +30,9 @@
 import org.codehaus.plexus.archiver.jar.JarArchiver;
 
 import aQute.lib.osgi.Analyzer;
+import aQute.lib.osgi.Builder;
 import aQute.lib.osgi.Jar;
-import aQute.lib.osgi.PatchedBuilder;
+import aQute.lib.osgi.PatchedAnalyzer;
 
 /**
  * Test for {@link BundlePlugin}.
@@ -99,14 +100,15 @@
         project.setArtifactId( "artifact" );
         project.setVersion( "1.1.0.0" );
 
-        PatchedBuilder builder = new PatchedBuilder();
+        PatchedAnalyzer analyzer = new PatchedAnalyzer();
         Jar jar = new Jar( "name", osgiBundleFile );
-        builder.setClasspath( new Jar[] { jar } );
+        analyzer.setJar( jar );
+        analyzer.setClasspath( new Jar[] { jar } );
 
-        builder.setProperty( Analyzer.EXPORT_PACKAGE, "*" );
-        builder.build();
+        analyzer.setProperty( Analyzer.EXPORT_PACKAGE, "*" );
+        analyzer.calcManifest();
 
-        assertEquals( 3, builder.getExports().size() );
+        assertEquals( 3, analyzer.getExports().size() );
     }
 
     public void testGetPackages()