Author: thomas.diesler(a)jboss.com
Date: 2010-02-04 09:41:34 -0500 (Thu, 04 Feb 2010)
New Revision: 100417
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Revert support for circular dependencies. Supported at MC level needed
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2010-02-04
14:04:16 UTC (rev 100416)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/resolver/internal/basic/BasicResolverImpl.java 2010-02-04
14:41:34 UTC (rev 100417)
@@ -54,7 +54,7 @@
* @author thomas.diesler(a)jboss.com
* @since 10-Sep-2009
*/
-public class BasicResolverImpl extends AbstractResolver
+public class BasicResolverImpl extends AbstractResolver
{
/** The log */
private static final Logger log = Logger.getLogger(BasicResolverImpl.class);
@@ -74,7 +74,7 @@
AbstractBundleState bundleState = AbstractBundleState.assertBundleState(bundle);
if (bundleState instanceof OSGiBundleState == false)
return null;
-
+
return super.addBundle(bundle);
}
@@ -84,7 +84,7 @@
AbstractBundleState bundleState = AbstractBundleState.assertBundleState(bundle);
if (bundleState instanceof OSGiBundleState == false)
return null;
-
+
ResolverBundle removedBundle = super.removeBundle(bundle);
bundleCapabilitiesMap.remove(bundleState);
@@ -133,46 +133,36 @@
unresolvedBundles.add(OSGiBundleState.assertBundleState(aux));
}
- // Add the capabilities and requirements of the unresolved bundles
- for (OSGiBundleState bundleState : unresolvedBundles)
- {
- getBundleCapabilities(bundleState);
- getBundleRequirements(bundleState);
- }
+ int resolved = 1;
+ int resolveRounds = 0;
- // Get the list of all capabilities for all resolved and unresolved bundles
+ // Get the list of all capabilities
List<BundleCapability> allCapabilities = new
ArrayList<BundleCapability>();
for (List<BundleCapability> list : bundleCapabilitiesMap.values())
{
allCapabilities.addAll(list);
}
- // Reduce the capabilities for bundles that cannot be resolved
- for (OSGiBundleState bundleState : unresolvedBundles)
- {
- if (reduceCapabilities(allCapabilities, bundleState) == false)
- {
- bundleCapabilitiesMap.remove(bundleState);
- bundleRequirementsMap.remove(bundleState);
- }
- }
-
-
log.debug("START****************************************************************");
- log.debug("Unresolved bundles: " + unresolvedBundles);
-
List<OSGiBundleState> resolvedBundles = new
ArrayList<OSGiBundleState>();
- Iterator<OSGiBundleState> itUnresolved = unresolvedBundles.iterator();
- while (itUnresolved.hasNext())
+ while (resolved > 0 && unresolvedBundles.isEmpty() == false)
{
- OSGiBundleState bundleState = itUnresolved.next();
+ resolveRounds++;
- log.debug("Resolving: " + bundleState);
- if (resolveBundle(allCapabilities, bundleState))
- {
- logResolvedBundleInfo(bundleState);
+ log.debug("#" + resolveRounds + "
*****************************************************************");
+ log.debug("Unresolved bundles: " + unresolvedBundles);
- resolvedBundles.add(bundleState);
- itUnresolved.remove();
+ resolved = 0;
+ Iterator<OSGiBundleState> it = unresolvedBundles.iterator();
+ while (it.hasNext())
+ {
+ OSGiBundleState bundleState = it.next();
+ log.debug("Resolving: " + bundleState);
+ if (resolveBundle(allCapabilities, bundleState))
+ {
+ resolvedBundles.add(bundleState);
+ it.remove();
+ resolved++;
+ }
}
}
@@ -231,46 +221,19 @@
return result;
}
- private boolean reduceCapabilities(List<BundleCapability> allCapabilities,
OSGiBundleState bundleState)
+ private boolean resolveBundle(List<BundleCapability> allCapabilities,
OSGiBundleState bundle)
{
- boolean canResolve = true;
+ List<BundleCapability> bundleCapabilities = getBundleCapabilities(bundle);
+ List<BundleRequirement> bundleRequirements = getBundleRequirements(bundle);
- List<BundleRequirement> bundleRequirements =
getBundleRequirements(bundleState);
- for (BundleRequirement requirement : bundleRequirements)
- {
- PackageRequirement packreq = requirement.getPackageRequirement();
- BundleCapability bestMatch = findBestMatch(allCapabilities, requirement);
- if (bestMatch == null && packreq.isOptional() == false &&
packreq.isDynamic() == false)
- {
- log.debug("Cannot resolve: " + packreq);
- canResolve = false;
- break;
- }
- }
+ List<BundleCapability> futureCapabilities = new
ArrayList<BundleCapability>(allCapabilities);
+ futureCapabilities.addAll(bundleCapabilities);
- canResolve &= processRequiredBundle(bundleState, bundleRequirements);
- if (canResolve == false)
- {
- Iterator<BundleCapability> iterator = allCapabilities.iterator();
- while (iterator.hasNext())
- {
- BundleCapability next = iterator.next();
- OSGiBundleState exportingBundle = next.getExportingBundle();
- if (exportingBundle == bundleState)
- iterator.remove();
- }
- }
-
- return canResolve;
- }
-
- private boolean resolveBundle(List<BundleCapability> allCapabilities,
OSGiBundleState bundleState)
- {
- List<BundleRequirement> bundleRequirements =
getBundleRequirements(bundleState);
for (BundleRequirement requirement : bundleRequirements)
{
PackageRequirement packreq = requirement.getPackageRequirement();
- BundleCapability bestMatch = findBestMatch(allCapabilities, requirement);
+
+ BundleCapability bestMatch = findBestMatch(futureCapabilities, requirement);
if (bestMatch == null && packreq.isOptional() == false &&
packreq.isDynamic() == false)
return false;
@@ -281,28 +244,29 @@
Iterator<BundleRequirement> it = bundleRequirements.iterator();
while (it.hasNext())
{
- BundleRequirement requirement = it.next();
- PackageRequirement packreq = requirement.getPackageRequirement();
- if ((packreq.isOptional() || packreq.isDynamic()) &&
requirement.getWiredCapability() == null)
+ if (it.next().getWiredCapability() == null)
it.remove();
}
- if (processRequiredBundle(bundleState, bundleRequirements) == false)
+ if (processRequiredBundle(bundle, bundleCapabilities, bundleRequirements) ==
false)
return false;
+ allCapabilities.addAll(bundleCapabilities);
+ bundleCapabilitiesMap.put(bundle, bundleCapabilities);
+ bundleRequirementsMap.put(bundle, bundleRequirements);
+
+ logResolvedBundleInfo(bundle, bundleCapabilities, bundleRequirements);
+
return true;
}
/**
* Logs information about a resolved bundle
*/
- private void logResolvedBundleInfo(OSGiBundleState bundleState)
+ private void logResolvedBundleInfo(OSGiBundleState bundle,
List<BundleCapability> bundleCapabilities, List<BundleRequirement>
bundleRequirements)
{
- List<BundleCapability> bundleCapabilities =
getBundleCapabilities(bundleState);
- List<BundleRequirement> bundleRequirements =
getBundleRequirements(bundleState);
-
// Log the package wiring information
- StringBuffer message = new StringBuffer("Resolved: " + bundleState);
+ StringBuffer message = new StringBuffer("Resolved: " + bundle);
// Log the exports
int nameLengthMax = 0;
@@ -372,38 +336,24 @@
{
BundleCapability bestCapability = null;
OSGiBundleState bestExporter = null;
- int bestState = 0;
for (BundleCapability capability : capabilities)
{
if (capability.matches(requirement))
{
OSGiBundleState capExporter = capability.getExportingBundle();
- int capState = capExporter.getState();
- boolean updateMatch = false;
if (bestCapability == null)
{
- updateMatch = true;
+ bestCapability = capability;
+ bestExporter = bestCapability.getExportingBundle();
}
- // Update if we can wire to an already resolved bundle
- else if (bestState == Bundle.INSTALLED && (capState ==
Bundle.RESOLVED || capState == Bundle.ACTIVE))
- {
- updateMatch = true;
- }
-
// Update if we can wire to a bundle with lower id
else if (bestExporter.getBundleId() > capExporter.getBundleId())
{
- updateMatch = true;
- }
-
- if (updateMatch == true)
- {
bestCapability = capability;
bestExporter = bestCapability.getExportingBundle();
- bestState = bestExporter.getState();
}
}
}
@@ -415,25 +365,21 @@
*/
private List<BundleCapability> getBundleCapabilities(OSGiBundleState bundle)
{
- List<BundleCapability> result = bundleCapabilitiesMap.get(bundle);
- if (result == null)
- {
- bundleCapabilitiesMap.put(bundle, result = new
ArrayList<BundleCapability>());
+ List<BundleCapability> result = new ArrayList<BundleCapability>();
- OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ClassLoadingMetaData metadata = unit.getAttachment(ClassLoadingMetaData.class);
- List<Capability> capabilities =
metadata.getCapabilities().getCapabilities();
- if (capabilities != null)
+ List<Capability> capabilities =
metadata.getCapabilities().getCapabilities();
+ if (capabilities != null)
+ {
+ for (Capability capability : capabilities)
{
- for (Capability capability : capabilities)
+ if (capability instanceof PackageCapability)
{
- if (capability instanceof PackageCapability)
- {
- PackageCapability packageCapability = (PackageCapability)capability;
- result.add(new BundleCapability(bundle, packageCapability));
- }
+ PackageCapability packageCapability = (PackageCapability)capability;
+ result.add(new BundleCapability(bundle, packageCapability));
}
}
}
@@ -445,32 +391,29 @@
*/
private List<BundleRequirement> getBundleRequirements(OSGiBundleState bundle)
{
- List<BundleRequirement> result = bundleRequirementsMap.get(bundle);
- if (result == null)
- {
- bundleRequirementsMap.put(bundle, result = new
ArrayList<BundleRequirement>());
+ List<BundleRequirement> result = new ArrayList<BundleRequirement>();
- OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
- DeploymentUnit unit = bundleState.getDeploymentUnit();
- ClassLoadingMetaData classloadingMetaData =
unit.getAttachment(ClassLoadingMetaData.class);
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ DeploymentUnit unit = bundleState.getDeploymentUnit();
+ ClassLoadingMetaData classloadingMetaData =
unit.getAttachment(ClassLoadingMetaData.class);
- List<Requirement> requirements =
classloadingMetaData.getRequirements().getRequirements();
- if (requirements != null)
+ List<Requirement> requirements =
classloadingMetaData.getRequirements().getRequirements();
+ if (requirements != null)
+ {
+ for (Requirement requirement : requirements)
{
- for (Requirement requirement : requirements)
+ if (requirement instanceof PackageRequirement)
{
- if (requirement instanceof PackageRequirement)
- {
- PackageRequirement packageRequirement =
(PackageRequirement)requirement;
- result.add(new BundleRequirement(bundle, packageRequirement));
- }
+ PackageRequirement packageRequirement = (PackageRequirement)requirement;
+ result.add(new BundleRequirement(bundle, packageRequirement));
}
}
}
+
return result;
}
- private boolean processRequiredBundle(OSGiBundleState bundle,
List<BundleRequirement> bundleRequirements)
+ private boolean processRequiredBundle(OSGiBundleState bundle,
List<BundleCapability> bundleCapabilities, List<BundleRequirement>
bundleRequirements)
{
// The Require-Bundle header specifies that all exported packages from
// another bundle must be imported, effectively requiring the public interface
@@ -516,7 +459,8 @@
if (Constants.VISIBILITY_REEXPORT.equals(visibility))
{
- // [TODO] vivibility=reexport
+ BundleCapability newBundleCapability = new BundleCapability(bundle,
otherPackage);
+ bundleCapabilities.add(newBundleCapability);
}
}
}
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2010-02-04
14:04:16 UTC (rev 100416)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2010-02-04
14:41:34 UTC (rev 100417)
@@ -76,9 +76,6 @@
<parameter><inject bean="DeploymentRegistry"
/></parameter>
</constructor>
</bean>
- <bean name="OSGiBundleResolver"
class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
- <constructor><parameter><inject bean="OSGiBundleManager"
/></parameter></constructor>
- </bean>
<bean name="OSGiFrameworkEventsPlugin"
class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager"
/></parameter></constructor>
</bean>
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2010-02-04
14:04:16 UTC (rev 100416)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2010-02-04
14:41:34 UTC (rev 100417)
@@ -61,9 +61,6 @@
<parameter><inject bean="DeploymentRegistry"
/></parameter>
</constructor>
</bean>
- <bean name="OSGiBundleResolver"
class="org.jboss.osgi.framework.resolver.internal.basic.BasicResolverImpl">
- <constructor><parameter><inject bean="OSGiBundleManager"
/></parameter></constructor>
- </bean>
<bean name="OSGiFrameworkEventsPlugin"
class="org.jboss.osgi.framework.plugins.internal.FrameworkEventsPluginImpl">
<constructor><parameter><inject bean="OSGiBundleManager"
/></parameter></constructor>
</bean>