[jboss-osgi-commits] JBoss-OSGI SVN: r99732 - in projects: jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base and 4 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Jan 21 07:39:51 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-21 07:39:50 -0500 (Thu, 21 Jan 2010)
New Revision: 99732

Added:
   projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibrary.java
   projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibraryMetaData.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodePolicyDeployer.java
Removed:
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java
Modified:
   projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java
   projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
   projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java
   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/AbstractOSGiClassLoadingDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java
   projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
Log:
[JBCL-136] Add a notion of native library mapping

Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/ClassLoaderPolicy.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -21,6 +21,7 @@
  */
 package org.jboss.classloader.spi;
 
+import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
@@ -30,7 +31,9 @@
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.management.MalformedObjectNameException;
@@ -59,8 +62,106 @@
 
    /** The class found handlers */
    private List<ClassFoundHandler> classFoundHandlers;
+
+   /** Maps native library to its provider */
+   private Map<String, NativeLibraryProvider> libraryMap;
    
    /**
+    * Provides the actual local file location for a native library
+    */
+   public interface NativeLibraryProvider
+   {
+      /** Get the library path */
+      String getLibraryPath();
+      
+      /** Get the local library file location. This may be proved lazily. */
+      File getLibraryLocation() throws IOException;
+   }
+   
+   /**
+    * Get the set of registered native library names.
+    * 
+    * @return Null if there are no native libraries registered.
+    */
+   public Set<String> getNativeLibraryNames()
+   {
+      if (libraryMap == null)
+         return Collections.emptySet();
+      
+      return libraryMap.keySet(); 
+   }
+   
+   /**
+    * Get the native library provider for the given name.
+    * 
+    * @param libname The library name 
+    * @return Null if there is no library with that name.
+    */
+   public NativeLibraryProvider getNativeLibrary(String libname)
+   {
+      return (libraryMap != null ? libraryMap.get(libname) : null);
+   }
+   
+   /**
+    * Add a native library provider.
+    * @param libname The library name 
+    * @param provider The library file provider
+    */
+   public void addNativeLibrary(String libname, NativeLibraryProvider provider)
+   {
+      if (libraryMap == null)
+         libraryMap = new ConcurrentHashMap<String, NativeLibraryProvider>();
+      
+      libraryMap.put(libname, provider);
+   }
+   
+   /**
+    * Remove the native library provider for the given name.
+    * 
+    * @param libname The library name 
+    * @return Null if there is no library with that name.
+    */
+   public NativeLibraryProvider removeNativeLibrary(String libname)
+   {
+      return (libraryMap != null ? libraryMap.remove(libname) : null);
+   }
+   
+   /**
+    * Returns the absolute path name of a native library.
+    * 
+    * @see ClassLoader.findLibrary(String libname)
+    * @param libname The library name 
+    * @return The absolute path of the native library, or null
+    */
+   public String findLibrary(String libname)
+   {
+      if (libraryMap == null)
+         return null;
+      
+      NativeLibraryProvider libProvider = libraryMap.get(libname);
+      
+      // [TODO] why does the TCK use 'Native' to mean 'libNative' ? 
+      if (libProvider == null)
+         libProvider = libraryMap.get("lib" + libname);
+         
+      if (libProvider == null)
+         return null;
+      
+      File libfile;
+      try
+      {
+         libfile = libProvider.getLibraryLocation();
+      }
+      catch (IOException ex)
+      {
+         log.error("Cannot privide native library location for: " + libname, ex);
+         return null;
+      }
+      
+      return libfile.getAbsolutePath();
+   }
+   
+   /**
     * Get the delegate loader for exported stuff<p>
     *
     * By default this uses {@link #getPackageNames()} to create a {@link FilteredDelegateLoader}

Modified: projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java
===================================================================
--- projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-cl/trunk/classloader/src/main/java/org/jboss/classloader/spi/base/BaseClassLoader.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -374,6 +374,20 @@
       return domain.checkClassCacheAndBlackList(this, name, null, basePolicy.isImportAll(), false);
    }
 
+   @Override
+   protected String findLibrary(String libname)
+   {
+      String libraryPath = null;
+
+      if (policy != null)
+         libraryPath = policy.findLibrary(libname);
+
+      if (libraryPath == null)
+         libraryPath = super.findLibrary(libname);
+
+      return libraryPath;
+   }
+   
    /**
     * Find the classloader for a class but don't load the class
     *

Modified: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/ClassLoadingMetaData.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -22,6 +22,7 @@
 package org.jboss.classloading.spi.metadata;
 
 import java.util.List;
+
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlTransient;
 
@@ -45,7 +46,7 @@
 public class ClassLoadingMetaData extends NameAndVersionSupport
 {
    /** The serialVersionUID */
-   private static final long serialVersionUID = -2782951093046585620L;
+   private static final long serialVersionUID = 8525659521747922713L;
    
    /** The classloading domain */
    private String domain;
