[jboss-osgi-commits] JBoss-OSGI SVN: r93341 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src: test/resources/bootstrap and 1 other directory.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Thu Sep 10 04:36:56 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-09-10 04:36:55 -0400 (Thu, 10 Sep 2009)
New Revision: 93341

Added:
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderPolicyDeployer.java
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoader.java
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/resources/bootstrap/bootstrap.xml
Log:
wip

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoader.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoader.java	2009-09-10 08:35:49 UTC (rev 93340)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiBundleClassLoader.java	2009-09-10 08:36:55 UTC (rev 93341)
@@ -32,11 +32,19 @@
  */
 public class OSGiBundleClassLoader extends BaseClassLoader
 {
+   private ClassLoaderPolicy policy;
+   
    public OSGiBundleClassLoader(ClassLoaderPolicy policy)
    {
       super(policy);
+      this.policy = policy;
    }
 
+   public ClassLoaderPolicy getClassLoaderPolicy()
+   {
+      return policy;
+   }
+
    @Override
    public String toString()
    {

Added: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderPolicyDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderPolicyDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderPolicyDeployer.java	2009-09-10 08:36:55 UTC (rev 93341)
@@ -0,0 +1,143 @@
+/*
+* 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.plugins.facade.classloading;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.classloader.spi.filter.PackageClassFilter;
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+
+/**
+ * OSGiClassLoaderPolicyDeployer
+ * 
+ * A deployer that modifies the ClassLoaderPolicy of a deployed bundle
+ * to exclude import packages that are wired to another bundle.  
+ * 
+ * @author Thomas.Diesler at jboss.com
+ * @since 10-Sep-2009
+ */
+public class OSGiClassLoaderPolicyDeployer extends AbstractDeployer implements Deployer
+{
+   /**
+    * Create a new OSGiClassLoaderPolicyDeployer.
+    */
+   public OSGiClassLoaderPolicyDeployer()
+   {
+      setStage(DeploymentStages.CLASSLOADER);
+      setInput(ClassLoader.class);
+      addInput(OSGiBundleState.class);
+      setTopLevelOnly(true);
+      setAllInputs(true);
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+      
+      OSGiBundleClassLoader classLoader;
+      try
+      {
+         classLoader = (OSGiBundleClassLoader)unit.getClassLoader();
+      }
+      catch (IllegalStateException ex)
+      {
+         // How can I get the CL ?
+         return;
+      }
+      
+      ClassLoaderPolicy policy = classLoader.getClassLoaderPolicy();
+
+      // Get excluded packages
+      List<String> excludedPackages = getExcludedPackages(bundleState, policy);
+      
+      // Exclude the packages from the policy
+      if (excludedPackages.isEmpty() == false && policy instanceof VFSClassLoaderPolicy)
+      {
+         String[] packageArr = new String[excludedPackages.size()];
+         excludedPackages.toArray(packageArr);
+
+         VFSClassLoaderPolicy vfsPolicy = (VFSClassLoaderPolicy)policy;
+         vfsPolicy.setExcluded(new PackageClassFilter(packageArr));
+      }
+   }
+
+   private List<String> getExcludedPackages(OSGiBundleState bundleState, ClassLoaderPolicy policy)
+   {
+      String location = bundleState.getLocation();
+      
+      List<String> exportedPackages = new ArrayList<String>();
+      List<String> excludedPackages = new ArrayList<String>();
+
+      // Collect the exported package names
+      DeploymentUnit unit = bundleState.getDeploymentUnit();
+      ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
+      for (Capability capability : metadata.getCapabilities().getCapabilities())
+      {
+         if (capability instanceof PackageCapability)
+         {
+            PackageCapability packageCapability = (PackageCapability)capability;
+            exportedPackages.add(packageCapability.getName());
+         }
+      }
+
+      // Collect the imported package names
+      DependencyInfo dependencyInfo = unit.getDependencyInfo();
+      for (DependencyItem item : dependencyInfo.getIDependOn(RequirementDependencyItem.class))
+      {
+         RequirementDependencyItem reqdi = (RequirementDependencyItem)item;
+         Requirement requirement = reqdi.getRequirement();
+         if (requirement instanceof PackageRequirement)
+         {
+            PackageRequirement packageRequirement = (PackageRequirement)requirement;
+            String packageName = packageRequirement.getName();
+
+            // If the imported package is also an exported package
+            if (exportedPackages.contains(packageName))
+            {
+               // Exclude if the import comes from another module
+               Object other = item.getIDependOn();
+               if (other != null && location.equals(other) == false)
+               {
+                  excludedPackages.add(packageName);
+               }
+            }
+         }
+      }
+      return excludedPackages;
+   }
+}


Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderPolicyDeployer.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java	2009-09-10 08:35:49 UTC (rev 93340)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java	2009-09-10 08:36:55 UTC (rev 93341)
@@ -21,34 +21,17 @@
 */
 package org.jboss.osgi.plugins.facade.classloading;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
 import org.jboss.classloader.spi.ClassLoaderDomain;
 import org.jboss.classloader.spi.ClassLoaderPolicy;
 import org.jboss.classloader.spi.ClassLoaderSystem;
 import org.jboss.classloader.spi.ParentPolicy;
 import org.jboss.classloader.spi.base.BaseClassLoader;
-import org.jboss.classloader.spi.filter.PackageClassFilter;
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
-import org.jboss.classloading.spi.metadata.Capability;
-import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
-import org.jboss.classloading.spi.metadata.Requirement;
-import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.DependencyInfo;
-import org.jboss.dependency.spi.DependencyItem;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
 
 /**
- * OSGiClassLoaderSystem.
- * <p>
+ * The OSGi ClassLoaderSystem.
  * 
  * @author <a href="adrian at jboss.com">Adrian Brock</a>
  * @author Thomas.Diesler at jboss.com
@@ -56,19 +39,11 @@
  */
 public class OSGiClassLoaderSystem extends ClassLoaderSystem
 {
-   private OSGiBundleManager bundleManager;
-
    /**
     * Create a new OSGiClassLoaderSystem.
-    * 
-    * @throws IllegalArgumentException for a null bundle manager
     */
-   public OSGiClassLoaderSystem(OSGiBundleManager bundleManager)
+   public OSGiClassLoaderSystem()
    {
-      if (bundleManager == null)
-         throw new IllegalArgumentException("Null bundleManager");
-      this.bundleManager = bundleManager;
-
       ClassLoaderDomain domain = getDefaultDomain();
 
       domain.setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
@@ -85,71 +60,6 @@
    @Override
    protected BaseClassLoader createClassLoader(ClassLoaderPolicy policy)
    {
-      // Get excluded packages
-      List<String> excludedPackages = getExcludedPackages(policy);
-      
-      // Exclude the packages from the policy
-      if (excludedPackages.isEmpty() == false && policy instanceof VFSClassLoaderPolicy)
-      {
-         String[] packageArr = new String[excludedPackages.size()];
-         excludedPackages.toArray(packageArr);
-
-         VFSClassLoaderPolicy vfsPolicy = (VFSClassLoaderPolicy)policy;
-         vfsPolicy.setExcluded(new PackageClassFilter(packageArr));
-      }
-
       return new OSGiBundleClassLoader(policy);
    }
-
-   private List<String> getExcludedPackages(ClassLoaderPolicy policy)
-   {
-      // Get the bundle location from the policy id
-      String location = policy.getObjectName().getKeyProperty("id");
-      if (location.startsWith("\"") && location.endsWith("\""))
-         location = location.substring(1, location.length() - 1);
-
-      List<String> exportedPackages = new ArrayList<String>();
-      List<String> excludedPackages = new ArrayList<String>();
-
-      OSGiBundleState bundle = (OSGiBundleState)bundleManager.getBundleByLocation(location);
-      if (bundle != null)
-      {
-         // Collect the exported package names
-         DeploymentUnit unit = bundle.getDeploymentUnit();
-         ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
-         for (Capability capability : metadata.getCapabilities().getCapabilities())
-         {
-            if (capability instanceof PackageCapability)
-            {
-               PackageCapability packageCapability = (PackageCapability)capability;
-               exportedPackages.add(packageCapability.getName());
-            }
-         }
-         
-         // Collect the imported package names
-         DependencyInfo di = unit.getAttachment(ControllerContext.class).getDependencyInfo();
-         for (DependencyItem item : di.getIDependOn(RequirementDependencyItem.class))
-         {
-            RequirementDependencyItem reqdi = (RequirementDependencyItem)item;
-            Requirement requirement = reqdi.getRequirement();
-            if (requirement instanceof PackageRequirement)
-            {
-               PackageRequirement packageRequirement = (PackageRequirement)requirement;
-               String packageName = packageRequirement.getName();
-               
-               // If the imported package is also an exported package
-               if (exportedPackages.contains(packageName))
-               {
-                  // Exclude if the import comes from another module
-                  Object other = item.getIDependOn();
-                  if (other != null && location.equals(other) == false)
-                  {
-                     excludedPackages.add(packageName);
-                  }
-               }
-            }
-         }
-      }
-      return excludedPackages;
-   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/resources/bootstrap/bootstrap.xml	2009-09-10 08:35:49 UTC (rev 93340)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/resources/bootstrap/bootstrap.xml	2009-09-10 08:36:55 UTC (rev 93341)
@@ -148,6 +148,7 @@
     <property name="classLoaderSystem"><inject bean="OSGiClassLoaderSystem"/></property>
     <property name="bundleManager"><inject bean="OSGiBundleManager" /></property>
   </bean>
+  <!-- bean name="OSGiClassLoaderPolicyDeployer" class="org.jboss.osgi.plugins.facade.classloading.OSGiClassLoaderPolicyDeployer"/-->
    
   <bean name="ClassLoading" class="org.jboss.classloading.spi.dependency.ClassLoading">
     <incallback method="addModule" state="Configured" />



More information about the jboss-osgi-commits mailing list