in core/bootstrap/src/main/java/org/jboss/modules/maven/MavenArtifactUtil.java [100:215]
public static File resolveArtifact(final ArtifactCoordinates coordinates, final String packaging) throws IOException {
String artifactRelativePath = coordinates.relativeArtifactPath(File.separatorChar);
String artifactRelativeHttpPath = coordinates.relativeArtifactPath('/');
String artifactRelativeMetadataHttpPath = coordinates.relativeMetadataPath('/');
final MavenSettings settings = MavenSettings.getSettings();
final Path localRepository = settings.getLocalRepository();
final File localRepositoryFile = localRepository.toFile();
final String pomPath = artifactRelativePath + ".pom";
// serialize artifact lookup because we want to prevent parallel download
synchronized (artifactLock) {
if ("pom".equals(packaging)) {
// ignore classifier
Path fp = localRepository.resolve(pomPath);
if (Files.exists(fp)) {
return fp.toFile();
}
List<String> remoteRepos = settings.getRemoteRepositories();
if (remoteRepos.isEmpty()) {
return null;
}
final File pomFile = new File(localRepositoryFile, pomPath);
for (String remoteRepository : remoteRepos) {
try {
String remotePomPath = remoteRepository + artifactRelativeHttpPath + ".pom";
downloadFile(coordinates + ":" + packaging, remotePomPath, pomFile);
if (pomFile.exists()) { //download successful
return pomFile;
}
} catch (IOException e) {
Module.getModuleLogger().trace(e, "Could not download '%s' from '%s' repository", artifactRelativePath, remoteRepository);
// try next one
}
}
if (coordinates.isSnapshot()) {
// Check repositories for timestamp snapshots
String timestampedArtifactRelativePath;
for (String remoteRepository : remoteRepos) {
try {
String remoteMetadataPath = remoteRepository + artifactRelativeMetadataHttpPath;
timestampedArtifactRelativePath = coordinates.relativeArtifactPath('/', downloadTimestampVersion(coordinates + ":" + packaging, remoteMetadataPath));
String remotePomPath = remoteRepository + timestampedArtifactRelativePath + ".pom";
downloadFile(coordinates + ":" + packaging, remotePomPath, pomFile);
if (pomFile.exists()) { //download successful
return pomFile;
}
} catch (IOException | XPathExpressionException e) {
Module.getModuleLogger().trace(e, "Could not download '%s' from '%s' repository", artifactRelativePath, remoteRepository);
// try next one
}
}
}
} else {
final String coordinatesClassifier = coordinates.getClassifier();
String classifier = coordinatesClassifier.isEmpty() ? "" : "-" + coordinatesClassifier;
String artifactPath = artifactRelativePath + classifier + "." + packaging;
Path fp = localRepository.resolve(artifactPath);
if (Files.exists(fp)) {
return fp.toFile();
}
List<String> remoteRepos = settings.getRemoteRepositories();
if (remoteRepos.isEmpty()) {
return null;
}
final File artifactFile = new File(localRepositoryFile, artifactPath);
final File pomFile = new File(localRepositoryFile, pomPath);
for (String remoteRepository : remoteRepos) {
try {
String remotePomPath = remoteRepository + artifactRelativeHttpPath + ".pom";
String remoteArtifactPath = remoteRepository + artifactRelativeHttpPath + classifier + "." + packaging;
downloadFile(coordinates + ":pom", remotePomPath, pomFile);
if (!pomFile.exists()) {
// no POM; skip it
continue;
}
downloadFile(coordinates + ":" + packaging, remoteArtifactPath, artifactFile);
if (artifactFile.exists()) { //download successful
return artifactFile;
}
} catch (IOException e) {
Module.getModuleLogger().trace(e, "Could not download '%s' from '%s' repository", artifactRelativePath, remoteRepository);
//
}
}
if (coordinates.isSnapshot()) {
String timestampedArtifactRelativePath;
for (String remoteRepository : remoteRepos) {
try {
String remoteMetadataPath = remoteRepository + artifactRelativeMetadataHttpPath;
timestampedArtifactRelativePath = coordinates.relativeArtifactPath('/', downloadTimestampVersion(coordinates + ":" + packaging, remoteMetadataPath));
String remotePomPath = remoteRepository + timestampedArtifactRelativePath + ".pom";
String remoteArtifactPath = remoteRepository + timestampedArtifactRelativePath + classifier + "." + packaging;
downloadFile(coordinates + ":pom", remotePomPath, pomFile);
if (!pomFile.exists()) {
// no POM; skip it
continue;
}
downloadFile(coordinates + ":" + packaging, remoteArtifactPath, artifactFile);
if (artifactFile.exists()) { //download successful
return artifactFile;
}
} catch (IOException | XPathExpressionException e) {
Module.getModuleLogger().trace(e, "Could not download '%s' from '%s' repository", artifactRelativePath, remoteRepository);
// try next one
}
}
}
}
//could not find it in remote
Module.getModuleLogger().trace("Could not find in any remote repository");
return null;
}
}