Modify fragment merging aglorithm to properly update dependent map
so that all caps/reqs get replaced by their corresponding synthesized
cap/req from the synthesized host module. If you don't do this, then
hosts with inter-dependencies can get invalid wires. (FELIX-3043)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1147238 13f79535-47bb-0310-9956-ffa450edef68
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 65321a3..d0a3381 100644
--- a/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/BundleWiringImpl.java
@@ -35,13 +35,12 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;
import org.apache.felix.framework.cache.JarContent;
import org.apache.felix.framework.cache.Content;
-import org.apache.felix.framework.resolver.HostedCapability;
-import org.apache.felix.framework.resolver.HostedRequirement;
import org.apache.felix.framework.resolver.ResolveException;
import org.apache.felix.framework.resolver.ResourceNotFoundException;
import org.apache.felix.framework.util.CompoundEnumeration;
@@ -50,7 +49,6 @@
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.apache.felix.framework.wiring.BundleCapabilityImpl;
import org.apache.felix.framework.wiring.BundleRequirementImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
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 7475ed6..c81e286 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
@@ -711,14 +711,21 @@
// really be attached to the original host, not the wrapper.
if (!c.getNamespace().equals(BundleRevision.HOST_NAMESPACE))
{
- Set<BundleRequirement> dependents =
- m_dependentMap.get(((HostedCapability) c).getDeclaredCapability());
+ BundleCapability origCap =
+ ((HostedCapability) c).getOriginalCapability();
+ // Note that you might think we could remove the original cap
+ // from the dependent map, but you can't since it may come from
+ // a fragment that is attached to multiple hosts, so each host
+ // will need to make their own copy.
+ Set<BundleRequirement> dependents = m_dependentMap.get(origCap);
if (dependents != null)
{
+ dependents = new HashSet<BundleRequirement>(dependents);
+ m_dependentMap.put(c, dependents);
for (BundleRequirement r : dependents)
{
Set<BundleCapability> cands = m_candidateMap.get(r);
- cands.remove(((HostedCapability) c).getDeclaredCapability());
+ cands.remove(origCap);
cands.add(c);
}
}
@@ -726,15 +733,20 @@
}
// Copy candidates for fragment requirements to the host.
- // This doesn't record the reverse dependency, but that
- // information should not be needed at this point anymore.
for (BundleRequirement r : hostRevision.getDeclaredRequirements(null))
{
- SortedSet<BundleCapability> cands =
- m_candidateMap.get(((HostedRequirement) r).getDeclaredRequirement());
+ BundleRequirement origReq =
+ ((HostedRequirement) r).getOriginalRequirement();
+ SortedSet<BundleCapability> cands = m_candidateMap.get(origReq);
if (cands != null)
{
m_candidateMap.put(r, new TreeSet<BundleCapability>(cands));
+ for (BundleCapability cand : cands)
+ {
+ Set<BundleRequirement> dependents = m_dependentMap.get(cand);
+ dependents.remove(origReq);
+ dependents.add(r);
+ }
}
}
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
index f24ada3..dbdad1c 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedCapability.java
@@ -68,7 +68,7 @@
return hash;
}
- public BundleCapabilityImpl getDeclaredCapability()
+ public BundleCapabilityImpl getOriginalCapability()
{
return m_cap;
}
diff --git a/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
index 7af7a14..58dadce 100644
--- a/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
+++ b/framework/src/main/java/org/apache/felix/framework/resolver/HostedRequirement.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -67,7 +67,7 @@
return hash;
}
- public BundleRequirementImpl getDeclaredRequirement()
+ public BundleRequirementImpl getOriginalRequirement()
{
return m_req;
}
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 436f692..84f5b27 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
@@ -157,7 +157,7 @@
{
faultyRevision =
((HostedRequirement) rethrow.getRequirement())
- .getDeclaredRequirement().getRevision();
+ .getOriginalRequirement().getRevision();
}
if (optional.remove(faultyRevision))
{
@@ -313,7 +313,7 @@
{
faultyRevision =
((HostedRequirement) rethrow.getRequirement())
- .getDeclaredRequirement().getRevision();
+ .getOriginalRequirement().getRevision();
}
if (revisions.remove(faultyRevision))
{
@@ -465,7 +465,7 @@
{
faultyRevision =
((HostedRequirement) rethrow.getRequirement())
- .getDeclaredRequirement().getRevision();
+ .getOriginalRequirement().getRevision();
}
if (optional.remove(faultyRevision))
{
@@ -1503,7 +1503,7 @@
{
if (c instanceof HostedCapability)
{
- return ((HostedCapability) c).getDeclaredCapability();
+ return ((HostedCapability) c).getOriginalCapability();
}
return c;
}
@@ -1512,7 +1512,7 @@
{
if (r instanceof HostedRequirement)
{
- return ((HostedRequirement) r).getDeclaredRequirement();
+ return ((HostedRequirement) r).getOriginalRequirement();
}
return r;
}