You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rs...@apache.org on 2008/06/01 22:03:40 UTC

svn commit: r662277 - /incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java

Author: rsivaram
Date: Sun Jun  1 13:03:39 2008
New Revision: 662277

URL: http://svn.apache.org/viewvc?rev=662277&view=rev
Log:
itest/osgi-tuscany - Dump virtual bundles to disk to experiment with versioning

Modified:
    incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java

Modified: incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java?rev=662277&r1=662276&r2=662277&view=diff
==============================================================================
--- incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java (original)
+++ incubator/tuscany/java/sca/itest/osgi-tuscany/tuscany-osgi-installer/src/main/java/org/apache/tuscany/sca/installer/InstallerBundleActivator.java Sun Jun  1 13:03:39 2008
@@ -4,9 +4,11 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.security.CodeSource;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -94,6 +96,7 @@
             HashSet<File> thirdPartyJars = new HashSet<File>();
             
             findJars(bundleContext, tuscanyJars, thirdPartyJars, thirdPartyJarsWithManifests);
+            File tuscanyInstallDir = findTuscanyInstallDir(bundleContext.getBundle());
             
             for (File bundleFile : thirdPartyJarsWithManifests.keySet()) {
                                 
@@ -102,7 +105,11 @@
                 HashSet<File> jarSet = new HashSet<File>();
                 jarSet.add(bundleFile);
                 
-                createAndInstallBundle(bundleContext, bundleLocation, bundleManifestStream, jarSet);
+                File realBundleFile = new File(tuscanyInstallDir, "org.apache.tuscany.sca."+bundleFile.getName());
+                if (realBundleFile.exists()) 
+                    bundleContext.installBundle(realBundleFile.toURI().toURL().toString());
+                else                
+                    createAndInstallBundle(bundleContext, bundleLocation, realBundleFile, bundleManifestStream, jarSet);
                 bundleManifestStream.close();
                 
             }
@@ -122,8 +129,12 @@
                 InputStream bundleManifestStream = createBundleManifest(bundleFile, bundleSymbolicName);
                 HashSet<File> jarSet = new HashSet<File>();
                 jarSet.add(bundleFile);
-                
-                createAndInstallBundle(bundleContext, bundleLocation, bundleManifestStream, jarSet);
+
+                File realBundleFile = new File(tuscanyInstallDir, "org.apache.tuscany.sca."+bundleFile.getName());
+                if (realBundleFile.exists()) 
+                    bundleContext.installBundle(realBundleFile.toURI().toURL().toString());
+                else 
+                    createAndInstallBundle(bundleContext, bundleLocation, realBundleFile, bundleManifestStream, jarSet);
                 bundleManifestStream.close();
                
             }
@@ -203,33 +214,44 @@
     private File findTuscanyInstallDir(Bundle installerBundle) 
     throws IOException
     {
-        
-        File tuscanyInstallDir = null;
-        String location = installerBundle.getLocation();
-        
         String tuscanyDirName;
         if ((tuscanyDirName = System.getenv("TUSCANY_HOME")) != null) {
-            tuscanyInstallDir = new File(tuscanyDirName);
-            if (!tuscanyInstallDir.exists() || !tuscanyInstallDir.isDirectory())
-                tuscanyInstallDir = null;
-        }
-        if (tuscanyInstallDir == null && System.getProperty("TUSCANY_HOME") != null) {
-            tuscanyInstallDir = new File(tuscanyDirName);
-            if (!tuscanyInstallDir.exists() || !tuscanyInstallDir.isDirectory())
-                tuscanyInstallDir = null;
+            File tuscanyInstallDir = new File(tuscanyDirName);
+            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
+                return tuscanyInstallDir;
+        }
+        if ((tuscanyDirName = System.getProperty("TUSCANY_HOME")) != null) {
+            File tuscanyInstallDir = new File(tuscanyDirName);
+            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
+                return tuscanyInstallDir;
         }
-            
-        if (tuscanyInstallDir == null && location != null && location.startsWith("file:") && location.endsWith(TUSCANY_INSTALLER_JAR)) {
+         
+        String location = installerBundle.getLocation();
+        
+        if (location != null && location.startsWith("file:") && location.endsWith(TUSCANY_INSTALLER_JAR)) {
             tuscanyDirName = location.substring(5, location.length()-TUSCANY_INSTALLER_JAR.length()); // strip "file:" and installer jar name
-            tuscanyInstallDir = new File(tuscanyDirName);
-            if (!tuscanyInstallDir.exists() || !tuscanyInstallDir.isDirectory())
-                tuscanyInstallDir = null;
+            File tuscanyInstallDir = new File(tuscanyDirName);
+            if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
+                return tuscanyInstallDir;
+        }
+        if (this.getClass().getProtectionDomain() != null) {
+            CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource();
+            if (codeSource != null) {
+                try {
+                    File tuscanyInstallDir = new File(codeSource.getLocation().toURI());
+                    if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory())
+                        return tuscanyInstallDir;
+                } catch (Exception e) {
+                    // ignore
+                }                     
+            }
         }
-        return tuscanyInstallDir;
+        return null;
     }
     
     public Bundle createAndInstallBundle(BundleContext bundleContext, 
             String bundleLocation, 
+            File bundleFile,
             InputStream manifestStream,
             final HashSet<File> thirdPartyJars) throws Exception {
 
@@ -261,9 +283,19 @@
 
         jarOut.close();
         out.close();
-        
-        ByteArrayInputStream inStream = new ByteArrayInputStream(out.toByteArray());
-        return bundleContext.installBundle(bundleLocation, inStream);
+
+        Bundle bundle;
+        if (System.getenv("TUSCANY_OSGI_DEBUG") != null) {
+            FileOutputStream fileOut = new FileOutputStream(bundleFile);
+            fileOut.write(out.toByteArray());
+            bundle = bundleContext.installBundle(bundleFile.toURL().toString());
+            
+        } else {
+            ByteArrayInputStream inStream = new ByteArrayInputStream(out.toByteArray());
+            bundle = bundleContext.installBundle(bundleLocation, inStream);
+            inStream.close();
+        }
+        return bundle;
 
     }