org.eclipse.aether.repository.ProxySelector Java Examples

The following examples show how to use org.eclipse.aether.repository.ProxySelector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JreProxySelector.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public Proxy getProxy(final String url) {
  try {
    final java.net.ProxySelector systemSelector = java.net.ProxySelector.getDefault();
    if (systemSelector == null) {
      return null;
    }
    final URI uri = new URI(url).parseServerAuthority();
    final List<java.net.Proxy> selected = systemSelector.select(uri);
    if (selected == null || selected.isEmpty()) {
      return null;
    }
    for (java.net.Proxy proxy : selected) {
      if (proxy.type() == java.net.Proxy.Type.HTTP && isValid(proxy.address())) {
        final String proxyType = chooseProxyType(uri.getScheme());
        if (proxyType != null) {
          final InetSocketAddress addr = (InetSocketAddress)proxy.address();
          return new Proxy(proxyType, addr.getHostName(), addr.getPort(), JreProxyAuthentication.INSTANCE);
        }
      }
    }
  }
  catch (Throwable e) {
    // URL invalid or not accepted by selector or no selector at all, simply use no proxy
  }
  return null;
}
 
Example #2
Source File: DependencyResolver.java    From spring-cloud-function with Apache License 2.0 6 votes vote down vote up
private DefaultRepositorySystemSession createSession(Properties properties)
		throws NoLocalRepositoryManagerException {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	LocalRepository repository = localRepository(properties);
	session.setLocalRepositoryManager(
			this.localRepositoryManagerFactory.newInstance(session, repository));
	applySettings(session);
	ProxySelector existing = session.getProxySelector();
	if (existing == null || !(existing instanceof CompositeProxySelector)) {
		JreProxySelector fallback = new JreProxySelector();
		ProxySelector selector = existing == null ? fallback
				: new CompositeProxySelector(Arrays.asList(existing, fallback));
		session.setProxySelector(selector);
	}
	return session;
}
 
Example #3
Source File: DependencyResolver.java    From spring-init with Apache License 2.0 6 votes vote down vote up
private DefaultRepositorySystemSession createSession(Properties properties)
		throws NoLocalRepositoryManagerException {
	DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
	LocalRepository repository = localRepository(properties);
	session.setLocalRepositoryManager(
			localRepositoryManagerFactory.newInstance(session, repository));
	applySettings(session);
	ProxySelector existing = session.getProxySelector();
	if (existing == null || !(existing instanceof CompositeProxySelector)) {
		JreProxySelector fallback = new JreProxySelector();
		ProxySelector selector = existing == null ? fallback
				: new CompositeProxySelector(Arrays.asList(existing, fallback));
		session.setProxySelector(selector);
	}
	return session;
}
 
Example #4
Source File: Utils.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static Proxy getProxy(RemoteRepository repo, ProxySelector ... selectors) {
  Proxy proxy = null;
  
  for (ProxySelector selector : selectors) {
    if (selector != null) {
      proxy = selector.getProxy(repo);
    }
    
    if (proxy != null) return proxy;
  }
  
  return proxy;
}
 
Example #5
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #6
Source File: CompositeProxySelector.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@Override
public Proxy getProxy(RemoteRepository repository) {
	for (ProxySelector selector : this.selectors) {
		Proxy proxy = selector.getProxy(repository);
		if (proxy != null) {
			return proxy;
		}
	}
	return null;
}
 
Example #7
Source File: MavenArtifactResolvingHelperTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public MavenArtifactResolvingHelperTest() {
    sessionMock = Mockito.mock(RepositorySystemSession.class);
    MirrorSelector mirrorSelectorMock = Mockito.mock(MirrorSelector.class);
    Mockito.when(sessionMock.getMirrorSelector()).thenReturn(mirrorSelectorMock);
    ProxySelector proxySelectorMock = Mockito.mock(ProxySelector.class);
    Mockito.when(sessionMock.getProxySelector()).thenReturn(proxySelectorMock);
    localRepositoryManager = Mockito.mock(LocalRepositoryManager.class);
    Mockito.when(sessionMock.getLocalRepositoryManager()).thenReturn(localRepositoryManager);
    resolver = Mockito.mock(ArtifactResolver.class);
    system = Mockito.mock(RepositorySystem.class);

}
 
