Index: src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java =================================================================== --- src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java (revision 800795) +++ src/main/java/org/apache/maven/plugin/javadoc/JavadocUtil.java (working copy) @@ -735,7 +735,8 @@ { Proxy activeProxy = settings.getActiveProxy(); - if ( activeProxy != null ) + if ( activeProxy != null + && !JavadocUtil.validateNonProxyHosts(activeProxy.getNonProxyHosts(), url.getHost())) { String proxyHost = settings.getActiveProxy().getHost(); int proxyPort = settings.getActiveProxy().getPort(); @@ -791,7 +792,40 @@ IOUtil.close( in ); } } + + /** + * TODO : use ProxyUtils.java in wagon-provider-api-1.0-beta-6.jar + * Check if the specified host is in the list of non proxy hosts. + * + * @param nonProxyHosts list of non proxy hosts separated by | + * @param targetHost the target hostname + * @return true if the hostname is in the list of non proxy hosts, false otherwise. + */ + protected static boolean validateNonProxyHosts( String nonProxyHosts, String targetHost ) + { + if ( targetHost == null ) + { + targetHost = new String(); + } + if ( nonProxyHosts == null ) + { + return false; + } + + StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|" ); + while ( tokenizer.hasMoreTokens() ) + { + String pattern = tokenizer.nextToken(); + pattern = pattern.replaceAll( "\\.", "\\\\." ).replaceAll( "\\*", ".*" ); + if ( targetHost.matches( pattern ) ) + { + return true; + } + } + return false; + } + /** * Validate if a charset is supported on this platform. * Index: src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java =================================================================== --- src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java (revision 800745) +++ src/test/java/org/apache/maven/plugin/javadoc/JavadocUtilTest.java (working copy) @@ -24,6 +24,7 @@ import java.io.IOException; import java.net.SocketTimeoutException; import java.net.URL; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -445,6 +446,56 @@ } } } + + /** + * Method to test fetchURL() with nonproxyhosts option + * + * @throws Exception if any + */ + public void testFetchNonProxyHostsURL() + throws Exception + { + URL url = new URL( "http://maven.apache.org/plugins/maven-javadoc-plugin/apidocs/package-list" ); + String nonProxyHosts = "maven.apache.org"; + String host = "proxy"; + int port = 8080; + String protocol = "http"; + + try + { + Settings settings = new Settings(); + Proxy proxy = new Proxy(); + proxy.setActive( true ); + proxy.setHost( host ); + proxy.setPort( port ); + proxy.setProtocol( protocol ); + proxy.setNonProxyHosts( nonProxyHosts ); + settings.addProxy( proxy ); + JavadocUtil.fetchURL( settings, url ); + assertTrue( false ); + } + catch ( UnknownHostException e ) + { + assertTrue( true ); + } + + try + { + Settings settings = new Settings(); + Proxy proxy = new Proxy(); + proxy.setActive( true ); + proxy.setHost( host ); + proxy.setPort( port ); + proxy.setProtocol( protocol ); + settings.addProxy( proxy ); + JavadocUtil.fetchURL( settings, url ); + assertTrue( true ); + } + catch ( IOException e ) + { + assertTrue( false ); + } + } /** * Method to test copyJavadocResources()