Index: doc/settings/version-matchers.html =================================================================== --- doc/settings/version-matchers.html (revision 782979) +++ doc/settings/version-matchers.html (working copy) @@ -32,8 +32,6 @@ A version matcher is used to evaluate if a a dependency version contraint matches a dependency version. -See dependency doc for details about built-in version matchers. -

Child elements

@@ -45,7 +43,57 @@
- +

Built-in Version Matchers

+

Exact Version Matcher

+A matcher that matches a dependency revision id to the module revision id using simple string equality. + +

Version Range Matcher

+ +Range types are exhaustively listed by example in the table below. + + + + + + + + + + + + + + + + + + + + + + + + +
Example RangeMatches
[1.0,2.0] all versions greater or equal to 1.0 and lower or equal to 2.0
[1.0,2.0[ all versions greater or equal to 1.0 and lower than 2.0
]1.0,2.0] all versions greater than 1.0 and lower or equal to 2.0
]1.0,2.0[ all versions greater than 1.0 and lower than 2.0
[1.0,) all versions greater or equal to 1.0
]1.0,) all versions greater than 1.0
(,2.0] all versions lower or equal to 2.0
(,2.0[ all versions lower than 2.0
+ +

Version Pattern Matcher

+ +The version pattern matcher allows for more flexibility in pattern matching at the cost of adding a matcher declaration in Ivy settings. A simple example is given below. + +

Settings.xml

+ + + + + + +

Ivy.xml

+ + + + +The version pattern matcher may contain more than one match element. The matcher will attempt to match a dependency revision against each match in sequence, checking the revision tag (e.g. foo(..)) and then the pattern. +Matcher types may be one of "regexp", "exact", "glob", or "exactOrRegexp". Glob pattern matching requires Apache ORO 2.0.8 or higher to be on the classpath. Index: src/java/org/apache/ivy/core/settings/typedef.properties =================================================================== --- src/java/org/apache/ivy/core/settings/typedef.properties (revision 782979) +++ src/java/org/apache/ivy/core/settings/typedef.properties (working copy) @@ -48,6 +48,7 @@ latest-vm = org.apache.ivy.plugins.version.LatestVersionMatcher sub-vm = org.apache.ivy.plugins.version.SubVersionMatcher range-vm = org.apache.ivy.plugins.version.VersionRangeMatcher +pattern-vm = org.apache.ivy.plugins.version.PatternVersionMatcher ant-build = org.apache.ivy.ant.AntBuildTrigger ant-call = org.apache.ivy.ant.AntCallTrigger Index: test/java/org/apache/ivy/plugins/version/PatternVersionMatcherTest.java =================================================================== --- test/java/org/apache/ivy/plugins/version/PatternVersionMatcherTest.java (revision 0) +++ test/java/org/apache/ivy/plugins/version/PatternVersionMatcherTest.java (revision 0) @@ -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.plugins.version; + +import org.apache.ivy.core.module.id.ModuleRevisionId; + +import junit.framework.TestCase; + +public class PatternVersionMatcherTest extends TestCase { + public void testSingleMatch() { + PatternVersionMatcher pvm = new PatternVersionMatcher(); + pvm.addMatch(generateRegexpMatch1()); + + assertAccept(pvm, "foo(1,3)", "1.4.1", false); + assertAccept(pvm, "foo(1,3)", "1.3", false); + assertAccept(pvm, "foo(1,3)", "2.3.1", false); + + assertAccept(pvm, "foo(1,3)", "1.3.1", true); + } + + public void testMultipleMatchEqualRevisions() { + PatternVersionMatcher pvm = new PatternVersionMatcher(); + pvm.addMatch(generateRegexpMatch1()); + pvm.addMatch(generateRegexpMatch2()); + + assertAccept(pvm, "foo(1,3)", "1.3", true); + assertAccept(pvm, "foo(1,3)", "1.3.1", true); + } + + public void testMultipleMatchNonEqualRevisions() { + PatternVersionMatcher pvm = new PatternVersionMatcher(); + pvm.addMatch(generateRegexpMatch1()); + pvm.addMatch(generateRegexpMatch3()); + + assertAccept(pvm, "foo(1,3)", "1.3", false); + assertAccept(pvm, "bar(1,3)", "1.3", true); + assertAccept(pvm, "foo(1,3)", "1.3.1", true); + } + + /** + * Generates a Match instance that has the following xml representation: + * + * @return + */ + private Match generateRegexpMatch1() { + Match match = new Match(); + match.setRevision("foo"); + match.setPattern("${major}\\.${minor}\\.\\d+"); + match.setArgs("major, minor"); + match.setMatcher("regexp"); + + return match; + } + + /** + * Generates a Match instance that has the following xml representation: + * + * @return + */ + private Match generateRegexpMatch2() { + Match match = new Match(); + match.setRevision("foo"); + match.setPattern("${major}\\.${minor}"); + match.setArgs("major, minor"); + match.setMatcher("regexp"); + + return match; + } + + private Match generateRegexpMatch3() { + Match match = new Match(); + match.setRevision("bar"); + match.setPattern("${major}\\.${minor}"); + match.setArgs("major, minor"); + match.setMatcher("regexp"); + + return match; + } + + + private void assertAccept(PatternVersionMatcher matcher, String askedVersion, + String depVersion, boolean b) { + assertEquals(b, matcher.accept(ModuleRevisionId.newInstance("org", "name", askedVersion), + ModuleRevisionId.newInstance("org", "name", depVersion))); + } +}