@@ -95,6 +96,9 @@
    /** The capabilities */
    private CapabilitiesMetaData capabilities = new CapabilitiesMetaData();
    
+   /** The native code libraries */
+   private NativeLibraryMetaData libraries = new NativeLibraryMetaData();
+   
    /**
     * Get the domain.
     * 
@@ -485,6 +489,29 @@
    }
 
    /**
+    * Get the native libraries.
+    * 
+    * @return the native libraries.
+    */
+   public NativeLibraryMetaData getNativeLibraries()
+   {
+      return libraries;
+   }
+
+   /**
+    * Set the native libraries.
+    * 
+    * @param native libraries the native libraries.
+    * @throws IllegalArgumentException for null native libraries
+    */
+   public void setNativeLibraries(NativeLibraryMetaData nativeLibraries)
+   {
+      if (nativeLibraries == null)
+         throw new IllegalArgumentException("Null libraries");
+      this.libraries = nativeLibraries;
+   }
+
+   /**
     * Set the requirements.
     * 
     * @param requirements the requirements.
@@ -540,6 +567,9 @@
       List<Requirement> requirements = getRequirements().getRequirements();
       if (requirements != null)
          builder.append(" requirements=").append(requirements);
+      List<NativeLibrary> libraries = getNativeLibraries().getNativeLibraries();
+      if (libraries != null)
+         builder.append(" libraries=").append(libraries);
    }
    
    @Override
@@ -570,6 +600,8 @@
          return false;
       if (equals(this.getRequirements().getRequirements(), other.getRequirements().getRequirements()) == false)
          return false;
+      if (equals(this.getNativeLibraries().getNativeLibraries(), other.getNativeLibraries().getNativeLibraries()) == false)
+         return false;
       return true;
    }
    
@@ -593,6 +625,7 @@
       ClassLoadingMetaData clone = (ClassLoadingMetaData) super.clone();
       requirements = clone.requirements.clone();
       capabilities = clone.capabilities.clone();
+      libraries = clone.libraries.clone();
       return clone;
    }
 }

Added: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibrary.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibrary.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibrary.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -0,0 +1,141 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.classloading.spi.metadata;
+
+// $Id$
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.classloading.spi.version.VersionRange;
+
+/**
+ * Meta data for native code libraries as defined by OSGi R4V42.  
+ * 
+ * 3.9 Loading Native Code Libraries
+ * http://www.osgi.org/Download/File?url=/download/r4v42/r4.core.pdf
+ * 
+ * @author thomas.diesler at jboss.com
+ * @version $Revision$
+ * @since 21-Jan-2010
+ */
+public class NativeLibrary implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 5059911178465658041L;
+
+   private List<String> osNames = new ArrayList<String>();
+   private String librarySource;
+   private String libraryPath;
+   private List<String> processors = new ArrayList<String>();
+   private List<VersionRange> osVersions = new ArrayList<VersionRange>();
+   private List<String> languages = new ArrayList<String>();
+   private String selectionFilter;
+   private boolean optional;
+
+   /**
+    * Create a NativeCode instance with mandatory properties.
+    * @param osNames The set of OS names 
+    * @param libraryPath The library path
+    * @param fileProvider An interface from which to retrieve the actual library location
+    */
+   public NativeLibrary(List<String> osNames, String libraryPath, String librarySource)
+   {
+      if (libraryPath == null)
+         throw new IllegalArgumentException("Null library path: " + libraryPath);
+      if (osNames == null || osNames.isEmpty())
+         throw new IllegalArgumentException("Illegal OS names: " + osNames);
+      if (librarySource == null)
+         throw new IllegalArgumentException("Null file privider: " + librarySource);
+
+      this.osNames = osNames;
+      this.libraryPath = libraryPath;
+      this.librarySource = librarySource;
+   }
+
+   public String getLibrarySource()
+   {
+      return librarySource;
+   }
+
+   public String getLibraryPath()
+   {
+      return libraryPath;
+   }
+
+   public List<String> getOsNames()
+   {
+      return Collections.unmodifiableList(osNames);
+   }
+
+   public List<VersionRange> getOsVersions()
+   {
+      return Collections.unmodifiableList(osVersions);
+   }
+
+   public void setOsVersions(List<VersionRange> osVersions)
+   {
+      this.osVersions = osVersions;
+   }
+
+   public List<String> getProcessors()
+   {
+      return Collections.unmodifiableList(processors);
+   }
+
+   public void setProcessors(List<String> processors)
+   {
+      this.processors = processors;
+   }
+
+   public void setLanguages(List<String> languages)
+   {
+      this.languages = languages;
+   }
+   
+   public List<String> getLanguages()
+   {
+      return Collections.unmodifiableList(languages);
+   }
+
+   public String getSelectionFilter()
+   {
+      return selectionFilter;
+   }
+
+   public void setSelectionFilter(String selectionFilter)
+   {
+      this.selectionFilter = selectionFilter;
+   }
+
+   public boolean isOptional()
+   {
+      return optional;
+   }
+
+   public void setOptional(boolean optional)
+   {
+      this.optional = optional;
+   }
+}


