Search in sources :

Example 26 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException 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 27 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project kie-wb-common by kiegroup.

the class MavenArtifactResolverTest method resolveArtifactOffline.

@Test
public void resolveArtifactOffline() throws Exception {
    final boolean[] executedOffline = { true };
    RepositorySystemSession session = Aether.getAether().getSession();
    assertThat(checksIfArtifactIsPresent(session)).isFalse();
    File file = new File("target/test-classes/fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
    assertThat(file).exists();
    Artifact artifact = getArtifact();
    artifact = artifact.setFile(file);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(artifact);
    ArtifactResult result;
    try {
        Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
    } catch (ArtifactResolutionException ex) {
        assertThat(ex).isNotNull();
    }
    deployTestJar(artifact, session);
    MavenArtifactResolver resolver = new MavenArtifactResolver() {

        public URI resolve(final String groupId, final String artifactId, final String version) throws Exception {
            return internalResolver(true, groupId, artifactId, version);
        }

        URI resolveEmbedded(final String groupId, final String artifactId, final String version) throws IOException {
            executedOffline[0] = false;
            return super.resolveEmbedded(groupId, artifactId, version);
        }
    };
    URI uri = resolver.resolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
    assertThat(uri).isNotNull();
    assertThat(uri.getPath()).endsWith(File.separator + "fake-uberfire-m2repo-editor-backend" + File.separator + "100-SNAPSHOT" + File.separator + "fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
    result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
    assertThat(result.isMissing()).isFalse();
    assertThat(result.isResolved()).isTrue();
    assertThat(executedOffline[0]).isTrue();
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) File(java.io.File) URI(java.net.URI) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 28 with ArtifactResolutionException

use of org.eclipse.aether.resolution.ArtifactResolutionException in project kie-wb-common by kiegroup.

the class MavenArtifactResolverTest method checksIfArtifactIsPresent.

private boolean checksIfArtifactIsPresent(RepositorySystemSession session) {
    try {
        ArtifactRequest artifactRequest = new ArtifactRequest();
        artifactRequest.setArtifact(getArtifact());
        Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
        return true;
    } catch (ArtifactResolutionException e) {
        return false;
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest)

Example 29 with ArtifactResolutionException

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

the class Dependency31Helper method resolveById.

@Override
public File resolveById(String id, Log log) throws MojoFailureException {
    if (id.startsWith("mvn:")) {
        if (id.contains("!")) {
            id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
        }
        if (id.endsWith("/")) {
            id = id.substring(0, id.length() - 1);
        }
    }
    id = MavenUtil.mvnToAether(id);
    if (log.isDebugEnabled()) {
        log.debug("Resolving artifact " + id + " from " + projectRepositories);
    }
    ArtifactResult result;
    try {
        result = resolveArtifact(MavenUtil.aetherToArtifact(id));
    } catch (ArtifactResolutionException e) {
        log.warn("Could not resolve " + id, e);
        throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
    }
    if (log.isDebugEnabled()) {
        log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
    }
    return result.getArtifact().getFile();
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 30 with ArtifactResolutionException

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

the class MavenServerImpl method resolveArtifact.

@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
    Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
    List<ArtifactRepository> repos = new ArrayList<>();
    ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
    for (MavenRemoteRepository repository : repositories) {
        try {
            ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
            repos.add(artifactRepository);
        } catch (InvalidRepositoryException e) {
            MavenServerContext.getLogger().error(e);
        }
    }
    MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
    repos.forEach(request::addRemoteRepository);
    DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
    RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
    org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
    InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
    if (artifactResolver instanceof DefaultArtifactResolver) {
        ((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
    }
    org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
    if (repositorySystem instanceof DefaultRepositorySystem) {
        ((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
    }
    List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
    remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
    try {
        ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
        return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
    } catch (ArtifactResolutionException e) {
        MavenServerContext.getLogger().info(e);
    }
    return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Also used : DefaultMaven(org.apache.maven.DefaultMaven) Maven(org.apache.maven.Maven) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) DefaultRepositorySystem(org.eclipse.aether.internal.impl.DefaultRepositorySystem) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultMavenExecutionRequest(org.apache.maven.execution.DefaultMavenExecutionRequest) ArrayList(java.util.ArrayList) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifactResolver(org.eclipse.aether.internal.impl.DefaultArtifactResolver) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactRepositoryFactory(org.apache.maven.artifact.repository.ArtifactRepositoryFactory) DefaultMaven(org.apache.maven.DefaultMaven) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) MavenArtifact(org.eclipse.che.maven.data.MavenArtifact) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) ArtifactFactory(org.apache.maven.artifact.factory.ArtifactFactory) MavenRemoteRepository(org.eclipse.che.maven.data.MavenRemoteRepository)

Aggregations

ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)52 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)33 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)32 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)27 File (java.io.File)21 Artifact (org.eclipse.aether.artifact.Artifact)21 IOException (java.io.IOException)19 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)10 FileNotFoundException (java.io.FileNotFoundException)9 MalformedURLException (java.net.MalformedURLException)9 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)9 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)8 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)7 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)7 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)7 ArrayList (java.util.ArrayList)6 Model (org.apache.maven.model.Model)6 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)6