Example #8
Source File: Util.java    From galleon with Apache License 2.0 5 votes vote down vote up
public static RepositorySystemSession newRepositorySession(final RepositorySystem repoSystem,
        Path path, RepositoryListener listener, ProxySelector proxySelector, boolean offline) {
    final DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
    session.setRepositoryListener(listener);
    session.setOffline(offline);
    final LocalRepository localRepo = new LocalRepository(path.toString());
    session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
    if (proxySelector != null) {
        session.setProxySelector(proxySelector);
    }
    return session;
}
 
Example #9
Source File: ChainedProxySelector.java    From gate-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Proxy getProxy(RemoteRepository repo) {
  Proxy proxy = null;
  
  for (ProxySelector selector : selectors) {
    if (selector != null) {
      proxy = selector.getProxy(repo);
    }
    
    if (proxy != null) return proxy;
  }
  
  return proxy;
}
 
Example #10
Source File: MavenSettings.java    From spring-init with Apache License 2.0 5 votes vote down vote up
private ProxySelector createProxySelector(
		SettingsDecryptionResult decryptedSettings) {
	DefaultProxySelector selector = new DefaultProxySelector();
	for (Proxy proxy : decryptedSettings.getProxies()) {
		Authentication authentication = new AuthenticationBuilder()
				.addUsername(proxy.getUsername()).addPassword(proxy.getPassword())
				.build();
		selector.add(
				new org.eclipse.aether.repository.Proxy(proxy.getProtocol(),
						proxy.getHost(), proxy.getPort(), authentication),
				proxy.getNonProxyHosts());
	}
	return selector;
}
 
Example #11
Source File: CompositeProxySelector.java    From spring-init with Apache License 2.0 5 votes vote down vote up
@Override
public Proxy getProxy(RemoteRepository repository) {
	for (ProxySelector selector : this.selectors) {
		Proxy proxy = selector.getProxy(repository);
		if (proxy != null) {
			return proxy;
		}
	}
	return null;
}
 
Example #12
Source File: MvnSettingsTestCase.java    From galleon with Apache License 2.0 5 votes vote down vote up
@Test
public void testProxy() throws Exception {
    RepositorySystem system = Util.newRepositorySystem();
    MavenConfig config = new MavenConfig();
    InputStream stream = MvnSettingsTestCase.class.getClassLoader().
            getResourceAsStream("settings_cli_test_proxy.xml");
    File tmp = File.createTempFile("cli_mvn_test", null);
    tmp.deleteOnExit();
    Files.copy(stream, tmp.toPath(), StandardCopyOption.REPLACE_EXISTING);
    config.setSettings(tmp.toPath());
    MavenMvnSettings settings = new MavenMvnSettings(config, system, null);
    ProxySelector proxy = settings.getSession().getProxySelector();
    assertEquals(6, settings.getRepositories().size());
    for (RemoteRepository remote : settings.getRepositories()) {
        if (remote.getId().equals("repo1")) {
            assertNull(proxy.getProxy(remote));
            assertNull(remote.getProxy());
        }
        if (remote.getId().equals("repo2")) {
            assertNull(proxy.getProxy(remote));
            assertNull(remote.getProxy());
        }
        if (remote.getId().equals("repo3")) {
            Proxy p = proxy.getProxy(remote);
            assertEquals("proxy1", p.getHost());
            assertNotNull(remote.getProxy());
        }
    }
}
 
Example #13
Source File: ChainedProxySelector.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void addSelector(ProxySelector sel) {
  selectors.add(sel);
}
 
Example #14
Source File: RepositorySystemSessionWrapper.java    From wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public ProxySelector getProxySelector() {
    return delegate.getProxySelector();
}
 
Example #15
Source File: RepositorySystemSessionWrapper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public ProxySelector getProxySelector() {
    return delegate.getProxySelector();
}
 
Example #16
Source File: MavenSettings.java    From spring-init with Apache License 2.0 4 votes vote down vote up
public ProxySelector getProxySelector() {
	return this.proxySelector;
}
 
Example #17
Source File: CompositeProxySelector.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public CompositeProxySelector(List<ProxySelector> selectors) {
	this.selectors = selectors;
}
 
Example #18
Source File: MavenSettings.java    From spring-cloud-function with Apache License 2.0 4 votes vote down vote up
public ProxySelector getProxySelector() {
	return this.proxySelector;
}
 
Example #19
Source File: CompositeProxySelector.java    From spring-init with Apache License 2.0 4 votes vote down vote up
public CompositeProxySelector(List<ProxySelector> selectors) {
	this.selectors = selectors;
}