[jboss-osgi-commits] JBoss-OSGI SVN: r98040 - in projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework: deployers and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Sun Dec 20 03:39:03 EST 2009


Author: thomas.diesler at jboss.com
Date: 2009-12-20 03:39:02 -0500 (Sun, 20 Dec 2009)
New Revision: 98040

Modified:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java
Log:
Copy the native library to the bundle storage area

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2009-12-20 03:56:40 UTC (rev 98039)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2009-12-20 08:39:02 UTC (rev 98040)
@@ -23,8 +23,7 @@
 
 // $Id$
 
-import java.net.URL;
-import java.util.Collections;
+import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -47,7 +46,7 @@
  */
 public class OSGiClassLoaderPolicy extends VFSClassLoaderPolicy
 {
-   private Map<String, URL> libraryMap = new HashMap<String, URL>();
+   private Map<String, File> libraryMap = new HashMap<String, File>();
    
    public OSGiClassLoaderPolicy(OSGiBundleState bundleState, VirtualFile[] roots)
    {
@@ -74,24 +73,19 @@
       setDelegates(vfsModule.getDelegates());
    }
 
-   public Map<String, URL> getLibraryMapppings()
+   public void addLibraryMapping(String libname, File libfile)
    {
-      return Collections.unmodifiableMap(libraryMap);
+      libraryMap.put(libname, libfile);
    }
 
-   public void addLibraryMapping(String libname, URL liburl)
-   {
-      libraryMap.put(libname, liburl);
-   }
-
    public String findLibrary(String libname)
    {
-      URL liburl = libraryMap.get(libname);
+      File libfile = libraryMap.get(libname);
       
       // [TODO] why does the TCK use 'Native' to mean 'libNative' ? 
-      if (liburl == null)
-         liburl = libraryMap.get("lib" + libname);
+      if (libfile == null)
+         libfile = libraryMap.get("lib" + libname);
          
-      return (liburl != null ? liburl.toExternalForm() : null);
+      return (libfile != null ? libfile.getAbsolutePath() : null);
    }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java	2009-12-20 03:56:40 UTC (rev 98039)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java	2009-12-20 08:39:02 UTC (rev 98040)
@@ -24,6 +24,8 @@
 // $Id: $
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -43,6 +45,9 @@
 import org.jboss.osgi.framework.metadata.OSGiMetaData;
 import org.jboss.osgi.framework.metadata.Parameter;
 import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
 import org.osgi.framework.Constants;
 
 /**
@@ -201,11 +206,27 @@
          throw new DeploymentException("Cannot find native library: " + nativeLib);
 
       // Get the library name key
-      String libname = new File(nativeLib).getName();
-      libname = libname.substring(0, libname.lastIndexOf('.'));
+      String libfile = new File(nativeLib).getName();
+      String libname = libfile.substring(0, libfile.lastIndexOf('.'));
       
+      // Copy the native library to the bundle storage area
+      File nativeFileCopy;
+      try
+      {
+         VirtualFile nativeVirtualFile = bundleState.getRoot().getChild(nativeLib);
+         BundleStoragePlugin plugin = bundleManager.getPlugin(BundleStoragePlugin.class);
+         nativeFileCopy = plugin.getDataFile(bundleState, nativeLib);
+         FileOutputStream fos = new FileOutputStream(nativeFileCopy);
+         VFSUtils.copyStream(nativeVirtualFile.openStream(), fos);
+         fos.close();
+      }
+      catch (IOException ex)
+      {
+         throw new DeploymentException("Cannot copy native library: " + nativeLib, ex);
+      }
+      
       // Add the native library mapping to the OSGiClassLoaderPolicy
       OSGiClassLoaderPolicy policy = (OSGiClassLoaderPolicy)unit.getAttachment(ClassLoaderPolicy.class);
-      policy.addLibraryMapping(libname, entryURL);
+      policy.addLibraryMapping(libname, nativeFileCopy);
    }
 }



More information about the jboss-osgi-commits mailing list