Property changes on: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibrary.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibraryMetaData.java
===================================================================
--- projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibraryMetaData.java	                        (rev 0)
+++ projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibraryMetaData.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -0,0 +1,100 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.classloading.spi.metadata;
+
+// $Id$
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+
+/**
+ * Meta data for native code libraries as defined by OSGi R4V42.  
+ * 
+ * 3.9 Loading Native Code Libraries
+ * http://www.osgi.org/Download/File?url=/download/r4v42/r4.core.pdf
+ * 
+ * @author thomas.diesler at jboss.com
+ * @version $Revision$
+ * @since 21-Jan-2010
+ */
+// [TODO] @XmlType(name="nativeLibraries", propOrder={"nativeLibraries"})
+public class NativeLibraryMetaData implements Serializable, Cloneable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 8341019167903636599L;
+   
+   /** The nativeLibraries */
+   private List<NativeLibrary> nativeLibraries;
+
+   public List<NativeLibrary> getNativeLibraries()
+   {
+      return nativeLibraries;
+   }
+
+   public void setNativeLibraries(List<NativeLibrary> nativeLibraries)
+   {
+      this.nativeLibraries = nativeLibraries;
+   }
+
+   public void addNativeLibrary(NativeLibrary nativeLibrary)
+   {
+      if (nativeLibrary == null)
+         throw new IllegalArgumentException("Null library");
+      
+      if (nativeLibraries == null)
+         nativeLibraries = new CopyOnWriteArrayList<NativeLibrary>();
+      
+      nativeLibraries.add(nativeLibrary);
+   }
+
+   public void removeNativeLibrary(NativeLibrary nativeLibrary)
+   {
+      if (nativeLibrary == null)
+         throw new IllegalArgumentException("Null library");
+      
+      if (nativeLibraries == null)
+         return;
+      
+      nativeLibraries.remove(nativeLibrary);
+   }
+
+   @Override
+   public NativeLibraryMetaData clone()
+   {
+      try
+      {
+         NativeLibraryMetaData clone = (NativeLibraryMetaData) super.clone();
+         if (nativeLibraries != null)
+         {
+            List<NativeLibrary> clonedNativeCodes = new CopyOnWriteArrayList<NativeLibrary>(nativeLibraries);
+            clone.setNativeLibraries(clonedNativeCodes);
+         }
+         return clone;
+      }
+      catch (CloneNotSupportedException e)
+      {
+         throw new RuntimeException("Unexpected", e);
+      }
+   }
+}


Property changes on: projects/jboss-cl/trunk/classloading/src/main/java/org/jboss/classloading/spi/metadata/NativeLibraryMetaData.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiBundleClassLoader.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -29,13 +29,12 @@
 /**
  * An OSGi bundle class loader.
  * 
- * This implementation supports the notion of OSGi Native Code Libraries.
- * 
  * @author Thomas.Diesler at jboss.com
  * @since 19-Dec-2009
  */
 public class OSGiBundleClassLoader extends BaseClassLoader
 {
+   @SuppressWarnings("unused")
    private OSGiClassLoaderPolicy osgiPolicy;
 
    public OSGiBundleClassLoader(ClassLoaderPolicy policy)
@@ -45,18 +44,4 @@
       if (policy instanceof OSGiClassLoaderPolicy)
          osgiPolicy = (OSGiClassLoaderPolicy)policy;
    }
-
-   @Override
-   protected String findLibrary(String libname)
-   {
-      String libraryPath = null;
-
-      if (osgiPolicy != null)
-         libraryPath = osgiPolicy.findLibrary(libname);
-
-      if (libraryPath == null)
-         libraryPath = super.findLibrary(libname);
-
-      return libraryPath;
-   }
 }

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	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/classloading/OSGiClassLoaderPolicy.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -23,10 +23,6 @@
 
 // $Id$
 
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
 import org.jboss.classloading.spi.dependency.Module;
 import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
 import org.jboss.deployers.vfs.plugins.classloader.VFSDeploymentClassLoaderPolicyModule;
@@ -37,17 +33,11 @@
 /**
  * The ClassLoaderPolicy for OSGi bundles.
  * 
- * This implementation supports the notion of OSGi Native Code Libraries.
- * 
  * @author Thomas.Diesler at jboss.com
  * @since 11-Sep-2209
  */
 public class OSGiClassLoaderPolicy extends VFSClassLoaderPolicy
 {
-   // Maps the lib name to native code archive
-   // https://jira.jboss.org/jira/browse/JBCL-136
-   private Map<String, File> libraryMap;
-   
    public OSGiClassLoaderPolicy(AbstractBundleState bundleState, VirtualFile[] roots)
    {
       super(roots);
@@ -75,26 +65,4 @@
          setDelegates(vfsModule.getDelegates());
       }
    }
