Example usage for org.apache.maven.artifact.manager WagonManager getProxy

List of usage examples for org.apache.maven.artifact.manager WagonManager getProxy

Introduction

In this page you can find the example usage for org.apache.maven.artifact.manager WagonManager getProxy.

Prototype

ProxyInfo getProxy(String protocol);

Source Link

Usage

From source file:com.opoopress.maven.plugins.plugin.AbstractDeployMojo.java

License:Apache License

public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }/*from   ww w  .  ja  va2 s .c  om*/

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    for (String nonProxyHost : StringUtils.split(nonProxyHostsAsString, ",;|")) {
        if (org.apache.commons.lang.StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or middle of the nonProxyHost
            final int pos = nonProxyHost.indexOf('*');
            String nonProxyHostPrefix = nonProxyHost.substring(0, pos);
            String nonProxyHostSuffix = nonProxyHost.substring(pos + 1);
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix)
                    && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}

From source file:de.faustedition.maven.OddSchemaDeployMojo.java

License:Apache License

/**
 * <p>//from  www.j a  v  a  2 s  . c  om
 * Get the <code>ProxyInfo</code> of the proxy associated with the
 * <code>host</code> and the <code>protocol</code> of the given
 * <code>repository</code>.
 * </p>
 * <p>
 * Extract from <a href=
 * "http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html"> J2SE
 * Doc : Networking Properties - nonProxyHosts</a> : "The value can be a
 * list of hosts, each separated by a |, and in addition a wildcard
 * character (*) can be used for matching"
 * </p>
 * <p>
 * Defensively support for comma (",") and semi colon (";") in addition
 * to pipe ("|") as separator.
 * </p>
 * 
 * @param repository
 *                the Repository to extract the ProxyInfo from.
 * @param wagonManager
 *                the WagonManager used to connect to the Repository.
 * @return a ProxyInfo object instantiated or <code>null</code> if no
 *         matching proxy is found
 */
public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|");
    for (int i = 0; i < nonProxyHosts.length; i++) {
        String nonProxyHost = nonProxyHosts[i];
        if (StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or
            // middle of the nonProxyHost
            String nonProxyHostPrefix = StringUtils.substringBefore(nonProxyHost, "*");
            String nonProxyHostSuffix = StringUtils.substringAfter(nonProxyHost, "*");
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix)
                    && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}

From source file:org.fusesource.mvnplugins.updatesite.UpdateSiteDeployMojo.java

License:Apache License

/**
 * <p>//w  ww .  ja  va  2 s.c  o  m
 * Get the <code>ProxyInfo</code> of the proxy associated with the <code>host</code>
 * and the <code>protocol</code> of the given <code>repository</code>.
 * </p>
 * <p>
 * Extract from <a href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
 * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be a list of hosts,
 * each separated by a |, and in addition a wildcard character (*) can be used for matching"
 * </p>
 * <p>
 * Defensively support for comma (",") and semi colon (";") in addition to pipe ("|") as separator.
 * </p>
 *
 * @param repository   the Repository to extract the ProxyInfo from.
 * @param wagonManager the WagonManager used to connect to the Repository.
 * @return a ProxyInfo object instantiated or <code>null</code> if no matching proxy is found
 */
public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|");
    for (int i = 0; i < nonProxyHosts.length; i++) {
        String nonProxyHost = nonProxyHosts[i];
        if (StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or middle of the nonProxyHost
            String nonProxyHostPrefix = StringUtils.substringBefore(nonProxyHost, "*");
            String nonProxyHostSuffix = StringUtils.substringAfter(nonProxyHost, "*");
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix)
                    && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}

From source file:org.objectstyle.woproject.maven2.javamonitor.JavaMonitorDeployMojo.java

License:Open Source License

/**
 * <p>//from   w  w  w.  j ava  2  s.c om
 * Get the <code>ProxyInfo</code> of the proxy associated with the
 * <code>host</code> and the <code>protocol</code> of the given
 * <code>repository</code>.
 * </p>
 * <p>
 * Extract from <a
 * href="http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html">
 * J2SE Doc : Networking Properties - nonProxyHosts</a> : "The value can be
 * a list of hosts, each separated by a |, and in addition a wildcard
 * character (*) can be used for matching"
 * </p>
 * <p>
 * Defensively support for comma (",") and semi colon (";") in addition to
 * pipe ("|") as separator.
 * </p>
 *
 * @return a ProxyInfo object instantiated or <code>null</code> if no
 *         matching proxy is found
 */
public static ProxyInfo getProxyInfo(Repository repository, WagonManager wagonManager) {
    ProxyInfo proxyInfo = wagonManager.getProxy(repository.getProtocol());

    if (proxyInfo == null) {
        return null;
    }

    String host = repository.getHost();
    String nonProxyHostsAsString = proxyInfo.getNonProxyHosts();
    String[] nonProxyHosts = StringUtils.split(nonProxyHostsAsString, ",;|");
    for (int i = 0; i < nonProxyHosts.length; i++) {
        String nonProxyHost = nonProxyHosts[i];
        if (StringUtils.contains(nonProxyHost, "*")) {
            // Handle wildcard at the end, beginning or middle of the
            // nonProxyHost
            String nonProxyHostPrefix = StringUtils.substringBefore(nonProxyHost, "*");
            String nonProxyHostSuffix = StringUtils.substringAfter(nonProxyHost, "*");
            // prefix*
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isEmpty(nonProxyHostSuffix)) {
                return null;
            }
            // *suffix
            if (StringUtils.isEmpty(nonProxyHostPrefix) && StringUtils.isNotEmpty(nonProxyHostSuffix)
                    && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
            // prefix*suffix
            if (StringUtils.isNotEmpty(nonProxyHostPrefix) && host.startsWith(nonProxyHostPrefix)
                    && StringUtils.isNotEmpty(nonProxyHostSuffix) && host.endsWith(nonProxyHostSuffix)) {
                return null;
            }
        } else if (host.equals(nonProxyHost)) {
            return null;
        }
    }
    return proxyInfo;
}