summaryrefslogtreecommitdiffstats
path: root/maven-plugins/trunk/maven-bundle-plugin/src/main
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-01-09 18:10:58 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2010-01-09 18:10:58 +0000
commitebbaaef8b69146cde512ed3ce34af55d68f82297 (patch)
treebb3dfe929f664d420de825731129910ac3725ada /maven-plugins/trunk/maven-bundle-plugin/src/main
parentaadbcc8ee91a4b2ecba60c8e71ae0393bda56301 (diff)
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
Diffstat (limited to 'maven-plugins/trunk/maven-bundle-plugin/src/main')
-rw-r--r--maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleAggregatorMojo.java36
-rw-r--r--maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java44
2 files changed, 60 insertions, 20 deletions
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;
/**
@@ -57,15 +56,6 @@ import org.apache.tuscany.maven.bundle.plugin.HeaderParser.HeaderClause;
*/
public class BundleAggregatorMojo extends AbstractMojo {
/**
- * The project to create a distribution for.
- *
- * @parameter expression="${project}"
- * @required
- * @readonly
- */
- private MavenProject project;
-
- /**
* Root directory.
*
* @parameter expression="${project.build.directory}/modules"
@@ -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<File> jarFiles = new HashSet<File>();
List<Manifest> manifests = new ArrayList<Manifest>();
- 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
@@ -256,6 +256,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"
*/
private boolean generateBundleStart = 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<String, Set<String>> e : bundleLocations.nameMap.entrySet()) {
+ Set<String> locations = new HashSet<String>(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<String, Set<String>> e : bundleSymbolicNames.nameMap.entrySet()) {