Search in sources :

Example 31 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project BIMserver by opensourceBIM.

the class RemotePluginRepository method main.

public static void main(String[] args) throws ArtifactResolutionException {
    System.out.println("------------------------------------------------------------");
    System.out.println(RemotePluginRepository.class.getSimpleName());
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.eclipse.aether:aether-util:1.0.0.v20140518");
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    artifactRequest.setRepositories(newRepositories(system, session));
    ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
    artifact = artifactResult.getArtifact();
    System.out.println(artifact + " resolved to  " + artifact.getFile());
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 32 with ArtifactRequest

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

the class Dependency31Helper method resolveArtifact.

private ArtifactResult resolveArtifact(Artifact artifact) throws ArtifactResolutionException {
    ArtifactResult result = artifactCache.get(artifact);
    if (result != null) {
        return result;
    }
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact);
    request.setRepositories(projectRepositories);
    result = repositorySystem.resolveArtifact(repositorySystemSession, request);
    if (result != null) {
        artifactCache.put(artifact, result);
    }
    return result;
}
Also used : ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 33 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project liferay-ide by liferay.

the class AetherUtil method getLatestAvailableArtifact.

public static Artifact getLatestAvailableArtifact(String gavCoords) {
    Artifact retval = null;
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    String latestVersion = getLatestVersion(gavCoords, system, session);
    String[] gav = gavCoords.split(":");
    Artifact defaultArtifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":" + latestVersion);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(defaultArtifact);
    artifactRequest.addRepository(newCentralRepository());
    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
        retval = artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        LiferayMavenCore.logError("Unable to get latest Liferay archetype", e);
        artifactRequest.setArtifact(new DefaultArtifact(gavCoords));
        try {
            retval = system.resolveArtifact(session, artifactRequest).getArtifact();
        } catch (ArtifactResolutionException e1) {
            LiferayMavenCore.logError("Unable to get default Liferay archetype", e1);
        }
    }
    if (retval == null) {
        retval = defaultArtifact;
    }
    return retval;
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 34 with ArtifactRequest

use of org.eclipse.aether.resolution.ArtifactRequest in project fabric8-maven-plugin by fabric8io.

the class AbstractArtifactSearchMojo method resolveArtifactFile.

protected File resolveArtifactFile(HelmIndexMojo.ArtifactDTO artifactDTO, String classifier, String extension) {
    File file = null;
    try {
        ArtifactRequest artifactRequest = new ArtifactRequest();
        org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(artifactDTO.getG(), artifactDTO.getA(), classifier, extension, artifactDTO.getV());
        artifactRequest.setArtifact(artifact);
        // convert maven remote repositories to Aether repos
        List<RemoteRepository> aetherRepoList = new ArrayList<>();
        for (MavenArtifactRepository remoteRepository : remoteRepositories) {
            RemoteRepository.Builder builder = new RemoteRepository.Builder(remoteRepository.getId(), remoteRepository.getLayout().getId(), remoteRepository.getUrl());
            RemoteRepository aetherRepo = builder.build();
            aetherRepoList.add(aetherRepo);
        }
        artifactRequest.setRepositories(aetherRepoList);
        ArtifactResult artifactResult = artifactResolver.resolveArtifact(repoSession, artifactRequest);
        org.eclipse.aether.artifact.Artifact resolvedArtifact = artifactResult.getArtifact();
        if (resolvedArtifact == null) {
            getLog().warn("Could not resolve artifact " + artifactDTO.description());
            return null;
        }
        file = resolvedArtifact.getFile();
    } catch (Exception e) {
        getLog().warn("Failed to resolve manifest manifest for " + artifactDTO.description() + ". " + e, e);
        return null;
    }
    if (file == null) {
        getLog().warn("Could not resolve artifact file for " + artifactDTO.description());
        return null;
    }
    if (!file.isFile() || !file.exists()) {
        getLog().warn("Resolved artifact file does not exist for " + artifactDTO.description());
        return null;
    }
    return file;
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) MavenArtifactRepository(org.apache.maven.artifact.repository.MavenArtifactRepository) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 35 with ArtifactRequest

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

the class ArtifactResolver method resolveArtifact.

private Artifact resolveArtifact(Artifact artifact, RepositorySystemSession session) throws ArtifactResolutionException {
    ArtifactRequest request = new ArtifactRequest().setArtifact(artifact).setRepositories(repositories);
    ArtifactResult result = repositorySystem.resolveArtifact(session, request);
    return result.getArtifact();
}
Also used : LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

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