Search in sources :

Example 1 with Proxy

use of org.apache.maven.settings.Proxy in project frontend-maven-plugin by eirslett.

the class MojoUtils method getProxyConfig.

static ProxyConfig getProxyConfig(MavenSession mavenSession, SettingsDecrypter decrypter) {
    if (mavenSession == null || mavenSession.getSettings() == null || mavenSession.getSettings().getProxies() == null || mavenSession.getSettings().getProxies().isEmpty()) {
        return new ProxyConfig(Collections.<ProxyConfig.Proxy>emptyList());
    } else {
        final List<Proxy> mavenProxies = mavenSession.getSettings().getProxies();
        final List<ProxyConfig.Proxy> proxies = new ArrayList<ProxyConfig.Proxy>(mavenProxies.size());
        for (Proxy mavenProxy : mavenProxies) {
            if (mavenProxy.isActive()) {
                mavenProxy = decryptProxy(mavenProxy, decrypter);
                proxies.add(new ProxyConfig.Proxy(mavenProxy.getId(), mavenProxy.getProtocol(), mavenProxy.getHost(), mavenProxy.getPort(), mavenProxy.getUsername(), mavenProxy.getPassword(), mavenProxy.getNonProxyHosts()));
            }
        }
        LOGGER.info("Found proxies: {}", proxies);
        return new ProxyConfig(proxies);
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy) ArrayList(java.util.ArrayList) ProxyConfig(com.github.eirslett.maven.plugins.frontend.lib.ProxyConfig)

Example 2 with Proxy

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

the class AbstractGrailsMojo method configureMavenProxy.

private void configureMavenProxy() {
    if (settings != null) {
        Proxy activeProxy = settings.getActiveProxy();
        if (activeProxy != null) {
            String host = activeProxy.getHost();
            int port = activeProxy.getPort();
            String noProxy = activeProxy.getNonProxyHosts();
            String username = activeProxy.getUsername();
            String password = activeProxy.getPassword();
            System.setProperty("http.proxyHost", host);
            System.setProperty("http.proxyPort", String.valueOf(port));
            if (noProxy != null) {
                System.setProperty("http.nonProxyHosts", noProxy);
            }
            if (username != null) {
                System.setProperty("http.proxyUser", username);
            }
            if (password != null) {
                System.setProperty("http.proxyPassword", password);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy)

Example 3 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 4 with Proxy

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

the class JavadocUtil method hideProxyPassword.

/**
     * For security reasons, if an active proxy is defined and needs an authentication by
     * username/password, hide the proxy password in the command line.
     *
     * @param cmdLine a command line, not null
     * @param settings the user settings
     * @return the cmdline with '*' for the http.proxyPassword JVM property
     */
protected static String hideProxyPassword(String cmdLine, Settings settings) {
    if (cmdLine == null) {
        throw new IllegalArgumentException("cmdLine could not be null");
    }
    if (settings == null) {
        return cmdLine;
    }
    Proxy activeProxy = settings.getActiveProxy();
    if (activeProxy != null && StringUtils.isNotEmpty(activeProxy.getHost()) && StringUtils.isNotEmpty(activeProxy.getUsername()) && StringUtils.isNotEmpty(activeProxy.getPassword())) {
        String pass = "-J-Dhttp.proxyPassword=\"" + activeProxy.getPassword() + "\"";
        String hidepass = "-J-Dhttp.proxyPassword=\"" + StringUtils.repeat("*", activeProxy.getPassword().length()) + "\"";
        return StringUtils.replace(cmdLine, pass, hidepass);
    }
    return cmdLine;
}
Also used : Proxy(org.apache.maven.settings.Proxy)

Example 5 with Proxy

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

the class JavadocUtilTest method testIsValidPackageList.

/**
     * Method to test isValidPackageList()
     *
     * @throws Exception if any
     */
public void testIsValidPackageList() throws Exception {
    Settings settings = null;
    Proxy proxy;
    URL url = null;
    URL wrongUrl;
    try {
        JavadocUtil.isValidPackageList(url, settings, false);
        fail();
    } catch (IllegalArgumentException e) {
        assertTrue(true);
    }
    url = new File(getBasedir(), "/pom.xml").toURL();
    assertTrue(JavadocUtil.isValidPackageList(url, settings, false));
    try {
        assertFalse(JavadocUtil.isValidPackageList(url, settings, true));
    } catch (IOException e) {
        assertTrue(true);
    }
    url = this.getClass().getResource("/JavadocUtilTest-package-list.txt").toURI().toURL();
    assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
    url = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list");
    assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
    wrongUrl = new URL("http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list2");
    try {
        JavadocUtil.isValidPackageList(wrongUrl, settings, false);
        fail();
    } catch (IOException e) {
        assertTrue(true);
    }
    // real proxy
    ProxyServer proxyServer = null;
    AuthAsyncProxyServlet proxyServlet;
    try {
        proxyServlet = new AuthAsyncProxyServlet();
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
        try {
            JavadocUtil.isValidPackageList(wrongUrl, settings, false);
            fail();
        } catch (IOException e) {
            assertTrue(true);
        }
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
    Map<String, String> authentications = new HashMap<String, String>();
    authentications.put("foo", "bar");
    // wrong auth
    try {
        proxyServlet = new AuthAsyncProxyServlet(authentications);
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        settings.addProxy(proxy);
        JavadocUtil.isValidPackageList(url, settings, false);
        fail();
    } catch (FileNotFoundException e) {
        assertTrue(true);
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
    // auth proxy
    try {
        proxyServlet = new AuthAsyncProxyServlet(authentications);
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        proxy.setUsername("foo");
        proxy.setPassword("bar");
        settings.addProxy(proxy);
        assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
        try {
            JavadocUtil.isValidPackageList(wrongUrl, settings, false);
            fail();
        } catch (IOException e) {
            assertTrue(true);
        }
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
    // timeout
    try {
        // more than 2000, see fetchURL
        proxyServlet = new AuthAsyncProxyServlet(authentications, 3000);
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        proxy.setUsername("foo");
        proxy.setPassword("bar");
        settings.addProxy(proxy);
        JavadocUtil.isValidPackageList(url, settings, true);
        fail();
    } catch (SocketTimeoutException e) {
        assertTrue(true);
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
    // nonProxyHosts
    try {
        proxyServlet = new AuthAsyncProxyServlet(authentications);
        proxyServer = new ProxyServer(proxyServlet);
        proxyServer.start();
        settings = new Settings();
        proxy = new Proxy();
        proxy.setActive(true);
        proxy.setHost(proxyServer.getHostName());
        proxy.setPort(proxyServer.getPort());
        proxy.setProtocol("http");
        proxy.setUsername("foo");
        proxy.setPassword("bar");
        proxy.setNonProxyHosts("maven.apache.org");
        settings.addProxy(proxy);
        assertTrue(JavadocUtil.isValidPackageList(url, settings, true));
    } finally {
        if (proxyServer != null) {
            proxyServer.stop();
        }
    }
}
Also used : HashMap(java.util.HashMap) AuthAsyncProxyServlet(org.apache.maven.plugin.javadoc.ProxyServer.AuthAsyncProxyServlet) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URL(java.net.URL) Proxy(org.apache.maven.settings.Proxy) SocketTimeoutException(java.net.SocketTimeoutException) File(java.io.File) Settings(org.apache.maven.settings.Settings)

Aggregations

Proxy (org.apache.maven.settings.Proxy)23 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 MalformedURLException (java.net.MalformedURLException)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 HttpRequest (org.apache.maven.plugins.site.deploy.SimpleDavServerHandler.HttpRequest)2 SiteMavenProjectStub (org.apache.maven.plugins.site.stubs.SiteMavenProjectStub)2