JBoss-OSGI SVN: r93341 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src: test/resources/bootstrap and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)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(a)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(a)jboss.com">Adrian Brock</a>
* @author Thomas.Diesler(a)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" />
16 years, 10 months
JBoss-OSGI SVN: r93340 - projects/jboss-osgi/projects/runtime/microcontainer/branches.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-10 04:35:49 -0400 (Thu, 10 Sep 2009)
New Revision: 93340
Added:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/
Log:
recreate userbranch
Copied: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler (from rev 93339, projects/jboss-osgi/projects/runtime/microcontainer/trunk)
16 years, 10 months
JBoss-OSGI SVN: r93337 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/facade/bundle and 4 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-10 00:35:14 -0400 (Thu, 10 Sep 2009)
New Revision: 93337
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
Log:
[JBOSGI-151] Cannot resolve circular dependencies
Exclude package from policy that are imported from another module
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleRequiredStageDeployer.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,54 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.deployers.bundle;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-
-/**
- * Change required stage to reset.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public class BundleRequiredStageDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
-{
- public BundleRequiredStageDeployer()
- {
- super(OSGiMetaData.class);
- setStage(DeploymentStages.POST_CLASSLOADER);
- setTopLevelOnly(true);
- }
-
- public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
- {
- unit.setRequiredStage(BundleResolver.RESET_STAGE);
- }
-
- @Override
- public void undeploy(DeploymentUnit unit, OSGiMetaData deployment)
- {
- unit.setRequiredStage(DeploymentStages.INSTALLED);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResetDeployer.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.deployers.bundle;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-
-/**
- * Simple bundle reset deployer.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public class BundleResetDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
-{
- private BundleResolver resolver;
-
- public BundleResetDeployer(BundleResolver resolver)
- {
- super(OSGiMetaData.class);
-
- if (resolver == null)
- throw new IllegalArgumentException("Null resolver");
-
- this.resolver = resolver;
-
- setStage(BundleResolver.RESET_STAGE);
- setTopLevelOnly(true);
- }
-
- public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
- {
- resolver.reset(unit);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolveDeployer.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,58 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.deployers.bundle;
-
-import org.jboss.classloading.spi.dependency.Module;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.spi.metadata.OSGiMetaData;
-
-/**
- * Simple bundle resolve deployer.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public class BundleResolveDeployer extends AbstractSimpleRealDeployer<OSGiMetaData>
-{
- private BundleResolver resolver;
-
- public BundleResolveDeployer(BundleResolver resolver)
- {
- super(OSGiMetaData.class);
-
- if (resolver == null)
- throw new IllegalArgumentException("Null resolver");
-
- this.resolver = resolver;
-
- addInput(Module.class);
- setStage(DeploymentStages.DESCRIBE);
- setTopLevelOnly(true);
- }
-
- public void deploy(DeploymentUnit unit, OSGiMetaData deployment) throws DeploymentException
- {
- resolver.resolve(unit);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleResolver.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,125 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.deployers.bundle;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArraySet;
-
-import org.jboss.dependency.spi.Controller;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.DependencyInfo;
-import org.jboss.dependency.spi.DependencyItem;
-import org.jboss.deployers.spi.deployer.DeploymentStage;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-
-/**
- * Simple bundle resolve helper.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public class BundleResolver
-{
- static final ControllerState DESCRIBED_STATE = new ControllerState(DeploymentStages.DESCRIBE.getName());
- static final ControllerState CLASSLOADER_STATE = new ControllerState(DeploymentStages.CLASSLOADER.getName());
-
- static final ControllerState RESET_STATE = new ControllerState("Reset");
- static final DeploymentStage RESET_STAGE = new DeploymentStage("Reset", "Installed");
-
- private Set<DeploymentUnit> units = new CopyOnWriteArraySet<DeploymentUnit>();
-
- public BundleResolver(Controller controller)
- {
- controller.addState(RESET_STATE, null);
- }
-
- void resolve(DeploymentUnit unit)
- {
- run(unit, new Action()
- {
- public void resolved(DeploymentUnit unit)
- {
- unit.setRequiredStage(DeploymentStages.CLASSLOADER);
- for (DeploymentUnit unresolved : units)
- {
- unresolved.setRequiredStage(DeploymentStages.CLASSLOADER); // try moving
- ControllerContext context = unresolved.getAttachment(ControllerContext.class);
- if (context != null)
- context.setRequiredState(CLASSLOADER_STATE);
- }
- }
-
- public void unresolved(DeploymentUnit unit)
- {
- units.add(unit);
- }
- });
- }
-
- void reset(DeploymentUnit unit)
- {
- units.remove(unit); // remove, as we're clearly resolved
-
- Set<DeploymentUnit> copy = new HashSet<DeploymentUnit>(units);
- for (DeploymentUnit unresolved : copy)
- {
- run(unresolved, new Action()
- {
- public void resolved(DeploymentUnit unit)
- {
- units.remove(unit);
- }
-
- public void unresolved(DeploymentUnit unit)
- {
- unit.setRequiredStage(DeploymentStages.DESCRIBE); // move back
- ControllerContext context = unit.getAttachment(ControllerContext.class);
- if (context != null)
- context.setRequiredState(DESCRIBED_STATE);
- }
- });
- }
- }
-
- protected void run(DeploymentUnit unit, Action action)
- {
- ControllerContext context = unit.getAttachment(ControllerContext.class);
- if (context != null)
- {
- DependencyInfo info = context.getDependencyInfo();
- Set<DependencyItem> unresolvedDependencies = info.getUnresolvedDependencies(CLASSLOADER_STATE);
- if (unresolvedDependencies == null || unresolvedDependencies.isEmpty())
- action.resolved(unit);
- else
- action.unresolved(unit);
- }
- }
-
- private interface Action
- {
- void resolved(DeploymentUnit unit);
-
- void unresolved(DeploymentUnit unit);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/BundleStartStopDeployer.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,69 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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.deployers.bundle;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
-import org.osgi.framework.BundleException;
-
-/**
- * Simple bundle start/stop deployer.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public class BundleStartStopDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
-{
- public BundleStartStopDeployer()
- {
- super(OSGiBundleState.class);
- setStage(DeploymentStages.CLASSLOADER);
- setTopLevelOnly(true);
- }
-
- public void deploy(DeploymentUnit unit, OSGiBundleState deployment) throws DeploymentException
- {
- try
- {
- deployment.start();
- }
- catch (BundleException e)
- {
- throw DeploymentException.rethrowAsDeploymentException("Cannot start bundle.", e);
- }
- }
-
- @Override
- public void undeploy(DeploymentUnit unit, OSGiBundleState deployment)
- {
- try
- {
- deployment.stop();
- }
- catch (BundleException e)
- {
- log.warn("Exception stopping bundle: " + e);
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/deployers/bundle/OSGiBundleResolverDeployer.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -1,168 +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.plugins.deployers.bundle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.DependencyInfo;
-import org.jboss.dependency.spi.LifecycleCallbackItem;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.logging.Logger;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * OSGiBundleResolverDeployer.
- *
- * @author Thomas.Diesler(a)jboss.com
- * @version $Revision: 1.1 $
- */
-public class OSGiBundleResolverDeployer extends AbstractSimpleRealDeployer<OSGiBundleState>
-{
- /** The log */
- private static final Logger log = Logger.getLogger(OSGiBundleResolverDeployer.class);
-
- /** The list of unresolved bundles */
- private List<OSGiBundleState> unresolvedBundles = new ArrayList<OSGiBundleState>();
-
- public OSGiBundleResolverDeployer()
- {
- super(OSGiBundleState.class);
- setStage(DeploymentStages.DESCRIBE);
- setTopLevelOnly(true);
- }
-
- @Override
- public void deploy(DeploymentUnit unit, OSGiBundleState bundleState) throws DeploymentException
- {
- bundleState.getBundleManager();
-
- ControllerContext context = unit.getAttachment(ControllerContext.class);
- DependencyInfo di = context.getDependencyInfo();
-
- LifecycleCallbackItem lifecycleCallbackItem = new LifecycleCallback(unit);
- di.addLifecycleCallback(lifecycleCallbackItem);
- }
-
- private class LifecycleCallback implements LifecycleCallbackItem
- {
- private DeploymentUnit unit;
- private PackageAdmin packageAdmin;
- private DeployerClient deployerClient;
-
- public LifecycleCallback(DeploymentUnit unit)
- {
- this.unit = unit;
-
- OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
- BundleContext sysContext = bundleState.getBundleManager().getSystemContext();
- ServiceReference sref = sysContext.getServiceReference(PackageAdmin.class.getName());
- packageAdmin = (PackageAdmin)sysContext.getService(sref);
-
- deployerClient = unit.getAttachment(MainDeployer.class);
- }
-
- public void uninstall(ControllerContext ctx)
- {
- OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
- unresolvedBundles.remove(bundleState);
- }
-
- public void install(ControllerContext ctx) throws Exception
- {
- Runnable runnable = new Runnable()
- {
- public void run()
- {
- try
- {
- // [TODO] remove this hack and find a way to trigger
- // PackageAdmin after the context has been deployed
- Thread.sleep(100);
- }
- catch (InterruptedException e)
- {
- // ignore
- }
-
- OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-
- // Add the new bundle to the list of unresolved
- unresolvedBundles.add(0, bundleState);
- OSGiBundleState[] unresolved = new OSGiBundleState[unresolvedBundles.size()];
- unresolvedBundles.toArray(unresolved);
-
- // Try to resolve all unresolved bundles
- packageAdmin.resolveBundles(unresolved);
- if (bundleState.getState() != Bundle.RESOLVED)
- log.info("Unresolved: " + bundleState);
-
- for (OSGiBundleState aux : unresolved)
- {
- if (aux.getState() == Bundle.RESOLVED)
- {
- unresolvedBundles.remove(aux);
-
- try
- {
- // When resolved progress to INSTALLED
- String name = aux.getDeploymentUnit().getName();
- deployerClient.change(name, DeploymentStages.INSTALLED);
- }
- catch (DeploymentException ex)
- {
- log.error(ex);
- }
- }
- }
- }
- };
- new Thread(runnable).start();
- }
-
- public ControllerState getWhenRequired()
- {
- return new ControllerState(getStage().getName());
- }
-
- public ControllerState getDependentState()
- {
- return null;
- }
-
- public Object getBean()
- {
- return null;
- }
- }
-}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -180,7 +180,7 @@
public Bundle getBundle(long id)
{
checkValidBundleContext();
- AbstractBundleState bundleState = getBundleManager().getBundle(id);
+ AbstractBundleState bundleState = getBundleManager().getBundleById(id);
return bundleState != null ? bundleState.getBundleInternal() : null;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -419,7 +419,7 @@
if (id == 0)
throw new IllegalArgumentException("Cannot uninstall system bundle");
- OSGiBundleState state = (OSGiBundleState)getBundle(id);
+ OSGiBundleState state = (OSGiBundleState)getBundleById(id);
if (state == null)
throw new BundleException(bundle + " not installed");
@@ -537,26 +537,6 @@
}
/**
- * Get a bundle by id
- *
- * @param id the id of the bundle
- * @return the bundle or null if there is no bundle with that id
- */
- public AbstractBundleState getBundle(long id)
- {
- AbstractBundleState result = null;
- for (AbstractBundleState aux : bundles)
- {
- if (id == aux.getBundleId())
- {
- result = aux;
- break;
- }
- }
- return result;
- }
-
- /**
* Get the system bundle
*
* @return the system bundle
@@ -587,7 +567,7 @@
if (id == 0)
throw new IllegalArgumentException("Cannot get deployment from system bundle");
- OSGiBundleState bundleState = (OSGiBundleState)getBundle(id);
+ OSGiBundleState bundleState = (OSGiBundleState)getBundleById(id);
if (bundleState == null)
return null;
@@ -595,6 +575,47 @@
}
/**
+ * Get a bundle by id
+ *
+ * @param id the id of the bundle
+ * @return the bundle or null if there is no bundle with that id
+ */
+ public AbstractBundleState getBundleById(long id)
+ {
+ AbstractBundleState result = null;
+ for (AbstractBundleState aux : bundles)
+ {
+ if (id == aux.getBundleId())
+ {
+ result = aux;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Get a bundle by location
+ *
+ * @param location the location of the bundle
+ * @return the bundle or null if there is no bundle with that location
+ */
+ public AbstractBundleState getBundleByLocation(String location)
+ {
+ AbstractBundleState result = null;
+ for (AbstractBundleState aux : bundles)
+ {
+ String auxLocation = aux.getLocation();
+ if (auxLocation.equals(location))
+ {
+ result = aux;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /**
* Get all the bundles
*
* @return the bundles
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleState.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -99,14 +99,7 @@
return url.toString();
DeploymentUnit unit = getDeploymentUnit();
- if (unit instanceof VFSDeploymentUnit)
- {
- VFSDeploymentUnit vfsDeploymentUnit = (VFSDeploymentUnit)unit;
- VirtualFile root = vfsDeploymentUnit.getRoot();
- return root.getPathName();
- }
-
- return null;
+ return unit.getName();
}
public URL getEntry(String path)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiClassLoaderSystem.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -21,17 +21,34 @@
*/
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>
+ * OSGiClassLoaderSystem.
+ * <p>
*
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @author Thomas.Diesler(a)jboss.com
@@ -39,14 +56,21 @@
*/
public class OSGiClassLoaderSystem extends ClassLoaderSystem
{
+ private OSGiBundleManager bundleManager;
+
/**
* Create a new OSGiClassLoaderSystem.
+ *
* @throws IllegalArgumentException for a null bundle manager
*/
- public OSGiClassLoaderSystem()
+ public OSGiClassLoaderSystem(OSGiBundleManager bundleManager)
{
+ if (bundleManager == null)
+ throw new IllegalArgumentException("Null bundleManager");
+ this.bundleManager = bundleManager;
+
ClassLoaderDomain domain = getDefaultDomain();
-
+
domain.setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
AbstractJDKChecker.getExcluded().add(AbstractBundleState.class);
AbstractJDKChecker.getExcluded().add(OSGiBundleState.class);
@@ -57,9 +81,75 @@
{
return new ClassLoaderDomain(name);
}
-
+
+ @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/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/launch/OSGiFrameworkFactory.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -100,7 +100,7 @@
throw new IllegalStateException("Cannot obtain installed bean: " + OSGiBundleManager.BEAN_BUNDLE_MANAGER);
OSGiBundleManager manager = (OSGiBundleManager)managerContext.getTarget();
- OSGiSystemState sysBundle = (OSGiSystemState)manager.getBundle(0);
+ OSGiSystemState sysBundle = (OSGiSystemState)manager.getBundleById(0);
return new OSGiFramework(manager, sysBundle);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-09-10 04:35:14 UTC (rev 93337)
@@ -122,7 +122,7 @@
*/
protected Bundle getSystemBundle()
{
- return getBundleManager().getBundle(0).getBundleInternal();
+ return getBundleManager().getBundleById(0).getBundleInternal();
}
/**
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-09-10 01:03:11 UTC (rev 93336)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/resources/bootstrap/bootstrap.xml 2009-09-10 04:35:14 UTC (rev 93337)
@@ -140,7 +140,9 @@
********************************
-->
- <bean name="OSGiClassLoaderSystem" class="org.jboss.osgi.plugins.facade.classloading.OSGiClassLoaderSystem" />
+ <bean name="OSGiClassLoaderSystem" class="org.jboss.osgi.plugins.facade.classloading.OSGiClassLoaderSystem" >
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<bean name="OSGiClassLoaderDomain" class="org.jboss.osgi.plugins.facade.classloading.OSGiClassLoaderDomain" >
<constructor><parameter>OSGiClassLoaderDomain</parameter></constructor>
<property name="classLoaderSystem"><inject bean="OSGiClassLoaderSystem"/></property>
16 years, 10 months
JBoss-OSGI SVN: r93326 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade: service and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 15:26:16 -0400 (Wed, 09 Sep 2009)
New Revision: 93326
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
Log:
[JBOSGI-151] Cannot resolve circular dependencies
Simplify cache API
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 18:50:07 UTC (rev 93325)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 19:26:16 UTC (rev 93326)
@@ -144,20 +144,24 @@
PackageAttribute ourParameters = exportPackage;
PackageAttribute otherParameters = packageRequirement.getRequirePackage();
- OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance();
+ OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance(bundleState);
if (capabilityCache != null)
{
+ String packageName = packageRequirement.getName();
+
if (capabilityCache.isBlacklisted(packageRequirement, capModule))
{
- log.debug("Blacklisted: " + requirement + " " + capModule);
+ log.debug("Blacklisted: " + packageName + " " + getModuleName(capModule));
return false;
}
Module cachedModule = capabilityCache.getCachedModule(packageRequirement);
if (cachedModule != null)
{
- log.debug("Cached: " + requirement + " " + capModule);
- return cachedModule == capModule;
+ boolean isCached = (cachedModule == capModule);
+ if (isCached == true)
+ log.debug("Cached: " + packageName + " " + getModuleName(capModule));
+ return isCached;
}
}
@@ -221,6 +225,11 @@
return validMatch;
}
+ private String getModuleName(Module module)
+ {
+ return module.getName() + ":" + module.getVersion();
+ }
+
@Override
public boolean equals(Object obj)
{
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 18:50:07 UTC (rev 93325)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 19:26:16 UTC (rev 93326)
@@ -52,30 +52,13 @@
private Map<String, List<Module>> moduleAssociations = new HashMap<String, List<Module>>();
private Map<String, Module> blacklistedModules = new HashMap<String, Module>();
private Map<String, Module> endorsedModules = new HashMap<String, Module>();
- private static ThreadLocal<OSGiPackageCapabilityCache> threadLocal = new ThreadLocal<OSGiPackageCapabilityCache>();
- public static OSGiPackageCapabilityCache createInstance()
+ public static OSGiPackageCapabilityCache getInstance(OSGiBundleState bundleState)
{
- OSGiPackageCapabilityCache cacheInstance = new OSGiPackageCapabilityCache();
- threadLocal.set(cacheInstance);
- return cacheInstance;
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ return unit.getAttachment(OSGiPackageCapabilityCache.class);
}
- public static OSGiPackageCapabilityCache getInstance()
- {
- OSGiPackageCapabilityCache cacheInstance = threadLocal.get();
- return cacheInstance;
- }
-
- public void release()
- {
- threadLocal.remove();
- }
-
- private OSGiPackageCapabilityCache()
- {
- }
-
public void addModuleAssociation(PackageRequirement requirement, Module module)
{
String packageName = requirement.getName();
@@ -114,9 +97,8 @@
return blacklisted;
}
- public void endorseModuleAssociations(OSGiBundleState bundleState)
+ public void endorseModuleAssociations(Module module)
{
- Module module = assertModule(bundleState);
Map<String, Module> firstMatches = getMapOfFirstMatches(module);
if (firstMatches.isEmpty() == false)
{
@@ -127,9 +109,8 @@
moduleAssociations.clear();
}
- public void blacklistModuleAssociations(OSGiBundleState bundleState)
+ public void blacklistModuleAssociations(Module module)
{
- Module module = assertModule(bundleState);
Map<String, Module> firstMatches = getMapOfFirstMatches(module);
if (firstMatches.isEmpty() == false)
{
@@ -137,9 +118,11 @@
blacklistedModules.putAll(firstMatches);
}
moduleAssociations.clear();
+ }
+ public void resetResolvedDependencies(ControllerContext context)
+ {
StringBuffer message = new StringBuffer("Unresolved requirements ");
- ControllerContext context = assertControllerContext(bundleState);
DependencyInfo dependencyInfo = context.getDependencyInfo();
for (DependencyItem iDependOn : dependencyInfo.getIDependOn(RequirementDependencyItem.class))
{
@@ -161,24 +144,6 @@
log.info(message);
}
- private ControllerContext assertControllerContext(OSGiBundleState bundleState)
- {
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ControllerContext context = unit.getAttachment(ControllerContext.class);
- if (context == null)
- throw new IllegalStateException("Cannot obtain ControllerContext from: " + unit);
- return context;
- }
-
- private Module assertModule(OSGiBundleState bundleState)
- {
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- Module module = unit.getAttachment(Module.class);
- if (module == null)
- throw new IllegalStateException("Cannot obtain Module from: " + unit);
- return module;
- }
-
private Map<String, Module> getMapOfFirstMatches(Module module)
{
Map<String, Module> firstMatches = new HashMap<String, Module>();
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 18:50:07 UTC (rev 93325)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 19:26:16 UTC (rev 93326)
@@ -28,11 +28,13 @@
import java.util.List;
import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
import org.jboss.classloading.spi.metadata.Capability;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.classloading.spi.metadata.Requirement;
+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;
@@ -182,35 +184,35 @@
return true;
int resolved = 1;
-
- // Repeatedly try to resolve the bundles until no more bundle can be resolved
- OSGiPackageCapabilityCache cacheInstance = OSGiPackageCapabilityCache.createInstance();
- try
+
+ // Repeatedly try to resolve the bundles until no more bundles can be resolved
+ OSGiPackageCapabilityCache cacheInstance = new OSGiPackageCapabilityCache();
+ while (resolved > 0)
{
- while (resolved > 0)
+ resolved = 0;
+ Iterator<AbstractBundleState> it = unresolvedBundles.iterator();
+ while (it.hasNext())
{
- resolved = 0;
- Iterator<AbstractBundleState> it = unresolvedBundles.iterator();
- while (it.hasNext())
+ OSGiBundleState bundleState = assertBundleState(it.next());
+ ControllerContext context = assertControllerContext(bundleState);
+ Module module = assertModule(bundleState);
+
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ unit.addAttachment(OSGiPackageCapabilityCache.class, cacheInstance);
+
+ if (bundleManager.resolve(bundleState, false))
{
- OSGiBundleState bundleState = assertBundleState(it.next());
- if (bundleManager.resolve(bundleState, false))
- {
- cacheInstance.endorseModuleAssociations(bundleState);
- it.remove();
- resolved++;
- }
- else
- {
- cacheInstance.blacklistModuleAssociations(bundleState);
- }
+ cacheInstance.endorseModuleAssociations(module);
+ it.remove();
+ resolved++;
}
+ else
+ {
+ cacheInstance.blacklistModuleAssociations(module);
+ cacheInstance.resetResolvedDependencies(context);
+ }
}
}
- finally
- {
- cacheInstance.release();
- }
// Log unresolved bundles
for (AbstractBundleState aux : unresolvedBundles)
@@ -249,6 +251,24 @@
return (OSGiBundleState)abstractState;
}
+ private ControllerContext assertControllerContext(OSGiBundleState bundleState)
+ {
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ControllerContext context = unit.getAttachment(ControllerContext.class);
+ if (context == null)
+ throw new IllegalStateException("Cannot obtain ControllerContext from: " + unit);
+ return context;
+ }
+
+ private Module assertModule(OSGiBundleState bundleState)
+ {
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ Module module = unit.getAttachment(Module.class);
+ if (module == null)
+ throw new IllegalStateException("Cannot obtain Module from: " + unit);
+ return module;
+ }
+
private static class ExportedPackageImpl implements ExportedPackage
{
private Bundle bundle;
16 years, 10 months
JBoss-OSGI SVN: r93319 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade: service and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 12:57:02 -0400 (Wed, 09 Sep 2009)
New Revision: 93319
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
Log:
[JBOSGI-151] Cannot resolve circular dependencies
Bundles resolve, but optional packages might come from different modules
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 16:51:54 UTC (rev 93318)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 16:57:02 UTC (rev 93319)
@@ -154,10 +154,10 @@
}
Module cachedModule = capabilityCache.getCachedModule(packageRequirement);
- if (cachedModule == capModule)
+ if (cachedModule != null)
{
log.debug("Cached: " + requirement + " " + capModule);
- return true;
+ return cachedModule == capModule;
}
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 16:51:54 UTC (rev 93318)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 16:57:02 UTC (rev 93319)
@@ -51,7 +51,7 @@
private Map<String, List<Module>> moduleAssociations = new HashMap<String, List<Module>>();
private Map<String, Module> blacklistedModules = new HashMap<String, Module>();
- private Map<String, Module> cachedModules = new HashMap<String, Module>();
+ private Map<String, Module> endorsedModules = new HashMap<String, Module>();
private static ThreadLocal<OSGiPackageCapabilityCache> threadLocal = new ThreadLocal<OSGiPackageCapabilityCache>();
public static OSGiPackageCapabilityCache createInstance()
@@ -103,7 +103,7 @@
public Module getCachedModule(PackageRequirement requirement)
{
String packageName = requirement.getName();
- return cachedModules.get(packageName);
+ return endorsedModules.get(packageName);
}
public boolean isBlacklisted(PackageRequirement requirement, Module module)
@@ -114,20 +114,23 @@
return blacklisted;
}
- public void endorseModuleAssociations()
+ public void endorseModuleAssociations(OSGiBundleState bundleState)
{
- Map<String, Module> firstMatches = getMapOfFirstMatches(moduleAssociations);
+ Module module = assertModule(bundleState);
+ Map<String, Module> firstMatches = getMapOfFirstMatches(module);
if (firstMatches.isEmpty() == false)
{
log.info(getLogMessage("Endorse module associations", firstMatches));
- cachedModules.putAll(firstMatches);
+ endorsedModules.putAll(firstMatches);
}
+ blacklistedModules.clear();
moduleAssociations.clear();
}
-
+
public void blacklistModuleAssociations(OSGiBundleState bundleState)
{
- Map<String, Module> firstMatches = getMapOfFirstMatches(moduleAssociations);
+ Module module = assertModule(bundleState);
+ Map<String, Module> firstMatches = getMapOfFirstMatches(module);
if (firstMatches.isEmpty() == false)
{
log.info(getLogMessage("Blacklist module associations", firstMatches));
@@ -135,12 +138,10 @@
}
moduleAssociations.clear();
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ControllerContext context = unit.getAttachment(ControllerContext.class);
- DependencyInfo di = context.getDependencyInfo();
-
- StringBuffer message = new StringBuffer("Unresolved requirements: ");
- for (DependencyItem iDependOn : di.getIDependOn(RequirementDependencyItem.class))
+ StringBuffer message = new StringBuffer("Unresolved requirements ");
+ ControllerContext context = assertControllerContext(bundleState);
+ DependencyInfo dependencyInfo = context.getDependencyInfo();
+ for (DependencyItem iDependOn : dependencyInfo.getIDependOn(RequirementDependencyItem.class))
{
// Reset all resolved dependency items
// [JBKERNEL-54] DependencyItem inconsistency when multiple possible matches
@@ -160,15 +161,34 @@
log.info(message);
}
- private Map<String, Module> getMapOfFirstMatches(Map<String, List<Module>> moduleAssociations)
+ private ControllerContext assertControllerContext(OSGiBundleState bundleState)
{
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ControllerContext context = unit.getAttachment(ControllerContext.class);
+ if (context == null)
+ throw new IllegalStateException("Cannot obtain ControllerContext from: " + unit);
+ return context;
+ }
+
+ private Module assertModule(OSGiBundleState bundleState)
+ {
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ Module module = unit.getAttachment(Module.class);
+ if (module == null)
+ throw new IllegalStateException("Cannot obtain Module from: " + unit);
+ return module;
+ }
+
+ private Map<String, Module> getMapOfFirstMatches(Module module)
+ {
Map<String, Module> firstMatches = new HashMap<String, Module>();
for (Entry<String, List<Module>> entry : moduleAssociations.entrySet())
{
String packageName = entry.getKey();
List<Module> modules = entry.getValue();
- if (modules.size() > 1)
- firstMatches.put(packageName, modules.get(0));
+ Module other = modules.get(0);
+ if (module == other)
+ firstMatches.put(packageName, other);
}
return firstMatches;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 16:51:54 UTC (rev 93318)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 16:57:02 UTC (rev 93319)
@@ -196,7 +196,7 @@
OSGiBundleState bundleState = assertBundleState(it.next());
if (bundleManager.resolve(bundleState, false))
{
- cacheInstance.endorseModuleAssociations();
+ cacheInstance.endorseModuleAssociations(bundleState);
it.remove();
resolved++;
}
16 years, 10 months
JBoss-OSGI SVN: r93317 - projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 11:58:05 -0400 (Wed, 09 Sep 2009)
New Revision: 93317
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java
Log:
[JBOSGI-151] Cannot resolve circular dependencies
Ignore true cycle test
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java 2009-09-09 15:55:44 UTC (rev 93316)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java 2009-09-09 15:58:05 UTC (rev 93317)
@@ -21,8 +21,6 @@
*/
package org.jboss.test.osgi.jbosgi151;
-//$Id: $
-
import static org.junit.Assert.assertEquals;
import org.jboss.osgi.spi.framework.OSGiBootstrap;
@@ -113,7 +111,6 @@
}
@Test
- @Ignore
public void testCircularInstallCbeforeD() throws Exception
{
BundleContext sysContext = framework.getBundleContext();
@@ -141,7 +138,6 @@
}
@Test
- @Ignore
public void testCircularInstallDbeforeC() throws Exception
{
BundleContext sysContext = framework.getBundleContext();
@@ -169,6 +165,7 @@
}
@Test
+ @Ignore
public void testCompendiumAndHttpService() throws Exception
{
BundleContext sysContext = framework.getBundleContext();
16 years, 10 months
JBoss-OSGI SVN: r93316 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade: classloading and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 11:55:44 -0400 (Wed, 09 Sep 2009)
New Revision: 93316
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
Log:
[JBOSGI-151] Cannot resolve circular dependencies
Associate capability cache with PackageAdmin
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-09-09 15:55:10 UTC (rev 93315)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-09-09 15:55:44 UTC (rev 93316)
@@ -61,7 +61,6 @@
import org.jboss.osgi.plugins.facade.api.PackageAdminServicePlugin;
import org.jboss.osgi.plugins.facade.api.Plugin;
import org.jboss.osgi.plugins.facade.api.ServicePlugin;
-import org.jboss.osgi.plugins.facade.classloading.OSGiPackageCapabilityCache;
import org.jboss.osgi.plugins.filter.NoFilter;
import org.jboss.osgi.plugins.metadata.AbstractOSGiMetaData;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
@@ -640,12 +639,11 @@
ControllerState requiredState = context.getRequiredState();
DeploymentStage requiredStage = unit.getRequiredStage();
- OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance(bundleState);
try
{
+ log.info("Resolve: " + bundleState.getCanonicalName());
deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
deployerClient.checkComplete(unit.getName());
- capabilityCache.commitPreliminaryMatches();
bundleState.changeState(Bundle.RESOLVED);
return true;
}
@@ -654,8 +652,6 @@
unit.setRequiredStage(requiredStage);
context.setRequiredState(requiredState);
- capabilityCache.rollbackPreliminaryMatches();
-
if (errorOnFail)
throw new IllegalStateException("Error resolving bundle: " + bundleState, ex);
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 15:55:10 UTC (rev 93315)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-09 15:55:44 UTC (rev 93316)
@@ -144,20 +144,23 @@
PackageAttribute ourParameters = exportPackage;
PackageAttribute otherParameters = packageRequirement.getRequirePackage();
- OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance(bundleState);
- if (capabilityCache.isBlacklistedMatch(requirement, capModule))
+ OSGiPackageCapabilityCache capabilityCache = OSGiPackageCapabilityCache.getInstance();
+ if (capabilityCache != null)
{
- log.debug("Blacklisted: " + requirement + " " + capModule);
- return false;
+ if (capabilityCache.isBlacklisted(packageRequirement, capModule))
+ {
+ log.debug("Blacklisted: " + requirement + " " + capModule);
+ return false;
+ }
+
+ Module cachedModule = capabilityCache.getCachedModule(packageRequirement);
+ if (cachedModule == capModule)
+ {
+ log.debug("Cached: " + requirement + " " + capModule);
+ return true;
+ }
}
- Module cachedModule = capabilityCache.getCachedMatch(requirement);
- if (cachedModule == capModule)
- {
- log.debug("Cached: " + requirement + " " + capModule);
- return true;
- }
-
boolean validMatch = true;
// Check all the manadatory attributes are present
@@ -212,8 +215,8 @@
}
}
- if (validMatch == true && capModule == reqModule)
- capabilityCache.addPreliminaryMatch(requirement, capModule);
+ if (capabilityCache != null && validMatch == true)
+ capabilityCache.addModuleAssociation(packageRequirement, capModule);
return validMatch;
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 15:55:10 UTC (rev 93315)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 15:55:44 UTC (rev 93316)
@@ -21,12 +21,13 @@
*/
package org.jboss.osgi.plugins.facade.classloading;
-// $Id: $
-
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
import org.jboss.classloading.spi.metadata.Requirement;
@@ -38,9 +39,7 @@
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
/**
- * A package capabilty cache that helps the OSGiPackageCapability to decide
- * if a given requirement matches against a capability in the context of both
- * modules.
+ * A package capabilty cache that helps the OSGiPackageCapability to decide if a given requirement matches against a capability in the context of both modules.
*
* @author Thomas.Diesler(a)jboss.com
* @since 08-Sep-2009
@@ -49,72 +48,97 @@
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiPackageCapabilityCache.class);
-
- private OSGiBundleState bundleState;
- private Map<Requirement, Module> preliminaryMatches = new HashMap<Requirement, Module>();
- private Map<Requirement, Module> blacklistedMatches = new HashMap<Requirement, Module>();
- private Map<Requirement, Module> cachedMatches = new HashMap<Requirement, Module>();
- public static OSGiPackageCapabilityCache getInstance(OSGiBundleState bundleState)
+ private Map<String, List<Module>> moduleAssociations = new HashMap<String, List<Module>>();
+ private Map<String, Module> blacklistedModules = new HashMap<String, Module>();
+ private Map<String, Module> cachedModules = new HashMap<String, Module>();
+ private static ThreadLocal<OSGiPackageCapabilityCache> threadLocal = new ThreadLocal<OSGiPackageCapabilityCache>();
+
+ public static OSGiPackageCapabilityCache createInstance()
{
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- OSGiPackageCapabilityCache cacheInstance = unit.getAttachment(OSGiPackageCapabilityCache.class);
- if (cacheInstance == null)
- {
- cacheInstance = new OSGiPackageCapabilityCache(bundleState);
- unit.addAttachment(OSGiPackageCapabilityCache.class, cacheInstance);
- }
+ OSGiPackageCapabilityCache cacheInstance = new OSGiPackageCapabilityCache();
+ threadLocal.set(cacheInstance);
return cacheInstance;
}
-
- private OSGiPackageCapabilityCache(OSGiBundleState bundleState)
+
+ public static OSGiPackageCapabilityCache getInstance()
{
- if (bundleState == null)
- throw new IllegalArgumentException("Null bundle");
- this.bundleState = bundleState;
+ OSGiPackageCapabilityCache cacheInstance = threadLocal.get();
+ return cacheInstance;
}
-
- public Module getCachedMatch(Requirement requirement)
+
+ public void release()
{
- return cachedMatches.get(requirement);
+ threadLocal.remove();
}
-
- public void addPreliminaryMatch(Requirement requirement, Module module)
+
+ private OSGiPackageCapabilityCache()
{
- if (preliminaryMatches.containsKey(requirement) == false)
+ }
+
+ public void addModuleAssociation(PackageRequirement requirement, Module module)
+ {
+ String packageName = requirement.getName();
+ if (isBlacklisted(requirement, module))
+ throw new IllegalStateException("Cannot add blacklisted association: [" + packageName + "=" + getModuleName(module) + "]");
+
+ List<Module> modules = moduleAssociations.get(packageName);
+ if (modules == null)
{
- log.debug("Add " + requirement + " " + getModuleName(module));
- preliminaryMatches.put(requirement, module);
+ modules = new ArrayList<Module>();
+ moduleAssociations.put(packageName, modules);
+ modules.add(module);
}
+ else
+ {
+ Module firstMatch = modules.get(0);
+ if (firstMatch != module && modules.contains(module) == false)
+ {
+ log.info("Add [" + packageName + "=[" + getModuleName(firstMatch)+ " ... " + getModuleName(module) + "]]");
+ modules.add(module);
+ }
+ }
}
-
- public boolean isBlacklistedMatch(Requirement requirement, Module module)
+
+ public Module getCachedModule(PackageRequirement requirement)
{
- Module other = blacklistedMatches.get(requirement);
+ String packageName = requirement.getName();
+ return cachedModules.get(packageName);
+ }
+
+ public boolean isBlacklisted(PackageRequirement requirement, Module module)
+ {
+ String packageName = requirement.getName();
+ Module other = blacklistedModules.get(packageName);
boolean blacklisted = (module == other);
- if (blacklisted)
- log.info("Blacklisted " + requirement + " " + getModuleName(module));
-
return blacklisted;
}
-
- public void commitPreliminaryMatches()
+
+ public void endorseModuleAssociations()
{
- log.info(getLogMessage("Commit preliminary matches", preliminaryMatches));
- cachedMatches.putAll(preliminaryMatches);
- preliminaryMatches.clear();
+ Map<String, Module> firstMatches = getMapOfFirstMatches(moduleAssociations);
+ if (firstMatches.isEmpty() == false)
+ {
+ log.info(getLogMessage("Endorse module associations", firstMatches));
+ cachedModules.putAll(firstMatches);
+ }
+ moduleAssociations.clear();
}
- public void rollbackPreliminaryMatches()
+ public void blacklistModuleAssociations(OSGiBundleState bundleState)
{
- log.info(getLogMessage("Rollback preliminary matches", preliminaryMatches));
- blacklistedMatches.putAll(preliminaryMatches);
- preliminaryMatches.clear();
-
+ Map<String, Module> firstMatches = getMapOfFirstMatches(moduleAssociations);
+ if (firstMatches.isEmpty() == false)
+ {
+ log.info(getLogMessage("Blacklist module associations", firstMatches));
+ blacklistedModules.putAll(firstMatches);
+ }
+ moduleAssociations.clear();
+
DeploymentUnit unit = bundleState.getDeploymentUnit();
ControllerContext context = unit.getAttachment(ControllerContext.class);
DependencyInfo di = context.getDependencyInfo();
-
+
StringBuffer message = new StringBuffer("Unresolved requirements: ");
for (DependencyItem iDependOn : di.getIDependOn(RequirementDependencyItem.class))
{
@@ -131,19 +155,32 @@
message.append("\n " + unresolved);
}
}
-
+
// Log all unresolved dependency items
log.info(message);
}
- private String getLogMessage(String message, Map<Requirement, Module> matches)
+ private Map<String, Module> getMapOfFirstMatches(Map<String, List<Module>> moduleAssociations)
{
+ Map<String, Module> firstMatches = new HashMap<String, Module>();
+ for (Entry<String, List<Module>> entry : moduleAssociations.entrySet())
+ {
+ String packageName = entry.getKey();
+ List<Module> modules = entry.getValue();
+ if (modules.size() > 1)
+ firstMatches.put(packageName, modules.get(0));
+ }
+ return firstMatches;
+ }
+
+ private String getLogMessage(String message, Map<String, Module> matches)
+ {
StringBuffer buffer = new StringBuffer(message);
- for (Entry<Requirement, Module> entry : matches.entrySet())
+ for (Entry<String, Module> entry : matches.entrySet())
{
- Requirement requirement = entry.getKey();
+ String packageName = entry.getKey();
Module module = entry.getValue();
- buffer.append("\n " + requirement + " " + getModuleName(module));
+ buffer.append("\n [" + packageName + "=" + getModuleName(module) + "]");
}
return buffer.toString();
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 15:55:10 UTC (rev 93315)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-09 15:55:44 UTC (rev 93316)
@@ -42,6 +42,7 @@
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.jboss.osgi.plugins.facade.classloading.OSGiPackageCapabilityCache;
import org.jboss.osgi.plugins.facade.plugins.AbstractServicePluginImpl;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
@@ -180,22 +181,36 @@
if (unresolvedBundles.isEmpty())
return true;
+ int resolved = 1;
+
// Repeatedly try to resolve the bundles until no more bundle can be resolved
- int resolved = 1;
- while (resolved > 0)
+ OSGiPackageCapabilityCache cacheInstance = OSGiPackageCapabilityCache.createInstance();
+ try
{
- resolved = 0;
- Iterator<AbstractBundleState> it = unresolvedBundles.iterator();
- while (it.hasNext())
+ while (resolved > 0)
{
- OSGiBundleState bundleState = assertBundleState(it.next());
- if (bundleManager.resolve(bundleState, false))
+ resolved = 0;
+ Iterator<AbstractBundleState> it = unresolvedBundles.iterator();
+ while (it.hasNext())
{
- it.remove();
- resolved++;
+ OSGiBundleState bundleState = assertBundleState(it.next());
+ if (bundleManager.resolve(bundleState, false))
+ {
+ cacheInstance.endorseModuleAssociations();
+ it.remove();
+ resolved++;
+ }
+ else
+ {
+ cacheInstance.blacklistModuleAssociations(bundleState);
+ }
}
}
}
+ finally
+ {
+ cacheInstance.release();
+ }
// Log unresolved bundles
for (AbstractBundleState aux : unresolvedBundles)
16 years, 10 months
JBoss-OSGI SVN: r93313 - in projects/jboss-osgi/trunk: testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151 and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 09:32:56 -0400 (Wed, 09 Sep 2009)
New Revision: 93313
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/auto-install-template.xml
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/user-input-spec.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java
Log:
[JBOSGI-151] Add HttpService & Compendium test
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/auto-install-template.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/auto-install-template.xml 2009-09-09 13:31:19 UTC (rev 93312)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/auto-install-template.xml 2009-09-09 13:32:56 UTC (rev 93313)
@@ -21,7 +21,7 @@
</com.izforge.izpack.panels.UserInputPanel>
<com.izforge.izpack.panels.UserInputPanel>
<userInput>
- <entry key="jbossTargetServer" value="minimal" />
+ <entry key="jbossTargetServer" value="default" />
<entry key="jbossSelection" value="@target.container@" />
</userInput>
</com.izforge.izpack.panels.UserInputPanel>
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/user-input-spec.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/user-input-spec.xml 2009-09-09 13:31:19 UTC (rev 93312)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/installer/user-input-spec.xml 2009-09-09 13:32:56 UTC (rev 93313)
@@ -34,7 +34,7 @@
</spec>
</field>
<field type="text" variable="jbossTargetServer">
- <spec txt="Server:" size="15" set="minimal" />
+ <spec txt="Server:" size="15" set="default" />
</field>
</panel>
<panel order="3" id="jboss.home.select">
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java 2009-09-09 13:31:19 UTC (rev 93312)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGI151TestCase.java 2009-09-09 13:32:56 UTC (rev 93313)
@@ -36,6 +36,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.launch.Framework;
+import org.osgi.service.http.HttpService;
/**
* [JBOSGI-151] Cannot resolve circular dependencies
@@ -112,6 +113,7 @@
}
@Test
+ @Ignore
public void testCircularInstallCbeforeD() throws Exception
{
BundleContext sysContext = framework.getBundleContext();
@@ -139,6 +141,7 @@
}
@Test
+ @Ignore
public void testCircularInstallDbeforeC() throws Exception
{
BundleContext sysContext = framework.getBundleContext();
@@ -165,6 +168,29 @@
bundleC.uninstall();
}
+ @Test
+ public void testCompendiumAndHttpService() throws Exception
+ {
+ BundleContext sysContext = framework.getBundleContext();
+
+ Bundle httpBundle = sysContext.installBundle(getBundleLocation("bundles/org.apache.felix.http.jetty.jar"));
+ assertEquals("INSTALLED expected", Bundle.INSTALLED, httpBundle.getState());
+
+ Bundle cmpnBundle = sysContext.installBundle(getBundleLocation("bundles/org.osgi.compendium.jar"));
+ assertEquals("INSTALLED expected", Bundle.INSTALLED, cmpnBundle.getState());
+
+ httpBundle.start();
+ assertEquals("ACTIVE expected", Bundle.ACTIVE, httpBundle.getState());
+ assertEquals("RESOLVED expected", Bundle.RESOLVED, cmpnBundle.getState());
+
+ Class<?> classCmpn = cmpnBundle.loadClass(HttpService.class.getName());
+ Class<?> classHttp = httpBundle.loadClass(HttpService.class.getName());
+ assertEquals("Class for BeanB", classCmpn, classHttp);
+
+ httpBundle.uninstall();
+ cmpnBundle.uninstall();
+ }
+
private String getBundleLocation(String jarname)
{
return new OSGiTestHelper().getTestArchiveURL(jarname).toExternalForm();
16 years, 10 months
JBoss-OSGI SVN: r93312 - projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-09-09 09:31:19 -0400 (Wed, 09 Sep 2009)
New Revision: 93312
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
Log:
Add more debugging
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 12:04:45 UTC (rev 93311)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapabilityCache.java 2009-09-09 13:31:19 UTC (rev 93312)
@@ -21,8 +21,11 @@
*/
package org.jboss.osgi.plugins.facade.classloading;
+// $Id: $
+
import java.util.HashMap;
import java.util.Map;
+import java.util.Map.Entry;
import org.jboss.classloading.spi.dependency.Module;
import org.jboss.classloading.spi.dependency.RequirementDependencyItem;
@@ -31,9 +34,9 @@
import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.dependency.spi.DependencyItem;
import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.logging.Logger;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
-
/**
* A package capabilty cache that helps the OSGiPackageCapability to decide
* if a given requirement matches against a capability in the context of both
@@ -44,6 +47,9 @@
*/
public class OSGiPackageCapabilityCache
{
+ /** The log */
+ private static final Logger log = Logger.getLogger(OSGiPackageCapabilityCache.class);
+
private OSGiBundleState bundleState;
private Map<Requirement, Module> preliminaryMatches = new HashMap<Requirement, Module>();
private Map<Requirement, Module> blacklistedMatches = new HashMap<Requirement, Module>();
@@ -75,35 +81,75 @@
public void addPreliminaryMatch(Requirement requirement, Module module)
{
- preliminaryMatches.put(requirement, module);
+ if (preliminaryMatches.containsKey(requirement) == false)
+ {
+ log.debug("Add " + requirement + " " + getModuleName(module));
+ preliminaryMatches.put(requirement, module);
+ }
}
public boolean isBlacklistedMatch(Requirement requirement, Module module)
{
Module other = blacklistedMatches.get(requirement);
- return module == other;
+ boolean blacklisted = (module == other);
+ if (blacklisted)
+ log.info("Blacklisted " + requirement + " " + getModuleName(module));
+
+ return blacklisted;
}
public void commitPreliminaryMatches()
{
+ log.info(getLogMessage("Commit preliminary matches", preliminaryMatches));
cachedMatches.putAll(preliminaryMatches);
preliminaryMatches.clear();
}
-
+
public void rollbackPreliminaryMatches()
{
+ log.info(getLogMessage("Rollback preliminary matches", preliminaryMatches));
blacklistedMatches.putAll(preliminaryMatches);
preliminaryMatches.clear();
- // Reset all resolved dependency items
- // [JBKERNEL-54] DependencyItem inconsistency when multiple possible matches
DeploymentUnit unit = bundleState.getDeploymentUnit();
ControllerContext context = unit.getAttachment(ControllerContext.class);
DependencyInfo di = context.getDependencyInfo();
+
+ StringBuffer message = new StringBuffer("Unresolved requirements: ");
for (DependencyItem iDependOn : di.getIDependOn(RequirementDependencyItem.class))
{
+ // Reset all resolved dependency items
+ // [JBKERNEL-54] DependencyItem inconsistency when multiple possible matches
if (iDependOn.isResolved())
+ {
iDependOn.unresolved(context.getController());
+ }
+ else
+ {
+ RequirementDependencyItem reqdi = (RequirementDependencyItem)iDependOn;
+ Requirement unresolved = reqdi.getRequirement();
+ message.append("\n " + unresolved);
+ }
}
+
+ // Log all unresolved dependency items
+ log.info(message);
}
+
+ private String getLogMessage(String message, Map<Requirement, Module> matches)
+ {
+ StringBuffer buffer = new StringBuffer(message);
+ for (Entry<Requirement, Module> entry : matches.entrySet())
+ {
+ Requirement requirement = entry.getKey();
+ Module module = entry.getValue();
+ buffer.append("\n " + requirement + " " + getModuleName(module));
+ }
+ return buffer.toString();
+ }
+
+ private String getModuleName(Module module)
+ {
+ return module.getName() + ":" + module.getVersion();
+ }
}
16 years, 10 months