From ebbaaef8b69146cde512ed3ce34af55d68f82297 Mon Sep 17 00:00:00 2001 From: rfeng Date: Sat, 9 Jan 2010 18:10:58 +0000 Subject: Add the ability to generate feature-based aggregated bundles git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897505 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/bundle/plugin/BundleAggregatorMojo.java | 36 ++++++++---------- .../bundle/plugin/ModuleBundlesBuildMojo.java | 44 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 20 deletions(-) (limited to 'maven-plugins/trunk/maven-bundle-plugin/src/main') diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleAggregatorMojo.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleAggregatorMojo.java index c0952ad222..e098799085 100644 --- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleAggregatorMojo.java +++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleAggregatorMojo.java @@ -45,7 +45,6 @@ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; import org.apache.tuscany.maven.bundle.plugin.HeaderParser.HeaderClause; /** @@ -56,15 +55,6 @@ import org.apache.tuscany.maven.bundle.plugin.HeaderParser.HeaderClause; * @description Generate an aggregated bundle that contains all the modules and 3rd party jars */ public class BundleAggregatorMojo extends AbstractMojo { - /** - * The project to create a distribution for. - * - * @parameter expression="${project}" - * @required - * @readonly - */ - private MavenProject project; - /** * Root directory. * @@ -83,24 +73,24 @@ public class BundleAggregatorMojo extends AbstractMojo { * @parameter default-value== "org.apache.tuscany.sca.bundle"; */ private String bundleName = "org.apache.tuscany.sca.bundle"; - + /** * @parameter default-value== "2.0.0"; */ private String bundleVersion = "2.0.0"; - + // private static final Logger logger = Logger.getLogger(BundleAggregatorMojo.class.getName()); - public void aggregateBundles(File root, File targetBundleFile) throws Exception { - Log log = getLog(); - if (!root.isDirectory()) { - log.warn(root + " is not a directory"); - return; - } + public static void aggregateBundles(Log log, + File root, + File[] files, + File targetBundleFile, + String bundleName, + String bundleVersion) throws Exception { targetBundleFile.getParentFile().mkdirs(); Set jarFiles = new HashSet(); List manifests = new ArrayList(); - for (File child : root.listFiles()) { + for (File child : files) { try { Manifest manifest = null; if (child.isDirectory()) { @@ -254,7 +244,13 @@ public class BundleAggregatorMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { try { - aggregateBundles(rootDirectory, targetBundleFile); + Log log = getLog(); + if (!rootDirectory.isDirectory()) { + log.warn(rootDirectory + " is not a directory"); + return; + } + File[] files = rootDirectory.listFiles(); + aggregateBundles(log, rootDirectory, files, targetBundleFile, bundleName, bundleVersion); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } 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 8435691019..a90fb35e83 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 @@ -255,6 +255,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { */ private boolean generateConfig = true; + /** + * Generate an aggregated OSGi bundle for each feature + * @parameter default-value="false" + */ + private boolean generateAggregatedBundle = false; + /** * @parameter default-value="true" */ @@ -728,6 +734,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { generateGatewayBundle(serviceProviders); } + if (useDistributionName) { + bundleLocations.nameMap.remove(project.getArtifactId()); + jarNames.nameMap.remove(project.getArtifactId()); + bundleSymbolicNames.nameMap.remove(project.getArtifactId()); + } + // Generate a PDE target if (generateTargetPlatform) { generatePDETarget(bundleSymbolicNames, root, log); @@ -753,6 +765,10 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { if (generateAntScript) { generateANTPath(jarNames, root, log); } + + if (generateAggregatedBundle) { + generateAggregatedBundles(bundleLocations, root, log); + } } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); @@ -1029,6 +1045,34 @@ public class ModuleBundlesBuildMojo extends AbstractMojo { } } + private void generateAggregatedBundles(ProjectSet bundleLocations, File root, Log log) throws Exception { + for (Map.Entry> e : bundleLocations.nameMap.entrySet()) { + Set locations = new HashSet(e.getValue()); + String featureName = (useDistributionName ? trim(e.getKey()) : ""); + File feature = new File(root, "../" + featuresName + "/" + featureName); +// String bundleFileName = "tuscany-bundle-" + featureName + ".jar"; +// if ("".equals(featureName)) { +// bundleFileName = "tuscany-bundle.jar"; +// } + String bundleFileName = "tuscany-bundle.jar"; + File bundleFile = new File(feature, bundleFileName); + log.info("Generating aggregated OSGi bundle: " + bundleFile); + File[] files = new File[locations.size()]; + int i = 0; + for (String child : locations) { + files[i++] = new File(root, child); + } + String bundleVersion = "2.0.0"; + String bundleName = "org.apache.tuscany.sca.bundle"; + +// String bundleName = "org.apache.tuscany.sca.bundle." + featureName; +// if ("".equals(featureName)) { +// bundleName = "org.apache.tuscany.sca.bundle"; +// } + BundleAggregatorMojo.aggregateBundles(log, root, files, bundleFile, bundleName, bundleVersion); + } + } + private void generatePDETarget(ProjectSet bundleSymbolicNames, File root, Log log) throws FileNotFoundException, IOException { for (Map.Entry> e : bundleSymbolicNames.nameMap.entrySet()) { -- cgit v1.2.3