-
-   public void addLibraryMapping(String libname, File libfile)
-   {
-      if (libraryMap == null)
-         libraryMap = new HashMap<String, File>();
-      
-      libraryMap.put(libname, libfile);
-   }
-
-   public String findLibrary(String libname)
-   {
-      if (libraryMap == null)
-         return null;
-      
-      File libfile = libraryMap.get(libname);
-      
-      // [TODO] why does the TCK use 'Native' to mean 'libNative' ? 
-      if (libfile == null)
-         libfile = libraryMap.get("lib" + libname);
-         
-      return (libfile != null ? libfile.getAbsolutePath() : null);
-   }
 }

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiClassLoadingDeployer.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -99,6 +99,7 @@
       OSGiBundleCapability bundleCapability = OSGiBundleCapability.create(bundleState);
       capabilities.addCapability(bundleCapability);
 
+      // Required Bundles
       List<ParameterizedAttribute> requireBundles = osgiMetaData.getRequireBundles();
       if (requireBundles != null && requireBundles.isEmpty() == false)
       {
@@ -109,6 +110,7 @@
          }
       }
 
+      // Export Packages
       List<PackageAttribute> exported = osgiMetaData.getExportPackages();
       if (exported != null && exported.isEmpty() == false)
       {
@@ -119,6 +121,7 @@
          }
       }
 
