You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wagon-commits@maven.apache.org by br...@apache.org on 2008/05/20 10:39:11 UTC

svn commit: r658167 - in /maven/wagon/trunk: ./ wagon-provider-api/src/main/java/org/apache/maven/wagon/ wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/

Author: brett
Date: Tue May 20 01:39:11 2008
New Revision: 658167

URL: http://svn.apache.org/viewvc?rev=658167&view=rev
Log:
[WAGON-80] don't attempt to use proxySettings even when nonProxyHosts is defined
Submitted by: Thomas Champagne

Added:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java   (with props)
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java   (with props)
Modified:
    maven/wagon/trunk/pom.xml
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java

Modified: maven/wagon/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/pom.xml?rev=658167&r1=658166&r2=658167&view=diff
==============================================================================
--- maven/wagon/trunk/pom.xml (original)
+++ maven/wagon/trunk/pom.xml Tue May 20 01:39:11 2008
@@ -238,5 +238,8 @@
     <contributor>
       <name>ysoonleo</name>
     </contributor>
+    <contributor>
+      <name>Thomas Champagne</name>
+    </contributor>
   </contributors>
 </project>

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java?rev=658167&r1=658166&r2=658167&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java (original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java Tue May 20 01:39:11 2008
@@ -29,6 +29,7 @@
 import org.apache.maven.wagon.events.TransferEventSupport;
 import org.apache.maven.wagon.events.TransferListener;
 import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.proxy.ProxyUtils;
 import org.apache.maven.wagon.repository.Repository;
 import org.apache.maven.wagon.resource.Resource;
 import org.codehaus.plexus.util.IOUtil;
@@ -147,8 +148,15 @@
 
         // TODO: Do these needs to be fields, or are they only used in openConnection()?
         this.authenticationInfo = authenticationInfo;
-        this.proxyInfo = proxyInfo;
-
+        this.proxyInfo = null;
+        if ( proxyInfo != null )
+        {
+            if ( !ProxyUtils.validateNonProxyHosts( proxyInfo, this.repository.getHost() ) )
+            {
+                this.proxyInfo = proxyInfo;
+            }
+        }
+        
         fireSessionOpening();
 
         openConnectionInternal();

Added: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java?rev=658167&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java (added)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java Tue May 20 01:39:11 2008
@@ -0,0 +1,66 @@
+package org.apache.maven.wagon.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.StringTokenizer;
+
+/**
+ * @author <a href="mailto:lafeuil@gmail.com">Thomas Champagne</a>
+ */
+public class ProxyUtils
+{
+
+    /**
+     * Check if the specified host is in the list of non proxy hosts.
+     * 
+     * @param proxy the proxy info object contains set of properties.
+     * @param targetHost the target hostname
+     * @return true if the hostname is in the list of non proxy hosts, false otherwise.
+     */
+    public static boolean validateNonProxyHosts( ProxyInfo proxy, String targetHost )
+    {
+        if ( targetHost == null )
+        {
+            targetHost = new String();
+        }
+        if ( proxy == null )
+        {
+            return false;
+        }
+        String nonProxyHosts = proxy.getNonProxyHosts();
+        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;
+    }
+}

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/proxy/ProxyUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java?rev=658167&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java (added)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java Tue May 20 01:39:11 2008
@@ -0,0 +1,92 @@
+package org.apache.maven.wagon.proxy;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:lafeuil@gmail.com">Thomas Champagne</a>
+ */
+public class ProxyInfoUtilsTest
+    extends TestCase
+{
+    public ProxyInfoUtilsTest( final String name )
+    {
+        super( name );
+    }
+
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+    }
+
+    public void tearDown()
+        throws Exception
+    {
+        super.tearDown();
+    }
+
+    public void testValidateNonProxyHostsWithNullProxy()
+    {
+        assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( null, "maven.apache.org" ) );
+    }
+
+    public void testValidateNonProxyHostsWithUniqueHost()
+
+    {
+        final ProxyInfo proxyInfo = new ProxyInfo();
+        proxyInfo.setUserName( "username" );
+        proxyInfo.setPassword( "password" );
+        proxyInfo.setHost( "http://www.ibiblio.org" );
+        proxyInfo.setPort( 0 );
+        proxyInfo.setType( "SOCKSv4" );
+        proxyInfo.setNonProxyHosts( "*.apache.org" );
+
+        assertTrue( "maven.apache.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) );
+
+        assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "www.ibiblio.org" ) );
+
+        assertFalse( "null", ProxyUtils.validateNonProxyHosts( proxyInfo, null ) );
+
+        proxyInfo.setNonProxyHosts( null );
+        assertFalse( "NonProxyHosts = null", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) );
+
+        proxyInfo.setNonProxyHosts( "" );
+        assertFalse( "NonProxyHosts = \"\"", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) );
+    }
+
+    public void testValidateNonProxyHostsWithMultipleHost()
+
+    {
+        final ProxyInfo proxyInfo = new ProxyInfo();
+        proxyInfo.setUserName( "username" );
+        proxyInfo.setPassword( "password" );
+        proxyInfo.setHost( "http://www.ibiblio.org" );
+        proxyInfo.setPort( 0 );
+        proxyInfo.setType( "SOCKSv4" );
+        proxyInfo.setNonProxyHosts( "*.apache.org|*.codehaus.org" );
+
+        assertTrue( "maven.apache.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) );
+        assertTrue( "wiki.codehaus.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "wiki.codehaus.org" ) );
+
+        assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "www.ibiblio.org" ) );
+    }
+}

Propchange: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/proxy/ProxyInfoUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-commits-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-commits-help@maven.apache.org