Author: xavier
Date: Sun Jan  7 10:37:19 2007
New Revision: 493801

URL: http://svn.apache.org/viewvc?view=rev&rev=493801
Log:
IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) 
(thanks to Stephane Baillez)

Added:
    
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AbstractPatternMatcher.java
    incubator/ivy/trunk/test/java/org/apache/ivy/matcher/
    
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/AbstractPatternMatcherTest.java
    
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcherTest.java
    
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactPatternMatcherTest.java
    
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/GlobPatternMatcherTest.java
    
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/RegexpPatternMatcherTest.java
Modified:
    incubator/ivy/trunk/CHANGES.txt
    incubator/ivy/trunk/src/java/org/apache/ivy/Ivy.java
    incubator/ivy/trunk/src/java/org/apache/ivy/event/IvyEventFilter.java
    
incubator/ivy/trunk/src/java/org/apache/ivy/external/m2/PomModuleDescriptorParser.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AnyMatcher.java
    
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactPatternMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/GlobPatternMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/Matcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/MatcherHelper.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ModuleIdMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/NoMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/matcher/PatternMatcher.java
    
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/RegexpPatternMatcher.java
    incubator/ivy/trunk/src/java/org/apache/ivy/resolver/AbstractResolver.java
    
incubator/ivy/trunk/test/java/org/apache/ivy/resolver/IBiblioResolverTest.java
    incubator/ivy/trunk/test/java/org/apache/ivy/resolver/URLResolverTest.java

Modified: incubator/ivy/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/CHANGES.txt?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/CHANGES.txt (original)
+++ incubator/ivy/trunk/CHANGES.txt Sun Jan  7 10:37:19 2007
@@ -10,6 +10,7 @@
 - IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359)
 - IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to 
John Williams)
 - IMPROVE: Ability to have multiple roots in the <ivy:buildfilelist> task 