+      // Import Packages
       List<PackageAttribute> imported = osgiMetaData.getImportPackages();
       if (imported != null && imported.isEmpty() == false)
       {

Deleted: 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	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleNativeCodeDeployer.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -1,238 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.osgi.framework.deployers;
-
-// $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;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.classloading.OSGiClassLoaderPolicy;
-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;
-
-/**
- * A deployer that takes care of loading native code libraries.
- * 
- * @author Thomas.Diesler at jboss.com
- * @since 19-Dec-2009
- */
-public class OSGiBundleNativeCodeDeployer extends AbstractRealDeployer
-{
-   // Provide logging
-   private static final Logger log = Logger.getLogger(OSGiBundleNativeCodeDeployer.class);
-
-   /** Maps an alias to an OSGi processor name */
-   private static Map<String, String> processorAlias = new HashMap<String, String>();
-   static
-   {
-      processorAlias.put("pentium", "x86");
-      processorAlias.put("i386", "x86");
-      processorAlias.put("i486", "x86");
-      processorAlias.put("i586", "x86");
-      processorAlias.put("i686", "x86");
-      processorAlias.put("amd64", "x86-64");
-      processorAlias.put("em64t", "x86-64");
-      processorAlias.put("x86_64", "x86-64");
-   }
-   
-   /** Maps an alias to an OSGi osname */
-   private static Map<String, String> osAlias = new HashMap<String, String>();
-   static
-   {
-      osAlias.put("SymbianOS", "Epoc32");
-      osAlias.put("hp-ux", "HPUX");
-      osAlias.put("Mac OS", "MacOS");
-      osAlias.put("Mac OS X", "MacOSX");
-      osAlias.put("OS/2", "OS2");
-      osAlias.put("procnto", "QNX");
-      osAlias.put("Win95", "Windows95");
-      osAlias.put("Windows 95", "Windows95");
-      osAlias.put("Win32", "Windows95");
-      osAlias.put("Win98", "Windows98");
-      osAlias.put("Windows 98", "Windows98");
-      osAlias.put("Win32", "Windows98");
-      osAlias.put("WinNT", "WindowsNT");
-      osAlias.put("Windows NT", "WindowsNT");
-      osAlias.put("Win32", "WindowsNT");
-      osAlias.put("WinCE", "WindowsCE");
-      osAlias.put("Windows CE", "WindowsCE");
-      osAlias.put("Win2000", "Windows2000");
-      osAlias.put("Windows 2000", "Windows2000");
-      osAlias.put("Win32", "Windows2000");
-      osAlias.put("Win2003", "Windows2003");
-      osAlias.put("Windows 2003", "Windows2003");
-      osAlias.put("Win32", "Windows2003");
-      osAlias.put("Windows Server 2003", "Windows2003");
-      osAlias.put("WinXP", "WindowsXP");
-      osAlias.put("Windows XP", "WindowsXP");
-      osAlias.put("Win32", "WindowsXP");
-      osAlias.put("WinVista", "WindowsVista");
-      osAlias.put("Windows Vista", "WindowsVista");
-      osAlias.put("Win32", "WindowsVista");
-   }
-   
-   public OSGiBundleNativeCodeDeployer()
-   {
-      setInput(ClassLoaderFactory.class);
-      addInput(ClassLoaderPolicy.class);
-      addInput(OSGiBundleState.class);
-      setStage(DeploymentStages.CLASSLOADER);
-      setTopLevelOnly(true);
-   }
-
-   @Override
-   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
-   {
-      AbstractBundleState absBundleState = unit.getAttachment(AbstractBundleState.class);
-      if (absBundleState == null)
-         throw new IllegalStateException("No bundle state");
-      
-      if ((absBundleState instanceof OSGiBundleState) == false)
-         return;
-      
-      AbstractDeployedBundleState bundleState = (AbstractDeployedBundleState)absBundleState;
-      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
-      List<ParameterizedAttribute> nativeCodeParams = osgiMetaData.getBundleNativeCode();
-      if (nativeCodeParams == null)
-         return;
-      
-      OSGiBundleManager bundleManager = bundleState.getBundleManager();
-      String fwOSName = bundleManager.getProperty(Constants.FRAMEWORK_OS_NAME);
-      String fwProcessor = bundleManager.getProperty(Constants.FRAMEWORK_PROCESSOR);
-      //String fwOSVersion = bundleManager.getProperty(Constants.FRAMEWORK_OS_VERSION);
-      
-      List<ParameterizedAttribute> matchedParams = new ArrayList<ParameterizedAttribute>();
-      for (ParameterizedAttribute param : nativeCodeParams)
-      {
-         // Only select the native code clauses for which the following expressions all evaluate to true
-         //  * osname ~= [org.osgi.framework.os.name]
-         //  * processor ~= [org.osgi.framework.processor]
-         //  * osversion range includes [org.osgi.framework.os.version] or osversion is not specified
-         //  * language ~= [org.osgi.framework.language] or language is not specified
-         //  * selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
-
-         Parameter osnameParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSNAME);
-         Parameter procParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_PROCESSOR);
-         //Parameter osversionParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSVERSION);
-         
-         boolean match = (osnameParam != null);
-         
-         // osname ~= [org.osgi.framework.os.name]
-         if (match && osnameParam != null)
-         {
-            String osname = (String)osnameParam.getValue();
-            match = (osname.equals(fwOSName) || osname.equals(osAlias.get(fwOSName)));
-         }
-         
-         // processor ~= [org.osgi.framework.processor]
-         match &= (procParam != null);
-         if (match && procParam != null)
-         {
-            String processor = (String)procParam.getValue();
-            match = (processor.equals(fwProcessor) || processor.equals(processorAlias.get(fwProcessor)));
-         }
-         
-         // [TODO] osversion range includes [org.osgi.framework.os.version] or osversion is not specified
-         // [TODO] language ~= [org.osgi.framework.language] or language is not specified
-         // [TODO] selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
-         
-         if (match == true)
-            matchedParams.add(param);
-      }
-      
-      // If no native clauses were selected in step 1, this algorithm is terminated
-      // and a BundleException is thrown if the optional clause is not present
-      if (matchedParams.size() == 0)
-      {
-         // [TODO] optional
-         throw new DeploymentException("No native clauses selected from: " + nativeCodeParams);
-      }
-      
-      // The selected clauses are now sorted in the following priority order:
-      //  * osversion: floor of the osversion range in descending order, osversion not specified
-      //  * language: language specified, language not specified
-      //  * Position in the Bundle-NativeCode manifest header: lexical left to right
-      if (matchedParams.size() > 1)
-      {
-         // [TODO] selected clauses are now sorted
-      }
-
-      // The first clause of the sorted clauses from step 3 must be used as the selected native code clause
-      ParameterizedAttribute selectedParams = matchedParams.get(0);
-      log.debug("Selected native code clause: " + selectedParams);
-      
-      String nativeLib = selectedParams.getAttribute();
-      URL entryURL = bundleState.getEntry(nativeLib);
-      
-      // If a native code library in a selected native code clause cannot be found
-      // within the bundle then the bundle must fail to resolve
-      if (entryURL == null)
-         throw new DeploymentException("Cannot find native library: " + nativeLib);
-
-      // 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);
-      }
-      
-      // Generate the key for the library mapping
-      String libfile = new File(nativeLib).getName();
-      String libname = libfile.substring(0, libfile.lastIndexOf('.'));
-      
-      // Add the native library mapping to the OSGiClassLoaderPolicy
-      OSGiClassLoaderPolicy policy = (OSGiClassLoaderPolicy)unit.getAttachment(ClassLoaderPolicy.class);
-      policy.addLibraryMapping(libname, nativeFileCopy);
-   }
-}

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiFragmentAttachmentDeployer.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -25,6 +25,7 @@
 
 import org.jboss.classloader.spi.ClassLoaderPolicy;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
@@ -33,7 +34,6 @@
 import org.jboss.osgi.framework.bundle.OSGiBundleManager;
 import org.jboss.osgi.framework.bundle.OSGiBundleState;
 import org.jboss.osgi.framework.bundle.OSGiFragmentState;
