From d8da679db3c406c9c56cc14d047645d0cebb7afd Mon Sep 17 00:00:00 2001 From: rfeng Date: Wed, 27 May 2009 01:22:08 +0000 Subject: Add capability to override MANIFEST.MF git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@778954 13f79535-47bb-0310-9956-ffa450edef68 --- .../bundle/plugin/ModuleBundlesBuildMojo.java | 89 ++++++++++++++++------ 1 file changed, 66 insertions(+), 23 deletions(-) (limited to 'maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java') 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 4fa5762118..a13734e316 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 @@ -238,6 +238,11 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { */ private ArtifactAggregation[] artifactAggregations; + /** + * @parameter + */ + private ArtifactManifest[] artifactManifests; + /** * Inserts a generic Eclipse-BuddyPolicy header into generated artifacts manifests * @parameter @@ -305,6 +310,25 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { } } + private Manifest findManifest(Artifact artifact) throws IOException { + if (artifactManifests == null) { + return null; + } + for (ArtifactManifest m : artifactManifests) { + if (m.matches(artifact)) { + File mf = m.getManifestFile(); + if (mf != null) { + FileInputStream is = new FileInputStream(mf); + Manifest manifest = new Manifest(is); + is.close(); + getLog().info("MANIFEST.MF found for " + artifact + " (" + mf + ")"); + return manifest; + } + } + } + return null; + } + public void execute() throws MojoExecutionException { Log log = getLog(); @@ -403,6 +427,8 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { log.debug("Processing artifact: " + artifact); } + Manifest customizedMF = findManifest(artifact); + // Get the bundle name if the artifact is an OSGi bundle Manifest mf = null; String bundleName = null; @@ -413,7 +439,7 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { throw new MojoExecutionException(e.getMessage(), e); } - if (bundleName != null) { + if (bundleName != null && customizedMF == null) { // Exclude artifact if its file name is excluded if (excludedFileNames.contains(artifactFile.getName())) { @@ -432,16 +458,9 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { jarNames.add(artifact, artifactFile.getName()); } else { // Expanding the bundle into a folder - - // Add the Bundle-ClassPath - String cp = mf.getMainAttributes().getValue(BUNDLE_CLASSPATH); - if (cp == null) { - cp = artifactFile.getName(); - } else { - cp = cp + "," + artifactFile.getName(); - } - mf.getMainAttributes().putValue(BUNDLE_CLASSPATH, cp); - + + setBundleClassPath(mf, artifactFile); + int index = artifactFile.getName().lastIndexOf('.'); String dirName = artifactFile.getName().substring(0, index); File dir = new File(root, dirName); @@ -499,18 +518,30 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { // Create a bundle directory for a non-OSGi JAR log.info("Adding JAR artifact: " + artifact); - String version = BundleUtil.osgiVersion(artifact.getVersion()); - Set jarFiles = new HashSet(); - jarFiles.add(artifactFile); - String symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId()); - mf = - BundleUtil.libraryManifest(jarFiles, - symbolicName, - symbolicName, - version, - null, - this.eclipseBuddyPolicy); + String symbolicName = null; + if (customizedMF == null) { + String version = BundleUtil.osgiVersion(artifact.getVersion()); + + Set jarFiles = new HashSet(); + jarFiles.add(artifactFile); + symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId()); + mf = + BundleUtil.libraryManifest(jarFiles, + symbolicName, + symbolicName, + version, + null, + this.eclipseBuddyPolicy, + this.executionEnvironment); + } else { + mf = customizedMF; + symbolicName = BundleUtil.getBundleSymbolicName(mf); + if (symbolicName == null) { + throw new MojoExecutionException("Invalid customized MANIFEST.MF for " + artifact); + } + setBundleClassPath(mf, artifactFile); + } File file = new File(dir, "META-INF"); file.mkdirs(); file = new File(file, "MANIFEST.MF"); @@ -549,7 +580,8 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { symbolicName, version, null, - this.eclipseBuddyPolicy); + this.eclipseBuddyPolicy, + this.executionEnvironment); File file = new File(dir, "META-INF"); file.mkdirs(); file = new File(file, "MANIFEST.MF"); @@ -594,6 +626,17 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { } + private void setBundleClassPath(Manifest mf, File artifactFile) { + // Add the Bundle-ClassPath + String cp = mf.getMainAttributes().getValue(BUNDLE_CLASSPATH); + if (cp == null) { + cp = artifactFile.getName(); + } else { + cp = cp + "," + artifactFile.getName(); + } + mf.getMainAttributes().putValue(BUNDLE_CLASSPATH, cp); + } + private void generateANTPath(ProjectSet jarNames, File root, Log log) throws FileNotFoundException, IOException { for (Map.Entry> e : jarNames.nameMap.entrySet()) { Set jars = e.getValue(); -- cgit v1.2.3