maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [06/50] [abbrv] maven-aether git commit: Bug 435716 - Add overload of DefaultProxySelector.add() that accepts an already splitted collection of non-proxy hosts
Date Sun, 01 May 2016 10:56:08 GMT
Bug 435716 - Add overload of DefaultProxySelector.add() that accepts an already splitted collection
of non-proxy hosts

Introduced add(Proxy, Collection<String>) to DefaultProxySelector


Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/5dedc336
Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/5dedc336
Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/5dedc336

Branch: refs/heads/master
Commit: 5dedc336829ce5ede2af1b5ffde70646a9c9efd7
Parents: 5595ddf
Author: Benjamin Bentmann <bentmann@sonatype.com>
Authored: Sun May 25 18:00:47 2014 +0200
Committer: Benjamin Bentmann <bentmann@sonatype.com>
Committed: Sun May 25 18:00:47 2014 +0200

----------------------------------------------------------------------
 .../util/repository/DefaultProxySelector.java   | 44 ++++++++++++++++++--
 .../repository/DefaultProxySelectorTest.java    | 21 ++++++++--
 2 files changed, 58 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-aether/blob/5dedc336/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
index 3c5b03b..0fed710 100644
--- a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
+++ b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultProxySelector.java
@@ -11,6 +11,7 @@
 package org.eclipse.aether.util.repository;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -34,6 +35,10 @@ public final class DefaultProxySelector
     /**
      * Adds the specified proxy definition to the selector. Proxy definitions are ordered,
the first matching proxy for
      * a given repository will be used.
+     * <p>
+     * The syntax of the non-proxy host list matches that of the property "http.nonProxyHosts"
from the JRE, i.e. the
+     * asterisk character ('*') serves as a wildcard for pattern matching. Multiple non-proxy
hosts are separated by the
+     * pipe character ('|') but note that surrounding whitespace is not trimmed from the
entries.
      * 
      * @param proxy The proxy definition to add, must not be {@code null}.
      * @param nonProxyHosts The list of (case-insensitive) host names to exclude from proxying,
may be {@code null}.
@@ -41,6 +46,23 @@ public final class DefaultProxySelector
      */
     public DefaultProxySelector add( Proxy proxy, String nonProxyHosts )
     {
+        return add( proxy, NonProxyHosts.split( nonProxyHosts ) );
+    }
+
+    /**
+     * Adds the specified proxy definition to the selector. Proxy definitions are ordered,
the first matching proxy for
+     * a given repository will be used.
+     * <p>
+     * The asterisk character ('*') may be used as wildcard in a host name.
+     * 
+     * @param proxy The proxy definition to add, must not be {@code null}.
+     * @param nonProxyHosts The list of (case-insensitive) host names to exclude from proxying,
may be {@code null} but
+     *            must not contain {@code null} elements.
+     * @return This proxy selector for chaining, never {@code null}.
+     * @since 1.1.0
+     */
+    public DefaultProxySelector add( Proxy proxy, Collection<String> nonProxyHosts
)
+    {
         if ( proxy == null )
         {
             throw new IllegalArgumentException( "proxy not specified" );
@@ -96,14 +118,14 @@ public final class DefaultProxySelector
 
         private final Pattern[] patterns;
 
-        public NonProxyHosts( String nonProxyHosts )
+        public NonProxyHosts( Collection<String> nonProxyHosts )
         {
             List<Pattern> patterns = new ArrayList<Pattern>();
             if ( nonProxyHosts != null )
             {
-                for ( StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|"
); tokenizer.hasMoreTokens(); )
+                for ( String nonProxyHost : nonProxyHosts )
                 {
-                    String pattern = tokenizer.nextToken();
+                    String pattern = nonProxyHost;
                     pattern = pattern.replace( ".", "\\." ).replace( "*", ".*" );
                     patterns.add( Pattern.compile( pattern, Pattern.CASE_INSENSITIVE ) );
                 }
@@ -111,6 +133,20 @@ public final class DefaultProxySelector
             this.patterns = patterns.toArray( new Pattern[patterns.size()] );
         }
 
+        static List<String> split( String nonProxyHosts )
+        {
+            List<String> hosts = null;
+            if ( nonProxyHosts != null )
+            {
+                hosts = new ArrayList<String>();
+                for ( StringTokenizer tokenizer = new StringTokenizer( nonProxyHosts, "|"
); tokenizer.hasMoreTokens(); )
+                {
+                    hosts.add( tokenizer.nextToken() );
+                }
+            }
+            return hosts;
+        }
+
         boolean isNonProxyHost( String host )
         {
             if ( host != null )
@@ -135,7 +171,7 @@ public final class DefaultProxySelector
 
         final NonProxyHosts nonProxyHosts;
 
-        public ProxyDef( Proxy proxy, String nonProxyHosts )
+        public ProxyDef( Proxy proxy, Collection<String> nonProxyHosts )
         {
             this.proxy = proxy;
             this.nonProxyHosts = new NonProxyHosts( nonProxyHosts );

http://git-wip-us.apache.org/repos/asf/maven-aether/blob/5dedc336/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
----------------------------------------------------------------------
diff --git a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
index 5f06982..b33c1b2 100644
--- a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
+++ b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultProxySelectorTest.java
@@ -12,7 +12,9 @@ package org.eclipse.aether.util.repository;
 
 import static org.junit.Assert.*;
 
-import org.eclipse.aether.util.repository.DefaultProxySelector;
+import java.util.Arrays;
+
+import org.eclipse.aether.util.repository.DefaultProxySelector.NonProxyHosts;
 import org.junit.Test;
 
 /**
@@ -22,14 +24,22 @@ public class DefaultProxySelectorTest
 
     private boolean isNonProxyHost( String host, String nonProxyHosts )
     {
-        return new DefaultProxySelector.NonProxyHosts( nonProxyHosts ).isNonProxyHost( host
);
+        return new NonProxyHosts( NonProxyHosts.split( nonProxyHosts ) ).isNonProxyHost(
host );
+    }
+
+    private boolean isNonProxyHost( String host, String... nonProxyHosts )
+    {
+        return new NonProxyHosts( nonProxyHosts != null ? Arrays.asList( nonProxyHosts )
: null ).isNonProxyHost( host );
     }
 
     @Test
     public void testIsNonProxyHost_Blank()
     {
-        assertFalse( isNonProxyHost( "www.eclipse.org", null ) );
+        assertFalse( isNonProxyHost( "www.eclipse.org", (String) null ) );
         assertFalse( isNonProxyHost( "www.eclipse.org", "" ) );
+
+        assertFalse( isNonProxyHost( "www.eclipse.org", (String[]) null ) );
+        assertFalse( isNonProxyHost( "www.eclipse.org", new String[0] ) );
     }
 
     @Test
@@ -48,6 +58,11 @@ public class DefaultProxySelectorTest
         assertTrue( isNonProxyHost( "eclipse.org", "eclipse.org|host2" ) );
         assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org" ) );
         assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org|host2" ) );
+
+        // controversial (no trimming) but consistent with JRE's handling of http.nonProxyHosts
+        assertFalse( isNonProxyHost( "eclipse.org", "host1| eclipse.org |host2" ) );
+        assertFalse( isNonProxyHost( "eclipse.org", "host1|eclipse.org " ) );
+        assertFalse( isNonProxyHost( "eclipse.org", " eclipse.org|host2" ) );
     }
 
     @Test


Mime
View raw message