[jboss-osgi-commits] JBoss-OSGI SVN: r93372 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk: src/main/java/org/jboss/osgi/plugins/facade/classloading and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Thu Sep 10 17:12:16 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-09-10 17:12:15 -0400 (Thu, 10 Sep 2009)
New Revision: 93372
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleCapability.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleRequirement.java
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleExports.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleImports.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIsland.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIslands.java
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/pom.xml
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/service/PackageAdminImpl.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleResolver.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTestCase.java
Log:
Improve BundleREsolver to use wires
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/pom.xml 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/pom.xml 2009-09-10 21:12:15 UTC (rev 93372)
@@ -51,6 +51,7 @@
<version.jboss.osgi.jndi>1.0.1-SNAPSHOT</version.jboss.osgi.jndi>
<version.jboss.osgi.runtime.deployers>1.0.1-SNAPSHOT</version.jboss.osgi.runtime.deployers>
<version.jboss.osgi.spi>1.0.1-SNAPSHOT</version.jboss.osgi.spi>
+ <version.jboss.osgi.xml.binding>2.0.1-SNAPSHOT</version.jboss.osgi.xml.binding>
<version.jboss.microcontainer>2.0.9-SNAPSHOT</version.jboss.microcontainer>
<version.jboss.test>1.1.4.GA</version.jboss.test>
<version.osgi>r4v42-20090728</version.osgi>
@@ -259,6 +260,12 @@
<version>${version.jboss.osgi.jaxb}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.bundles</groupId>
+ <artifactId>jboss-osgi-xml-binding</artifactId>
+ <version>${version.jboss.osgi.xml.binding}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
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-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/classloading/OSGiPackageCapability.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -31,6 +31,7 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
import org.jboss.osgi.plugins.metadata.AbstractVersionRange;
+import org.jboss.osgi.plugins.resolver.BundleCapability;
import org.jboss.osgi.plugins.resolver.BundleResolver;
import org.jboss.osgi.spi.metadata.OSGiMetaData;
import org.jboss.osgi.spi.metadata.PackageAttribute;
@@ -148,9 +149,13 @@
if (bundleResolver != null)
{
// True if capModule matches with the resolved module
- Module resolvedModule = bundleResolver.getModule(this);
- if (resolvedModule != null)
- return (capModule == resolvedModule);
+ BundleCapability bundleCapability = bundleResolver.getMatchingCapability(reqModule, packageRequirement);
+ if (bundleCapability == null)
+ return false;
+
+ Module exportingModule = bundleCapability.getExportingModule();
+ PackageCapability packageCapability = bundleCapability.getPackageCapability();
+ return exportingModule == capModule && packageCapability == this;
}
boolean validMatch = true;
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-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/service/PackageAdminImpl.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -65,12 +65,13 @@
/** The log */
private static final Logger log = Logger.getLogger(PackageAdminImpl.class);
- private BundleResolver bundleResolver = new BundleResolver();
+ private BundleResolver bundleResolver;
private ServiceRegistration registration;
public PackageAdminImpl(OSGiBundleManager bundleManager)
{
super(bundleManager);
+ bundleResolver = new BundleResolver(bundleManager);
}
public void startService()
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleCapability.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleCapability.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleCapability.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.resolver;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.classloading.plugins.metadata.PackageCapability;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleState;
+import org.osgi.framework.Bundle;
+
+/**
+ * An association of bundle/capability.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 10-Sep-2009
+ */
+public class BundleCapability
+{
+ private Bundle bundle;
+ private PackageCapability packageCapability;
+ private List<BundleRequirement> wires;
+
+ BundleCapability(Bundle bundle, PackageCapability packageCapability)
+ {
+ this.bundle = bundle;
+ this.packageCapability = packageCapability;
+ }
+
+ public Bundle getExportingBundle()
+ {
+ return bundle;
+ }
+
+ public Module getExportingModule()
+ {
+ OSGiBundleState bundleState = BundleResolver.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ return unit.getAttachment(Module.class);
+ }
+
+ public PackageCapability getPackageCapability()
+ {
+ return packageCapability;
+ }
+
+ public List<BundleRequirement> getWires()
+ {
+ return Collections.unmodifiableList(wires);
+ }
+
+ void addWire(BundleRequirement bundleRequirement)
+ {
+ if (wires == null)
+ wires = new ArrayList<BundleRequirement>();
+
+ wires.add(bundleRequirement);
+ }
+
+ boolean matches(BundleRequirement bundleRequirement)
+ {
+ String capName = packageCapability.getName();
+ String reqName = bundleRequirement.getPackageRequirement().getName();
+ if (capName.equals(reqName) == false)
+ return false;
+
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleCapability.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleExports.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleExports.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleExports.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -1,49 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.plugins.resolver;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-
-/**
- * An abstraction of bundle exports.
- *
- * @author thomas.diesler at jboss.com
- * @since 10-Sep-2009
- */
-public class BundleExports
-{
- private Set<PackageCapability> exports = new HashSet<PackageCapability>();
-
- void addExport(PackageCapability capability)
- {
- exports.add(capability);
- }
-
- public Set<PackageCapability> getPackageCapabilities()
- {
- return Collections.unmodifiableSet(exports);
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleImports.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleImports.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleImports.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -1,50 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.plugins.resolver;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-
-/**
- * An abstraction of bundle imports.
- *
- * @author thomas.diesler at jboss.com
- * @since 10-Sep-2009
- */
-public class BundleImports
-{
- private Set<PackageRequirement> imports = new HashSet<PackageRequirement>();
-
- void addImport(PackageRequirement requirement)
- {
- imports.add(requirement);
- }
-
- public Set<PackageRequirement> getPackageRequiremens()
- {
- return Collections.unmodifiableSet(imports);
- }
-
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIsland.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIsland.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIsland.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -1,132 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.plugins.resolver;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.logging.Logger;
-import org.osgi.framework.Bundle;
-
-/**
- * A bundle island is a collection of bundles that are wired together.
- *
- * @author thomas.diesler at jboss.com
- * @since 10-Sep-2009
- */
-public class BundleIsland
-{
- /** The log */
- private static final Logger log = Logger.getLogger(BundleIsland.class);
-
- private Set<Bundle> bundles = new HashSet<Bundle>();
- private Map<PackageCapability, List<Bundle>> allExports = new HashMap<PackageCapability, List<Bundle>>();
-
- BundleIsland(Bundle bundle)
- {
- log.info("New island: " + bundle);
-
- BundleExports bundleExports = BundleResolver.getBundleExports(bundle);
- for (PackageCapability export : bundleExports.getPackageCapabilities())
- {
- ArrayList<Bundle> list = new ArrayList<Bundle>();
- allExports.put(export, list);
- list.add(bundle);
- }
-
- bundles.add(bundle);
- }
-
- boolean addBundle(Bundle bundle)
- {
- log.info("Try to add " + bundle + " to " + bundles);
-
- Set<PackageCapability> futureExports = new HashSet<PackageCapability>(allExports.keySet());
- BundleExports bundleExports = BundleResolver.getBundleExports(bundle);
- futureExports.addAll(bundleExports.getPackageCapabilities());
-
- BundleImports bundleImports = BundleResolver.getBundleImports(bundle);
- Set<PackageRequirement> requirements = bundleImports.getPackageRequiremens();
- if (BundleResolver.matchImportsToExports(futureExports, requirements) == false)
- return false;
-
- for (PackageCapability export : bundleExports.getPackageCapabilities())
- {
- List<Bundle> list = allExports.get(export);
- if (list == null)
- {
- list = new ArrayList<Bundle>();
- allExports.put(export, list);
- }
- list.add(bundle);
- }
-
- bundles.add(bundle);
-
- log.info("Added: " + bundles);
-
- return true;
- }
-
- void removeBundle(Bundle bundle)
- {
- Set<PackageCapability> keySet = new HashSet<PackageCapability>(allExports.keySet());
- for (PackageCapability key : keySet)
- {
- List<Bundle> list = allExports.get(key);
- if (list.size() == 1 && list.contains(bundle))
- allExports.remove(key);
- else
- list.remove(bundle);
- }
- bundles.remove(bundle);
- }
-
- Bundle getExportingBundle(PackageCapability capability)
- {
- List<Bundle> list = allExports.get(capability);
- return (list != null ? list.get(0) : null);
- }
-
- boolean hasBundle(Bundle bundle)
- {
- return bundles.contains(bundle);
- }
-
- boolean hasExport(PackageCapability capability)
- {
- List<Bundle> list = allExports.get(capability);
- return (list != null && list.size() > 0);
- }
-
- @Override
- public String toString()
- {
- return "BundleIsland: " + bundles;
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIslands.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIslands.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleIslands.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.plugins.resolver;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.jboss.classloading.plugins.metadata.PackageCapability;
-import org.jboss.classloading.plugins.metadata.PackageRequirement;
-import org.jboss.logging.Logger;
-import org.osgi.framework.Bundle;
-
-/**
- * The collection of bundle islands
- *
- * @author thomas.diesler at jboss.com
- * @since 10-Sep-2009
- */
-public class BundleIslands
-{
- /** The log */
- private static final Logger log = Logger.getLogger(BundleIslands.class);
-
- private Set<BundleIsland> bundleIslands = new HashSet<BundleIsland>();
-
- public Set<BundleIsland> getBundleIslands()
- {
- return Collections.unmodifiableSet(bundleIslands);
- }
-
- BundleIsland addBundle(Bundle bundle)
- {
- for (BundleIsland bundleIsland : bundleIslands)
- {
- if (bundleIsland.addBundle(bundle))
- return bundleIsland;
- }
-
- if (isIsland(bundle))
- {
- BundleIsland bundleIsland = new BundleIsland(bundle);
- bundleIslands.add(bundleIsland);
- return bundleIsland;
- }
-
- return null;
- }
-
- BundleIsland getBundleIsland(Bundle bundle)
- {
- for (BundleIsland bundleIsland : bundleIslands)
- {
- if (bundleIsland.hasBundle(bundle))
- return bundleIsland;
- }
- return null;
- }
-
- boolean isIsland(Bundle bundle)
- {
- log.info("Tying is island: " + bundle);
-
- BundleExports bundleExports = BundleResolver.getBundleExports(bundle);
- Set<PackageCapability> capabilities = bundleExports.getPackageCapabilities();
-
- BundleImports bundleImports = BundleResolver.getBundleImports(bundle);
- Set<PackageRequirement> requirements = bundleImports.getPackageRequiremens();
-
- boolean isIsland = BundleResolver.matchImportsToExports(capabilities, requirements);
- return isIsland;
- }
-
- public BundleIsland getBundleIsland(PackageCapability capability)
- {
- for (BundleIsland bundleIsland : bundleIslands)
- {
- if (bundleIsland.hasExport(capability))
- return bundleIsland;
- }
- return null;
- }
-}
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleRequirement.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleRequirement.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleRequirement.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.plugins.resolver;
+
+import org.jboss.classloading.plugins.metadata.PackageRequirement;
+import org.osgi.framework.Bundle;
+
+/**
+ * An association of bundle/requirement.
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 10-Sep-2009
+ */
+public class BundleRequirement
+{
+ private Bundle bundle;
+ private PackageRequirement packageRequirement;
+ private BundleCapability wire;
+
+ BundleRequirement(Bundle bundle, PackageRequirement packageRequirement)
+ {
+ this.bundle = bundle;
+ this.packageRequirement = packageRequirement;
+ }
+
+ void setWire(BundleCapability bundleCapability)
+ {
+ wire = bundleCapability;
+ if (bundleCapability != null)
+ bundleCapability.addWire(this);
+ }
+
+ public BundleCapability getWire()
+ {
+ return wire;
+ }
+
+ public Bundle getImportingBundle()
+ {
+ return bundle;
+ }
+
+ public PackageRequirement getPackageRequirement()
+ {
+ return packageRequirement;
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleRequirement.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleResolver.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleResolver.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/resolver/BundleResolver.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -22,22 +22,23 @@
package org.jboss.osgi.plugins.resolver;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.jboss.classloading.plugins.metadata.PackageCapability;
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.Capability;
import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.classloading.spi.metadata.Requirement;
-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.AbstractBundleState;
+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.osgi.framework.Bundle;
@@ -45,12 +46,10 @@
/**
* The bundle resolver.
*
- * The BundleResolver has the notion of bundle islands, which maintain sets of
- * bundles that are wired together.
- *
- * [TODO] versions
- * [TODO] import/export properties
- *
+ * The BundleResolver has the notion of bundle islands, which maintain sets of bundles that are wired together.
+ *
+ * [TODO] versions [TODO] import/export properties
+ *
* @author thomas.diesler at jboss.com
* @since 10-Sep-2009
*/
@@ -59,8 +58,16 @@
/** The log */
private static final Logger log = Logger.getLogger(BundleResolver.class);
- private BundleIslands bundleIslands = new BundleIslands();
+ private OSGiBundleManager bundleManager;
+ private Set<BundleCapability> allCapabilities = new HashSet<BundleCapability>();
+ private Map<Bundle, Set<BundleCapability>> bundleCapabilitiesMap = new HashMap<Bundle, Set<BundleCapability>>();
+ private Map<Bundle, Set<BundleRequirement>> bundleRequirementsMap = new HashMap<Bundle, Set<BundleRequirement>>();
+ public BundleResolver(OSGiBundleManager bundleManager)
+ {
+ this.bundleManager = bundleManager;
+ }
+
public boolean resolveBundles(List<Bundle> unresolvedBundles)
{
if (unresolvedBundles == null)
@@ -70,27 +77,27 @@
int resolveRounds = 0;
// Normalize the bundles to OSGiBundleState instances
- for (int i=0; i < unresolvedBundles.size(); i++)
+ for (int i = 0; i < unresolvedBundles.size(); i++)
{
Bundle bundle = unresolvedBundles.get(i);
unresolvedBundles.set(i, assertBundleState(bundle));
}
-
+
unresolvedBundles = new ArrayList<Bundle>(unresolvedBundles);
while (resolved > 0)
{
resolveRounds++;
- log.info("#" + resolveRounds + " *****************************************************************");
- log.info("Unresolved bundles: " + unresolvedBundles);
+ log.debug("#" + resolveRounds + " *****************************************************************");
+ log.debug("Unresolved bundles: " + unresolvedBundles);
resolved = 0;
Iterator<Bundle> it = unresolvedBundles.iterator();
while (it.hasNext())
{
Bundle bundle = it.next();
- log.info("Resolving: " + bundle);
- if (bundleIslands.addBundle(bundle) != null)
+ log.debug("Resolving: " + bundle);
+ if (resolveBundle((OSGiBundleState)bundle))
{
it.remove();
resolved++;
@@ -100,120 +107,171 @@
break;
}
- log.info("* END *****************************************************************");
- for (BundleIsland island : bundleIslands.getBundleIslands())
- {
- log.info(island);
- }
- log.info("Unresolved bundles: " + unresolvedBundles);
+ log.debug("END *****************************************************************");
+ log.debug("Unresolved bundles: " + unresolvedBundles);
boolean allResolved = unresolvedBundles.isEmpty();
return allResolved;
}
- public Module getModule(PackageCapability capability)
+ private boolean resolveBundle(OSGiBundleState bundle)
{
- BundleIsland bundleIsland = bundleIslands.getBundleIsland(capability);
- if (bundleIsland == null)
- return null;
+ Set<BundleCapability> bundleCapabilities = getBundleCapabilities(bundle);
+ Set<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
+
+ Set<BundleCapability> futureCapabilities = new HashSet<BundleCapability>(allCapabilities);
+ futureCapabilities.addAll(bundleCapabilities);
+
+ int nameLengthMax = 0;
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ PackageRequirement packreq = requirement.getPackageRequirement();
+ nameLengthMax = Math.max(nameLengthMax, packreq.getName().length());
+
+ BundleCapability bestMatch = findBestMatch(futureCapabilities, requirement);
+ if (bestMatch == null && packreq.isOptional() == false && packreq.isDynamic() == false)
+ return false;
+
+ requirement.setWire(bestMatch);
+ }
- OSGiBundleState bundle = (OSGiBundleState)bundleIsland.getExportingBundle(capability);
- if (bundle == null)
- return null;
+ // Remove optional or dynamic requirements that don't have a wire
+ Iterator<BundleRequirement> it = bundleRequirements.iterator();
+ while (it.hasNext())
+ {
+ if (it.next().getWire() == null)
+ it.remove();
+ }
+
+ allCapabilities.addAll(bundleCapabilities);
+ bundleCapabilitiesMap.put(bundle, bundleCapabilities);
+ bundleRequirementsMap.put(bundle, bundleRequirements);
+
+ // Log the package wiring information
+ StringBuffer message = new StringBuffer("Resolved: " + bundle);
+ for (BundleRequirement requirement : bundleRequirements)
+ {
+ String packageName = requirement.getPackageRequirement().getName();
+ message.append("\n " + packageName + ": ");
+ for (int i = 0; i < (nameLengthMax - packageName.length()); i++)
+ message.append(" ");
- DeploymentUnit unit = bundle.getDeploymentUnit();
- return unit.getAttachment(Module.class);
+ BundleCapability wire = requirement.getWire();
+ message.append(wire != null ? wire.getExportingBundle() : "null");
+ }
+ log.debug(message);
+
+ return true;
}
- public Bundle getBundle(PackageCapability capability)
+ public void removeBundle(Bundle bundle)
{
- BundleIsland bundleIsland = bundleIslands.getBundleIsland(capability);
- if (bundleIsland == null)
- return null;
-
- OSGiBundleState bundle = (OSGiBundleState)bundleIsland.getExportingBundle(capability);
- return bundle.getBundle();
+ OSGiBundleState bundleState = assertBundleState(bundle);
+ Iterator<BundleCapability> it = allCapabilities.iterator();
+ while (it.hasNext())
+ {
+ BundleCapability aux = it.next();
+ if (aux.getExportingBundle().equals(bundleState))
+ it.remove();
+ }
+ bundleCapabilitiesMap.remove(bundleState);
+ bundleRequirementsMap.remove(bundleState);
}
-
- public void removeBundle(Bundle bundle)
+
+ public BundleCapability getMatchingCapability(Module module, PackageRequirement packageRequirement)
{
- bundle = assertBundleState(bundle);
- BundleIsland bundleIsland = bundleIslands.getBundleIsland(bundle);
- if (bundleIsland != null)
- bundleIsland.removeBundle(bundle);
+ String location = module.getContextName();
+ AbstractBundleState bundle = bundleManager.getBundleByLocation(location);
+ if (bundle == null)
+ return null;
+
+ Set<BundleRequirement> requirements = bundleRequirementsMap.get(bundle);
+ if (requirements == null)
+ return null;
+
+ BundleCapability result = null;
+ for (BundleRequirement req : requirements)
+ {
+ if (req.getPackageRequirement() == packageRequirement)
+ {
+ result = req.getWire();
+ break;
+ }
+ }
+
+ return result;
}
-
- static boolean matchImportsToExports(Set<PackageCapability> capabilities, Set<PackageRequirement> requirements)
+
+ private BundleCapability findBestMatch(Set<BundleCapability> capabilities, BundleRequirement requirement)
{
- Set<String> exportNames = new HashSet<String>();
- for (PackageCapability capability : capabilities)
- exportNames.add(capability.getName());
-
- Set<String> unsatisfiedImports = new HashSet<String>();
- for (PackageRequirement requirement : requirements)
+ BundleCapability result = null;
+ for (BundleCapability capability : capabilities)
{
- if (requirement.isOptional() == false)
+ if (capability.matches(requirement))
{
- String packageName = requirement.getName();
- if (exportNames.contains(packageName) == false)
- unsatisfiedImports.add(packageName);
+ if (result == null)
+ {
+ result = capability;
+ }
+ else
+ {
+ // [TODO] handle multiple matches
+ }
}
}
-
- boolean isMatch = unsatisfiedImports.isEmpty();
- if (isMatch == false)
- log.info("Unsatisfied imports: " + unsatisfiedImports);
-
- return isMatch;
+ return result;
}
- static BundleExports getBundleExports(Bundle bundle)
+ /**
+ * Get the set of bundle capabilities
+ */
+ private Set<BundleCapability> getBundleCapabilities(Bundle bundle)
{
- OSGiBundleState bundleState = BundleResolver.assertBundleState(bundle);
+ Set<BundleCapability> result = new HashSet<BundleCapability>();
+
+ OSGiBundleState bundleState = assertBundleState(bundle);
DeploymentUnit unit = bundleState.getDeploymentUnit();
-
- BundleExports bundleExports = unit.getAttachment(BundleExports.class);
- if (bundleExports == null)
+ ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
+
+ List<Capability> capabilities = metadata.getCapabilities().getCapabilities();
+ if (capabilities != null)
{
- bundleExports = new BundleExports();
- ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
- for (Capability capability : metadata.getCapabilities().getCapabilities())
+ for (Capability capability : capabilities)
{
if (capability instanceof PackageCapability)
{
PackageCapability packageCapability = (PackageCapability)capability;
- bundleExports.addExport(packageCapability);
+ result.add(new BundleCapability(bundle, packageCapability));
}
}
- unit.addAttachment(BundleExports.class, bundleExports);
}
-
- return bundleExports;
+ return result;
}
+
+ /**
+ * Get the set of bundle requirements
+ */
+ private Set<BundleRequirement> getBundleRequirements(Bundle bundle)
+ {
+ Set<BundleRequirement> result = new HashSet<BundleRequirement>();
- static BundleImports getBundleImports(Bundle bundle)
- {
- OSGiBundleState bundleState = BundleResolver.assertBundleState(bundle);
+ OSGiBundleState bundleState = assertBundleState(bundle);
DeploymentUnit unit = bundleState.getDeploymentUnit();
-
- BundleImports bundleImports = unit.getAttachment(BundleImports.class);
- if (bundleImports == null)
+ ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
+
+ List<Requirement> requirements = metadata.getRequirements().getRequirements();
+ if (requirements != null)
{
- bundleImports = new BundleImports();
- DependencyInfo dependencyInfo = unit.getDependencyInfo();
- for (DependencyItem item : dependencyInfo.getIDependOn(RequirementDependencyItem.class))
+ for (Requirement requirement : requirements)
{
- RequirementDependencyItem reqdi = (RequirementDependencyItem)item;
- Requirement requirement = reqdi.getRequirement();
if (requirement instanceof PackageRequirement)
{
PackageRequirement packageRequirement = (PackageRequirement)requirement;
- bundleImports.addImport(packageRequirement);
+ result.add(new BundleRequirement(bundle, packageRequirement));
}
}
- unit.addAttachment(BundleImports.class, bundleImports);
}
- return bundleImports;
+ return result;
}
static OSGiBundleState assertBundleState(Bundle bundle)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTestCase.java 2009-09-10 19:30:15 UTC (rev 93371)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/resolver/BundleResolverTestCase.java 2009-09-10 21:12:15 UTC (rev 93372)
@@ -79,7 +79,7 @@
bundles.add(bundle);
}
- BundleResolver bundleResolver = new BundleResolver();
+ BundleResolver bundleResolver = new BundleResolver(null);
boolean resolved = bundleResolver.resolveBundles(bundles);
assertTrue("All bundles resolved", resolved);
More information about the jboss-osgi-commits
mailing list