private ProxyInfo getProxy()

in src/main/java/org/apache/maven/plugins/site/deploy/AbstractDeployMojo.java [396:459]


    private ProxyInfo getProxy(Repository repository, SettingsDecrypter settingsDecrypter) {
        String protocol = repository.getProtocol();
        String url = repository.getUrl();

        getLog().debug("repository protocol " + protocol);

        String originalProtocol = protocol;
        // olamy: hackish here protocol (wagon hint in fact !) is dav
        // but the real protocol (transport layer) is http(s)
        // and it's the one use in wagon to find the proxy arghhh
        // so we will check both
        if ("dav".equalsIgnoreCase(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/
                            proxyInfo.setType(protocol); // proxy.getProtocol() );
                            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;
    }