Bug 436290 - Trim whitespace from id/type list strings in DefaultMirrorSelector
Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/93310af9 Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/93310af9 Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/93310af9 Branch: refs/heads/master Commit: 93310af9fbeee588555148145ee3c5f560a3bb34 Parents: c9aeca7 Author: Benjamin Bentmann <bentm...@sonatype.com> Authored: Sat May 31 17:20:09 2014 +0200 Committer: Benjamin Bentmann <bentm...@sonatype.com> Committed: Sat May 31 17:20:09 2014 +0200 ---------------------------------------------------------------------- .../util/repository/DefaultMirrorSelector.java | 12 ++++++------ .../repository/DefaultMirrorSelectorTest.java | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-aether/blob/93310af9/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java ---------------------------------------------------------------------- diff --git a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java index b5ad2b2..a0f9a3b 100644 --- a/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java +++ b/aether-util/src/main/java/org/eclipse/aether/util/repository/DefaultMirrorSelector.java @@ -40,12 +40,12 @@ public final class DefaultMirrorSelector * @param type The content type of the mirror, may be {@code null}. * @param repositoryManager A flag whether the mirror is a repository manager or a simple server. * @param mirrorOfIds The identifier(s) of remote repositories to mirror, may be {@code null}. Multiple identifiers - * can be separated by comma (',') and additionally the wildcards "*" and "external:*" can be used to - * match all (external) repositories, prefixing a repo id with an exclamation mark allows to express an - * exclusion. For example "external:*,!central". + * can be separated by comma (',') and surrounding whitespace is trimmed. Additionally the wildcards "*" + * and "external:*" can be used to match all (external) repositories, prefixing a repo id with an + * exclamation mark allows to express an exclusion. For example "external:*,!central". * @param mirrorOfTypes The content type(s) of remote repositories to mirror, may be {@code null} or empty to match - * any content type. Multiple types can be separated by comma (','), the wildcard "*" and the "!" - * negation syntax are also supported. For example "*,!p2". + * any content type. Multiple types can be separated by comma (',') and surrounding whitespace is + * trimmed. The wildcard "*" and the "!" negation syntax are also supported. For example "*,!p2". * @return This selector for chaining, never {@code null}. */ public DefaultMirrorSelector add( String id, String url, String type, boolean repositoryManager, @@ -137,7 +137,7 @@ public final class DefaultMirrorSelector List<String> tokens = null; if ( list != null ) { - tokens = Arrays.asList( list.split( "," ) ); + tokens = Arrays.asList( list.trim().split( "\\s*,\\s*" ) ); } return tokens; } http://git-wip-us.apache.org/repos/asf/maven-aether/blob/93310af9/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultMirrorSelectorTest.java ---------------------------------------------------------------------- diff --git a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultMirrorSelectorTest.java b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultMirrorSelectorTest.java index b73c812..fd5aea4 100644 --- a/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultMirrorSelectorTest.java +++ b/aether-util/src/test/java/org/eclipse/aether/util/repository/DefaultMirrorSelectorTest.java @@ -81,6 +81,16 @@ public class DefaultMirrorSelectorTest } @Test + public void testMatchesType_Trimming() + { + assertEquals( true, matchesType( "any", " " ) ); + assertEquals( true, matchesType( "default", " default " ) ); + assertEquals( true, matchesType( "default", "foo, default ,bar" ) ); + assertEquals( true, matchesType( "default", " default ,bar" ) ); + assertEquals( true, matchesType( "default", "foo, default " ) ); + } + + @Test public void testMatchesPattern() { assertEquals( false, matchesPattern( newRepo( "id", "type", "url" ), null ) ); @@ -103,6 +113,16 @@ public class DefaultMirrorSelectorTest } @Test + public void testMatchesPattern_Trimming() + { + assertEquals( false, matchesPattern( newRepo( "central", "type", "url" ), " " ) ); + assertEquals( true, matchesPattern( newRepo( "central", "type", "url" ), " central " ) ); + assertEquals( true, matchesPattern( newRepo( "central", "type", "url" ), "foo, central ,bar" ) ); + assertEquals( true, matchesPattern( newRepo( "central", "type", "url" ), " central ,bar" ) ); + assertEquals( true, matchesPattern( newRepo( "central", "type", "url" ), "foo, central " ) ); + } + + @Test public void testGetMirror_FirstMatchWins() { DefaultMirrorSelector selector = new DefaultMirrorSelector();