tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rsiva...@apache.org
Subject svn commit: r656026 - in /incubator/tuscany/java/sca: itest/osgi-tuscany/ itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/ itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/ ...
Date Tue, 13 May 2008 22:01:19 GMT
Author: rsivaram
Date: Tue May 13 15:01:18 2008
New Revision: 656026

URL: http://svn.apache.org/viewvc?rev=656026&view=rev
Log:
Install individual virtual bundles for 3rd party jars

Modified:
    incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/TuscanyLoader.java
    incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
    incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/OSGiSupplyChainTestCase.java
    incubator/tuscany/java/sca/itest/osgi-tuscany/pom.xml
    incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/pom.xml
    incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
    incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/TuscanyLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/TuscanyLoader.java?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/TuscanyLoader.java
(original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/main/java/org/apache/tuscany/sca/test/util/TuscanyLoader.java
Tue May 13 15:01:18 2008
@@ -59,6 +59,8 @@
     
     private static final HashSet<String> ignoreTuscanyModules = new HashSet<String>();
     
+    private static String manifestClassPath = null;
+    
     static {
         for (String ignoreModule : tuscanyModulesToIgnore) {
             ignoreTuscanyModules.add(ignoreModule);
@@ -119,6 +121,8 @@
         String tuscanyManifestBundleName = new File(tuscanyManifestDir + "/target/" + tuscanyManifestJar).toURI().toURL().toString();
         Bundle tuscanyManifestBundle = bundleContext.installBundle(tuscanyManifestBundleName);
       
         tuscanyManifestBundle.start();
+        
+        manifestClassPath = (String)tuscanyManifestBundle.getHeaders().get("Class-Path");
     }
     
     
@@ -146,6 +150,8 @@
                 for (File file : files) {
                     if (ignoreTuscanyModules.contains(file.getName()))
                         continue;
+                    if (manifestClassPath != null && manifestClassPath.indexOf(file.getName())
< 0)
+                        continue;
                     String bundleURL = findBundle(file.toString(), "tuscany");
                     if (bundleURL != null) {
                         Bundle bundle = bundleContext.installBundle(bundleURL);

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
(original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/harness/OSGiTuscanyTestHarness.java
Tue May 13 15:01:18 2008
@@ -81,6 +81,9 @@
         OSGiRuntimeLoader.shutdownOSGiRuntime();
     }
     
+    public BundleContext getBundleContext() {
+        return bundleContext;
+    }
    
     public void runTest(String... testDirs) throws Exception {
         

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/OSGiSupplyChainTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/OSGiSupplyChainTestCase.java?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/OSGiSupplyChainTestCase.java
(original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/osgi-tuscany-test/src/test/java/org/apache/tuscany/sca/test/osgi/tuscany/OSGiSupplyChainTestCase.java
Tue May 13 15:01:18 2008
@@ -23,6 +23,8 @@
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 /*
  * Test Tuscany running in an OSGi container
@@ -45,6 +47,14 @@
     @After
     public void tearDown() throws Exception {
 
+        BundleContext bundleContext = testHarness.getBundleContext();
+        if (bundleContext != null) {
+            Bundle[] bundles = bundleContext.getBundles();
+            for (Bundle bundle : bundles) {
+                if (bundle.getSymbolicName() != null && bundle.getSymbolicName().startsWith("supplychain"))
+                    bundle.uninstall();
+            }
+        }
         if (testHarness != null) {
             testHarness.tearDown();
         }

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/pom.xml?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/pom.xml (original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/pom.xml Tue May 13 15:01:18 2008
@@ -37,9 +37,11 @@
         <module>tuscany-runtime</module>
         <module>tuscany-extensions</module>
         <module>tuscany-3rdparty</module>
--->
+
 
         <module>tuscany-3rdparty-manifest</module>
+-->
+
         <module>tuscany-manifest</module>
 
 

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/pom.xml?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/pom.xml (original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/pom.xml Tue May 13 15:01:18
2008
@@ -473,6 +473,12 @@
             <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>

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
(original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-manifest/src/main/java/org/apache/tuscany/sca/manifest/ManifestBundleActivator.java
Tue May 13 15:01:18 2008
@@ -10,6 +10,8 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
+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;
@@ -48,28 +50,48 @@
     private void install3rdPartyJarsIntoOSGi(BundleContext bundleContext) {
     
         try {
-            HashMap<String, InputStream> separateBundles = new HashMap<String, InputStream>();
-            HashSet<String> thirdPartyJars = new HashSet<String>();
-            
-            File tuscanyInstallDir = find3rdPartyJars(bundleContext, thirdPartyJars, separateBundles);
+            // FIXME: SDO bundles dont have the correct dependencies
+            System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl");
             
-            String thirdPartyBundleLocation = tuscanyInstallDir.toURI().toURL().toString()
+ "/tuscany-3rdparty.jar";
+            HashMap<String, InputStream> thirdPartyJarsWithManifests = new HashMap<String,
InputStream>();
+            HashSet<String> thirdPartyJars = new HashSet<String>();
             
-            InputStream manifestStream = this.getClass().getClassLoader().getResourceAsStream(TUSCANY_OSGI_MANIFEST_DIR
+ "/MANIFEST.MF");
+            File tuscanyInstallDir = find3rdPartyJars(bundleContext, thirdPartyJars, thirdPartyJarsWithManifests);
             
-            if (manifestStream != null) {
+//            Install 3rd party libs as a single virtual bundle            
+//            String thirdPartyBundleLocation = tuscanyInstallDir.toURI().toURL().toString()
+ "/tuscany-3rdparty.jar";
+//            
+//            InputStream manifestStream = this.getClass().getClassLoader().getResourceAsStream(TUSCANY_OSGI_MANIFEST_DIR
+ "/MANIFEST.MF");
+//            
+//            if (manifestStream != null) {
+//            
+//                createAndInstallBundle(bundleContext, thirdPartyBundleLocation, manifestStream,
tuscanyInstallDir, thirdPartyJars);
+//            }
             
-                createAndInstallBundle(bundleContext, thirdPartyBundleLocation, manifestStream,
tuscanyInstallDir, thirdPartyJars);
+            for (String bundleName : thirdPartyJarsWithManifests.keySet()) {
+                                
+                String bundleLocation = tuscanyInstallDir.toURI().toURL().toString() + "/"
+ bundleName;
+                InputStream bundleManifestStream = thirdPartyJarsWithManifests.get(bundleName);
+                HashSet<String> jarSet = new HashSet<String>();
+                jarSet.add(bundleName);
+                
+                createAndInstallBundle(bundleContext, bundleLocation, bundleManifestStream,
tuscanyInstallDir, jarSet);
+                bundleManifestStream.close();
+                
             }
             
-            for (String bundleName : separateBundles.keySet()) {
-                                
+            for (String bundleName : thirdPartyJars) {
+                
+                if (bundleName.startsWith("org.apache.felix"))
+                    continue;
+                
                 String bundleLocation = tuscanyInstallDir.toURI().toURL().toString() + "/"
+ bundleName;
-                InputStream bundleManifestStream = separateBundles.get(bundleName);
+                InputStream bundleManifestStream = createBundleManifest(tuscanyInstallDir,
bundleName);
                 HashSet<String> jarSet = new HashSet<String>();
-                jarSet.add(bundleLocation);
+                jarSet.add(bundleName);
                 
                 createAndInstallBundle(bundleContext, bundleLocation, bundleManifestStream,
tuscanyInstallDir, jarSet);
+                bundleManifestStream.close();
                 
             }
             
@@ -80,7 +102,7 @@
         
     private File find3rdPartyJars(BundleContext bundleContext, 
             HashSet<String> thirdPartyJars, 
-            HashMap<String, InputStream> individual3rdPartyBundles) 
+            HashMap<String, InputStream> thirdPartyBundleManifests) 
     throws IOException
     {
         
@@ -116,14 +138,15 @@
         String[] classPathEntries = classPath.split(" ");
         for (String classPathEntry : classPathEntries) {
             classPathEntry = classPathEntry.trim();
-            if (!classPathEntry.startsWith("tuscany") || classPathEntry.startsWith("tuscany-sdo"))
{
+            if (!classPathEntry.startsWith("tuscany") || classPathEntry.startsWith("tuscany-sdo")
|| classPathEntry.startsWith("tuscany-das")) {
                 if (classPathEntry.endsWith(".jar")) {
                     String manifestName = TUSCANY_OSGI_MANIFEST_DIR + "/" + classPathEntry.substring(0,
classPathEntry.length()-4) + ".mf";
                     InputStream manifestStream;
                     if ((manifestStream = this.getClass().getClassLoader().getResourceAsStream(manifestName))
!= null)
-                        individual3rdPartyBundles.put(classPathEntry, manifestStream);
+                        thirdPartyBundleManifests.put(classPathEntry, manifestStream);
+                    else
+                        thirdPartyJars.add(classPathEntry);
                 }
-                thirdPartyJars.add(classPathEntry);
             }
         }
         
@@ -190,5 +213,75 @@
             e.printStackTrace();
         }
     }
+    
+    private InputStream createBundleManifest(File tuscanyDir, String bundleName) throws Exception
{
+        File jarFile = new File(tuscanyDir.getPath() + File.separator + bundleName);
+        if (!jarFile.exists())
+            return null;
+        JarInputStream jar = new JarInputStream(new FileInputStream(jarFile));
+        Manifest manifest = jar.getManifest();
+        if (manifest == null)
+            manifest = new Manifest();
+        Attributes attributes = manifest.getMainAttributes();
+        if (attributes.getValue("Manifest-Version") == null) {
+            attributes.putValue("Manifest-Version", "1.0");
+        }
+        attributes.putValue("Bundle-ClassPath", bundleName);
+        
+        String packages = getPackagesInJar(bundleName, jar);
+
+        attributes.remove(new Attributes.Name("Require-Bundle"));
+        attributes.remove(new Attributes.Name("Import-Package"));
+        
+        if (attributes.getValue("Bundle-SymbolicName") == null)
+            attributes.putValue("Bundle-SymbolicName", bundleName);
+        if (attributes.getValue("Bundle-Version") == null)
+            attributes.putValue("Bundle-Version", "1.0.0");
+        // 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("tuscany-sdo-impl"))
{
+            attributes.putValue("Export-Package", packages);
+            attributes.putValue("Import-Package", packages);
+        }
+        
+        attributes.putValue("DynamicImport-Package", "*");       
+        
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        manifest.write(out);
+        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
+        out.close();
+               
+        return in;
+        
+    }
+    
+    private String getPackagesInJar(String bundleName, JarInputStream jar) throws Exception
{
+        HashSet<String> packages = new HashSet<String>();
+        ZipEntry entry;
+        while ((entry = jar.getNextEntry()) != null) {
+            String entryName = entry.getName();
+            if (!entry.isDirectory() && entryName != null && entryName.length()
> 0 && 
+                    !entryName.startsWith(".") && !entryName.startsWith("META-INF")
&&
+                    entryName.lastIndexOf("/") > 0) {
+                String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/',
'.');
+                packages.add(pkg);
+                
+            }
+        }
+        // FIXME: Split package
+        if (bundleName.startsWith("axis2-adb"))
+            packages.remove("org.apache.axis2.util");
+        if (bundleName.startsWith("axis2-codegen")) {
+            packages.remove("org.apache.axis2.wsdl");
+            packages.remove("org.apache.axis2.wsdl.util");
+        }
+        
+        StringBuilder pkgBuf = new StringBuilder();
+        for (String pkg : packages) {
+            if (pkgBuf.length() >0) pkgBuf.append(',');
+            pkgBuf.append(pkg);
+        }
+        return pkgBuf.toString();
+    }
 	
 }

Modified: incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java?rev=656026&r1=656025&r2=656026&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
(original)
+++ incubator/tuscany/java/sca/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiBundleActivator.java
Tue May 13 15:01:18 2008
@@ -131,7 +131,9 @@
                     }
                 }
 		    }
-		}
+		} else {
+            threadContextClassLoader.addBundle(bundle); 
+        }
 	}
 
 



Mime
View raw message