Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2005-05-26 00:23:54 +0000
committerThomas Watson2005-05-26 00:23:54 +0000
commit886eee4827ebd91ad5e72d0b5657bf84d407e24f (patch)
treeef6dcc549c5075501625efd9431580796c3a0091
parentcd42e68db4ed7ddeb4277be119f3ec205fea301e (diff)
downloadrt.equinox.framework-886eee4827ebd91ad5e72d0b5657bf84d407e24f.tar.gz
rt.equinox.framework-886eee4827ebd91ad5e72d0b5657bf84d407e24f.tar.xz
rt.equinox.framework-886eee4827ebd91ad5e72d0b5657bf84d407e24f.zip
Bug 96710 State.getBundle() returns an unresolved bundle
-rw-r--r--bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/service/resolver/State.java8
-rw-r--r--bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java42
2 files changed, 41 insertions, 9 deletions
diff --git a/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/service/resolver/State.java b/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/service/resolver/State.java
index 2eacd2c9b..c551df4ad 100644
--- a/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/service/resolver/State.java
+++ b/bundles/org.eclipse.osgi/core/adaptor/org/eclipse/osgi/service/resolver/State.java
@@ -97,9 +97,11 @@ public interface State {
/**
* Returns the bundle descriptor for the bundle with the given name and
- * version. null is returned if no such bundle is found in this state. If
- * the version argument is null then the bundle with the given name which
- * is resolve and/or has the highest version number is returned.
+ * version. A null value is returned if no such bundle is found in this state.
+ * A resolved bundle is always preferably returned over an unresolved bundle.
+ * If multiple bundles with the same resolution state are available, the bundle
+ * with the highest version number is returned if the <code>version<code> is
+ * null.
*
* @param symbolicName symbolic name of the bundle to query
* @param version version of the bundle to query. null matches any bundle
diff --git a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
index 90a6659ed..5855d33eb 100644
--- a/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
+++ b/bundles/org.eclipse.osgi/resolver/src/org/eclipse/osgi/internal/resolver/StateImpl.java
@@ -158,14 +158,44 @@ public abstract class StateImpl implements State {
return null;
}
- // TODO: this does not comply with the spec
public BundleDescription getBundle(String name, Version version) {
- for (Iterator i = bundleDescriptions.iterator(); i.hasNext();) {
- BundleDescription current = (BundleDescription) i.next();
- if (name.equals(current.getSymbolicName()) && (version == null || current.getVersion().equals(version)))
- return current;
+ BundleDescription[] allBundles = getBundles(name);
+ if (allBundles.length == 1)
+ return allBundles[0];
+
+ if (allBundles.length == 0)
+ return null;
+
+ BundleDescription unresolvedFound = null;
+ BundleDescription resolvedFound = null;
+ for (int i = 0; i < allBundles.length; i++) {
+ BundleDescription current = allBundles[i];
+ BundleDescription base;
+
+ if (current.isResolved())
+ base = resolvedFound;
+ else
+ base = unresolvedFound;
+
+ if (version == null || current.getVersion().equals(version)) {
+ if (base != null && (base.getVersion().compareTo(current.getVersion()) <= 0 || base.getBundleId() > current.getBundleId())) {
+ if (base == resolvedFound)
+ resolvedFound = current;
+ else
+ unresolvedFound = current;
+ } else {
+ if (current.isResolved())
+ resolvedFound = current;
+ else
+ unresolvedFound = current;
+ }
+
+ }
}
- return null;
+ if (resolvedFound != null)
+ return resolvedFound;
+
+ return unresolvedFound;
}
public long getTimeStamp() {

Back to the top