summaryrefslogtreecommitdiffstats
path: root/java/sca
diff options
context:
space:
mode:
authorrsivaram <rsivaram@13f79535-47bb-0310-9956-ffa450edef68>2008-07-26 21:15:13 +0000
committerrsivaram <rsivaram@13f79535-47bb-0310-9956-ffa450edef68>2008-07-26 21:15:13 +0000
commit56e572665cba4b30f4b954e19c1ebabee5cc90d4 (patch)
tree0657e4b263ac3857b4e400cce3d6e496a54bc636 /java/sca
parentd20702d6c1d949a182366bff26f271b35637279f (diff)
Version Tuscany modules and 3rd party libraries in itest/osgi-tuscany
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@680048 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java4
-rw-r--r--java/sca/itest/osgi-tuscany/pom.xml1
-rw-r--r--java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java186
-rw-r--r--java/sca/itest/osgi-tuscany/tuscany-versioned/pom.xml644
-rw-r--r--java/sca/modules/sca-api/pom.xml2
-rw-r--r--java/sca/tools/maven/maven-tuscany-bundle-plugin/pom.xml77
-rw-r--r--java/sca/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java492
7 files changed, 1402 insertions, 4 deletions
diff --git a/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java b/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
index 6362385a13..6356718fe5 100644
--- a/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
+++ b/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/osgi/runtime/impl/OSGiTestRuntime.java
@@ -134,12 +134,15 @@ public abstract class OSGiTestRuntime {
"javax.xml.xpath, " +
"javax.sql," +
"org.w3c.dom, " +
+ "org.w3c.dom.bootstrap, " +
+ "org.w3c.dom.ls, " +
"org.xml.sax, " +
"org.xml.sax.ext, " +
"org.xml.sax.helpers, " +
"javax.security.auth, " +
"javax.security.auth.login, " +
"javax.security.auth.callback, " +
+ "javax.security.cert, " +
"javax.naming, " +
"javax.naming.spi, " +
"javax.naming.directory, " +
@@ -147,6 +150,7 @@ public abstract class OSGiTestRuntime {
"javax.imageio, " +
"sun.misc, " +
"javax.net, " +
+ "javax.net.ssl, " +
"javax.crypto, " +
"javax.rmi, " +
"javax.transaction, " +
diff --git a/java/sca/itest/osgi-tuscany/pom.xml b/java/sca/itest/osgi-tuscany/pom.xml
index 4b432782a9..0da4f09d61 100644
--- a/java/sca/itest/osgi-tuscany/pom.xml
+++ b/java/sca/itest/osgi-tuscany/pom.xml
@@ -31,6 +31,7 @@
<modules>
<module>test-bundles</module>
+ <module>tuscany-versioned</module>
<module>tuscany-osgi-installer</module>
<module>osgi-tuscany-test</module>
</modules>
diff --git a/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java b/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java
index 2366acd094..059200302c 100644
--- a/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java
+++ b/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java
@@ -77,9 +77,28 @@ public class InstallerBundleActivator implements BundleActivator {
};
+ private static final String[] rebundleJars = {
+ "org.apache.tuscany.sdo", // Recreate export statements
+ };
+
public void start(BundleContext bundleContext) throws Exception {
+
+ String tuscanyHome = System.getProperty("TUSCANY_HOME");
+ if (tuscanyHome == null) {
+ File homeDir = new File("../tuscany-versioned/target/classes");
+ if (homeDir.exists()) {
+ tuscanyHome = homeDir.getCanonicalPath();
+ }
+ }
- installTuscanyIntoOSGi(bundleContext);
+ if (tuscanyHome == null) {
+ System.out.println("Installing Tuscany bundles and virtual 3rd party bundles.");
+ installTuscanyIntoOSGi(bundleContext);
+ }
+ else {
+ System.out.println("Installing Tuscany from TUSCANY_HOME=" + tuscanyHome);
+ installVersionedTuscanyIntoOSGi(bundleContext, tuscanyHome);
+ }
}
public void stop(BundleContext bundleContext) throws Exception {
@@ -92,6 +111,75 @@ public class InstallerBundleActivator implements BundleActivator {
}
}
}
+
+ private void installVersionedTuscanyIntoOSGi(BundleContext bundleContext, String tuscanyHome) {
+
+ try {
+ Bundle[] installedBundles = bundleContext.getBundles();
+ HashSet<String> installedBundleSet = new HashSet<String>();
+ for (Bundle bundle : installedBundles) {
+ if (bundle.getSymbolicName() != null)
+ installedBundleSet.add(bundle.getSymbolicName());
+ }
+
+ // FIXME: SDO bundles dont have the correct dependencies
+ System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");
+
+ HashSet<File> tuscanyJars = new HashSet<File>();
+ HashSet<File> thirdPartyJars = new HashSet<File>();
+
+
+ File tuscanyInstallDir = new File(tuscanyHome).getCanonicalFile();
+ findBundles(bundleContext, tuscanyInstallDir, tuscanyJars, thirdPartyJars);
+
+
+ for (File bundleFile : thirdPartyJars) {
+
+ String bundleName = bundleFile.getName();
+ if (bundleName.startsWith("org.apache.felix"))
+ continue;
+
+ boolean installed = false;
+ for (String name : rebundleJars) {
+ if (bundleName.startsWith(name)) {
+ rebundleAndInstall(bundleContext, tuscanyInstallDir, bundleFile);
+ installed = true;
+ }
+ }
+ if (installed)
+ continue;
+
+ bundleContext.installBundle(bundleFile.toURI().toURL().toString());
+
+ }
+
+ Bundle osgiRuntimeBundle = null;
+ for (File bundleFile : tuscanyJars) {
+ Bundle bundle = bundleContext.installBundle(bundleFile.toURI().toURL().toString());
+ if ("org.apache.tuscany.sca.osgi.runtime".equals(bundle.getSymbolicName()))
+ osgiRuntimeBundle = bundle;
+ }
+ if (osgiRuntimeBundle != null)
+ osgiRuntimeBundle.start();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void rebundleAndInstall(BundleContext bundleContext, File tuscanyInstallDir, File bundleFile) throws Exception {
+ String bundleSymbolicName = "org.apache.tuscany.sca.3rdparty." + bundleFile.getName();
+ if (bundleSymbolicName.endsWith(".jar")) bundleSymbolicName = bundleSymbolicName.substring(0, bundleSymbolicName.length()-4);
+
+ String bundleLocation = bundleFile.toURI().toURL().toString();
+ InputStream bundleManifestStream = updateBundleManifest(bundleFile, bundleSymbolicName);
+ HashSet<File> jarSet = new HashSet<File>();
+ jarSet.add(bundleFile);
+
+ File newBundleFile = new File(tuscanyInstallDir, "org.apache.tuscany.sca." + bundleFile.getName());
+ createAndInstallBundle(bundleContext, bundleLocation, newBundleFile, bundleManifestStream, jarSet);
+ bundleManifestStream.close();
+ }
private void installTuscanyIntoOSGi(BundleContext bundleContext) {
@@ -167,6 +255,98 @@ public class InstallerBundleActivator implements BundleActivator {
e.printStackTrace();
}
}
+
+ private void findBundles(BundleContext bundleContext,
+ File tuscanyInstallDir,
+ HashSet<File> tuscanyJars,
+ HashSet<File> thirdPartyJars)
+ throws IOException
+ {
+
+ File[] jars = tuscanyInstallDir.listFiles();
+ for (File jar : jars) {
+ String jarName = jar.getName();
+ if (!jarName.endsWith(".jar"))
+ continue;
+
+ if (!jarName.startsWith("org.apache.tuscany.sca")) {
+ if (jarName.endsWith(".jar"))
+ {
+ thirdPartyJars.add(jar);
+ }
+ } else {
+ boolean installTuscanyJar = true;
+ for (String name : tuscanyModulesToIgnore) {
+ name = name.replaceAll("-", ".");
+ if (jarName.startsWith("org.apache.tuscany.sca." + name)) {
+ installTuscanyJar = false;
+ break;
+ }
+ }
+ if (installTuscanyJar)
+ tuscanyJars.add(jar);
+ }
+ }
+ }
+
+
+ private InputStream updateBundleManifest(File jarFile, String bundleSymbolicName) throws Exception {
+
+ if (!jarFile.exists())
+ return null;
+ JarInputStream jar = new JarInputStream(new FileInputStream(jarFile));
+ Manifest manifest = jar.getManifest();
+ if (manifest == null) {
+ ZipEntry ze;
+ while ((ze = jar.getNextEntry()) != null) {
+ if (ze.getName().equals("META-INF/MANIFEST.MF"))
+ break;
+ }
+ if (ze != null) {
+ byte[] bytes = new byte[(int)ze.getSize()];
+ jar.read(bytes);
+ manifest = new Manifest(new ByteArrayInputStream(bytes));
+ }
+ }
+ if (manifest == null) {
+ manifest = new Manifest();
+ }
+
+ String bundleName = jarFile.getName();
+ boolean isImmutableJar = false;
+ for (String immutableJar : immutableJars) {
+ if (bundleName.startsWith(immutableJar)) {
+ isImmutableJar = true;
+ break;
+ }
+ }
+ Attributes attributes = manifest.getMainAttributes();
+ if (isImmutableJar)
+ attributes.putValue("Bundle-ClassPath", bundleName);
+
+
+ attributes.remove(new Attributes.Name("Require-Bundle"));
+ attributes.putValue("DynamicImport-Package", "*");
+
+ // Existing export statements in bundles may contain versions, so they should be used as is
+ // SDO exports are not sufficient, and should be changed
+ if (attributes.getValue("Export-Package") == null || bundleName.startsWith("org.apache.tuscany.sdo.tuscany-sdo-impl")) {
+
+ HashSet<String> packages = getPackagesInJar(bundleName, jar);
+ String version = getJarVersion(bundleName);
+
+ attributes.putValue("Export-Package", packagesToString(packages, version));
+ attributes.putValue("Import-Package", packagesToString(packages, null));
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ manifest.write(out);
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+ out.close();
+
+ return in;
+
+ }
private void findJars(BundleContext bundleContext,
HashSet<File> tuscanyJars,
@@ -222,10 +402,10 @@ public class InstallerBundleActivator implements BundleActivator {
tuscanyJars.add(jar);
}
}
-
-
}
+
+
private File findTuscanyInstallDir(Bundle installerBundle)
throws IOException
{
diff --git a/java/sca/itest/osgi-tuscany/tuscany-versioned/pom.xml b/java/sca/itest/osgi-tuscany/tuscany-versioned/pom.xml
new file mode 100644
index 0000000000..2a0ff0dcc8
--- /dev/null
+++ b/java/sca/itest/osgi-tuscany/tuscany-versioned/pom.xml
@@ -0,0 +1,644 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-itest</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../../pom.xml</relativePath>
+ </parent>
+ <artifactId>itest-osgi-tuscany-versioned</artifactId>
+ <name>Apache Tuscany OSGi - Versioned Tuscany Bundles</name>
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ <tuscany.version>${pom.version}</tuscany.version>
+
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-monitor-logging</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-dwr</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-ejb-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-atom</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-atom-abdera</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+-->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-feed</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-rss</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-rss-rome</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-http-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-jms-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>apache-activemq</artifactId>
+ <version>4.1.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-fileupload</groupId>
+ <artifactId>commons-fileupload</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-console</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-optional</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-web</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-web-demo</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-jaas</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-jacc_1.0_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jms_1.1_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jsp_2.0_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-j2ee-management_1.0_spec</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>servlet-api-2.5</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>backport-util-concurrent</groupId>
+ <artifactId>backport-util-concurrent</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>activesoap</groupId>
+ <artifactId>jaxp-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>activemq</groupId>
+ <artifactId>jmdns</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>jrms</groupId>
+ <artifactId>jrms</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xerces</groupId>
+ <artifactId>xmlParserAPIs</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xstream</groupId>
+ <artifactId>xstream</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>xmlpull</groupId>
+ <artifactId>xmlpull</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>mx4j</groupId>
+ <artifactId>mx4j-remote</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-notification</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-rmi</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-sca-axis2</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-ws</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-ws-axis2</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-binding-ws-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-contribution-groovy</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-contribution-java</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-contribution-namespace</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-axiom</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-fastinfoset</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-sdo</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-sdo-axiom</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-xmlbeans</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-databinding-xstream</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-embedded</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-http</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-rmi</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-webapp</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-jetty</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-interface</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-interface-java-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-interface-wsdl</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-interface-wsdl-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-bpel</artifactId>
+ <version>${pom.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+-->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-das</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-ejb</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-ejb</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-java</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-java-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-node</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-node-runtime</artifactId>
+ <version>${pom.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-osgi</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-resource-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-script</artifactId>
+ <version>${pom.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all-minimal</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-spring</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-xquery</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-implementation-widget-runtime</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-node2-api</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-node2-impl</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-node2-launcher</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-policy-logging</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-policy-security</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-workspace</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-domain-manager</artifactId>
+ <version>${pom.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-host-tomcat</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-workspace-impl</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-workspace-xml</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-java2wsdl</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-wsdl2java</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+-->
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-impl</artifactId>
+ <version>1.1-incubating</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sdo</groupId>
+ <artifactId>tuscany-sdo-tools</artifactId>
+ <version>1.1-incubating</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.1.6</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-maven-bundle-plugin</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
+ </plugins>
+ </build>
+
+</project>
diff --git a/java/sca/modules/sca-api/pom.xml b/java/sca/modules/sca-api/pom.xml
index f345c6aa5c..54e43ce91c 100644
--- a/java/sca/modules/sca-api/pom.xml
+++ b/java/sca/modules/sca-api/pom.xml
@@ -40,7 +40,7 @@
<configuration>
<instructions>
- <Bundle-Version>2.0</Bundle-Version>
+ <Bundle-Version>1.4</Bundle-Version>
<Bundle-SymbolicName>org.apache.tuscany.sca.api</Bundle-SymbolicName>
<Bundle-Description>${pom.description}</Bundle-Description>
<Export-Package>org.osoa.sca*</Export-Package>
diff --git a/java/sca/tools/maven/maven-tuscany-bundle-plugin/pom.xml b/java/sca/tools/maven/maven-tuscany-bundle-plugin/pom.xml
new file mode 100644
index 0000000000..b7eec4f2aa
--- /dev/null
+++ b/java/sca/tools/maven/maven-tuscany-bundle-plugin/pom.xml
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-maven-tools</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-maven-bundle-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>Apache Tuscany SCA Maven OSGi Bundle Plugin</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-settings</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-model</artifactId>
+ <version>2.0.7</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-dependency-tree</artifactId>
+ <version>1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.1</version>
+ </dependency>
+
+
+ </dependencies>
+</project>
diff --git a/java/sca/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java b/java/sca/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java
new file mode 100644
index 0000000000..64f99a38d3
--- /dev/null
+++ b/java/sca/tools/maven/maven-tuscany-bundle-plugin/src/main/java/org/apache/tuscany/tools/sca/tuscany/bundle/plugin/TuscanyBundlePluginMojo.java
@@ -0,0 +1,492 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.tools.sca.tuscany.bundle.plugin;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Attributes;
+import java.util.jar.JarInputStream;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.ZipEntry;
+
+import org.apache.felix.bundleplugin.BundleAllPlugin;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactCollector;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
+import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.shared.dependency.tree.DependencyTree;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder;
+import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException;
+import org.apache.maven.shared.osgi.Maven2OsgiConverter;
+import org.osgi.framework.Version;
+
+import aQute.lib.header.OSGiHeader;
+
+/**
+ * @version $$
+ * @goal execute
+ * @phase compile
+ * @requiresDependencyResolution test
+ * @description Generate versioned OSGi bundles corresponding to Tuscany modules and all 3rd party dependencies
+ */
+public class TuscanyBundlePluginMojo extends BundleAllPlugin {
+ /**
+ * The maven project
+ *
+ * @parameter expression="${project}"
+ * @required
+ */
+ private MavenProject project;
+
+ /**
+ * Directory containing pom.
+ *
+ * @parameter expression="${basedir}"
+ * @required
+ */
+ private File baseDir;
+
+ /**
+ * Build directory for project
+ *
+ * @parameter expression="${project.build.directory}"
+ * @required
+ */
+ private String buildDirectory;
+
+ /**
+ * Output directory where bundles are generated.
+ *
+ * @parameter expression="${project.build.outputDirectory}"
+ * @required
+ */
+ private File outputDirectory;
+
+ /**
+ * Artifact resolver
+ *
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * Artifact factory
+ *
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * @component
+ */
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ /**
+ * Dependency tree builder
+ *
+ * @component
+ */
+ private DependencyTreeBuilder dependencyTreeBuilder;
+
+ /**
+ * @component
+ */
+ private ArtifactCollector collector;
+
+ /**
+ * @component
+ */
+ private MavenProjectBuilder mavenProjectBuilder;
+
+ /**
+ * The local repository
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ */
+ private ArtifactRepository localRepository;
+
+ /**
+ * The remote repositories
+ *
+ * @parameter expression="${project.remoteArtifactRepositories}"
+ */
+ private List remoteRepositories;
+
+ /**
+ * @component
+ */
+ private Maven2OsgiConverter maven2OsgiConverter;
+
+ private static final HashSet<String> dependenciesToIgnore = new HashSet<String>();
+ private static final HashSet<String> importDirectives = new HashSet<String>();
+ private static final HashSet<String> exportDirectives = new HashSet<String>();
+ private static final Hashtable<String, String> privatePackages = new Hashtable<String, String>();
+ private static final Hashtable<String, String> dynamicImports = new Hashtable<String, String>();
+
+ static {
+ importDirectives.add("resolution");
+
+ exportDirectives.add("uses");
+ exportDirectives.add("mandatory");
+ exportDirectives.add("include");
+ exportDirectives.add("exclude");
+
+ dependenciesToIgnore.add("xml-apis:xml-apis");
+ dependenciesToIgnore.add("stax:stax-api");
+
+
+ // Comma separated list of packages
+ privatePackages.put("org.apache.woden:woden", "javax.xml.namespace");
+ privatePackages.put("org.apache.xmlbeans:xmlbeans", "org.w3c.dom");
+ privatePackages.put("org.apache.axis2:axis2-adb", "org.apache.axis2.util");
+ privatePackages.put("org.apache.axis2:addressing", "org.apache.axis2.addressing");
+ privatePackages.put("org.apache.axis2:axis2-kernel", "org.apache.axis2.wsdl");
+ privatePackages.put("org.apache.bsf:bsf-all", "org.mozilla.javascript");
+ privatePackages.put("org.apache.axis2:axis2-codegen", "org.apache.axis2.wsdl,org.apache.axis2.wsdl.util");
+
+ dynamicImports.put("org.apache.ws.commons.axiom:axiom-api", "org.apache.axiom.om.impl.*,org.apache.axiom.soap.impl.*");
+ dynamicImports.put("org.apache.bsf:bsf-all", "org.mozilla.*");
+ dynamicImports.put("org.apache.santuario:xmlsec", "org.apache.ws.security.*");
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public void execute() throws MojoExecutionException {
+ try {
+
+ setBasedir(baseDir);
+ setBuildDirectory(buildDirectory);
+ setOutputDirectory(outputDirectory);
+ setMaven2OsgiConverter(maven2OsgiConverter);
+ try {
+ Field importField = this.getClass().getSuperclass().getDeclaredField("wrapImportPackage");
+ importField.setAccessible(true);
+ importField.set(this, "*;resolution:=optional");
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ getLog().error("Could not set import instructions");
+ }
+
+
+ DependencyTree dependencyTree = dependencyTreeBuilder.buildDependencyTree(project,
+ localRepository, artifactFactory,
+ artifactMetadataSource, collector );
+
+ Hashtable<String, String> duplicateWarnings = new Hashtable<String, String>();
+ Hashtable<String, Artifact> artifactsToBundle = new Hashtable<String, Artifact>();
+
+ for (Object a : dependencyTree.getArtifacts()) {
+ Artifact artifact = (Artifact)a;
+
+ if (project.getArtifactId().equals(artifact.getArtifactId()) && project.getGroupId().equals(artifact.getGroupId()))
+ continue;
+
+ if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())||Artifact.SCOPE_TEST.equals(artifact.getScope()))
+ continue;
+
+ String id = artifact.getGroupId() + ":" + artifact.getArtifactId();
+ if (dependenciesToIgnore.contains(id))
+ continue;
+
+ Artifact old = artifactsToBundle.get(id);
+ if (old != null && !old.getVersion().equals(artifact.getVersion())) {
+ String oldVersion = old.getVersion();
+ String thisVersion = artifact.getVersion();
+ if (!thisVersion.equals(duplicateWarnings.get(oldVersion))&&!oldVersion.equals(duplicateWarnings.get(thisVersion))) {
+ getLog().warn("Multiple versions of artifacts : " + old + ", " + artifact);
+ duplicateWarnings.put(oldVersion, thisVersion);
+ }
+
+ }
+
+ VersionRange versionRange = artifact.getVersionRange();
+ if (versionRange == null)
+ versionRange = VersionRange.createFromVersion(artifact.getVersion());
+
+ Artifact dependencyArtifact = artifactFactory.createDependencyArtifact(artifact.getGroupId(),
+ artifact.getArtifactId(),
+ versionRange,
+ artifact.getType(),
+ artifact.getClassifier(),
+ artifact.getScope());
+
+ try {
+ if (old != null && old.getSelectedVersion().compareTo(artifact.getSelectedVersion()) >= 0)
+ continue;
+ else
+ artifactsToBundle.remove(id);
+ } catch (OverConstrainedVersionException e1) {
+ getLog().warn("Could not process maven version for artifact " + artifact);
+ continue;
+ }
+
+ try {
+ artifactResolver.resolve(dependencyArtifact, remoteRepositories, localRepository);
+ } catch (ArtifactResolutionException e) {
+ getLog().warn("Artifact " + artifact + " could not be resolved.");
+ } catch (ArtifactNotFoundException e) {
+ getLog().warn("Artifact " + artifact + " could not be found.");
+ }
+
+ artifact.setFile(dependencyArtifact.getFile());
+
+ artifactsToBundle.put(id, artifact);
+
+ }
+
+ bundleArtifacts(artifactsToBundle.values());
+
+
+ } catch (DependencyTreeBuilderException e) {
+ throw new MojoExecutionException("Could not build dependency tree", e);
+ } catch (ProjectBuildingException e) {
+ throw new MojoExecutionException("Could not build project for artifact", e);
+ } catch (InvalidDependencyVersionException e) {
+ throw new MojoExecutionException("Invalid dependency version", e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Could not build bundle manifest", e);
+ }
+ }
+
+
+ private void bundleArtifacts(Collection<Artifact> artifacts) throws ProjectBuildingException,
+ InvalidDependencyVersionException, MojoExecutionException, IOException {
+
+ for (Artifact artifact : artifacts) {
+
+ artifact.setFile(getFile( artifact ));
+
+ MavenProject bundleProject = mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
+ bundleProject.setArtifact(artifact);
+
+ if ( bundleProject.getDependencyArtifacts() == null ) {
+ bundleProject.setDependencyArtifacts(bundleProject.createArtifacts(artifactFactory, null, null ) );
+ }
+
+ File outputFile = getOutputFile(bundleProject.getArtifact());
+ if (outputFile.exists())
+ outputFile.delete();
+ bundle(bundleProject);
+ postProcessBundle(artifact, outputFile);
+
+ }
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void postProcessBundle(Artifact artifact, File bundleFile) throws IOException {
+
+ if (!bundleFile.exists())
+ return;
+
+ boolean retainManifestEntries = false;
+ if (!artifact.getGroupId().equals("org.apache.tuscany.sca")) {
+ // For pre-bundled 3rd party bundles, retain all OSGi manifest entries except Require-Bundle
+ Manifest manifest = getManifest(artifact.getFile());
+ if (manifest != null && manifest.getMainAttributes() != null &&
+ manifest.getMainAttributes().getValue("Bundle-SymbolicName") != null) {
+ retainManifestEntries = true;
+ }
+ }
+
+ Manifest manifest = getManifest(bundleFile);
+ Attributes attributes = manifest.getMainAttributes();
+
+ if (attributes == null) {
+ return;
+ }
+
+ String artifactId = artifact.getGroupId() + ":" + artifact.getArtifactId();
+
+ String bundleSymName = (String)attributes.getValue("Bundle-SymbolicName");
+ if (!bundleSymName.startsWith("org.apache.tuscany.sca")) {
+ bundleSymName = "org.apache.tuscany.sca.3rdparty." + bundleSymName;
+ attributes.putValue("Bundle-SymbolicName", bundleSymName);
+ }
+
+ String imports = (String)attributes.getValue("Import-Package");
+ String exports = (String)attributes.getValue("Export-Package");
+
+ // For EMF jars
+ if (attributes.getValue("Require-Bundle") != null) {
+ attributes.remove(new Attributes.Name("Require-Bundle"));
+ attributes.putValue("DynamicImport-Package", "*");
+ attributes.remove(new Attributes.Name("Eclipse-LazyStart"));
+ }
+
+ if (!retainManifestEntries && imports != null) {
+ StringBuilder newImportBuf = new StringBuilder();
+ Map importMap = OSGiHeader.parseHeader(imports);
+ for (Object pkg : importMap.keySet()) {
+
+ if (isPrivatePackage(artifactId, (String)pkg)) {
+ continue;
+ }
+
+ Map importAttr = (Map)importMap.get(pkg);
+ String version = (String)importAttr.get("version");
+ if (version != null && version.indexOf(',') == -1) {
+ if (!version.matches(".*\\..*\\.")) {
+ Version curVersion = new Version(version);
+ Version nextVersion = new Version(curVersion.getMajor(), curVersion.getMinor()+1, 0);
+ version = '[' + version + ',' + nextVersion + ')';
+ }
+ else
+ version = '[' + version + ',' + version + ']';
+ importAttr.put("version", version);
+ }
+ updateManifestAttribute((String)pkg, importAttr, importDirectives, newImportBuf);
+
+ }
+ attributes.putValue("Import-Package", newImportBuf.toString());
+ }
+
+ if (!retainManifestEntries && exports != null) {
+ StringBuilder newExportBuf = new StringBuilder();
+ Map exportMap = OSGiHeader.parseHeader(exports);
+
+ for (Object value : exportMap.keySet()) {
+ String pkg = (String)value;
+ if (!isPrivatePackage(artifactId, pkg)) {
+ Map exportAttr = (Map)exportMap.get(pkg);
+ updateManifestAttribute((String)pkg, exportAttr, exportDirectives, newExportBuf);
+ }
+ }
+ if (newExportBuf.length() > 0)
+ attributes.putValue("Export-Package", newExportBuf.toString());
+ else
+ attributes.remove(new Attributes.Name("Export-Package"));
+ }
+
+ String dynImport = dynamicImports.get(artifactId);
+ if (dynImport != null)
+ attributes.putValue("DynamicImport-Package", dynImport);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ JarOutputStream jarOut = new JarOutputStream(out, manifest);
+ copyJar(bundleFile, jarOut);
+ jarOut.close();
+ out.close();
+ bundleFile.delete();
+ FileOutputStream fileOut = new FileOutputStream(bundleFile);
+ fileOut.write(out.toByteArray());
+ fileOut.close();
+
+ }
+
+
+ private void copyJar(File file, JarOutputStream jarOut) throws IOException {
+
+ try {
+ JarInputStream jarIn = new JarInputStream(new FileInputStream(file));
+ ZipEntry ze;
+ byte[] readBuf = new byte[1000];
+ int bytesRead;
+ while ((ze = jarIn.getNextEntry()) != null) {
+ if (ze.getName().equals("META-INF/MANIFEST.MF"))
+ continue;
+ jarOut.putNextEntry(ze);
+ while ((bytesRead = jarIn.read(readBuf)) > 0) {
+ jarOut.write(readBuf, 0, bytesRead);
+ }
+ }
+ jarIn.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private Manifest getManifest(File jar) {
+ try {
+ JarInputStream jarIn = new JarInputStream(new FileInputStream(jar));
+ Manifest manifest = jarIn.getManifest();
+ if (manifest == null) {
+ ZipEntry ze;
+ while ((ze = jarIn.getNextEntry()) != null) {
+ if (ze.getName().equals("META-INF/MANIFEST.MF"))
+ break;
+ }
+ if (ze != null) {
+ byte[] bytes = new byte[(int)ze.getSize()];
+ jarIn.read(bytes);
+ manifest = new Manifest(new ByteArrayInputStream(bytes));
+ }
+ }
+ jarIn.close();
+ return manifest;
+ } catch (IOException e) {
+ return null;
+ }
+ }
+
+ private boolean isPrivatePackage(String artifactId, String pkg) {
+ String privatePkgs = privatePackages.get(artifactId);
+ if (privatePkgs != null) {
+ String[] pkgs = privatePkgs.split(",");
+ for (int i = 0; i < pkgs.length; i++) {
+ if (pkgs[i].trim().equals(pkg))
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ private void updateManifestAttribute(String pkg, Map newMap, Set<String> directives, StringBuilder newAttrBuffer) {
+ if (newAttrBuffer.length() != 0) newAttrBuffer.append(',');
+ newAttrBuffer.append(pkg);
+ if (newMap.size() > 0) {
+ for (Object attrName : newMap.keySet()) {
+ newAttrBuffer.append(';');
+ newAttrBuffer.append(attrName);
+ if (directives.contains(attrName))
+ newAttrBuffer.append(":=");
+ else
+ newAttrBuffer.append('=');
+ newAttrBuffer.append('\"');
+ newAttrBuffer.append(newMap.get(attrName));
+ newAttrBuffer.append('\"');
+ }
+ }
+ }
+} \ No newline at end of file