Search in sources :

Example 1 with ProxySelector

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

the class DefaultRemoteRepositoryManagerTest method testProxySelector.

@Test
public void testProxySelector() {
    final RemoteRepository repo = newRepo("a", "http://", false, "", "");
    final Proxy proxy = new Proxy("http", "host", 2011, null);
    session.setProxySelector(new ProxySelector() {

        public Proxy getProxy(RemoteRepository repository) {
            return proxy;
        }
    });
    session.setMirrorSelector(new MirrorSelector() {

        public RemoteRepository getMirror(RemoteRepository repository) {
            return null;
        }
    });
    List<RemoteRepository> result = manager.aggregateRepositories(session, Collections.<RemoteRepository>emptyList(), Arrays.asList(repo), true);
    assertEquals(1, result.size());
    assertEquals("http", result.get(0).getProxy().getType());
    assertEquals("host", result.get(0).getProxy().getHost());
    assertEquals(2011, result.get(0).getProxy().getPort());
}
Also used : ProxySelector(org.sonatype.aether.repository.ProxySelector) Proxy(org.sonatype.aether.repository.Proxy) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 2 with ProxySelector

use of org.sonatype.aether.repository.ProxySelector 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

MirrorSelector (org.sonatype.aether.repository.MirrorSelector)2 Proxy (org.sonatype.aether.repository.Proxy)2 ProxySelector (org.sonatype.aether.repository.ProxySelector)2 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)2 ArrayList (java.util.ArrayList)1 ListIterator (java.util.ListIterator)1 Test (org.junit.Test)1 Authentication (org.sonatype.aether.repository.Authentication)1 AuthenticationSelector (org.sonatype.aether.repository.AuthenticationSelector)1