Search in sources :

Example 6 with RepositoryException

use of org.eclipse.aether.RepositoryException in project revapi by revapi.

the class Main method convertGavs.

private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo) {
    RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem();
    DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, localRepo);
    session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
    session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
    RemoteRepository mavenCentral = new RemoteRepository.Builder("@@forced-maven-central@@", "default", "http://repo.maven.apache.org/maven2/").build();
    List<RemoteRepository> remoteRepositories = singletonList(mavenCentral);
    ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories);
    List<FileArchive> archives = new ArrayList<>();
    List<FileArchive> supplementaryArchives = new ArrayList<>();
    for (String gav : gavs) {
        try {
            archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile()));
            ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav);
            res.getResolvedArtifacts().forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile())));
            if (!res.getFailures().isEmpty()) {
                LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString());
            }
        } catch (RepositoryException e) {
            throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage());
        }
    }
    return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives);
}
Also used : ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) FileArchive(org.revapi.simple.FileArchive) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector)

Example 7 with RepositoryException

use of org.eclipse.aether.RepositoryException in project zeppelin by apache.

the class DependencyResolver method getArtifactsWithDep.

/**
 * @param dependency
 * @param excludes list of pattern can either be of the form groupId:artifactId
 * @return
 * @throws Exception
 */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
    Artifact artifact = new DefaultArtifact(dependency);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    try {
        return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    } catch (NullPointerException | DependencyResolutionException ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) RepositoryException(org.eclipse.aether.RepositoryException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter)

Example 8 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class AetherBasedResolver method resolveFile.

/**
 * Resolve maven artifact as file in repository.
 */
public File resolveFile(Artifact artifact, MavenRepositoryURL repositoryURL, Exception previousException) throws IOException {
    List<LocalRepository> defaultRepos = selectDefaultRepositories();
    List<RemoteRepository> remoteRepos = selectRepositories();
    if (repositoryURL != null) {
        addRepo(remoteRepos, repositoryURL);
    }
    if (previousException != null) {
        // we'll try using previous repositories, without these that will fail again anyway
        List<RemoteRepository> altered = new LinkedList<>();
        RepositoryException repositoryException = findAetherException(previousException);
        if (repositoryException instanceof ArtifactResolutionException) {
            // check only this aggregate exception and assume it's related to current artifact
            ArtifactResult result = ((ArtifactResolutionException) repositoryException).getResult();
            if (result != null && result.getRequest() != null && result.getRequest().getArtifact().equals(artifact)) {
                // - these exceptions contain repository that was checked
                for (Exception exception : result.getExceptions()) {
                    RepositoryException singleException = findAetherException(exception);
                    if (singleException instanceof ArtifactTransferException) {
                        RemoteRepository repository = ((ArtifactTransferException) singleException).getRepository();
                        if (repository != null) {
                            RetryChance chance = isRetryableException(singleException);
                            if (chance == RetryChance.NEVER) {
                                LOG.debug("Removing " + repository + " from list of repositories, previous exception: " + singleException.getClass().getName() + ": " + singleException.getMessage());
                            } else {
                                altered.add(repository);
                            }
                        }
                    }
                }
                // swap list of repos now
                remoteRepos = altered;
            }
        }
    }
    assignProxyAndMirrors(remoteRepos);
    File resolved = resolve(defaultRepos, remoteRepos, artifact);
    LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
    return resolved;
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) LocalRepository(org.eclipse.aether.repository.LocalRepository) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) RepositoryException(org.eclipse.aether.RepositoryException) File(java.io.File) JarFile(java.util.jar.JarFile) LinkedList(java.util.LinkedList) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 9 with RepositoryException

use of org.eclipse.aether.RepositoryException in project fabric8 by jboss-fuse.

the class ReplaceConflictingVersionResolver method transformGraph.

public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
    List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    if (sortedConflictIds == null) {
        ConflictIdSorter sorter = new ConflictIdSorter();
        sorter.transformGraph(node, context);
        sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
    }
    Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
    if (conflictIds == null) {
        throw new RepositoryException("conflict groups have not been identified");
    }
    Map<DependencyNode, Integer> depths = new TreeMap<DependencyNode, Integer>(DependencyNodeComparator.INSTANCE);
    for (Object key : sortedConflictIds) {
        ConflictGroup group = new ConflictGroup(key);
        depths.clear();
        selectVersion(node, null, 0, depths, group, conflictIds);
        updateNonSelectedVersions(group, conflictIds);
    }
    return node;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) ConflictIdSorter(org.eclipse.aether.util.graph.transformer.ConflictIdSorter) RepositoryException(org.eclipse.aether.RepositoryException) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 10 with RepositoryException

use of org.eclipse.aether.RepositoryException in project zeppelin by apache.

the class InstallInterpreter method install.

public void install(String name, String artifact) {
    Proxy proxy = null;
    if (proxyUrl != null) {
        Authentication auth = new AuthenticationBuilder().addUsername(proxyUser).addPassword(proxyPassword).build();
        proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
    }
    DependencyResolver depResolver = new DependencyResolver(localRepoDir, proxy);
    File installDir = new File(interpreterBaseDir, name);
    if (installDir.exists()) {
        System.err.println("Directory " + installDir.getAbsolutePath() + " already exists" + "\n\nSkipped");
        return;
    }
    System.out.println("Install " + name + "(" + artifact + ") to " + installDir.getAbsolutePath() + " ... ");
    try {
        depResolver.load(artifact, installDir);
        System.out.println("Interpreter " + name + " installed under " + installDir.getAbsolutePath() + ".");
        startTip();
    } catch (RepositoryException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Proxy(org.eclipse.aether.repository.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) Authentication(org.eclipse.aether.repository.Authentication) RepositoryException(org.eclipse.aether.RepositoryException) IOException(java.io.IOException) File(java.io.File) DependencyResolver(org.apache.zeppelin.dep.DependencyResolver)

Aggregations

RepositoryException (org.eclipse.aether.RepositoryException)10 IOException (java.io.IOException)7 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)5 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)5 ArtifactNotFoundException (org.eclipse.aether.transfer.ArtifactNotFoundException)5 ArtifactTransferException (org.eclipse.aether.transfer.ArtifactTransferException)5 ConnectException (java.net.ConnectException)4 MalformedURLException (java.net.MalformedURLException)4 NoRouteToHostException (java.net.NoRouteToHostException)4 SocketTimeoutException (java.net.SocketTimeoutException)4 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)4 MetadataNotFoundException (org.eclipse.aether.transfer.MetadataNotFoundException)4 MetadataTransferException (org.eclipse.aether.transfer.MetadataTransferException)4 InvalidVersionSpecificationException (org.eclipse.aether.version.InvalidVersionSpecificationException)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)3 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)3