You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/12/14 17:41:08 UTC
svn commit: r890400 - in
/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver:
CapabilityImpl.java Main.java prototype/ProtoResolver.java
Author: rickhall
Date: Mon Dec 14 16:41:07 2009
New Revision: 890400
URL: http://svn.apache.org/viewvc?rev=890400&view=rev
Log:
Fixed some bugs.
Modified:
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java?rev=890400&r1=890399&r2=890400&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/CapabilityImpl.java Mon Dec 14 16:41:07 2009
@@ -134,6 +134,10 @@
public String toString()
{
+ if (m_namespace.equals(Capability.PACKAGE_NAMESPACE))
+ {
+ return "[" + m_module + "] " + m_namespace + "; " + m_attrs.get(Capability.PACKAGE_ATTR);
+ }
return "[" + m_module + "] " + m_namespace + "; " + m_attrs.values();
}
}
\ No newline at end of file
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java?rev=890400&r1=890399&r2=890400&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/Main.java Mon Dec 14 16:41:07 2009
@@ -574,22 +574,23 @@
// Bundle B
moduleList.add(
(m = new Module("B"))
- .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooB"))
+ .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooB").using("fooE"))
.requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=fooE")));
// Bundle C
moduleList.add(
(m = new Module("C"))
- .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooC"))
+ .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooC").using("fooE"))
.requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=fooE")));
// Bundle D
moduleList.add(
(m = new Module("D"))
- .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooD"))
+ .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooD").using("fooE"))
.requiring(new RequirementImpl(Capability.PACKAGE_NAMESPACE).with("package=fooE")));
// Bundle E
moduleList.add(
(m = new Module("E"))
- .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooE")));
+ .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=fooE").using("used"))
+ .providing(new CapabilityImpl(m, Capability.PACKAGE_NAMESPACE).with("package=used")));
return target;
}
Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java?rev=890400&r1=890399&r2=890400&view=diff
==============================================================================
--- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java (original)
+++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java Mon Dec 14 16:41:07 2009
@@ -192,79 +192,86 @@
// Loop through all of the target module's imports and see
// if there is a consistent candidate provider.
- for (Requirement req : reqs)
+ try
{
- // Get the current candidate capability for the current import.
- Set<Capability> candidates = candidateMap.get(req);
- // Optional imports may not have any exporters.
- if (candidates == null)
+ for (Requirement req : reqs)
{
- continue;
- }
+ // Get the current candidate capability for the current import.
+ Set<Capability> candidates = candidateMap.get(req);
+ // Optional imports may not have any exporters.
+ if (candidates == null)
+ {
+ continue;
+ }
- // Find a consistent candidate.
- Capability selectedCandidate = null;
- Iterator<Capability> itCandidates = candidates.iterator();
- while ((selectedCandidate == null) && itCandidates.hasNext())
- {
- Capability cap = itCandidates.next();
-//System.out.println("+++ RESOLVING " + cap + " FOR " + module);
- try
+ // Find a consistent candidate.
+ Capability selectedCandidate = null;
+ Iterator<Capability> itCandidates = candidates.iterator();
+ while ((selectedCandidate == null) && itCandidates.hasNext())
{
- // If current candidate is resolved, then try to merge
- // in its constraints with the existing constraints.
- if (cap.getModule().isResolved())
- {
- mergeResolvedConstraints(
- module, candidateMap, currentConstraintsCopy,
- cap);
- }
- // If current candidate is the same as the module being
- // resolved, then just directly add it as a constraint.
- else if (cap.getModule().equals(module))
+ Capability cap = itCandidates.next();
+//System.out.println("+++ RESOLVING " + cap + " FOR " + module);
+ try
{
- currentConstraintsCopy.put(
- (String) cap.getAttribute(Capability.PACKAGE_ATTR).getValue(),
- new Blame(cap, module));
+ // If current candidate is resolved, then try to merge
+ // in its constraints with the existing constraints.
+ if (cap.getModule().isResolved())
+ {
+ mergeResolvedConstraints(
+ module, candidateMap, currentConstraintsCopy,
+ cap);
+ }
+ // If current candidate is the same as the module being
+ // resolved, then just directly add it as a constraint.
+ else if (cap.getModule().equals(module))
+ {
+ currentConstraintsCopy.put(
+ (String) cap.getAttribute(Capability.PACKAGE_ATTR).getValue(),
+ new Blame(cap, module));
+ }
+ // If the current candidate is not resolved, then try to resolve
+ // it, which will also merge packages while verify constraints.
+ else
+ {
+ resolveCandidate(
+ cap.getModule(),
+ cap,
+ module,
+ candidateMap,
+ currentConstraintsCopy,
+ cycleMap);
+ }
+
+ // This candidate was consistent, so select it.
+ selectedCandidate = cap;
}
- // If the current candidate is not resolved, then try to resolve
- // it, which will also merge packages while verify constraints.
- else
+ // If we have a resolve exception, then the current candidate
+ // should be removed. If we are at the root, we should try the
+ // next permutated candidate map if there are no more candidates.
+ catch (ResolveException ex)
{
- resolveCandidate(
- cap.getModule(),
- cap,
- module,
- candidateMap,
- currentConstraintsCopy,
- cycleMap);
- }
-
- // This candidate was consistent, so select it.
- selectedCandidate = cap;
- }
- // If we have a resolve exception, then the current candidate
- // should be removed. If we are at the root, we should try the
- // next permutated candidate map if there are no more candidates.
- catch (ResolveException ex)
- {
// TODO: PROTO RESOLVER: This should be logged.
- System.out.println("DEBUG1: " + ex);
+ System.out.println("DEBUG1: " + ex);
System.out.println("RE " + ex);
ex.printStackTrace();
//System.out.println("Current candidate map : " + candidateMap);
// Remove offending candidate.
- itCandidates.remove();
+ itCandidates.remove();
//System.out.println("Updated candidate map : " + candidateMap);
- if (!itCandidates.hasNext() && !req.isOptional())
- {
- candidateMap.remove(req);
- rethrow = new ResolveException("Unresolved constraint "
- + req + " in " + module);
+ if (!itCandidates.hasNext() && !req.isOptional())
+ {
+ candidateMap.remove(req);
+ throw new ResolveException("Unresolved constraint "
+ + req + " in " + module);
+ }
}
}
}
}
+ catch (ResolveException ex)
+ {
+ rethrow = ex;
+ }
}
while ((rethrow != null) && (m_candidatePermutations.size() > 0));
@@ -302,7 +309,7 @@
private Map<Requirement, Set<Capability>> resolveCandidate(
Module module, Capability capGoal, Module blameModule,
Map<Requirement, Set<Capability>> candidateMap,
- Map<String, Blame> existingConstrains,
+ Map<String, Blame> existingConstraints,
Map<Module, Boolean> cycleMap)
{
if (m_isInvokeCount)
@@ -319,7 +326,7 @@
// Copy the existing constraints, since we need to be able
// to freely modify them.
Map<String, Blame> existingConstraintsCopy =
- new HashMap<String, Blame>(existingConstrains);
+ new HashMap<String, Blame>(existingConstraints);
try
{
@@ -339,7 +346,7 @@
calculateResolvingConstraints(module, blameModule);
checkConsistency(module, capGoal, candidateMap,
existingConstraintsCopy, currentConstraints);
- existingConstrains.putAll(existingConstraintsCopy);
+ existingConstraints.putAll(existingConstraintsCopy);
}
return candidateMap;
}
@@ -467,9 +474,9 @@
module, capGoal, candidateMap, existingConstraintsCopy, currentConstraintsCopy);
// If we are here, then the candidates were consistent with
// existing constraints, so cache the result.
- m_resolvingConstraintCache.put(module, existingConstraintsCopy);
+ m_resolvingConstraintCache.put(module, currentConstraintsCopy);
// Finally, modify the original existing constraints.
- existingConstrains.putAll(existingConstraintsCopy);
+ existingConstraints.putAll(existingConstraintsCopy);
}
catch (RuntimeException ex)
{
@@ -620,6 +627,7 @@
// Cache answer.
m_moduleConstraintCache.put(module, constraints);
+ constraints = new HashMap<String, Blame>(constraints);
}
// If they are cached, then we need to make a copy to set the
// blame module correctly.
@@ -731,6 +739,7 @@
// Cache answer.
m_resolvedConstraintCache.put(capTarget, constraints);
+ constraints = new HashMap<String, Blame>(constraints);
}
// If they are cached, then we need to make a copy to set the
// blame module correctly.
@@ -817,9 +826,23 @@
}
}
+ private static void dumpCandidateMap(Map<Requirement, Set<Capability>> candidateMap)
+ {
+ System.out.println("CANDIDATE MAP");
+ for (Entry<Requirement, Set<Capability>> entry : candidateMap.entrySet())
+ {
+ System.out.println(entry.getKey());
+ for (Capability cap : entry.getValue())
+ {
+ System.out.println("---> " + cap);
+ }
+ }
+ }
+
private void checkConsistency(
- Module targetModule, Capability capGoal, Map<Requirement,
- Set<Capability>> candidateMap, Map<String, Blame> existingConstraints,
+ Module targetModule, Capability capGoal,
+ Map<Requirement, Set<Capability>> candidateMap,
+ Map<String, Blame> existingConstraints,
Map<String, Blame> currentConstraints)
throws ResolveConflictException
@@ -941,11 +964,11 @@
Set<Capability> caps = candidateMapCopy.get(blameImports.get(impIdx));
if (caps != null)
{
- for (Iterator<Capability> cmIt = caps.iterator(); cmIt.hasNext(); )
+ for (Iterator<Capability> capIt = caps.iterator(); capIt.hasNext(); )
{
- if (cmIt.next().getModule().equals(existing.m_capability.getModule()))
+ if (capIt.next().getModule().equals(existing.m_capability.getModule()))
{
- cmIt.remove();
+ capIt.remove();
modified = true;
if (candidateMapCopy.get(blameImports.get(impIdx)).size() == 0)
{
@@ -969,12 +992,12 @@
}
else
{
-//System.out.println("Permutated candidate map: Unchanged, so ignoring.");
}
// TODO: PROTO RESOLVER - We could perhaps check to see if the candidate permutation
// is even viable, e.g., the conflicting candidate may be the only candidate
// so the resulting permutation may not be resolveable.
+//dumpCandidateMap(candidateMapCopy);
throw new ResolveConflictException("Unable to resolve "
+ targetModule + ": constraint conflict with '"
+ pkgName + "' between " + current + " and "
@@ -1088,7 +1111,7 @@
public String toString()
{
- return m_capability.getModule() + " {Blamed on " + m_blameModules + "}";
+ return m_capability + " {Blamed on " + m_blameModules + "}";
}
}