Author: rickhall
Date: Wed Dec 2 21:27:49 2009
New Revision: 886309
URL: http://svn.apache.org/viewvc?rev=886309&view=rev
Log:
Simplify main resolver loop.
Modified:
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/prototype/ProtoResolver.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/prototype/ProtoResolver.java?rev=886309&r1=886308&r2=886309&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
Wed Dec 2 21:27:49 2009
@@ -205,7 +205,8 @@
{
repeat = false;
- // Loop through all of the target module's imports and
v
+ // Loop through all of the target module's imports and
see
+ // if there is a consistent candidate provider.
for (Requirement req : reqs)
{
// Get the current candidate capability for the
current import.
@@ -215,77 +216,81 @@
{
continue;
}
+
+ // Find a consistent candidate.
+ Capability selectedCandidate = null;
Iterator<Capability> itExporters =
exporters.iterator();
- Capability cap = itExporters.next();
-//System.out.println("+++ RESOLVING " + cap + " FOR " + module);
- try
+ while ((selectedCandidate == null) &&
itExporters.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 = itExporters.next();
+//System.out.println("+++ RESOLVING " + cap + " FOR " + module);
+ try
{
- currentConstraintsCopy.put(
- (String)
cap.getAttribute(Capability.PACKAGE_ATTR).getValue(),
- new Blame(cap, blameModule));
+ // 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, blameModule));
+ }
+ // If the current candidate is not
resolved, then try to resolve
+ // it, which will also merge packages
while verify constraints.
+ else
+ {
+ resolve(
+ 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)
{
- resolve(
- cap.getModule(),
- cap,
- module,
- candidateMap,
- currentConstraintsCopy,
- cycleMap);
- }
- }
- // 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)
- {
System.out.println("RE " + ex);
ex.printStackTrace();
//System.out.println("Current candidate map : " + candidateMap);
- // Remove offending candidate.
- itExporters.remove();
+ // Remove offending candidate.
+ itExporters.remove();
//System.out.println("Updated candidate map : " + candidateMap);
- if (!itExporters.hasNext() &&
!req.isOptional())
- {
- // TODO: PROTO RESOLVER - Maybe this
should be moved.
- if ((module == m_rootModule) &&
(m_candidatePermutations.size() > 0))
+ if (!itExporters.hasNext() &&
!req.isOptional())
{
- currentConstraintsCopy.clear();
-
currentConstraintsCopy.putAll(currentConstraints);
- candidateMap =
m_candidatePermutations.remove(0);
+ // TODO: PROTO RESOLVER - Maybe this
should be moved.
+ if ((module == m_rootModule) &&
(m_candidatePermutations.size() > 0))
+ {
+ currentConstraintsCopy.clear();
+
currentConstraintsCopy.putAll(currentConstraints);
+ candidateMap =
m_candidatePermutations.remove(0);
//System.out.println("+++ TRYING ALTERNATIVE: " + candidateMap);
- // Flush various caches for new
candidates.
- m_resolvingConstraintCache.clear();
- m_verifyCache.clear();
- repeat = true;
- }
- else
- {
- candidateMap.remove(req);
- throw new ResolveException("Unresolved
constraint "
- + req + " in " + module);
+ // Flush various caches for new
candidates.
+ m_resolvingConstraintCache.clear();
+ m_verifyCache.clear();
+ repeat = true;
+ }
+ else
+ {
+ candidateMap.remove(req);
+ throw new
ResolveException("Unresolved constraint "
+ + req + " in " + module);
+ }
}
}
- else
- {
- repeat = true;
- }
- break;
}
}
}