use of org.eclipse.aether.version.InvalidVersionSpecificationException in project buck by facebook.
the class Resolver method getNewerVersionFile.
/**
* @return {@link Path} to the file in {@code project} with filename consistent with the given
* {@link Artifact}, but with a newer version. If no such file exists, {@link Optional#empty} is
* returned. If multiple such files are present one with the newest version will be returned.
*/
@VisibleForTesting
Optional<Path> getNewerVersionFile(final Artifact artifactToDownload, Path project) throws IOException {
final Version artifactToDownloadVersion;
try {
artifactToDownloadVersion = versionScheme.parseVersion(artifactToDownload.getVersion());
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
final Pattern versionExtractor = Pattern.compile(String.format(ARTIFACT_FILE_NAME_REGEX_FORMAT, artifactToDownload.getArtifactId(), VERSION_REGEX_GROUP, artifactToDownload.getExtension()));
Iterable<Version> versionsPresent = FluentIterable.from(Files.newDirectoryStream(project)).transform(new Function<Path, Version>() {
@Nullable
@Override
public Version apply(Path input) {
Matcher matcher = versionExtractor.matcher(input.getFileName().toString());
if (matcher.matches()) {
try {
return versionScheme.parseVersion(matcher.group(1));
} catch (InvalidVersionSpecificationException e) {
throw new RuntimeException(e);
}
} else {
return null;
}
}
}).filter(Objects::nonNull);
List<Version> newestPresent = Ordering.natural().greatestOf(versionsPresent, 1);
if (newestPresent.isEmpty() || newestPresent.get(0).compareTo(artifactToDownloadVersion) <= 0) {
return Optional.empty();
} else {
return Optional.of(project.resolve(String.format(ARTIFACT_FILE_NAME_FORMAT, artifactToDownload.getArtifactId(), newestPresent.get(0).toString(), artifactToDownload.getExtension())));
}
}
use of org.eclipse.aether.version.InvalidVersionSpecificationException in project fabric8 by jboss-fuse.
the class AetherBasedResolver method resolve.
private File resolve(List<LocalRepository> defaultRepos, List<RemoteRepository> remoteRepos, Artifact artifact) throws IOException {
if (artifact.getExtension().isEmpty()) {
artifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "jar", artifact.getVersion());
}
// Try with default repositories
try {
VersionConstraint vc = new GenericVersionScheme().parseVersionConstraint(artifact.getVersion());
if (vc.getVersion() != null) {
for (LocalRepository repo : defaultRepos) {
if (vc.getVersion().toString().endsWith("SNAPSHOT") && !handlesSnapshot(repo)) {
continue;
}
DefaultRepositorySystemSession session = newSession(repo);
try {
return m_repoSystem.resolveArtifact(session, new ArtifactRequest(artifact, null, null)).getArtifact().getFile();
} catch (ArtifactResolutionException e) {
// Ignore
} finally {
releaseSession(session);
}
}
}
} catch (InvalidVersionSpecificationException e) {
// Should not happen
}
DefaultRepositorySystemSession session = newSession(null);
try {
artifact = resolveLatestVersionRange(session, remoteRepos, artifact);
ArtifactResult result = m_repoSystem.resolveArtifact(session, new ArtifactRequest(artifact, remoteRepos, null));
File resolved = result.getArtifact().getFile();
LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
return resolved;
} catch (ArtifactResolutionException e) {
// we know there's one ArtifactResult, because there was one ArtifactRequest
ArtifactResolutionException original = new ArtifactResolutionException(e.getResults(), "Error resolving artifact " + artifact.toString(), null);
original.setStackTrace(e.getStackTrace());
List<String> messages = new ArrayList<>(e.getResult().getExceptions().size());
List<Exception> suppressed = new ArrayList<>();
for (Exception ex : e.getResult().getExceptions()) {
messages.add(ex.getMessage() == null ? ex.getClass().getName() : ex.getMessage());
suppressed.add(ex);
}
IOException exception = new IOException(original.getMessage() + ": " + messages, original);
for (Exception ex : suppressed) {
exception.addSuppressed(ex);
}
LOG.warn(exception.getMessage(), exception);
for (Exception ex : suppressed) {
LOG.warn(" - " + ex.getMessage());
}
throw exception;
} catch (RepositoryException e) {
throw new IOException("Error resolving artifact " + artifact.toString(), e);
} finally {
releaseSession(session);
}
}
Aggregations