private ResolutionNode checkPreviousNodes(
ResolutionNode node,
List listeners,
List previousNodes) throws OverConstrainedVersionException {
for (Iterator i = previousNodes.iterator(); i.hasNext();) {
ResolutionNode previous = (ResolutionNode) i.next();
if (previous.isActive()) {
// Version mediation
VersionRange previousRange = previous.getArtifact().getVersionRange();
VersionRange currentRange = node.getArtifact().getVersionRange();
// TODO: why do we force the version on it? what if they
// don't match?
if (previousRange == null) {
// version was already resolved
node.getArtifact().setVersion(previous.getArtifact().getVersion());
}
else if (currentRange == null) {
// version was already resolved
previous.getArtifact().setVersion(node.getArtifact().getVersion());
}
else {
// TODO: shouldn't need to double up on this work, only
// done for simplicity of handling recommended
// version but the restriction is identical
VersionRange newRange = previousRange.restrict(currentRange);
// TODO: ick. this forces the OCE that should have come
// from the previous call. It is still correct
if (newRange.isSelectedVersionKnown(previous.getArtifact())) {
fireEvent(ResolutionListener.RESTRICT_RANGE,
listeners, node, previous.getArtifact(),
newRange);
}
previous.getArtifact().setVersionRange(newRange);
node.getArtifact().setVersionRange(
currentRange.restrict(previousRange));
// Select an appropriate available version from the (now
// restricted) range
// Note this version was selected before to get the
// appropriate POM
// But it was reset by the call to setVersionRange on
// restricting the version
ResolutionNode[] resetNodes = {previous, node};
for (int j = 0; j < 2; j++) {
Artifact resetArtifact = resetNodes[j]
.getArtifact();
if (resetArtifact.getVersion() == null
&& resetArtifact.getVersionRange() != null
&& resetArtifact.getAvailableVersions() != null) {
resetArtifact
.selectVersion(resetArtifact
.getVersionRange()
.matchVersion(
resetArtifact
.getAvailableVersions())
.toString());
fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE,
listeners, resetNodes[j]);
}
}
}
// Conflict Resolution
// TODO: use as conflict resolver(s), chain
// TODO: should this be part of mediation?
// previous one is more dominant
if (previous.getDepth() <= node.getDepth()) {
checkScopeUpdate(node, previous, listeners);
}
else {
checkScopeUpdate(previous, node, listeners);
}
if (previous.getDepth() <= node.getDepth()) {
// previous was nearer
fireEvent(ResolutionListener.OMIT_FOR_NEARER,
listeners, node, previous.getArtifact());
node.disable();
node = previous;
}
else {
fireEvent(ResolutionListener.OMIT_FOR_NEARER,
listeners, previous, node.getArtifact());
previous.disable();
}
}
}
return node;
}