-import org.jboss.osgi.framework.classloading.OSGiClassLoaderPolicy;
 import org.osgi.framework.Bundle;
 
 /**
@@ -89,7 +89,7 @@
          OSGiFragmentState fragState = (OSGiFragmentState)absBundleState;
          OSGiBundleState hostState = fragState.getFragmentHost();
          DeploymentUnit hostUnit = hostState.getDeploymentUnit();
-         OSGiClassLoaderPolicy hostPolicy = (OSGiClassLoaderPolicy)hostUnit.getAttachment(ClassLoaderPolicy.class);
+         VFSClassLoaderPolicy hostPolicy = (VFSClassLoaderPolicy)hostUnit.getAttachment(ClassLoaderPolicy.class);
          hostPolicy.attachFragment(fragState.getRoot());
       }
    }

Added: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -0,0 +1,265 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.deployers;
+
+// $Id$
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.NativeLibrary;
+import org.jboss.classloading.spi.metadata.NativeLibraryMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.framework.metadata.Parameter;
+import org.jboss.osgi.framework.metadata.ParameterizedAttribute;
+import org.osgi.framework.Constants;
+
+/**
+ * A deployer that takes care of loading native code libraries.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 19-Dec-2009
+ */
+public class OSGiNativeCodeMetaDataDeployer extends AbstractRealDeployer
+{
+   /** Maps an alias to an OSGi processor name */
+   private static Map<String, String> processorAlias = new HashMap<String, String>();
+   static
+   {
+      processorAlias.put("pentium", "x86");
+      processorAlias.put("i386", "x86");
+      processorAlias.put("i486", "x86");
+      processorAlias.put("i586", "x86");
+      processorAlias.put("i686", "x86");
+      processorAlias.put("amd64", "x86-64");
+      processorAlias.put("em64t", "x86-64");
+      processorAlias.put("x86_64", "x86-64");
+   }
+
+   /** Maps an alias to an OSGi osname */
+   private static Map<String, String> osAlias = new HashMap<String, String>();
+   static
+   {
+      osAlias.put("SymbianOS", "Epoc32");
+      osAlias.put("hp-ux", "HPUX");
+      osAlias.put("Mac OS", "MacOS");
+      osAlias.put("Mac OS X", "MacOSX");
+      osAlias.put("OS/2", "OS2");
+      osAlias.put("procnto", "QNX");
+      osAlias.put("Win95", "Windows95");
+      osAlias.put("Windows 95", "Windows95");
+      osAlias.put("Win32", "Windows95");
+      osAlias.put("Win98", "Windows98");
+      osAlias.put("Windows 98", "Windows98");
+      osAlias.put("Win32", "Windows98");
+      osAlias.put("WinNT", "WindowsNT");
+      osAlias.put("Windows NT", "WindowsNT");
+      osAlias.put("Win32", "WindowsNT");
+      osAlias.put("WinCE", "WindowsCE");
+      osAlias.put("Windows CE", "WindowsCE");
+      osAlias.put("Win2000", "Windows2000");
+      osAlias.put("Windows 2000", "Windows2000");
+      osAlias.put("Win32", "Windows2000");
+      osAlias.put("Win2003", "Windows2003");
+      osAlias.put("Windows 2003", "Windows2003");
+      osAlias.put("Win32", "Windows2003");
+      osAlias.put("Windows Server 2003", "Windows2003");
+      osAlias.put("WinXP", "WindowsXP");
+      osAlias.put("Windows XP", "WindowsXP");
+      osAlias.put("Win32", "WindowsXP");
+      osAlias.put("WinVista", "WindowsVista");
+      osAlias.put("Windows Vista", "WindowsVista");
+      osAlias.put("Win32", "WindowsVista");
+   }
+
+   public OSGiNativeCodeMetaDataDeployer()
+   {
+      setInput(ClassLoadingMetaData.class);
+      setStage(DeploymentStages.POST_PARSE);
+      setTopLevelOnly(true);
+   }
+
+   @SuppressWarnings("unchecked")
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      ClassLoadingMetaData classLoadingMetaData = unit.getAttachment(ClassLoadingMetaData.class);
+      if (classLoadingMetaData == null)
+         throw new IllegalStateException("No ClassLoadingMetaData");
+
+      AbstractBundleState absBundleState = unit.getAttachment(AbstractBundleState.class);
+      if (absBundleState == null)
+         throw new IllegalStateException("No AbstractBundleState");
+
+      if ((absBundleState instanceof OSGiBundleState) == false)
+         return;
+
+      OSGiBundleState bundleState = (OSGiBundleState)absBundleState;
+      OSGiBundleManager bundleManager = bundleState.getBundleManager();
+      OSGiMetaData osgiMetaData = bundleState.getOSGiMetaData();
+      List<ParameterizedAttribute> nativeCodeParams = osgiMetaData.getBundleNativeCode();
+      if (nativeCodeParams == null)
+         return;
+
+      // Find the matching parameters
+      List<ParameterizedAttribute> matchedParams = new ArrayList<ParameterizedAttribute>();
+      for (ParameterizedAttribute param : nativeCodeParams)
+      {
+         if (matchParameter(bundleManager, param))
+            matchedParams.add(param);
+      }
+
+      // If no native clauses were selected in step 1, this algorithm is terminated
+      // and a BundleException is thrown if the optional clause is not present
+      if (matchedParams.size() == 0)
+      {
+         // [TODO] optional
+         throw new DeploymentException("No native clauses selected from: " + nativeCodeParams);
+      }
+
+      // The selected clauses are now sorted in the following priority order:
+      //  * osversion: floor of the osversion range in descending order, osversion not specified
+      //  * language: language specified, language not specified
+      //  * Position in the Bundle-NativeCode manifest header: lexical left to right
+      if (matchedParams.size() > 1)
+      {
+         // [TODO] selected clauses are now sorted
+      }
+
+      NativeLibraryMetaData nativeLibraries = classLoadingMetaData.getNativeLibraries();
+      for (ParameterizedAttribute param : matchedParams)
+      {
+         Parameter osnameParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSNAME);
+         Parameter procParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_PROCESSOR);
+         //Parameter osversionParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSVERSION);
+
+         List<String> osNames;
+         if (osnameParam.isCollection())
+            osNames = (List<String>)osnameParam.getValue();
+         else
+            osNames = Collections.singletonList((String)osnameParam.getValue());
+
+         String libpath = param.getAttribute();
+         String libsource = bundleState.getCanonicalName();
+
+         NativeLibrary library = new NativeLibrary(osNames, libpath, libsource);
+         
+         // Processors
+         if (procParam != null)
+         {
+            List<String> processors;
+            if (procParam.isCollection())
+               processors = (List<String>)procParam.getValue();
+            else
+               processors = Collections.singletonList((String)procParam.getValue());
+            
+            library.setProcessors(processors);
+         }
+         
+         // [TODO] osVersions, languages, selectionFilter, optional
+         // library.setOsVersions(osVersions);
+         // library.setLanguages(languages);
+         // library.setSelectionFilter(selectionFilter);
+         // library.setOptional(optional);
+         
+         nativeLibraries.addNativeLibrary(library);
+      }
+   }
+
+   @SuppressWarnings("unchecked")
+   private boolean matchParameter(OSGiBundleManager bundleManager, ParameterizedAttribute param)
+   {
+      String fwOSName = bundleManager.getProperty(Constants.FRAMEWORK_OS_NAME);
+      String fwProcessor = bundleManager.getProperty(Constants.FRAMEWORK_PROCESSOR);
+      //String fwOSVersion = bundleManager.getProperty(Constants.FRAMEWORK_OS_VERSION);
+
+      // Only select the native code clauses for which the following expressions all evaluate to true
+      //  * osname ~= [org.osgi.framework.os.name]
+      //  * processor ~= [org.osgi.framework.processor]
+      //  * osversion range includes [org.osgi.framework.os.version] or osversion is not specified
+      //  * language ~= [org.osgi.framework.language] or language is not specified
+      //  * selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
+
+      Parameter osnameParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSNAME);
+      Parameter procParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_PROCESSOR);
+      //Parameter osversionParam = param.getAttribute(Constants.BUNDLE_NATIVECODE_OSVERSION);
+
+      boolean match = (osnameParam != null);
+
+      // osname ~= [org.osgi.framework.os.name]
+      if (match == true && osnameParam != null)
+      {
+         List<String> osNames;
+         if (osnameParam.isCollection())
+            osNames = (List<String>)osnameParam.getValue();
+         else
+            osNames = Collections.singletonList((String)osnameParam.getValue());
+
+         boolean osmatch = false;
+         for (String osname : osNames)
+         {
+            osmatch = (osname.equals(fwOSName) || osname.equals(osAlias.get(fwOSName)));
+            if (osmatch == true)
+               break;
+         }
+
+         match &= osmatch;
+      }
+
+      // processor ~= [org.osgi.framework.processor]
+      match &= (procParam != null);
+      if (match && procParam != null)
+      {
+         List<String> processors;
+         if (procParam.isCollection())
+            processors = (List<String>)procParam.getValue();
+         else
+            processors = Collections.singletonList((String)procParam.getValue());
+
+         boolean procmatch = false;
+         for (String proc : processors)
+         {
+            procmatch = (proc.equals(fwProcessor) || proc.equals(processorAlias.get(fwProcessor)));
+            if (procmatch == true)
+               break;
+         }
+
+         match &= procmatch;
+      }
+
+      // [TODO] osversion range includes [org.osgi.framework.os.version] or osversion is not specified
+      // [TODO] language ~= [org.osgi.framework.language] or language is not specified
+      // [TODO] selection-filter evaluates to true when using the values of the system properties or selection-filter is not specified
+      return match;
+   }
+}


