Search in sources :

Example 1 with Proxy

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

the class AbstractDependencyResolver method setProxy.

public void setProxy(URL proxyUrl, String proxyUser, String proxyPassword) {
    Authentication auth = new Authentication(proxyUser, proxyPassword);
    Proxy proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            repo.setProxy(proxy);
        }
    }
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) RemoteRepository(org.sonatype.aether.repository.RemoteRepository)

Example 2 with Proxy

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

the class ProxyGetTest method before.

@Override
@Before
public void before() throws Exception {
    super.before();
    Authentication auth = new Authentication("puser", "password");
    Proxy proxy = new Proxy("http", "localhost", provider().getPort(), auth);
    repository().setProxy(proxy);
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) Before(org.junit.Before)

Example 3 with Proxy

use of org.sonatype.aether.repository.Proxy 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 4 with Proxy

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

the class DefaultRemoteRepositoryManagerTest method testMirrorProxy.

@Test
public void testMirrorProxy() {
    final RemoteRepository repo = newRepo("a", "http://", false, "", "");
    final RemoteRepository mirror = newRepo("a", "http://", false, "", "");
    mirror.setProxy(new Proxy("http", "host", 2011, null));
    session.setMirrorSelector(new MirrorSelector() {

        public RemoteRepository getMirror(RemoteRepository repository) {
            return mirror;
        }
    });
    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 : Proxy(org.sonatype.aether.repository.Proxy) MirrorSelector(org.sonatype.aether.repository.MirrorSelector) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Test(org.junit.Test)

Example 5 with Proxy

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

the class DefaultRemoteRepositoryManager method getRepositoryConnector.

public RepositoryConnector getRepositoryConnector(RepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException {
    if (repository == null) {
        throw new IllegalArgumentException("remote repository has not been specified");
    }
    List<RepositoryConnectorFactory> factories = new ArrayList<RepositoryConnectorFactory>(connectorFactories);
    Collections.sort(factories, COMPARATOR);
    for (RepositoryConnectorFactory factory : factories) {
        try {
            RepositoryConnector connector = factory.newInstance(session, repository);
            if (logger.isDebugEnabled()) {
                StringBuilder buffer = new StringBuilder(256);
                buffer.append("Using connector ").append(connector.getClass().getSimpleName());
                buffer.append(" with priority ").append(factory.getPriority());
                buffer.append(" for ").append(repository.getUrl());
                Authentication auth = repository.getAuthentication();
                if (auth != null) {
                    buffer.append(" as ").append(auth.getUsername());
                }
                Proxy proxy = repository.getProxy();
                if (proxy != null) {
                    buffer.append(" via ").append(proxy.getHost()).append(':').append(proxy.getPort());
                    auth = proxy.getAuthentication();
                    if (auth != null) {
                        buffer.append(" as ").append(auth.getUsername());
                    }
                }
                logger.debug(buffer.toString());
            }
            return connector;
        } catch (NoRepositoryConnectorException e) {
        // continue and try next factory
        }
    }
    StringBuilder buffer = new StringBuilder(256);
    buffer.append("No connector available to access repository ");
    buffer.append(repository.getId());
    buffer.append(" (").append(repository.getUrl());
    buffer.append(") of type ").append(repository.getContentType());
    buffer.append(" using the available factories ");
    for (ListIterator<RepositoryConnectorFactory> it = factories.listIterator(); it.hasNext(); ) {
        RepositoryConnectorFactory factory = it.next();
        buffer.append(factory.getClass().getSimpleName());
        if (it.hasNext()) {
            buffer.append(", ");
        }
    }
    throw new NoRepositoryConnectorException(repository, buffer.toString());
}
Also used : Proxy(org.sonatype.aether.repository.Proxy) Authentication(org.sonatype.aether.repository.Authentication) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) ArrayList(java.util.ArrayList) RepositoryConnectorFactory(org.sonatype.aether.spi.connector.RepositoryConnectorFactory) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector)

Aggregations

Proxy (org.sonatype.aether.repository.Proxy)12 Authentication (org.sonatype.aether.repository.Authentication)8 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)5 Test (org.junit.Test)3 MirrorSelector (org.sonatype.aether.repository.MirrorSelector)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 ProxySelector (org.sonatype.aether.repository.ProxySelector)2 ProxyServer (com.ning.http.client.ProxyServer)1 ListIterator (java.util.ListIterator)1 RemoteRepository (org.apache.maven.artifact.ant.RemoteRepository)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1 ProxyInfoProvider (org.apache.maven.wagon.proxy.ProxyInfoProvider)1 AuthenticationSelector (org.sonatype.aether.repository.AuthenticationSelector)1 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)1 RepositoryConnectorFactory (org.sonatype.aether.spi.connector.RepositoryConnectorFactory)1 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)1 DefaultProxySelector (org.sonatype.aether.util.repository.DefaultProxySelector)1