Search in sources :

Example 11 with Proxy

use of org.apache.maven.settings.Proxy in project maven-plugins by apache.

the class RepositoryUtils method getProxyInfo.

// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
     * Convenience method to map a <code>Proxy</code> object from the user system settings to a <code>ProxyInfo</code>
     * object.
     *
     * @return a proxyInfo object instanced or null if no active proxy is define in the settings.xml
     */
private ProxyInfo getProxyInfo() {
    if (settings == null || settings.getActiveProxy() == null) {
        return null;
    }
    Proxy settingsProxy = settings.getActiveProxy();
    ProxyInfo proxyInfo = new ProxyInfo();
    proxyInfo.setHost(settingsProxy.getHost());
    proxyInfo.setType(settingsProxy.getProtocol());
    proxyInfo.setPort(settingsProxy.getPort());
    proxyInfo.setNonProxyHosts(settingsProxy.getNonProxyHosts());
    proxyInfo.setUserName(settingsProxy.getUsername());
    proxyInfo.setPassword(settingsProxy.getPassword());
    return proxyInfo;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Proxy(org.apache.maven.settings.Proxy)

Example 12 with Proxy

use of org.apache.maven.settings.Proxy in project karaf by apache.

the class MojoSupport method configureProxyToInlineRepo.

private org.apache.maven.repository.Proxy configureProxyToInlineRepo() {
    if (mavenSession != null && mavenSession.getSettings() != null) {
        Proxy proxy = mavenSession.getSettings().getActiveProxy();
        org.apache.maven.repository.Proxy mavenProxy = new org.apache.maven.repository.Proxy();
        if (proxy != null) {
            mavenProxy.setProtocol(proxy.getProtocol());
            mavenProxy.setHost(proxy.getHost());
            mavenProxy.setPort(proxy.getPort());
            mavenProxy.setNonProxyHosts(proxy.getNonProxyHosts());
            mavenProxy.setUserName(proxy.getUsername());
            mavenProxy.setPassword(proxy.getPassword());
            return mavenProxy;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy)

Example 13 with Proxy

use of org.apache.maven.settings.Proxy in project cuke4duke by cucumber.

the class AbstractJRubyMojo method getProxyArg.

/**
 * Detect proxy from settings and convert to arg expected by RubyGems.
 */
protected String getProxyArg() {
    Proxy activeProxy = this.settings.getActiveProxy();
    if (activeProxy == null) {
        return "";
    }
    String proxyArg = " --http-proxy " + activeProxy.getProtocol() + "://" + activeProxy.getHost() + ":" + activeProxy.getPort();
    getLog().debug("Adding proxy from settings.xml: " + proxyArg);
    return proxyArg;
}
Also used : Proxy(org.apache.maven.settings.Proxy)

Example 14 with Proxy

use of org.apache.maven.settings.Proxy in project spring-boot by spring-projects.

the class MavenSettings method createProxySelector.

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;
}
Also used : Proxy(org.apache.maven.settings.Proxy) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) DefaultProxySelector(org.eclipse.aether.util.repository.DefaultProxySelector) Authentication(org.eclipse.aether.repository.Authentication)

Example 15 with Proxy

use of org.apache.maven.settings.Proxy in project maven-plugins by apache.

the class JavadocUtil method createHttpClient.

/**
     * Creates a new {@code HttpClient} instance.
     *
     * @param settings The settings to use for setting up the client or {@code null}.
     * @param url The {@code URL} to use for setting up the client or {@code null}.
     *
     * @return A new {@code HttpClient} instance.
     *
     * @see #DEFAULT_TIMEOUT
     * @since 2.8
     */
private static HttpClient createHttpClient(Settings settings, URL url) {
    DefaultHttpClient httpClient = new DefaultHttpClient(new PoolingClientConnectionManager());
    httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, DEFAULT_TIMEOUT);
    httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, DEFAULT_TIMEOUT);
    httpClient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    // Some web servers don't allow the default user-agent sent by httpClient
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
    if (settings != null && settings.getActiveProxy() != null) {
        Proxy activeProxy = settings.getActiveProxy();
        ProxyInfo proxyInfo = new ProxyInfo();
        proxyInfo.setNonProxyHosts(activeProxy.getNonProxyHosts());
        if (StringUtils.isNotEmpty(activeProxy.getHost()) && (url == null || !ProxyUtils.validateNonProxyHosts(proxyInfo, url.getHost()))) {
            HttpHost proxy = new HttpHost(activeProxy.getHost(), activeProxy.getPort());
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            if (StringUtils.isNotEmpty(activeProxy.getUsername()) && activeProxy.getPassword() != null) {
                Credentials credentials = new UsernamePasswordCredentials(activeProxy.getUsername(), activeProxy.getPassword());
                httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, credentials);
            }
        }
    }
    return httpClient;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) PoolingClientConnectionManager(org.apache.http.impl.conn.PoolingClientConnectionManager) Proxy(org.apache.maven.settings.Proxy) HttpHost(org.apache.http.HttpHost) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) Credentials(org.apache.http.auth.Credentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

Proxy (org.apache.maven.settings.Proxy)24 Settings (org.apache.maven.settings.Settings)6 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)5 File (java.io.File)4 URL (java.net.URL)3 HashMap (java.util.HashMap)3 MavenExecutionRequest (org.apache.maven.execution.MavenExecutionRequest)3 MavenSession (org.apache.maven.execution.MavenSession)3 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 Authenticator (java.net.Authenticator)2 MalformedURLException (java.net.MalformedURLException)2 PasswordAuthentication (java.net.PasswordAuthentication)2 SocketTimeoutException (java.net.SocketTimeoutException)2 ArrayList (java.util.ArrayList)2 Credentials (org.apache.commons.httpclient.Credentials)2 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)2 DefaultMavenExecutionRequest (org.apache.maven.execution.DefaultMavenExecutionRequest)2 AbstractMojo (org.apache.maven.plugin.AbstractMojo)2 AuthAsyncProxyServlet (org.apache.maven.plugin.javadoc.ProxyServer.AuthAsyncProxyServlet)2