You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2007/05/17 15:05:51 UTC

svn commit: r538899 - in /felix/trunk/tools/maven2/maven-bundle-plugin/src: main/java/org/apache/felix/tools/maven2/bundleplugin/ test/java/org/apache/felix/tools/maven2/bundleplugin/ test/resources/

Author: rickhall
Date: Thu May 17 06:05:50 2007
New Revision: 538899

URL: http://svn.apache.org/viewvc?view=rev&rev=538899
Log:
Applied patch (FELIX-283) to not regenerate the bundle manifest if the JAR
already has a manifest in the bundleall goal.

Modified:
    felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPlugin.java
    felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleInfo.java
    felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPluginTest.java
    felix/trunk/tools/maven2/maven-bundle-plugin/src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPlugin.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPlugin.java?view=diff&rev=538899&r1=538898&r2=538899
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPlugin.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPlugin.java Thu May 17 06:05:50 2007
@@ -20,6 +20,7 @@
 
 import java.io.File;
 import java.io.FilenameFilter;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -261,14 +262,31 @@
 
             Analyzer analyzer = getAnalyzer( project, getClasspath( project ) );
 
-            BundleInfo bundleInfo = addExportedPackages( project, analyzer.getExports().keySet() );
-
             Jar osgiJar = new Jar( project.getArtifactId(), project.getArtifact().getFile() );
-            Manifest manifest = analyzer.getJar().getManifest();
-            osgiJar.setManifest( manifest );
+
+            Collection exportedPackages;
+            if ( isOsgi( osgiJar ) )
+            {
+                /* if it is already an OSGi jar copy it as is */
+                getLog().info(
+                               "Using existing OSGi bundle for " + project.getGroupId() + ":" + project.getArtifactId()
+                                   + ":" + project.getVersion() );
+                String exportHeader = osgiJar.getManifest().getMainAttributes().getValue( Analyzer.EXPORT_PACKAGE );
+                exportedPackages = analyzer.parseHeader( exportHeader ).keySet();
+            }
+            else
+            {
+                /* else generate the mainfest from the packages */
+                exportedPackages = analyzer.getExports().keySet();
+                Manifest manifest = analyzer.getJar().getManifest();
+                osgiJar.setManifest( manifest );
+            }
+
             outputFile.getParentFile().mkdirs();
             osgiJar.write( outputFile );
 
+            BundleInfo bundleInfo = addExportedPackages( project, exportedPackages );
+
             return bundleInfo;
         }
         /* too bad Jar.write throws Exception */
@@ -277,6 +295,12 @@
             throw new MojoExecutionException( "Error generating OSGi bundle for project "
                 + getArtifactKey( project.getArtifact() ), e );
         }
+    }
+
+    private boolean isOsgi( Jar jar )
+        throws IOException
+    {
+        return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null;
     }
 
     private BundleInfo addExportedPackages( MavenProject project, Collection packages )

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleInfo.java?view=diff&rev=538899&r1=538898&r2=538899
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleInfo.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/main/java/org/apache/felix/tools/maven2/bundleplugin/BundleInfo.java Thu May 17 06:05:50 2007
@@ -49,7 +49,7 @@
         artifacts.add( artifact );
     }
 
-    private Map getExportedPackages()
+    Map getExportedPackages()
     {
         return exportedPackages;
     }

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPluginTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPluginTest.java?view=diff&rev=538899&r1=538898&r2=538899
==============================================================================
--- felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPluginTest.java (original)
+++ felix/trunk/tools/maven2/maven-bundle-plugin/src/test/java/org/apache/felix/tools/maven2/bundleplugin/BundleAllPluginTest.java Thu May 17 06:05:50 2007
@@ -8,9 +8,9 @@
  * to you under the Apache License, Version 2.0 (the
  * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -21,9 +21,12 @@
 
 import java.io.File;
 import java.util.Collections;
+import java.util.Map;
 
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.apache.maven.project.MavenProject;
 
 /**
  * Test for {@link BundleAllPlugin}
@@ -71,6 +74,45 @@
         artifact.setArtifactId( "artifactx" );
         artifact.setVersion( "2.1-SNAPSHOT" );
         assertFalse( plugin.snapshotMatch( artifact, bundleName ) );
+    }
+
+    public void testNoReBundling()
+        throws Exception
+    {
+        File testFile = getTestFile( "target/group.artifact_1.0.0.0.jar" );
+        if ( testFile.exists() )
+        {
+            testFile.delete();
+        }
+
+        ArtifactStub artifact = new ArtifactStub();
+        artifact.setGroupId( "group" );
+        artifact.setArtifactId( "artifact" );
+        artifact.setVersion( "1.0.0.0" );
+
+        MavenProject project = new MavenProjectStub();
+        project.setVersion( artifact.getVersion() );
+        project.setArtifact( artifact );
+        project.setArtifacts( Collections.EMPTY_SET );
+        project.setDependencyArtifacts( Collections.EMPTY_SET );
+        File bundleFile = getTestFile( "src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar" );
+        artifact.setFile( bundleFile );
+
+        BundleInfo bundleInfo = plugin.bundle( project );
+
+        Map exports = bundleInfo.getExportedPackages();
+        String[] packages = new String[] {
+            "org.apache.maven.model.io.jdom",
+            "org.apache.maven.model" };
+
+        for ( int i = 0; i < packages.length; i++ )
+        {
+            assertTrue( "Bundle info does not contain a package that it is  exported in the manifest: " + packages[i],
+                        exports.containsKey( packages[i] ) );
+        }
+
+        assertFalse( "Bundle info contains a package that it is not exported in the manifest", exports
+            .containsKey( "org.apache.maven.model.io.xpp3" ) );
     }
 
 //    public void testRewriting()

Modified: felix/trunk/tools/maven2/maven-bundle-plugin/src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/felix/trunk/tools/maven2/maven-bundle-plugin/src/test/resources/org.apache.maven.maven-model_2.1.0.SNAPSHOT.jar?view=diff&rev=538899&r1=538898&r2=538899
==============================================================================
Binary files - no diff available.