Removed impl-specific method for getting fragments and added a
utility method to get fragments using standard API, along with
other minor clean up. (FELIX-2950)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1153630 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
index 60be255..918a39c 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleImpl.java
@@ -509,9 +509,7 @@
BundleWiring wiring = br.getWiring();
if (wiring != null)
{
-// TODO: OSGi R4.3 - Technically, I think we can get the fragments using standard
-// R4.3 API once we get everything implemented.
- List<BundleRevision> fragments = ((BundleWiringImpl) wiring).getFragments();
+ List<BundleRevision> fragments = Util.getFragments(wiring);
if (fragments != null)
{
result.addAll(fragments);
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
index cc45988..84964d3 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleRevisionImpl.java
@@ -32,6 +32,7 @@
import org.apache.felix.framework.cache.Content;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.util.SecureAction;
+import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.util.manifestparser.ManifestParser;
import org.apache.felix.framework.util.manifestparser.R4Library;
import org.osgi.framework.Bundle;
@@ -282,7 +283,7 @@
{
// If the wiring has fragments, then close the old content path,
// since it'll need to be recalculated to include fragments.
- if (wiring.getFragments() != null)
+ if (!Util.getFragments(wiring).isEmpty())
{
for (int i = 0; (m_contentPath != null) && (i < m_contentPath.size()); i++)
{
@@ -359,7 +360,7 @@
List<Content> fragmentContents = null;
if (m_wiring != null)
{
- fragments = m_wiring.getFragments();
+ fragments = Util.getFragments(m_wiring);
fragmentContents = m_wiring.getFragmentContents();
}
if (fragments != null)
diff --git a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
index f691c35..a941a84 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
@@ -446,11 +446,6 @@
return m_importedPkgs.get(pkgName);
}
- List<BundleRevision> getFragments()
- {
- return m_fragments;
- }
-
List<Content> getFragmentContents()
{
return m_fragmentContents;
diff --git a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
index 76d5af0..290de06 100644
--- a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
+++ b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
@@ -22,6 +22,7 @@
import java.net.URL;
import java.util.*;
import org.apache.felix.framework.capabilityset.SimpleFilter;
+import org.apache.felix.framework.util.Util;
import org.osgi.framework.wiring.BundleRevision;
class EntryFilterEnumeration implements Enumeration
@@ -42,13 +43,10 @@
String filePattern, boolean recurse, boolean isURLValues)
{
m_revision = revision;
- if (includeFragments
- && (m_revision.getWiring() != null)
- && (((BundleWiringImpl) m_revision.getWiring()).getFragments() != null))
+ List<BundleRevision> fragments = Util.getFragments(revision.getWiring());
+ if (includeFragments && !fragments.isEmpty())
{
- m_revisions = new ArrayList(
- ((BundleWiringImpl) m_revision.getWiring()).getFragments().size() + 1);
- m_revisions.addAll(((BundleWiringImpl) m_revision.getWiring()).getFragments());
+ m_revisions = fragments;
}
else
{
diff --git a/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java b/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
index 28a4696..4a5aa36 100644
--- a/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/PackageAdminImpl.java
@@ -19,6 +19,7 @@
package org.apache.felix.framework;
import java.util.*;
+import org.apache.felix.framework.util.Util;
import org.apache.felix.framework.util.VersionRange;
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
@@ -171,8 +172,8 @@
if (revision.getWiring() != null)
{
List<BundleRevision> fragments =
- ((BundleWiringImpl) revision.getWiring()).getFragments();
- for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
+ Util.getFragments(revision.getWiring());
+ for (int i = 0; i < fragments.size(); i++)
{
Bundle b = fragments.get(i).getBundle();
if (b != null)
diff --git a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
index 90a4ea4..0e68de3 100644
--- a/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
+++ b/framework/src/main/java/org/apache/felix/framework/StatefulResolver.java
@@ -394,7 +394,6 @@
try
{
// Resolve the revision.
-// TODO: OSGi R4.3 - Shouldn't we still be passing in greedy attach fragments here?
wireMap = m_resolver.resolve(
m_resolverState, revisions, m_resolverState.getFragments());
}
@@ -982,7 +981,8 @@
{
if (wireMap != null)
{
- Iterator<Entry<BundleRevision, List<ResolverWire>>> iter = wireMap.entrySet().iterator();
+ Iterator<Entry<BundleRevision, List<ResolverWire>>> iter =
+ wireMap.entrySet().iterator();
// Iterate over the map to fire necessary RESOLVED events.
while (iter.hasNext())
{
@@ -991,10 +991,11 @@
// Fire RESOLVED events for all fragments.
List<BundleRevision> fragments =
- ((BundleWiringImpl) revision.getWiring()).getFragments();
- for (int i = 0; (fragments != null) && (i < fragments.size()); i++)
+ Util.getFragments(revision.getWiring());
+ for (int i = 0; i < fragments.size(); i++)
{
- m_felix.fireBundleEvent(BundleEvent.RESOLVED, fragments.get(i).getBundle());
+ m_felix.fireBundleEvent(
+ BundleEvent.RESOLVED, fragments.get(i).getBundle());
}
m_felix.fireBundleEvent(BundleEvent.RESOLVED, revision.getBundle());
}
@@ -1300,12 +1301,6 @@
{
// It we have a whitelist, then first filter out candidates
// from disallowed revisions.
-// TODO: OSGi R4.3 - It would be better if we could think of a way to do this
-// filtering that was less costly. One possibility it to do the check in
-// ResolverState.checkExecutionEnvironment(), since it will only need to
-// be done once for any black listed revision. However, as we move toward
-// OBR-like API, this is a non-standard call, so doing it here is the only
-// standard way of achieving it.
if (m_whitelist != null)
{
for (Iterator<BundleCapability> it = result.iterator(); it.hasNext(); )
@@ -1376,8 +1371,6 @@
{
// Next, try to resolve any native code, since the revision is
// not resolvable if its native code cannot be loaded.
-// TODO: OSGi R4.3 - Is it sufficient to just check declared native libs here?
-// List<R4Library> libs = ((BundleWiringImpl) revision.getWiring()).getNativeLibraries();
List<R4Library> libs = ((BundleRevisionImpl) revision).getDeclaredNativeLibraries();
if (libs != null)
{
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
index 484bec2..298cbb0 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/Candidates.java
@@ -1053,9 +1053,6 @@
System.out.println(" " + req + ": " + candidates);
}
}
-// TODO: OSGi R4.3 - Need to check what getWiring().getRequirements() returns
-// with respect to dynamic imports; is it the union of all declared
-// dynamic imports from fragments and host?
reqs = (br.getWiring() != null)
? Util.getDynamicRequirements(br.getWiring().getRequirements(null))
: Util.getDynamicRequirements(br.getDeclaredRequirements(null));
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
index cb2e751..15da660 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverImpl.java
@@ -41,7 +41,6 @@
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWire;
-// TODO: OSGi R4.3 - Make sure we have sufficient wrapping of caps/reqs.
public class ResolverImpl implements Resolver
{
private final Logger m_logger;
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
index 81ac47d..4f8420f 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/ResolverWireImpl.java
@@ -63,7 +63,6 @@
{
return m_req
+ " -> "
- + "[" + m_cap.getRevision() + " VIA " + m_provider + "]";
-// TODO: OSGi R4.3 - Simplify this message once we know wiring works.
+ + "[" + m_provider + "]";
}
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/util/Util.java b/framework/src/main/java/org/apache/felix/framework/util/Util.java
index d2b9151..f9a0719 100644
--- a/framework/src/main/java/org/apache/felix/framework/util/Util.java
+++ b/framework/src/main/java/org/apache/felix/framework/util/Util.java
@@ -22,6 +22,7 @@
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -38,6 +39,7 @@
import org.osgi.framework.wiring.BundleRequirement;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.BundleWire;
+import org.osgi.framework.wiring.BundleWiring;
public class Util
{
@@ -618,4 +620,30 @@
{
return ((revision.getTypes() & BundleRevision.TYPE_FRAGMENT) > 0);
}
+
+ public static List<BundleRevision> getFragments(BundleWiring wiring)
+ {
+ List<BundleRevision> fragments = Collections.EMPTY_LIST;
+ if (wiring != null)
+ {
+ List<BundleWire> wires = wiring.getProvidedWires(null);
+ if (wires != null)
+ {
+ for (BundleWire w : wires)
+ {
+ if (w.getCapability().getNamespace()
+ .equals(BundleRevision.HOST_NAMESPACE))
+ {
+ // Create array list if needed.
+ if (fragments.isEmpty())
+ {
+ fragments = new ArrayList<BundleRevision>();
+ }
+ fragments.add(w.getRequirerWiring().getRevision());
+ }
+ }
+ }
+ }
+ return fragments;
+ }
}
\ No newline at end of file
diff --git a/framework/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java b/framework/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java
index ccb8567..8925943 100644
--- a/framework/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java
@@ -24,7 +24,6 @@
import org.osgi.framework.wiring.BundleWire;
import org.osgi.framework.wiring.BundleWiring;
-// TODO: OSGi R4.3 - Should this be in framework package?
public class BundleWireImpl implements BundleWire
{
private final BundleRevision m_requirer;
@@ -75,7 +74,6 @@
{
return m_req
+ " -> "
- + "[" + m_cap.getRevision() + " VIA " + m_provider + "]";
-// TODO: OSGi R4.3 - Simplify this message once we know wiring works.
+ + "[" + m_provider + "]";
}
}
\ No newline at end of file