Search in sources :

Example 16 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project zeppelin by apache.

the class SparkDependencyResolver 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 Exception {
    Artifact artifact = new DefaultArtifact(inferScalaVersion(dependency));
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(inferScalaVersion(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));
    return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
}
Also used : DependencyRequest(org.sonatype.aether.resolution.DependencyRequest) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.sonatype.aether.util.filter.PatternExclusionsDependencyFilter)

Example 17 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project storm by apache.

the class DependencyResolverMain method main.

public static void main(String[] args) {
    if (args.length < 1) {
        throw new IllegalArgumentException("artifacts must be presented.");
    }
    String artifactsArg = args[0];
    // DO NOT CHANGE THIS TO SYSOUT
    System.err.println("DependencyResolver input - artifacts: " + artifactsArg);
    List<Dependency> dependencies = parseArtifactArgs(artifactsArg);
    List<RemoteRepository> repositories;
    if (args.length > 1) {
        String remoteRepositoryArg = args[1];
        // DO NOT CHANGE THIS TO SYSOUT
        System.err.println("DependencyResolver input - repositories: " + remoteRepositoryArg);
        repositories = parseRemoteRepositoryArgs(remoteRepositoryArg);
    } else {
        repositories = Collections.emptyList();
    }
    try {
        String localMavenRepoPath = getOrDefaultLocalMavenRepositoryPath("local-repo");
        DependencyResolver resolver = new DependencyResolver(localMavenRepoPath, repositories);
        List<ArtifactResult> artifactResults = resolver.resolve(dependencies);
        Iterable<ArtifactResult> missingArtifacts = filterMissingArtifacts(artifactResults);
        if (missingArtifacts.iterator().hasNext()) {
            printMissingArtifactsToSysErr(missingArtifacts);
            throw new RuntimeException("Some artifacts are not resolved");
        }
        System.out.println(JSONValue.toJSONString(transformArtifactResultToArtifactToPaths(artifactResults)));
        System.out.flush();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Dependency(org.sonatype.aether.graph.Dependency) DependencyResolver(org.apache.storm.submit.dependency.DependencyResolver) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 18 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class DefaultMirrorSelector method getMirror.

public RemoteRepository getMirror(RemoteRepository repository) {
    MirrorDef mirror = findMirror(repository);
    if (mirror == null) {
        return null;
    }
    RemoteRepository repo = new RemoteRepository();
    repo.setRepositoryManager(mirror.repositoryManager);
    repo.setId(mirror.id);
    repo.setUrl(mirror.url);
    if (mirror.type != null && mirror.type.length() > 0) {
        repo.setContentType(mirror.type);
    } else {
        repo.setContentType(repository.getContentType());
    }
    repo.setPolicy(true, repository.getPolicy(true));
    repo.setPolicy(false, repository.getPolicy(false));
    repo.setMirroredRepositories(Collections.singletonList(repository));
    return repo;
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 19 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class DefaultRepositorySystemSessionTest method testDefaultAuthenticationSelectorUsesExistingAuth.

@Test
public void testDefaultAuthenticationSelectorUsesExistingAuth() {
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
    RemoteRepository repo = new RemoteRepository("id", "default", "void");
    assertSame(null, session.getAuthenticationSelector().getAuthentication(repo));
    repo.setAuthentication(new Authentication("user", "pass"));
    assertSame(repo.getAuthentication(), session.getAuthenticationSelector().getAuthentication(repo));
}
Also used : Authentication(org.sonatype.aether.repository.Authentication) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 20 with RemoteRepository

use of org.sonatype.aether.repository.RemoteRepository in project sonatype-aether by sonatype.

the class DefaultRemoteRepositoryManager method aggregateRepositories.

public List<RemoteRepository> aggregateRepositories(RepositorySystemSession session, List<RemoteRepository> dominantRepositories, List<RemoteRepository> recessiveRepositories, boolean recessiveIsRaw) {
    if (recessiveRepositories.isEmpty()) {
        return dominantRepositories;
    }
    MirrorSelector mirrorSelector = session.getMirrorSelector();
    AuthenticationSelector authSelector = session.getAuthenticationSelector();
    ProxySelector proxySelector = session.getProxySelector();
    List<RemoteRepository> result = new ArrayList<RemoteRepository>(dominantRepositories);
    next: for (RemoteRepository recessiveRepository : recessiveRepositories) {
        RemoteRepository repository = recessiveRepository;
        if (recessiveIsRaw) {
            RemoteRepository mirrorRepository = mirrorSelector.getMirror(recessiveRepository);
            if (mirrorRepository == null) {
                repository = recessiveRepository;
            } else {
                logger.debug("Using mirror " + mirrorRepository.getId() + " (" + mirrorRepository.getUrl() + ") for " + recessiveRepository.getId() + " (" + recessiveRepository.getUrl() + ").");
                repository = mirrorRepository;
            }
        }
        String key = getKey(repository);
        for (ListIterator<RemoteRepository> it = result.listIterator(); it.hasNext(); ) {
            RemoteRepository dominantRepository = it.next();
            if (key.equals(getKey(dominantRepository))) {
                if (!dominantRepository.getMirroredRepositories().isEmpty() && !repository.getMirroredRepositories().isEmpty()) {
                    RemoteRepository mergedRepository = mergeMirrors(session, dominantRepository, repository);
                    if (mergedRepository != dominantRepository) {
                        it.set(mergedRepository);
                    }
                }
                continue next;
            }
        }
        if (recessiveIsRaw) {
            Authentication auth = authSelector.getAuthentication(repository);
            if (auth != null) {
                repository.setAuthentication(auth);
            }
            Proxy proxy = proxySelector.getProxy(repository);
            if (proxy != null) {
                repository.setProxy(proxy);
            }
        }
        result.add(repository);
    }
    return result;
}
Also used : ProxySelector(org.sonatype.aether.repository.ProxySelector) Proxy(org.sonatype.aether.repository.Proxy) AuthenticationSelector(org.sonatype.aether.repository.AuthenticationSelector) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) Authentication(org.sonatype.aether.repository.Authentication) ArrayList(java.util.ArrayList) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) ListIterator(java.util.ListIterator)

Aggregations

RemoteRepository (org.sonatype.aether.repository.RemoteRepository)71 Artifact (org.sonatype.aether.artifact.Artifact)30 Test (org.junit.Test)27 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)18 File (java.io.File)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)15 TestRepositorySystemSession (org.sonatype.aether.test.impl.TestRepositorySystemSession)13 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)13 Dependency (org.sonatype.aether.graph.Dependency)12 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)12 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)12 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)11 CollectRequest (org.sonatype.aether.collection.CollectRequest)10 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)10 ArrayList (java.util.ArrayList)8 RepositorySystem (org.sonatype.aether.RepositorySystem)8 IOException (java.io.IOException)7 Before (org.junit.Before)7 Metadata (org.sonatype.aether.metadata.Metadata)7 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)7