Set<Artifact> chosenArtifacts = new HashSet<Artifact>();
List<Artifact> unresolved = new ArrayList<Artifact>();
// process the initial list of requirements first getting the most
// recent artifact for all the requirements
for (Requirement req : initialRequirements) {
Artifact artifact = getArtifactFor(req);
chosenArtifacts.add(artifact);
unresolved.add(artifact);
}
// resolve all dependencies of the the artifacts chosen until now
while (unresolved.size() > 0) {
Artifact artifact = unresolved.remove(0);
// resolve the requirements for each
List<Artifact> newArtifacts = resolveReq(artifact, chosenArtifacts);
unresolved.addAll(newArtifacts);
chosenArtifacts.addAll(newArtifacts);
}