@Override
public Artifact lookup(Transport transport, Group group, UnresolvedArtifact artifact) {
if (!artifact.getVersionPattern().isDynamic()) {
// The version isn't dynamic so it can be 'looked-up' directly
final Version version = Version.fromString(artifact.getVersionPattern().getOriginal());
return new Artifact(artifact.getName(), version, artifact.getExtension(), artifact.getClassifier());
}
try {
Version latest = null;
final URI directory = calculateSearchURI(group, artifact);
for (URI uri : transport.list(directory)) {
final String moduleVersion = lastPathElement(uri.getPath());
final Matcher matcher = VERSION_PATTERN.matcher(moduleVersion);
if (!matcher.matches()) {
// invalid module link
continue;
}
final Version version = Version.fromString(matcher.group(1));
if (version.compareTo(latest) > 0) {
latest = version;
}
}
if (latest == null) {
throw new IllegalArgumentException("Unable to find latest version");
}
return new Artifact(artifact.getName(), latest, artifact.getExtension(), artifact.getClassifier());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}