for (int j = 0; j < mrids.length; j++) {
artifacts.add(parser.getMetadataArtifactReport(mrids[j]));
}
}
for (Iterator iter = artifacts.iterator(); iter.hasNext();) {
ArtifactDownloadReport artifact = (ArtifactDownloadReport) iter.next();
String destPattern = "ivy".equals(artifact.getType()) ? destIvyPattern
: destFilePattern;
if (!"ivy".equals(artifact.getType())
&& !options.getArtifactFilter().accept(artifact.getArtifact())) {
continue; // skip this artifact, the filter didn't accept it!
}
String destFileName = IvyPatternHelper.substitute(destPattern,
artifact.getArtifact().getModuleRevisionId(), artifact.getArtifact(),
conf, artifact.getArtifactOrigin());
Set dest = (Set) artifactsToCopy.get(artifact);
if (dest == null) {
dest = new HashSet();
artifactsToCopy.put(artifact, dest);
}
String copyDest = settings.resolveFile(destFileName).getAbsolutePath();
String[] destinations = new String[] {copyDest};
if (options.getMapper() != null) {
destinations = options.getMapper().mapFileName(copyDest);
}
for (int j = 0; j < destinations.length; j++) {
dest.add(destinations[j]);
Set conflicts = (Set) conflictsMap.get(destinations[j]);
Set conflictsReports = (Set) conflictsReportsMap.get(destinations[j]);
Set conflictsConf = (Set) conflictsConfMap.get(destinations[j]);
if (conflicts == null) {
conflicts = new HashSet();
conflictsMap.put(destinations[j], conflicts);
}
if (conflictsReports == null) {
conflictsReports = new HashSet();
conflictsReportsMap.put(destinations[j], conflictsReports);
}
if (conflictsConf == null) {
conflictsConf = new HashSet();
conflictsConfMap.put(destinations[j], conflictsConf);
}
if (conflicts.add(artifact.getArtifact().getId())) {
conflictsReports.add(artifact);
conflictsConf.add(conf);
}
}
}
}
// resolve conflicts if any
for (Iterator iter = conflictsMap.keySet().iterator(); iter.hasNext();) {
String copyDest = (String) iter.next();
Set artifacts = (Set) conflictsMap.get(copyDest);
Set conflictsConfs = (Set) conflictsConfMap.get(copyDest);
if (artifacts.size() > 1) {
List artifactsList = new ArrayList((Collection) conflictsReportsMap.get(copyDest));
// conflicts battle is resolved by a sort using a conflict resolving policy
// comparator which consider as greater a winning artifact
Collections.sort(artifactsList, getConflictResolvingPolicy());
// after the sort, the winning artifact is the greatest one, i.e. the last one
// we fail if different artifacts of the same module are mapped to the same file
ArtifactDownloadReport winner = (ArtifactDownloadReport)
artifactsList.get(artifactsList.size() - 1);
ModuleRevisionId winnerMD = winner.getArtifact().getModuleRevisionId();
for (int i = artifactsList.size() - 2; i >= 0; i--) {
ArtifactDownloadReport current = (ArtifactDownloadReport) artifactsList.get(i);
if (winnerMD.equals(current.getArtifact().getModuleRevisionId())) {
throw new RuntimeException("Multiple artifacts of the module " + winnerMD
+ " are retrieved to the same file! Update the retrieve pattern "
+ " to fix this error.");
}
}
Message.info("\tconflict on "
+ copyDest
+ " in "
+ conflictsConfs
+ ": "
+ winnerMD.getRevision() + " won");
// we now iterate over the list beginning with the artifact preceding the winner,
// and going backward to the least artifact
for (int i = artifactsList.size() - 2; i >= 0; i--) {
ArtifactDownloadReport looser = (ArtifactDownloadReport) artifactsList.get(i);
Message.verbose("\t\tremoving conflict looser artifact: "
+ looser.getArtifact());
// for each loser, we remove the pair (loser - copyDest) in the artifactsToCopy
// map
Set dest = (Set) artifactsToCopy.get(looser);
dest.remove(copyDest);
if (dest.isEmpty()) {