From 1b9131932b52a615c7481a293a411c56ffd63c2d Mon Sep 17 00:00:00 2001 From: slaws Date: Thu, 4 Feb 2010 14:28:54 +0000 Subject: 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. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@906492 13f79535-47bb-0310-9956-ffa450edef68 --- .../bundle/plugin/ModuleBundlesBuildMojo.java | 60 +++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) (limited to 'maven-plugins/trunk') diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java index 4b9198b741..0ab47f4ef4 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java @@ -649,6 +649,10 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { // 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 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { 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 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { 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 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { 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 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { 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]; -- cgit v1.2.3