Search in sources :

Example 21 with ProxyInfo

use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-plugins by apache.

the class AbstractDeployMojo method getProxy.

/**
 * Get proxy information for Maven 3.
 *
 * @param repository
 * @param settingsDecrypter
 * @return
 */
private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
    String protocol = repository.getProtocol();
    String url = repository.getUrl();
    getLog().debug("repository protocol " + protocol);
    String originalProtocol = protocol;
    // so we will check both
    if (StringUtils.equalsIgnoreCase("dav", protocol) && url.startsWith("dav:")) {
        url = url.substring(4);
        if (url.startsWith("http")) {
            try {
                URL urlSite = new URL(url);
                protocol = urlSite.getProtocol();
                getLog().debug("found dav protocol so transform to real transport protocol " + protocol);
            } catch (MalformedURLException e) {
                getLog().warn("fail to build URL with " + url);
            }
        }
    } else {
        getLog().debug("getProxy 'protocol': " + protocol);
    }
    if (mavenSession != null && protocol != null) {
        MavenExecutionRequest request = mavenSession.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && (protocol.equalsIgnoreCase(proxy.getProtocol()) || originalProtocol.equalsIgnoreCase(proxy.getProtocol()))) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        // so hackish for wagon the protocol is https for site dav:
                        // dav:https://dav.codehaus.org/mojo/
                        // proxy.getProtocol() );
                        proxyInfo.setType(protocol);
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        getLog().debug("found proxyInfo " + ("host:port " + proxyInfo.getHost() + ":" + proxyInfo.getPort() + ", " + proxyInfo.getUserName()));
                        return proxyInfo;
                    }
                }
            }
        }
    }
    getLog().debug("getProxy 'protocol': " + protocol + " no ProxyInfo found");
    return null;
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MalformedURLException(java.net.MalformedURLException) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult) URL(java.net.URL)

Example 22 with ProxyInfo

use of org.apache.maven.wagon.proxy.ProxyInfo in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getProxy.

private ProxyInfo getProxy(String protocol) {
    MavenSession session = legacySupport.getSession();
    if (session != null && protocol != null) {
        MavenExecutionRequest request = session.getRequest();
        if (request != null) {
            List<Proxy> proxies = request.getProxies();
            if (proxies != null) {
                for (Proxy proxy : proxies) {
                    if (proxy.isActive() && protocol.equalsIgnoreCase(proxy.getProtocol())) {
                        SettingsDecryptionResult result = settingsDecrypter.decrypt(new DefaultSettingsDecryptionRequest(proxy));
                        proxy = result.getProxy();
                        ProxyInfo proxyInfo = new ProxyInfo();
                        proxyInfo.setHost(proxy.getHost());
                        proxyInfo.setType(proxy.getProtocol());
                        proxyInfo.setPort(proxy.getPort());
                        proxyInfo.setNonProxyHosts(proxy.getNonProxyHosts());
                        proxyInfo.setUserName(proxy.getUsername());
                        proxyInfo.setPassword(proxy.getPassword());
                        return proxyInfo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : MavenSession(org.apache.maven.execution.MavenSession) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Proxy(org.apache.maven.settings.Proxy) MavenExecutionRequest(org.apache.maven.execution.MavenExecutionRequest) DefaultSettingsDecryptionRequest(org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest) SettingsDecryptionResult(org.apache.maven.settings.crypto.SettingsDecryptionResult)

Aggregations

ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)22 Proxy (org.apache.maven.settings.Proxy)8 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)8 RemoteRepository (org.apache.archiva.repository.RemoteRepository)7 ConnectionException (org.apache.maven.wagon.ConnectionException)7 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)6 Repository (org.apache.maven.wagon.repository.Repository)6 MalformedURLException (java.net.MalformedURLException)5 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)5 WagonFactoryRequest (org.apache.archiva.proxy.common.WagonFactoryRequest)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)5 AbstractHttpClientWagon (org.apache.maven.wagon.shared.http.AbstractHttpClientWagon)5 HttpConfiguration (org.apache.maven.wagon.shared.http.HttpConfiguration)5 HttpMethodConfiguration (org.apache.maven.wagon.shared.http.HttpMethodConfiguration)5 IOException (java.io.IOException)4 Path (java.nio.file.Path)4 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)4 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)4 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)4 TransferFailedException (org.apache.maven.wagon.TransferFailedException)4