fireEvent(ResolutionListener.TEST_ARTIFACT, listeners, node);
// TODO: use as a conflict resolver
Object key = node.getKey();
if (managedVersions.containsKey(key)) {
Artifact artifact = (Artifact) managedVersions.get(key);
fireEvent(ResolutionListener.MANAGE_ARTIFACT, listeners, node, artifact);
if (artifact.getVersion() != null) {
node.getArtifact().setVersion(artifact.getVersion());
}
if (artifact.getScope() != null) {
node.getArtifact().setScope(artifact.getScope());
}
}
List previousNodes = (List) resolvedArtifacts.get(key);
if (previousNodes != null) {
node = checkPreviousNodes(node, listeners, previousNodes);
}
else {
previousNodes = new ArrayList();
resolvedArtifacts.put(key, previousNodes);
}
previousNodes.add(node);
if (node.isActive()) {
fireEvent(ResolutionListener.INCLUDE_ARTIFACT, listeners, node);
}
// don't pull in the transitive deps of a system-scoped dependency.
if (node.isActive() && !Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) {
fireEvent(ResolutionListener.PROCESS_CHILDREN, listeners, node);
for (Iterator i = node.getChildrenIterator(); i.hasNext();) {
ResolutionNode child = (ResolutionNode) i.next();
// We leave in optional ones, but don't pick up its dependencies
if (!child.isResolved()
&& (!child.getArtifact().isOptional() || child.isChildOfRootNode())) {
Artifact artifact = child.getArtifact();
try {
if (artifact.getVersion() == null) {
// set the recommended version
// TODO: maybe its better to just pass the range
// through to retrieval and use a transformation?
ArtifactVersion version;
version = getArtifactVersion(localRepository, remoteRepositories, source, artifact);
artifact.selectVersion(version.toString());
fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE,
listeners, child);
}
ResolutionGroup rGroup = source.retrieve(artifact,
localRepository, remoteRepositories);
// TODO might be better to have source.retreive() throw
// a specific exception for this situation
// and catch here rather than have it return null
if (rGroup == null) {
// relocated dependency artifact is declared
// excluded, no need to add and recurse further
continue;
}
child.addDependencies(rGroup.getArtifacts(),
rGroup.getResolutionRepositories(), filter);
}
catch (CyclicDependencyException e) {
// would like to throw this, but we have crappy stuff in
// the repo
fireEvent(ResolutionListener.OMIT_FOR_CYCLE, listeners,
new ResolutionNode(e.getArtifact(), remoteRepositories, child));
}
catch (ArtifactMetadataRetrievalException e) {
artifact.setDependencyTrail(node.getDependencyTrail());
throw new ArtifactResolutionException(
"Unable to get dependency information: "
+ e.getMessage(), artifact, e);
}