You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/02/04 15:28:54 UTC

svn commit: r906492 - /tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java

Author: slaws
Date: Thu Feb  4 14:28:54 2010
New Revision: 906492

URL: http://svn.apache.org/viewvc?rev=906492&view=rev
Log:
TUSCANY-3457 - add temp code to copy the manifest file byte for byte to get round the problem of the copy via the Manifest object dropping some attributes.

Modified:
    tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java

Modified: tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java
URL: http://svn.apache.org/viewvc/tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java?rev=906492&r1=906491&r2=906492&view=diff
==============================================================================
--- tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java (original)
+++ tuscany/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java Thu Feb  4 14:28:54 2010
@@ -649,6 +649,10 @@
                     // Create a bundle directory for a non-OSGi JAR
                     log.info("Adding JAR artifact: " + artifact);
 
+                    // create manifest directory
+                    File file = new File(dir, "META-INF");
+                    file.mkdirs();
+
                     String symbolicName = null;
                     if (customizedMF == null) {
                         String version = BundleUtil.osgiVersion(artifact.getVersion());
@@ -664,6 +668,12 @@
                                                        null,
                                                        this.eclipseBuddyPolicy,
                                                        this.executionEnvironment);
+
+                        file = new File(file, "MANIFEST.MF");
+                        FileOutputStream fos = new FileOutputStream(file);
+                        write(mf, fos);
+                        fos.close();
+                        log.info("Writing generated manifest for: " + artifact + " to " + file);
                     } else {
                         mf = customizedMF;
                         symbolicName = BundleUtil.getBundleSymbolicName(mf);
@@ -671,14 +681,35 @@
                             throw new MojoExecutionException("Invalid customized MANIFEST.MF for " + artifact);
                         }
                         setBundleClassPath(mf, artifactFile);
+                        
+                        // re-find the custom MF file and copy it
+                        // I can't get the  manifest file from the manifest itself
+                        // the Manifest read/write operation seems to be filtering
+                        // out some entries that I've added manually????
+                        File artifactManifest = null;
+
+                        if (artifactManifests != null) {
+                            for (ArtifactManifest m : artifactManifests) {
+                                if (m.matches(artifact)) {
+                                    artifactManifest = m.getManifestFile();
+                                    break; 
+                                }
+                            }
+                        }
+
+                        file = new File(file, "MANIFEST.MF");
+
+                        if (artifactManifest != null){ 
+                            log.info("Copying: " + artifactManifest + " to " + file);
+                            copyManifest(artifactManifest, file);                         
+                        } else {
+                            FileOutputStream fos = new FileOutputStream(file);
+                            write(mf, fos);
+                            fos.close();
+                            log.info("Writing generated manifest for: " + artifact + " to " + file);
+                        }
                     }
-                    File file = new File(dir, "META-INF");
-                    file.mkdirs();
-                    file = new File(file, "MANIFEST.MF");
 
-                    FileOutputStream fos = new FileOutputStream(file);
-                    write(mf, fos);
-                    fos.close();
                     copyFile(artifactFile, dir);
                     bundleSymbolicNames.add(artifact, symbolicName);
                     bundleLocations.add(artifact, dir.getName());
@@ -722,6 +753,7 @@
                     FileOutputStream fos = new FileOutputStream(file);
                     write(mf, fos);
                     fos.close();
+                    log.info("Written aggregate manifest");
                     bundleSymbolicNames.add(artifact, symbolicName);
                     bundleLocations.add(artifact, dir.getName());
                     if (isServiceProvider(mf)) {
@@ -1167,6 +1199,22 @@
         out.close();
     }
 
+    private static void copyManifest(File mfFrom, File mfTo) throws FileNotFoundException, IOException {
+        byte[] buf = new byte[4096];
+        FileInputStream in = new FileInputStream(mfFrom);
+        FileOutputStream out = new FileOutputStream(mfTo);
+        for (;;) {
+            int len = in.read(buf);
+            if (len > 0) {
+                out.write(buf, 0, len);
+            } else {
+                break;
+            }
+        }
+        in.close();
+        out.close();
+    }
+
     private static void addFileToJar(JarOutputStream out, String entryName, URL file) throws FileNotFoundException,
         IOException {
         byte[] buf = new byte[4096];