summaryrefslogtreecommitdiffstats
path: root/maven-plugins/trunk/maven-bundle-plugin/src/main
diff options
context:
space:
mode:
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/BundleUtil.java43
-rw-r--r--maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/ModuleBundlesBuildMojo.java62
2 files changed, 78 insertions, 27 deletions
diff --git a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleUtil.java b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleUtil.java
index 68166931fa..cb44d1bfdc 100644
--- a/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleUtil.java
+++ b/maven-plugins/trunk/maven-bundle-plugin/src/main/java/org/apache/tuscany/maven/bundle/plugin/BundleUtil.java
@@ -32,6 +32,7 @@ import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
@@ -60,32 +61,44 @@ final class BundleUtil {
* @throws IOException
*/
static String getBundleSymbolicName(File file) throws IOException {
+ Manifest manifest = getManifest(file);
+ return getBundleSymbolicName(manifest);
+ }
+
+ static String getBundleSymbolicName(Manifest manifest) {
+ if (manifest == null) {
+ return null;
+ }
+
+ String bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
+ if (bundleName == null) {
+ return bundleName;
+ }
+ int sc = bundleName.indexOf(';');
+ if (sc != -1) {
+ bundleName = bundleName.substring(0, sc);
+ }
+ return bundleName;
+ }
+
+ static Manifest getManifest(File file) throws IOException {
if (!file.exists()) {
return null;
}
- String bundleName = null;
+ Manifest manifest = null;
if (file.isDirectory()) {
File mf = new File(file, "META-INF/MANIFEST.MF");
if (mf.isFile()) {
- Manifest manifest = new Manifest(new FileInputStream(mf));
- bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
+ InputStream is = new FileInputStream(mf);
+ manifest = new Manifest(new FileInputStream(mf));
+ is.close();
}
} else {
JarFile jar = new JarFile(file, false);
- Manifest manifest = jar.getManifest();
- if (manifest != null){
- bundleName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME);
- }
+ manifest = jar.getManifest();
jar.close();
}
- if (bundleName == null) {
- return bundleName;
- }
- int sc = bundleName.indexOf(';');
- if (sc != -1) {
- bundleName = bundleName.substring(0, sc);
- }
- return bundleName;
+ return manifest;
}
/**
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 efb08a62c8..4fa5762118 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
@@ -19,6 +19,7 @@
package org.apache.tuscany.maven.bundle.plugin;
import static org.apache.tuscany.maven.bundle.plugin.BundleUtil.write;
+import static org.osgi.framework.Constants.BUNDLE_CLASSPATH;
import java.io.File;
import java.io.FileInputStream;
@@ -171,6 +172,12 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
private boolean generateTargetPlatform = true;
/**
+ * Expand non-tuscany bundles as a folder
+ * @parameter default-value="false"
+ */
+ private boolean expandThirdPartyBundle = false;
+
+ /**
* OSGi execution environment
*/
private String executionEnvironment;
@@ -369,7 +376,8 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
}
// Only consider JAR and WAR files
- if (!"jar".equals(artifact.getType()) && !"war".equals(artifact.getType())) {
+ if (!"jar".equals(artifact.getType()) && !"bundle".equals(artifact.getType())
+ && !"war".equals(artifact.getType())) {
continue;
}
@@ -396,9 +404,11 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
}
// Get the bundle name if the artifact is an OSGi bundle
+ Manifest mf = null;
String bundleName = null;
try {
- bundleName = BundleUtil.getBundleSymbolicName(artifact.getFile());
+ mf = BundleUtil.getManifest(artifactFile);
+ bundleName = BundleUtil.getBundleSymbolicName(mf);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
@@ -413,10 +423,41 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
// Copy an OSGi bundle as is
log.info("Adding OSGi bundle artifact: " + artifact);
- copyFile(artifactFile, root);
- bundleSymbolicNames.add(artifact, bundleName);
- bundleLocations.add(artifact, artifactFile.getName());
- jarNames.add(artifact, artifactFile.getName());
+
+ if (!expandThirdPartyBundle || artifact.getGroupId().startsWith("org.apache.tuscany.sca")
+ || artifact.getGroupId().startsWith("org.eclipse")) {
+ copyFile(artifactFile, root);
+ bundleSymbolicNames.add(artifact, bundleName);
+ bundleLocations.add(artifact, artifactFile.getName());
+ 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);
+
+ int index = artifactFile.getName().lastIndexOf('.');
+ String dirName = artifactFile.getName().substring(0, index);
+ File dir = new File(root, dirName);
+
+ 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, bundleName);
+ bundleLocations.add(artifact, dir.getName());
+ jarNames.add(artifact, dirName + "/" + artifactFile.getName());
+ }
} else if ("war".equals(artifact.getType())) {
@@ -432,11 +473,8 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
} else {
- // String version = BundleUtil.osgiVersion(artifact.getVersion());
- // String symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId());
- // String dirName = symbolicName + "_" + version;
-
- String dirName = artifactFile.getName().substring(0, artifactFile.getName().length() - 4);
+ int index = artifactFile.getName().lastIndexOf('.');
+ String dirName = artifactFile.getName().substring(0, index);
File dir = new File(root, dirName);
// Exclude artifact if its file name is excluded
@@ -466,7 +504,7 @@ public class ModuleBundlesBuildMojo extends AbstractMojo {
Set<File> jarFiles = new HashSet<File>();
jarFiles.add(artifactFile);
String symbolicName = (artifact.getGroupId() + "." + artifact.getArtifactId());
- Manifest mf =
+ mf =
BundleUtil.libraryManifest(jarFiles,
symbolicName,
symbolicName,