Search in sources :

Example 16 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method resolve.

@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version());
        final LocalArtifactResult localResult = this.session.getLocalRepositoryManager().find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
        if (localResult.isAvailable()) {
            spec.file = localResult.getFile();
        } else {
            try {
                final ArtifactResult result = resolver.resolveArtifact(this.session, new ArtifactRequest(artifact, this.remoteRepositories, null));
                if (result.isResolved()) {
                    spec.file = result.getArtifact().getFile();
                }
            } catch (ArtifactResolutionException e) {
                e.printStackTrace();
            }
        }
    }
    return spec.file != null ? spec : null;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 17 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method resolveArtifact.

protected File resolveArtifact(Artifact artifact) throws MojoExecutionException, DependencyCollectionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(remoteRepos);
    ArtifactResult result;
    try {
        result = repositorySystem.resolveArtifact(repoSession, request);
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 18 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project grails-maven by grails.

the class AbstractGrailsMojo method resolveArtifact.

protected File resolveArtifact(String artifactId) throws MojoExecutionException {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(new DefaultArtifact(artifactId));
    request.setRepositories(remoteRepos);
    getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
    ArtifactResult result;
    File file;
    try {
        result = repoSystem.resolveArtifact(repoSession, request);
        file = result.getArtifact().getFile();
    } catch (ArtifactResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    getLog().debug("Resolved artifact " + artifactId + " to " + file + " from " + result.getRepository());
    return file;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 19 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project meecrowave by apache.

the class MeecrowaveBundleMojo method resolve.

private File resolve(final String group, final String artifact, final String version, final String classifier) {
    final DefaultArtifact art = new DefaultArtifact(group, artifact, classifier, "jar", version);
    final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);
    final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
    art.setFile(new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifactRequest.getArtifact())));
    try {
        final ArtifactResult result = repositorySystem.resolveArtifact(session, artifactRequest);
        if (result.isMissing()) {
            throw new IllegalStateException("Can't find commons-cli, please add it to the pom.");
        }
        return result.getArtifact().getFile();
    } catch (final ArtifactResolutionException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 20 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project che by eclipse.

the class CheArtifactResolver method resolveOrig.

private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
    if (artifact == null) {
        return;
    }
    if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
        File systemFile = artifact.getFile();
        if (systemFile == null) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
        }
        if (!systemFile.exists()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
        }
        if (!systemFile.isFile()) {
            throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
        }
        artifact.setResolved(true);
        return;
    }
    if (!artifact.isResolved()) {
        ArtifactResult result;
        try {
            ArtifactRequest artifactRequest = new ArtifactRequest();
            artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
            artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
            // Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
            LocalRepositoryManager lrm = session.getLocalRepositoryManager();
            String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
            artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
            result = repoSystem.resolveArtifact(session, artifactRequest);
        } catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
            if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
                throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
            } else {
                throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
            }
        }
        artifact.selectVersion(result.getArtifact().getVersion());
        artifact.setFile(result.getArtifact().getFile());
        artifact.setResolved(true);
        if (artifact.isSnapshot()) {
            Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
            if (matcher.matches()) {
                Snapshot snapshot = new Snapshot();
                snapshot.setTimestamp(matcher.group(2));
                try {
                    snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
                    artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
                } catch (NumberFormatException e) {
                    logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
                }
            }
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) AbstractArtifactResolutionException(org.apache.maven.artifact.resolver.AbstractArtifactResolutionException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Snapshot(org.apache.maven.artifact.repository.metadata.Snapshot) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalRepositoryManager(org.eclipse.aether.repository.LocalRepositoryManager) LegacyLocalRepositoryManager(org.apache.maven.artifact.repository.LegacyLocalRepositoryManager) SnapshotArtifactRepositoryMetadata(org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata) File(java.io.File) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException)

Aggregations

ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)45 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)41 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 Artifact (org.eclipse.aether.artifact.Artifact)20 File (java.io.File)18 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)9 IOException (java.io.IOException)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 ArrayList (java.util.ArrayList)7 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)7 FileNotFoundException (java.io.FileNotFoundException)5 Model (org.apache.maven.model.Model)4 FileReader (java.io.FileReader)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3 Dependency (org.eclipse.aether.graph.Dependency)3