(IVY-340) (thanks to Matt Inger)
+- IMPROVE: Refactoring / documentation / test of matcher package (IVY-375) 
(thanks to Stephane Baillez)
 
 - FIX: IOException during publish causes NullPointerException (IVY-371)
 - FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart)

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/Ivy.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/Ivy.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/Ivy.java (original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/Ivy.java Sun Jan  7 10:37:19 
2007
@@ -243,10 +243,10 @@
         addConflictManager("all", new NoConflictManager());    
         addConflictManager("strict", new StrictConflictManager());
         
-        addMatcher(ExactPatternMatcher.getInstance());
-        addMatcher(RegexpPatternMatcher.getInstance());
-        addMatcher(ExactOrRegexpPatternMatcher.getInstance());
-        addMatcher(GlobPatternMatcher.getInstance());
+        addMatcher(ExactPatternMatcher.INSTANCE);
+        addMatcher(RegexpPatternMatcher.INSTANCE);
+        addMatcher(ExactOrRegexpPatternMatcher.INSTANCE);
+        addMatcher(GlobPatternMatcher.INSTANCE);
         
         addReportOutputter(new XmlReportOutputter());
         addReportOutputter(new LogReportOutputter());
@@ -1767,7 +1767,7 @@
             
             DefaultModuleDescriptor md = new 
DefaultModuleDescriptor(ModuleRevisionId.newInstance("apache", "ivy-install", 
"1.0"), getStatusManager().getDefaultStatus(), new Date());
             md.addConfiguration(new Configuration("default"));
-            md.addConflictManager(new 
ModuleId(ExactPatternMatcher.ANY_EXPRESSION, 
ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.getInstance(), new 
NoConflictManager());
+            md.addConflictManager(new 
ModuleId(ExactPatternMatcher.ANY_EXPRESSION, 
ExactPatternMatcher.ANY_EXPRESSION), ExactPatternMatcher.INSTANCE, new 
NoConflictManager());
             
             if (MatcherHelper.isExact(matcher, mrid)) {
                 DefaultDependencyDescriptor dd = new 
DefaultDependencyDescriptor(md, mrid, false, false, transitive);
@@ -3118,7 +3118,7 @@
                                                        branches = new String[] 
 {getDefaultBranch(new ModuleId(orgs[i], mods[j]))};
                                                }
                                                for (int k = 0; k < 
branches.length; k++) {
-                                                       if 
(branchMatcher.matches(branches[k])) {
+                                                       if (branches[k] == null 
|| branchMatcher.matches(branches[k])) {
                                                                
tokenValues.put(IvyPatternHelper.BRANCH_KEY, tokenValues);
                                                                String[] revs = 
listTokenValues(IvyPatternHelper.REVISION_KEY, tokenValues);
                                                                for (int l = 0; 
l < revs.length; l++) {

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/event/IvyEventFilter.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/event/IvyEventFilter.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/event/IvyEventFilter.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/event/IvyEventFilter.java Sun 
Jan  7 10:37:19 2007
@@ -66,7 +66,7 @@
        private Filter _attFilter;
 
        public IvyEventFilter(String event, String filterExpression, 
PatternMatcher matcher) {
-               _matcher = matcher == null ? ExactPatternMatcher.getInstance() 
: matcher;
+               _matcher = matcher == null ? ExactPatternMatcher.INSTANCE : 
matcher;
                if (event == null) {
                        _nameFilter = NoFilter.INSTANCE;
                } else {

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/external/m2/PomModuleDescriptorParser.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/external/m2/PomModuleDescriptorParser.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- 
incubator/ivy/trunk/src/java/org/apache/ivy/external/m2/PomModuleDescriptorParser.java
 (original)
+++ 
incubator/ivy/trunk/src/java/org/apache/ivy/external/m2/PomModuleDescriptorParser.java
 Sun Jan  7 10:37:19 2007
@@ -162,7 +162,7 @@
                     ModuleId mid = (ModuleId)iter.next();
                     String[] confs = _dd.getModuleConfigurations();
                     for (int i = 0; i < confs.length; i++) {
-                        _dd.addDependencyArtifactExcludes(confs[i], new 
DefaultDependencyArtifactDescriptor(_dd, new ArtifactId(mid, 
PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, 
PatternMatcher.ANY_EXPRESSION), false, ExactPatternMatcher.getInstance()));
+                        _dd.addDependencyArtifactExcludes(confs[i], new 
DefaultDependencyArtifactDescriptor(_dd, new ArtifactId(mid, 
PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION, 
PatternMatcher.ANY_EXPRESSION), false, ExactPatternMatcher.INSTANCE));
                     }
                 }
                 _md.addDependency(_dd);

Added: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AbstractPatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AbstractPatternMatcher.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AbstractPatternMatcher.java 
(added)
+++ 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AbstractPatternMatcher.java 
Sun Jan  7 10:37:19 2007
@@ -0,0 +1,62 @@
+/*
+ *  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.
+ *
+ */
+
+package org.apache.ivy.matcher;
+
+/**
+ * An abstract implementation of the pattern matcher providing base template 
methods
+ */
+public abstract class AbstractPatternMatcher implements PatternMatcher {
+    private final String name;
+
+    /**
+     * Create a new instance of a pattern matcher
+     *
+     * @param name the name of the pattern matcher. Never null.
+     */
+    public AbstractPatternMatcher(/[EMAIL PROTECTED]/ String name) {
+        this.name = name;
+    }
+
+    public /[EMAIL PROTECTED]/ Matcher getMatcher(/[EMAIL PROTECTED]/String 
expression) {
+        if (expression == null) {
+            throw new NullPointerException();
+        }
+        if (ANY_EXPRESSION.equals(expression)) {
+            return AnyMatcher.INSTANCE;
+        }
+        return newMatcher(expression);
+    }
+
+    public /[EMAIL PROTECTED]/ String getName() {
+        return name;
+    }
+
+    /**
+     * Returns an instance of the implementation specific matcher.
+     *
+     * @param expression the string to be matched.
+     * @return the instance of the related matcher. Never null.
+     */
+    protected abstract /[EMAIL PROTECTED]/ Matcher newMatcher(/[EMAIL 
PROTECTED]/ String expression);
+
+    public String toString() {
+        return getName();
+    }
+}
+

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AnyMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AnyMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AnyMatcher.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/AnyMatcher.java Sun Jan 
 7 10:37:19 2007
@@ -17,18 +17,19 @@
  */
 package org.apache.ivy.matcher;
 
-public class AnyMatcher implements Matcher {
-    private final static Matcher INSTANCE = new AnyMatcher();
-    
-    public static Matcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private AnyMatcher() {
-        
+/**
+ * A matcher that will match everything.
+ */
+public /[EMAIL PROTECTED]/ class AnyMatcher implements Matcher {
+    public final static Matcher INSTANCE = new AnyMatcher();
+
+    public AnyMatcher() {
     }
 
-    public boolean matches(String str) {
+    public boolean matches(String input) {
+        if (input == null) {
+            throw new NullPointerException();
+        }
         return true;
     }
 

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcher.java
 (original)
+++ 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcher.java
 Sun Jan  7 10:37:19 2007
@@ -18,40 +18,45 @@
 package org.apache.ivy.matcher;
 
 
-public final class ExactOrRegexpPatternMatcher implements PatternMatcher {
-    public static class ExactOrRegexpMatcher implements Matcher {
+/**
+ * A pattern matcher that tries to match exactly the input with the 
expression, or match it as a pattern.
+ * <p/>
+ * The evaluation for matching is perform first by checking if expression and 
input are equals (via equals method)
+ * else it attempts to do it by trying to match the input using the expression 
as a regexp.
+ *
+ * @see ExactPatternMatcher
+ * @see RegexpPatternMatcher
+ */
+public /[EMAIL PROTECTED]/ final class ExactOrRegexpPatternMatcher extends 
AbstractPatternMatcher {
+
+    public static final ExactOrRegexpPatternMatcher INSTANCE = new 
ExactOrRegexpPatternMatcher();
+
+    public ExactOrRegexpPatternMatcher() {
+        super(EXACT_OR_REGEXP);
+    }
+
+    protected Matcher newMatcher(String expression) {
+        return new ExactOrRegexpMatcher(expression);
+    }
+
+    private static final class ExactOrRegexpMatcher implements Matcher {
         private Matcher _exact;
         private Matcher _regexp;
 
-        public ExactOrRegexpMatcher(String exp) {
-            _exact = ExactPatternMatcher.getInstance().getMatcher(exp);
-            _regexp = RegexpPatternMatcher.getInstance().getMatcher(exp);
+        public ExactOrRegexpMatcher(String expression) {
+            _exact = ExactPatternMatcher.INSTANCE.getMatcher(expression);
+            _regexp = RegexpPatternMatcher.INSTANCE.getMatcher(expression);
         }
 
-        public boolean matches(String str) {
-            return _exact.matches(str) || _regexp.matches(str);
+        public boolean matches(String input) {
+            if (input == null) {
+                throw new NullPointerException();
+            }
+            return _exact.matches(input) || _regexp.matches(input);
         }
 
         public boolean isExact() {
             return false;
         }
-    }
-    private static final ExactOrRegexpPatternMatcher INSTANCE = new 
ExactOrRegexpPatternMatcher();
-    public static PatternMatcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private ExactOrRegexpPatternMatcher() {        
-    }
-    
-    public String getName() {
-        return EXACT_OR_REGEXP;
-    }
-
-    public Matcher getMatcher(String exp) {
-        if (ANY_EXPRESSION.equals(exp)) {
-            return AnyMatcher.getInstance();
-        }
-        return new ExactOrRegexpMatcher(exp);
     }
 }

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactPatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactPatternMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactPatternMatcher.java 
(original)
+++ 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ExactPatternMatcher.java 
Sun Jan  7 10:37:19 2007
@@ -17,40 +17,40 @@
  */
 package org.apache.ivy.matcher;
 
-public final class ExactPatternMatcher implements PatternMatcher {
+/**
+ * Implementation of an exact matcher.
+ * <p/>
+ * The matching will be performed against an expression being a string. It 
will only
+ * matches if both strings are equal (per equals()) rule or if both strings 
are null.
+ */
+public /[EMAIL PROTECTED]/ final class ExactPatternMatcher extends 
AbstractPatternMatcher {
 
-    public static class ExactMatcher implements Matcher {
-        protected String _exp;
+    public static final ExactPatternMatcher INSTANCE = new 
ExactPatternMatcher();
 
-        public ExactMatcher(String exp) {
-            _exp = exp;
+    public ExactPatternMatcher() {
+        super(EXACT);
+    }
+
+    protected Matcher newMatcher(String expression) {
+        return new ExactMatcher(expression);
+    }
+
+    private static /[EMAIL PROTECTED]/ class ExactMatcher implements Matcher {
+        protected String _expression;
+
+        public ExactMatcher(String expression) {
+            _expression = expression;
         }
 
-        public boolean matches(String str) {
-            return str == null ? _exp == null : str.equals(_exp);
+        public boolean matches(String input) {
+            if (input == null) {
+                throw new NullPointerException();
+            }
+            return input.equals(_expression);
         }
 
         public boolean isExact() {
             return true;
         }
-    }
-
-    private static final ExactPatternMatcher INSTANCE = new 
ExactPatternMatcher();
-    public static PatternMatcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private ExactPatternMatcher() {        
-    }
-    
-    public String getName() {
-        return EXACT;
-    }
-
-    public Matcher getMatcher(String exp) {
-        if (ANY_EXPRESSION.equals(exp)) {
-            return AnyMatcher.getInstance();
-        }
-        return new ExactMatcher(exp);
     }
 }

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/GlobPatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/GlobPatternMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/GlobPatternMatcher.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/GlobPatternMatcher.java 
Sun Jan  7 10:37:19 2007
@@ -17,6 +17,8 @@
  */
 package org.apache.ivy.matcher;
 
+import java.util.regex.PatternSyntaxException;
+
 import org.apache.ivy.util.Message;
 import org.apache.oro.text.GlobCompiler;
 import org.apache.oro.text.regex.MalformedPatternException;
@@ -25,42 +27,57 @@
 
 
 
-public final class GlobPatternMatcher implements PatternMatcher {
-    public static class GlobMatcher implements Matcher {
-        private Pattern _p;
+/**
+ * A pattern matcher matching input using unix-like glob matcher expressions. 
Meta characters are:
+ * <ul>
+ * <li> * -  Matches zero or more characters</li>
+ * <li> ? - Matches exactly one character.</li>
+ * </ul>
+ * <p/>
+ * <b> Note that this matcher is available only with <a 
href="http://jakarta.apache.org/oro"Apache Jakarta Oro 2.0.8</a>
+ * in your classpath.</b>
+ *
+ * @see <a 
href="http://jakarta.apache.org/oro/api/org/apache/oro/text/GlobCompiler.html";>GlobCompiler</a>
+ */
+public /[EMAIL PROTECTED]/ final class GlobPatternMatcher extends 
AbstractPatternMatcher {
+
+    public static final GlobPatternMatcher INSTANCE = new GlobPatternMatcher();
+
+    /*
+    NOTE: GlobCompiler does ~100K compilation/s
+    - If necessary look into using ThreadLocal for GlobCompiler/Perl5Matcher 
to cut on useless object creation
+    - If expression are reused over and over a LRU cache could make sense
+     */
+
+    public GlobPatternMatcher() {
+        super(GLOB);
+    }
 
-        public GlobMatcher(String exp) {
+    protected Matcher newMatcher(String expression) {
+        return new GlobMatcher(expression);
+    }
+
+    private static class GlobMatcher implements Matcher {
+        private Pattern _pattern;
+
+        public GlobMatcher(String expression) throws PatternSyntaxException {
             try {
-                _p = new GlobCompiler().compile(exp);
+                _pattern = new GlobCompiler().compile(expression);
             } catch (MalformedPatternException e) {
-                Message.error("impossible to compile glob pattern: "+exp);
+                throw new PatternSyntaxException(e.getMessage(), expression, 
0);
             }
         }
 
-        public boolean matches(String str) {
-            return _p != null && new Perl5Matcher().matches(str, _p);
+        public boolean matches(String input) {
+            if (input == null) {
+                throw new NullPointerException();
+            }
+            return new Perl5Matcher().matches(input, _pattern);
         }
 
         public boolean isExact() {
             return false;
         }
     }
-    private static final GlobPatternMatcher INSTANCE = new 
GlobPatternMatcher();
-    public static PatternMatcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private GlobPatternMatcher() {        
-    }
-
-    public String getName() {
-        return GLOB;
-    }
 
-    public Matcher getMatcher(String exp) {
-        if (ANY_EXPRESSION.equals(exp)) {
-            return AnyMatcher.getInstance();
-        }
-        return new GlobMatcher(exp);
-    }
 }

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/matcher/Matcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/Matcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/Matcher.java (original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/Matcher.java Sun Jan  7 
10:37:19 2007
@@ -17,7 +17,31 @@
  */
 package org.apache.ivy.matcher;
 
+/**
+ * An interface that defines a string matcher.
+ */
 public interface Matcher {
-    public boolean matches(String str);
+
+    /**
+     * Check whether a given string is matched by this matcher.
+     *
+     * @param input the string to be matched. Cannot be null.
+     * @return true if the input string is matched, false otherwise.
+     */
+    public boolean matches(/[EMAIL PROTECTED]/ String input);
+
+    /**
+     * Return if the matcher will match *only* if the expression equals the 
input.
+     * <i>
+     * WARN:
+     * This is used only as a performance trick, to avoid scanning for things
+     * when you already know exactly what you want. In the install task where
+     * it used it avoid scanning the repository to list all modules to find
+     * that only one matches, and that it has the name requested.
+     * </i>
+     *
+     * @return true if the matcher only matches when the expression is
+     *         equals to the input, false otherwise.
+     */
     public boolean isExact();
 }

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/matcher/MatcherHelper.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/MatcherHelper.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/MatcherHelper.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/MatcherHelper.java Sun 
Jan  7 10:37:19 2007
@@ -21,38 +21,47 @@
 import org.apache.ivy.ModuleId;
 import org.apache.ivy.ModuleRevisionId;
 
+/**
+ * Set of helper methods to match ModuleId, ModuleRevisionId, ArtifactId
+ */
 public class MatcherHelper {
-    public static boolean matches(PatternMatcher m, String exp, String str) {
-        return m.getMatcher(exp).matches(str);
+    // TODO this class might be better off as MatcherUtils in util package
+
+    public static boolean matches(PatternMatcher m, String expression, String 
input) {
+        return m.getMatcher(expression).matches(input);
     }
+
     public static boolean matches(PatternMatcher m, ModuleId exp, ModuleId 
mid) {
         return matches(m, exp.getOrganisation(), mid.getOrganisation())
-        && matches(m, exp.getName(), mid.getName());
+                && matches(m, exp.getName(), mid.getName());
     }
-    
+
     public static boolean matches(PatternMatcher m, ModuleRevisionId exp, 
ModuleRevisionId mrid) {
         return matches(m, exp.getOrganisation(), mrid.getOrganisation())
-            && matches(m, exp.getName(), mrid.getName())
-            && matches(m, exp.getRevision(), mrid.getRevision());
+                && matches(m, exp.getName(), mrid.getName())
+                && matches(m, exp.getRevision(), mrid.getRevision());
     }
+
     public static boolean matches(PatternMatcher m, ArtifactId exp, ArtifactId 
aid) {
-        return matches(m, exp.getModuleId().getOrganisation(), 
aid.getModuleId().getOrganisation())
-            && matches(m, exp.getModuleId().getName(), 
aid.getModuleId().getName())
-            && matches(m, exp.getName(), aid.getName())
-            && matches(m, exp.getExt(), aid.getExt())
-            && matches(m, exp.getType(), aid.getType())
-            ;
+        return matches(m, exp.getModuleId(), aid.getModuleId())
+                && matches(m, exp.getName(), aid.getName())
+                && matches(m, exp.getExt(), aid.getExt())
+                && matches(m, exp.getType(), aid.getType())
+                ;
     }
-    
+
     public static boolean isExact(PatternMatcher m, ModuleRevisionId exp) {
         return isExact(m, exp.getOrganisation())
-            && isExact(m, exp.getName())
-            && isExact(m, exp.getRevision());
+                && isExact(m, exp.getName())
+                && isExact(m, exp.getRevision());
     }
+
+    // unused
     public static boolean isExact(PatternMatcher m, ModuleId exp) {
         return isExact(m, exp.getOrganisation())
-            && isExact(m, exp.getName());
+                && isExact(m, exp.getName());
     }
+
     public static boolean isExact(PatternMatcher m, String exp) {
         return m.getMatcher(exp).isExact();
     }

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ModuleIdMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ModuleIdMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ModuleIdMatcher.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/ModuleIdMatcher.java 
Sun Jan  7 10:37:19 2007
@@ -20,6 +20,7 @@
 import org.apache.ivy.ModuleId;
 
 public class ModuleIdMatcher {
+// TODO this class should be moved out of this package
     private Matcher _orgMatcher;
     private Matcher _moduleMatcher;
     private ModuleId _mid;

Modified: incubator/ivy/trunk/src/java/org/apache/ivy/matcher/NoMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/NoMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/NoMatcher.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/NoMatcher.java Sun Jan  
7 10:37:19 2007
@@ -17,17 +17,20 @@
  */
 package org.apache.ivy.matcher;
 
-public class NoMatcher implements Matcher {
-    private final static Matcher INSTANCE = new NoMatcher();
-    
-    public static Matcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private NoMatcher() {
+/**
+ * A matcher that matches nothing.
+ */
+public final /[EMAIL PROTECTED]/ class NoMatcher implements Matcher {
+
+    public final static Matcher INSTANCE = new NoMatcher();
+
+    public NoMatcher() {
     }
 
-    public boolean matches(String str) {
+    public boolean matches(String input) {
+        if (input == null) {
+            throw new NullPointerException();
+        }
         return false;
     }
 

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/PatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/PatternMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/matcher/PatternMatcher.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/matcher/PatternMatcher.java Sun 
Jan  7 10:37:19 2007
@@ -17,15 +17,56 @@
  */
 package org.apache.ivy.matcher;
 
-
+/**
+ * Interface for a pattern matcher.
+ * <p/>
+ * The pattern matcher is the main abstraction regarding the matching of an 
expression. Implementation may vary
+ * depending on the expression syntax handling that is desired.
+ */
 public interface PatternMatcher {
+
+    /**
+     * 'exact' pattern matcher name
+     */
     public static final String EXACT = "exact";
+
+    /**
+     * pattern matcher name 'regexp'
+     */
     public static final String REGEXP = "regexp";
+
+    /**
+     * pattern matcher 'glob'
+     */
     public static final String GLOB = "glob";
+
+    /**
+     * pattern matcher name 'exactOrRegexp'
+     */
     public static final String EXACT_OR_REGEXP = "exactOrRegexp";
-    
+
+    /**
+     * Any expression string: '*'
+     */
     public static final String ANY_EXPRESSION = "*";
 
-    public Matcher getMatcher(String exp);
-    public String getName();
+    /**
+     * Return the matcher for the given expression.
+     *
+     * @param expression the expression to be matched. Cannot be null ?
+     * @return the matcher instance for the given expression. Never null.
+     */
+    public /[EMAIL PROTECTED]/ Matcher getMatcher(/[EMAIL PROTECTED]/ String 
expression);
+
+    /**
+     * return the name of this pattern matcher
+     *
+     * @return the name of this pattern matcher. Never null.
+     * @see #EXACT
+     * @see #REGEXP
+     * @see #GLOB
+     * @see #EXACT_OR_REGEXP
+     */
+    public /[EMAIL PROTECTED]/ String getName();
 }
+

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/RegexpPatternMatcher.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/matcher/RegexpPatternMatcher.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/RegexpPatternMatcher.java 
(original)
+++ 
incubator/ivy/trunk/src/java/org/apache/ivy/matcher/RegexpPatternMatcher.java 
Sun Jan  7 10:37:19 2007
@@ -18,46 +18,50 @@
 package org.apache.ivy.matcher;
 
 import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
-public final class RegexpPatternMatcher implements PatternMatcher {
-    public static class RegexpMatcher implements Matcher {
-        private Pattern _p;
+/**
+ * A pattern matcher matching input using regular expressions.
+ *
+ * @see Pattern
+ */
+public final /[EMAIL PROTECTED]/ class RegexpPatternMatcher extends 
AbstractPatternMatcher {
+    public static final RegexpPatternMatcher INSTANCE = new 
RegexpPatternMatcher();
+
+    /*
+    NOTE: Regexp compiler does ~200K compilation/s
+    - If necessary look into using ThreadLocal Pattern to cut on useless 
object creation
+    - If expression are reused over and over a LRU cache could make sense
+     */
 
-        public RegexpMatcher(String exp) {
-            _p = Pattern.compile(exp);
-        }
-
-        public boolean matches(String str) {
-            return _p.matcher(str).matches();
-        }
 
-        public boolean isExact() {
-            return false;
-        }
+    public RegexpPatternMatcher() {
+        super(REGEXP);
     }
-    private static final RegexpPatternMatcher INSTANCE = new 
RegexpPatternMatcher();
-    public static PatternMatcher getInstance() {
-        return INSTANCE;
-    }
-    
-    private RegexpPatternMatcher() {        
+
+    protected Matcher newMatcher(String expression) {
+        return new RegexpMatcher(expression);
     }
-    
-    public boolean match(String str, String exp) {
-        if (exp == null) {
-            return str == null;
+
+    private static /[EMAIL PROTECTED]/ class RegexpMatcher implements Matcher {
+        private Pattern _pattern;
+
+        public RegexpMatcher(String expression) throws PatternSyntaxException {
+            if (expression == null) {
+                throw new NullPointerException();
+            }
+            _pattern = Pattern.compile(expression);
         }
-        return Pattern.matches(exp, str);
-    }
 
-    public String getName() {
-        return REGEXP;
-    }
+        public boolean matches(String input) {
+            if (input == null) {
+                throw new NullPointerException();
+            }
+            return _pattern.matcher(input).matches();
+        }
 
-    public Matcher getMatcher(String exp) {
-        if (ANY_EXPRESSION.equals(exp)) {
-            return AnyMatcher.getInstance();
+        public boolean isExact() {
+            return false;
         }
-        return new RegexpMatcher(exp);
     }
 }

Modified: 
incubator/ivy/trunk/src/java/org/apache/ivy/resolver/AbstractResolver.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/org/apache/ivy/resolver/AbstractResolver.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/src/java/org/apache/ivy/resolver/AbstractResolver.java 
(original)
+++ incubator/ivy/trunk/src/java/org/apache/ivy/resolver/AbstractResolver.java 
Sun Jan  7 10:37:19 2007
@@ -294,7 +294,7 @@
 
     public Matcher getChangingMatcher() {
         if (_changingPattern == null) {
-            return NoMatcher.getInstance();
+            return NoMatcher.INSTANCE;
         }
         PatternMatcher matcher = _ivy.getMatcher(_changingMatcherName);
         if (matcher == null) {

Added: 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/AbstractPatternMatcherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/matcher/AbstractPatternMatcherTest.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/AbstractPatternMatcherTest.java
 (added)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/AbstractPatternMatcherTest.java
 Sun Jan  7 10:37:19 2007
@@ -0,0 +1,101 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.matcher;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Base test classes for PatternMatcher testcase implementation
+ */
+public abstract class AbstractPatternMatcherTest extends TestCase {
+    protected PatternMatcher patternMatcher;
+    protected boolean exact;
+
+    protected abstract void setUp() throws Exception;
+    protected void setUp(PatternMatcher matcher, boolean exact) {
+        this.patternMatcher = matcher;
+        this.exact = exact;
+    }
+
+    public void testAnyExpression() {
+        Matcher matcher = patternMatcher.getMatcher("*");
+        assertTrue(matcher.matches(""));
+        assertTrue(matcher.matches("We shall transcend borders. The new is 
old."));
+        assertTrue(matcher.matches("        "));
+    }
+
+
+    public void testIsExact() {
+        Matcher matcher = patternMatcher.getMatcher("*");
+        assertEquals(false, matcher.isExact());
+        matcher.matches("The words aren't what they were.");
+        assertEquals(false, matcher.isExact());
+
+        matcher = patternMatcher.getMatcher("some expression");
+        assertEquals(exact, matcher.isExact());
+        matcher.matches("The words aren't what they were.");
+        assertEquals(exact, matcher.isExact());
+    }
+
+    public void testNullInput() {
+        Matcher matcher = patternMatcher.getMatcher("some expression");
+        try {
+            matcher.matches(null);
+            fail("Should fail for null input");
+        } catch (NullPointerException expected) {
+
+        }
+    }
+
+    public void testNullExpression() {
+        try {
+            Matcher matcher = patternMatcher.getMatcher(null);
+            fail("Should fail for null expression");
+        } catch (NullPointerException expected) {
+
+        }
+    }
+
+    public abstract void testImplementation();
+
+
+    public void testLoadTestMatches() {
+        Matcher matcher = patternMatcher.getMatcher("this.is.an.expression");
+        String[] inputs = {
+                "this.is.an.expression", "this:is:an:expression", "this is an 
expression",
+                "whatever this is", "maybe, maybe not"
+        };
+        for (int i = 0; i < 100000; i++) {
+            String input = inputs[i%inputs.length];
+            boolean success = matcher.matches(input);
+        }
+    }
+
+    public void testLoadTestGetMatcher() {
+        String[] inputs = {
+                "this.is.an.expression", "this:is:an:expression", "this is an 
expression",
+                "whatever this is", "maybe, maybe not"
+        };
+
+        for (int i = 0; i < 100000; i++) {
+            String expression = inputs[i%inputs.length];
+            Matcher matcher = patternMatcher.getMatcher(expression);
+        }
+    }
+}

Added: 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcherTest.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcherTest.java
 (added)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactOrRegexpPatternMatcherTest.java
 Sun Jan  7 10:37:19 2007
@@ -0,0 +1,51 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.matcher;
+
+import java.util.regex.PatternSyntaxException;
+
+/**
+ *
+ */
+public class ExactOrRegexpPatternMatcherTest extends 
AbstractPatternMatcherTest {
+
+    protected void setUp() throws Exception {
+        setUp(new ExactOrRegexpPatternMatcher(), false);
+    }
+
+    public void testImplementation() {
+        Matcher matcher = patternMatcher.getMatcher(".");
+        assertFalse(matcher.matches(""));
+        assertTrue("Exact match failed", matcher.matches("."));
+        assertTrue("Regexp match failed", matcher.matches("a"));
+        assertFalse(matcher.matches("aa"));
+
+        matcher = patternMatcher.getMatcher(".*");
+        assertTrue("Exact match failed", matcher.matches(".*"));
+        assertTrue("Regexp match failed", matcher.matches(""));
+        assertTrue(matcher.matches("a"));
+        assertTrue(matcher.matches("aa"));
+
+        try {
+            matcher = patternMatcher.getMatcher("(");
+            fail("Should fail on invalid regexp syntax");
+        } catch (PatternSyntaxException e) {
+            
+        }
+    }
+}

Added: 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactPatternMatcherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactPatternMatcherTest.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactPatternMatcherTest.java
 (added)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/ExactPatternMatcherTest.java
 Sun Jan  7 10:37:19 2007
@@ -0,0 +1,37 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.matcher;
+
+/**
+* @see ExactPatternMatcher
+ */
+public class ExactPatternMatcherTest extends AbstractPatternMatcherTest {
+
+
+    protected void setUp() throws Exception {
+        setUp(new ExactPatternMatcher(), true);
+    }
+
+    public void testImplementation() {
+        Matcher matcher = patternMatcher.getMatcher(".");
+        assertFalse(matcher.matches(""));
+        assertTrue(matcher.matches("."));
+        assertFalse(matcher.matches("a"));
+        assertFalse(matcher.matches("aa"));
+    }
+}

Added: 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/GlobPatternMatcherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/matcher/GlobPatternMatcherTest.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/GlobPatternMatcherTest.java
 (added)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/GlobPatternMatcherTest.java
 Sun Jan  7 10:37:19 2007
@@ -0,0 +1,80 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.matcher;
+
+import java.util.regex.PatternSyntaxException;
+
+/**
+* @see GlobPatternMatcher
+ */
+public class GlobPatternMatcherTest extends AbstractPatternMatcherTest {
+
+    protected void setUp() throws Exception {
+        setUp(new GlobPatternMatcher(), false);
+    }
+
+    public void testValidRegexpSyntaxAsNormalCharacter() {
+        Matcher matcher = patternMatcher.getMatcher(".");
+        assertFalse(matcher.matches(""));
+        assertTrue(matcher.matches("."));
+        assertFalse(matcher.matches("a"));
+        assertFalse(matcher.matches("aa"));
+    }
+
+    public void testRegexpSyntaxAndGlob() {
+        Matcher matcher = patternMatcher.getMatcher(".*");
+        assertTrue(matcher.matches(".*"));
+        assertFalse(matcher.matches(""));
+        assertFalse(matcher.matches("a"));
+        assertTrue(matcher.matches(".a"));
+        assertFalse(matcher.matches("abcdef"));
+        assertTrue(matcher.matches(".abcdef"));
+    }
+
+    public void testImplementation() {
+    }
+
+    public void testQuoteMeta() {
+        Matcher matcher = patternMatcher.getMatcher("\\*");
+        assertTrue(matcher.matches("*"));
+        assertFalse(matcher.matches("X"));
+        assertFalse(matcher.matches("Xsfsdfsd"));
+    }
+
+    public void testInvalidRegexpSyntaxAsNormalCharacter() {
+        Matcher matcher = patternMatcher.getMatcher("(");
+        assertTrue(matcher.matches("("));
+    }
+
+    public void testGlob() {
+        Matcher matcher = patternMatcher.getMatcher("*ivy*");
+        assertTrue(matcher.matches("ivy"));
+        assertTrue(matcher.matches("abcdefivyuvw"));
+        assertTrue(matcher.matches("ivyuvw"));
+        assertTrue(matcher.matches("abcdefivy"));
+    }
+
+    public void testInvalidSyntax() {
+        try {
+            Matcher matcher = patternMatcher.getMatcher("[");
+            fail("Should fail on invalid regexp syntax");
+        } catch (PatternSyntaxException e) {
+
+        }
+    }
+}

Added: 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/RegexpPatternMatcherTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/matcher/RegexpPatternMatcherTest.java?view=auto&rev=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/RegexpPatternMatcherTest.java
 (added)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/matcher/RegexpPatternMatcherTest.java
 Sun Jan  7 10:37:19 2007
@@ -0,0 +1,45 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ivy.matcher;
+
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * @see RegexpPatternMatcher
+ */
+public class RegexpPatternMatcherTest extends AbstractPatternMatcherTest {
+
+    protected void setUp() throws Exception {
+        setUp(new RegexpPatternMatcher(), false);
+    }
+
+    public void testImplementation() {
+        Matcher matcher = patternMatcher.getMatcher(".*");
+        assertTrue(matcher.matches(".*"));
+        assertTrue(matcher.matches(""));
+        assertTrue(matcher.matches("a"));
+        assertTrue(matcher.matches("aa"));
+
+        try {
+            matcher = patternMatcher.getMatcher("(");
+            fail("Should fail on invalid syntax");
+        } catch (PatternSyntaxException e) {
+
+        }
+    }
+}

Modified: 
incubator/ivy/trunk/test/java/org/apache/ivy/resolver/IBiblioResolverTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/resolver/IBiblioResolverTest.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- 
incubator/ivy/trunk/test/java/org/apache/ivy/resolver/IBiblioResolverTest.java 
(original)
+++ 
incubator/ivy/trunk/test/java/org/apache/ivy/resolver/IBiblioResolverTest.java 
Sun Jan  7 10:37:19 2007
@@ -169,8 +169,8 @@
         
         ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", 
"nanning", "0.9");
         DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, 
false);
-        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-profiler", "jar", "jar", true, 
ExactPatternMatcher.getInstance()));
-        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-trace", "jar", "jar", true, 
ExactPatternMatcher.getInstance()));
+        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-profiler", "jar", "jar", true, 
ExactPatternMatcher.INSTANCE));
+        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-trace", "jar", "jar", true, 
ExactPatternMatcher.INSTANCE));
         ResolvedModuleRevision rmr = resolver.getDependency(dd, _data);
         assertNotNull(rmr);
         assertEquals(mrid, rmr.getId());

Modified: 
incubator/ivy/trunk/test/java/org/apache/ivy/resolver/URLResolverTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/org/apache/ivy/resolver/URLResolverTest.java?view=diff&rev=493801&r1=493800&r2=493801
==============================================================================
--- incubator/ivy/trunk/test/java/org/apache/ivy/resolver/URLResolverTest.java 
(original)
+++ incubator/ivy/trunk/test/java/org/apache/ivy/resolver/URLResolverTest.java 
Sun Jan  7 10:37:19 2007
@@ -181,8 +181,8 @@
         
         ModuleRevisionId mrid = ModuleRevisionId.newInstance("apache", 
"nanning", "0.9");
         DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(mrid, 
false);
-        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-profiler", "jar", "jar", true, 
ExactPatternMatcher.getInstance()));
-        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-trace", "jar", "jar", true, 
ExactPatternMatcher.getInstance()));
+        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-profiler", "jar", "jar", true, 
ExactPatternMatcher.INSTANCE));
+        dd.addDependencyArtifactIncludes("default", new 
DefaultDependencyArtifactDescriptor(dd, "nanning-trace", "jar", "jar", true, 
ExactPatternMatcher.INSTANCE));
         ResolvedModuleRevision rmr = resolver.getDependency(dd, _data);
         assertNotNull(rmr);
         assertEquals(mrid, rmr.getId());


Reply via email to