Property changes on: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodeMetaDataDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Copied: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodePolicyDeployer.java (from rev 99715, 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/OSGiNativeCodePolicyDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiNativeCodePolicyDeployer.java	2010-01-21 12:39:50 UTC (rev 99732)
@@ -0,0 +1,124 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.osgi.framework.deployers;
+
+// $Id: $
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.ClassLoaderPolicy.NativeLibraryProvider;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.NativeLibrary;
+import org.jboss.classloading.spi.metadata.NativeLibraryMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.ClassLoaderFactory;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.plugins.BundleStoragePlugin;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A deployer that takes care of loading native code libraries.
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 19-Dec-2009
+ */
+public class OSGiNativeCodePolicyDeployer extends AbstractRealDeployer
+{
+   public OSGiNativeCodePolicyDeployer()
+   {
+      setInput(ClassLoaderFactory.class);
+      addInput(ClassLoaderPolicy.class);
+      addInput(OSGiBundleState.class);
+      setStage(DeploymentStages.CLASSLOADER);
+      setTopLevelOnly(true);
+   }
+
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      AbstractBundleState absBundleState = unit.getAttachment(AbstractBundleState.class);
+      if (absBundleState == null)
+         throw new IllegalStateException("No bundle state");
+
+      ClassLoadingMetaData classLoadingMetaData = unit.getAttachment(ClassLoadingMetaData.class);
+      NativeLibraryMetaData libMetaData = classLoadingMetaData.getNativeLibraries();
+      if (libMetaData == null || libMetaData.getNativeLibraries() == null)
+         return;
+         
+      final OSGiBundleState bundleState = (OSGiBundleState)absBundleState;
+      final OSGiBundleManager bundleManager = bundleState.getBundleManager();
+
+      // Add the native library mappings to the OSGiClassLoaderPolicy
+      ClassLoaderPolicy policy = (ClassLoaderPolicy)unit.getAttachment(ClassLoaderPolicy.class);
+      for (NativeLibrary library : libMetaData.getNativeLibraries())
+      {
+         final String libpath = library.getLibraryPath();
+
+         NativeLibraryProvider provider = new NativeLibraryProvider()
+         {
+            private File libraryFile;
+            
+            public String getLibraryPath()
+            {
+               return libpath;
+            }
+            
+            public File getLibraryLocation() throws IOException
+            {
+               if (libraryFile == null)
+               {
+                  URL entryURL = bundleState.getEntry(libpath);
+
+                  // If a native code library in a selected native code clause cannot be found
+                  // within the bundle then the bundle must fail to resolve
+                  if (entryURL == null)
+                     throw new IOException("Cannot find native library: " + libpath);
+
+                  // Copy the native library to the bundle storage area
+                  VirtualFile nativeVirtualFile = bundleState.getRoot().getChild(libpath);
+                  BundleStoragePlugin plugin = bundleManager.getPlugin(BundleStoragePlugin.class);
+                  libraryFile = plugin.getDataFile(bundleState, libpath);
+                  FileOutputStream fos = new FileOutputStream(libraryFile);
+                  VFSUtils.copyStream(nativeVirtualFile.openStream(), fos);
+                  fos.close();
+               }
+               return libraryFile;
+            }
+         };
+         
+         // Add the library provider to the policy
+         String libfile = new File(libpath).getName();
+         String libname = libfile.substring(0, libfile.lastIndexOf('.'));
+         policy.addNativeLibrary(libname, provider);
+      }
+   }
+}

Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-01-21 12:32:09 UTC (rev 99731)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2010-01-21 12:39:50 UTC (rev 99732)
@@ -143,16 +143,17 @@
   </bean>
 
   <!-- OSGI Deployment -->
-  <bean name="OSGiManifestParsingDeployer" class="org.jboss.osgi.framework.deployers.OSGiManifestParsingDeployer" />
+  <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiBundleStateAddDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateAddDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
   <bean name="OSGiBundleStateRemoveDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateRemoveDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
-  <bean name="OSGiBundleNativeCodeDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleNativeCodeDeployer" />
-  <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
+  <bean name="OSGiManifestParsingDeployer" class="org.jboss.osgi.framework.deployers.OSGiManifestParsingDeployer" />
+  <bean name="OSGiNativeCodeMetaDataDeployer" class="org.jboss.osgi.framework.deployers.OSGiNativeCodeMetaDataDeployer" />
+  <bean name="OSGiNativeCodePolicyDeployer" class="org.jboss.osgi.framework.deployers.OSGiNativeCodePolicyDeployer" />
 
   <!--
   ********************************



More information about the jboss-osgi-commits mailing list