use of org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException in project galleon by wildfly.
the class LocalArtifactVersionRangeResolver method resolveLatestVersionDir.
private Path resolveLatestVersionDir(MavenArtifact artifact, String lowestQualifier, Pattern includeVersion, Pattern excludeVersion) throws MavenUniverseException {
if (artifact.getGroupId() == null) {
MavenErrors.missingGroupId();
}
if (artifact.getArtifactId() == null) {
MavenErrors.missingArtifactId();
}
if (artifact.getVersionRange() == null) {
throw new MavenUniverseException("Version range is missing for " + artifact.getCoordsAsString());
}
Path artifactDir = repoHome;
final String[] groupParts = artifact.getGroupId().split("\\.");
for (String part : groupParts) {
artifactDir = artifactDir.resolve(part);
}
artifactDir = artifactDir.resolve(artifact.getArtifactId());
if (!Files.exists(artifactDir)) {
throw MavenErrors.artifactNotFound(artifact, repoHome);
}
final MavenArtifactVersionRange range = versionRangeParser.parseRange(artifact.getVersionRange());
if (lowestQualifier == null) {
lowestQualifier = "";
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(artifactDir)) {
final Iterable<String> versions = new Iterable<String>() {
@Override
public Iterator<String> iterator() {
return new Iterator<String>() {
final Iterator<Path> i = stream.iterator();
Path nextPath = toNext(range);
@Override
public boolean hasNext() {
return nextPath != null;
}
@Override
public String next() {
if (nextPath != null) {
final String s = nextPath.getFileName().toString();
nextPath = toNext(range);
return s;
}
throw new NoSuchElementException();
}
private Path toNext(final MavenArtifactVersionRange range) {
while (i.hasNext()) {
final Path path = i.next();
if (!Files.isDirectory(path)) {
continue;
}
final MavenArtifactVersion next = new MavenArtifactVersion(path.getFileName().toString());
if (range.includesVersion(next)) {
return path;
}
}
return null;
}
};
}
};
final MavenArtifactVersion latest = MavenArtifactVersion.getLatest(versions, lowestQualifier, includeVersion, excludeVersion);
if (latest == null) {
throw new MavenLatestVersionNotAvailableException(MavenErrors.failedToResolveLatestVersion(artifact.getCoordsAsString()));
}
return artifactDir.resolve(latest.toString());
} catch (MavenUniverseException e) {
throw e;
} catch (Exception e) {
throw new MavenUniverseException(MavenErrors.failedToResolveLatestVersion(artifact.getCoordsAsString()), e);
}
}
use of org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException in project galleon by wildfly.
the class AbstractMavenArtifactRepositoryManager method doGetHighestVersion.
private String doGetHighestVersion(MavenArtifact mavenArtifact, String lowestQualifier, boolean locallyAvailable, Pattern includeVersion, Pattern excludeVersion) throws MavenUniverseException {
if (locallyAvailable) {
if (localRangeResolver == null) {
localRangeResolver = new LocalArtifactVersionRangeResolver(getSession().getLocalRepository().getBasedir().toPath());
}
return localRangeResolver.getLatestVersion(mavenArtifact, lowestQualifier, includeVersion, excludeVersion);
}
final VersionRangeResult rangeResult = getVersionRange(new DefaultArtifact(mavenArtifact.getGroupId(), mavenArtifact.getArtifactId(), mavenArtifact.getExtension(), mavenArtifact.getVersionRange()));
final MavenArtifactVersion latest = rangeResult == null ? null : MavenArtifactVersion.getLatest(rangeResult.getVersions(), lowestQualifier, includeVersion, excludeVersion);
if (latest == null) {
throw new MavenLatestVersionNotAvailableException(MavenErrors.failedToResolveLatestVersion(mavenArtifact.getCoordsAsString()));
}
return latest.toString();
}
Aggregations