use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.
the class AbstractMavenArtifactRepositoryManager method resolve.
@Override
public void resolve(MavenArtifact artifact) throws MavenUniverseException {
if (artifact.isResolved()) {
throw new MavenUniverseException("Artifact is already resolved");
}
final ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), artifact.getVersion()));
request.setRepositories(getRepositories());
final ArtifactResult result;
try {
result = repoSystem.resolveArtifact(getSession(), request);
} catch (Exception e) {
throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()), e);
}
if (!result.isResolved()) {
throw new MavenUniverseException(FpMavenErrors.artifactResolution(request.getArtifact().toString()));
}
if (result.isMissing()) {
throw new MavenUniverseException(FpMavenErrors.artifactMissing(request.getArtifact().toString()));
}
artifact.setPath(Paths.get(result.getArtifact().getFile().toURI()));
}
use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.
the class AbstractMavenArtifactRepositoryManager method getVersionRange.
private VersionRangeResult getVersionRange(Artifact artifact) throws MavenUniverseException {
VersionRangeRequest rangeRequest = new VersionRangeRequest();
rangeRequest.setArtifact(artifact);
rangeRequest.setRepositories(getRepositories());
VersionRangeResult rangeResult;
try {
rangeResult = repoSystem.resolveVersionRange(getSession(), rangeRequest);
} catch (VersionRangeResolutionException ex) {
throw new MavenUniverseException(ex.getLocalizedMessage(), ex);
}
return rangeResult;
}
use of org.jboss.galleon.universe.maven.MavenUniverseException in project galleon by wildfly.
the class AbstractMavenArtifactRepositoryManager method install.
@Override
public void install(MavenArtifact coords, Path path) throws MavenUniverseException {
final InstallRequest request = new InstallRequest();
request.addArtifact(new DefaultArtifact(coords.getGroupId(), coords.getArtifactId(), coords.getClassifier(), coords.getExtension(), coords.getVersion(), Collections.emptyMap(), path.toFile()));
try {
repoSystem.install(getSession(), request);
} catch (InstallationException ex) {
throw new MavenUniverseException("Failed to install " + coords.getCoordsAsString(), ex);
}
}
use of org.jboss.galleon.universe.maven.MavenUniverseException 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.MavenUniverseException in project galleon by wildfly.
the class SimplisticMavenRepoManager method install.
@Override
public void install(MavenArtifact artifact, Path path) throws MavenUniverseException {
if (artifact.isResolved()) {
throw new MavenUniverseException("Artifact is already associated with a path " + path);
}
final Path targetPath = getArtifactPath(artifact);
try {
IoUtils.copy(path, targetPath);
} catch (IOException e) {
throw new MavenUniverseException("Failed to install " + artifact.getCoordsAsString(), e);
}
artifact.setPath(targetPath);
}
Aggregations