Search in sources :

Example 1 with MavenUniverseException

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()));
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) InstallationException(org.eclipse.aether.installation.InstallationException) MavenLatestVersionNotAvailableException(org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 2 with MavenUniverseException

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;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 3 with MavenUniverseException

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);
    }
}
Also used : InstallRequest(org.eclipse.aether.installation.InstallRequest) InstallationException(org.eclipse.aether.installation.InstallationException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException)

Example 4 with MavenUniverseException

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);
    }
}
Also used : Path(java.nio.file.Path) MavenLatestVersionNotAvailableException(org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) MavenLatestVersionNotAvailableException(org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException) NoSuchElementException(java.util.NoSuchElementException) Iterator(java.util.Iterator) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with MavenUniverseException

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);
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) MavenUniverseException(org.jboss.galleon.universe.maven.MavenUniverseException)

Aggregations

MavenUniverseException (org.jboss.galleon.universe.maven.MavenUniverseException)16 Path (java.nio.file.Path)6 MavenArtifact (org.jboss.galleon.universe.maven.MavenArtifact)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 InstallationException (org.eclipse.aether.installation.InstallationException)3 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)3 MavenArtifactRepositoryManager (org.jboss.galleon.maven.plugin.util.MavenArtifactRepositoryManager)3 MavenLatestVersionNotAvailableException (org.jboss.galleon.universe.maven.MavenLatestVersionNotAvailableException)3 MavenProducer (org.jboss.galleon.universe.maven.MavenProducer)3 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 MavenProducerInstaller (org.jboss.galleon.universe.maven.MavenProducerInstaller)2 MavenUniverseInstaller (org.jboss.galleon.universe.maven.MavenUniverseInstaller)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 InstallRequest (org.eclipse.aether.installation.InstallRequest)1 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)1