-1) {
+ subst.append("$(").append(value).append(")");
+ } else {
+ subst.append(c);
+ }
+ } else {
+ // XXX - should throw an exception instead?
+ subst.append('\\');
+ }
+ } else {
+ subst.append(c);
+ }
+ }
+ argument = subst.toString();
+
int sOptions = getSubsOptions(options);
Pattern p = getCompiledPattern(options);
StringBuffer sb = new StringBuffer();
@@ -95,10 +118,12 @@ public class Jdk14RegexpRegexp extends Jdk14RegexpMatcher implements Regexp
else
{
boolean res = m.find();
- if (res)
+ if (res) {
m.appendReplacement(sb, argument);
- else
+ m.appendTail(sb);
+ } else {
sb.append(input);
+ }
}
return sb.toString();
diff --git a/src/main/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexp.java b/src/main/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexp.java
new file mode 100644
index 000000000..e40064065
--- /dev/null
+++ b/src/main/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexp.java
@@ -0,0 +1,160 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+package org.apache.tools.ant.util.regexp;
+
+import org.apache.tools.ant.BuildException;
+
+import java.util.Vector;
+
+/**
+ * Helper class that adapts a RegexpMatcher to a Regexp.
+ *
+ * @author Stefan Bodewig
+ * @version $Revision$
+ */
+public class MatcherWrappedAsRegexp implements Regexp {
+
+ private RegexpMatcher matcher;
+
+ public MatcherWrappedAsRegexp(RegexpMatcher matcher) {
+ this.matcher = matcher;
+ }
+
+ /**
+ * Set the regexp pattern from the String description.
+ */
+ public void setPattern(String pattern) throws BuildException {
+ matcher.setPattern(pattern);
+ }
+
+ /**
+ * Get a String representation of the regexp pattern
+ */
+ public String getPattern() throws BuildException {
+ return matcher.getPattern();
+ }
+
+ /**
+ * Does the given argument match the pattern?
+ */
+ public boolean matches(String argument) throws BuildException {
+ return matcher.matches(argument);
+ }
+
+ /**
+ * Returns a Vector of matched groups found in the argument.
+ *
+ * Group 0 will be the full match, the rest are the
+ * parenthesized subexpressions
.
+ */
+ public Vector getGroups(String argument) throws BuildException {
+ return matcher.getGroups(argument);
+ }
+
+ /**
+ * Does this regular expression match the input, given
+ * certain options
+ * @param input The string to check for a match
+ * @param options The list of options for the match. See the
+ * MATCH_ constants above.
+ */
+ public boolean matches(String input, int options) throws BuildException {
+ return matcher.matches(input, options);
+ }
+
+ /**
+ * Get the match groups from this regular expression. The return
+ * type of the elements is always String.
+ * @param input The string to check for a match
+ * @param options The list of options for the match. See the
+ * MATCH_ constants above.
+ */
+ public Vector getGroups(String input, int options) throws BuildException {
+ return matcher.getGroups(input, options);
+ }
+
+ /**
+ * Perform a substitution on the regular expression.
+ * @param input The string to substitute on
+ * @param argument The string which defines the substitution
+ * @param options The list of options for the match and replace. See the
+ * MATCH_ and REPLACE_ constants above.
+ * REPLACE_ constants will be ignored.
+ */
+ public String substitute(String input, String argument, int options)
+ throws BuildException {
+ Vector v = matcher.getGroups(input, options);
+
+ StringBuffer result = new StringBuffer();
+ char[] to = argument.toCharArray();
+ for (int i=0; i -1) {
+ result.append((String) v.elementAt(value));
+ } else {
+ result.append(to[i]);
+ }
+ } else {
+ // XXX - should throw an exception instead?
+ result.append('\\');
+ }
+ } else {
+ result.append(to[i]);
+ }
+ }
+ return result.toString();
+ }
+}
diff --git a/src/main/org/apache/tools/ant/util/regexp/Regexp.java b/src/main/org/apache/tools/ant/util/regexp/Regexp.java
index cb03377da..1f946c39f 100644
--- a/src/main/org/apache/tools/ant/util/regexp/Regexp.java
+++ b/src/main/org/apache/tools/ant/util/regexp/Regexp.java
@@ -63,6 +63,17 @@ import org.apache.tools.ant.BuildException;
*/
public interface Regexp extends RegexpMatcher
{
+
+ /**
+ * Replace only the first occurance of the regular expression
+ */
+ int REPLACE_FIRST = 0x00000001;
+
+ /**
+ * Replace all occurances of the regular expression
+ */
+ int REPLACE_ALL = 0x00000010;
+
/**
* Perform a substitution on the regular expression.
* @param input The string to substitute on
diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
index 3ebd12360..75b180abb 100644
--- a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
+++ b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
@@ -90,24 +90,33 @@ public class RegexpFactory extends RegexpMatcherFactory
}
if (systemDefault != null) {
- return (Regexp)createInstance(systemDefault);
+ return createRegexpInstance(systemDefault);
// XXX should we silently catch possible exceptions and try to
// load a different implementation?
}
try {
- return (Regexp)createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp");
+ return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp");
} catch (BuildException be) {}
try {
- return (Regexp)createInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp");
+ return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp");
} catch (BuildException be) {}
try {
- return (Regexp)createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp");
+ return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp");
} catch (BuildException be) {}
throw new BuildException("No supported regular expression matcher found");
}
+ protected Regexp createRegexpInstance(String classname) {
+ RegexpMatcher m = createInstance(classname);
+ if (m instanceof Regexp) {
+ return (Regexp) m;
+ } else {
+ return new MatcherWrappedAsRegexp(m);
+ }
+ }
+
}
diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java
index fc424f7b1..7a6bcc002 100644
--- a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java
+++ b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcher.java
@@ -65,16 +65,6 @@ import java.util.Vector;
*/
public interface RegexpMatcher {
- /***
- * Replace only the first occurance of the regular expression
- */
- int REPLACE_FIRST = 0x00000001;
-
- /***
- * Replace all occurances of the regular expression
- */
- int REPLACE_ALL = 0x00000010;
-
/***
* Default Mask (case insensitive, neither multiline nor
* singleline specified).
diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
new file mode 100644
index 000000000..260c86aa0
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
@@ -0,0 +1,114 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.taskdefs.TaskdefsTest;
+
+import java.util.Properties;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+/**
+ * JUnit Testcase for the optional replaceregexp task.
+ *
+ * @author Stefan Bodewig
+ * @version $Revision$
+ */
+public class ReplaceRegExpTest extends TaskdefsTest {
+
+ public ReplaceRegExpTest(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/taskdefs/optional/replaceregexp.xml");
+ }
+
+ public void tearDown() {
+ executeTarget("cleanup");
+ }
+
+ public void testReplace() throws IOException {
+ Properties original = new Properties();
+ FileInputStream propsFile = null;
+ try {
+ propsFile = new FileInputStream("src/etc/testcases/taskdefs/optional/replaceregexp.properties");
+ original.load(propsFile);
+ } finally {
+ if (propsFile != null) {
+ propsFile.close();
+ propsFile = null;
+ }
+ }
+
+ assertEquals("Def", original.get("OldAbc"));
+
+ executeTarget("testReplace");
+
+ Properties after = new Properties();
+ try {
+ propsFile = new FileInputStream("src/etc/testcases/taskdefs/optional/test.properties");
+ after.load(propsFile);
+ } finally {
+ if (propsFile != null) {
+ propsFile.close();
+ propsFile = null;
+ }
+ }
+
+ assertNull(after.get("OldAbc"));
+ assertEquals("AbcDef", after.get("NewProp"));
+ }
+
+}// ReplaceRegExpTest
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java b/src/testcases/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java
new file mode 100644
index 000000000..3c095bd13
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java
@@ -0,0 +1,72 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.util.regexp;
+
+/**
+ * Tests for the jakarta-oro implementation of the Regexp interface.
+ *
+ * @author Stefan Bodewig
+ */
+public class JakartaOroRegexpTest extends RegexpTest {
+
+ public Regexp getRegexpImplementation() {
+ return new JakartaOroRegexp();
+ }
+
+ public JakartaOroRegexpTest(String name) {
+ super(name);
+ }
+
+}
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java b/src/testcases/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java
new file mode 100644
index 000000000..bf0392b1f
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java
@@ -0,0 +1,76 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2000 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.util.regexp;
+
+/**
+ * Tests for the jakarta-regexp implementation of the Regexp interface.
+ *
+ * @author Stefan Bodewig
+ */
+public class JakartaRegexpRegexpTest extends RegexpTest {
+
+ public Regexp getRegexpImplementation() {
+ return new JakartaRegexpRegexp();
+ }
+
+ public JakartaRegexpRegexpTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Fails for "default" mode.
+ */
+ protected void doEndTest2(String text) {}
+}
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java b/src/testcases/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java
new file mode 100644
index 000000000..88247c3d3
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java
@@ -0,0 +1,72 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.util.regexp;
+
+/**
+ * Tests for the JDK 1.4 implementation of the Regexp interface.
+ *
+ * @author Stefan Bodewig
+ */
+public class Jdk14RegexpRegexpTest extends RegexpTest {
+
+ public Regexp getRegexpImplementation() {
+ return new Jdk14RegexpRegexp();
+ }
+
+ public Jdk14RegexpRegexpTest(String name) {
+ super(name);
+ }
+
+}
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexpTest.java b/src/testcases/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexpTest.java
new file mode 100644
index 000000000..2508feb5e
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/util/regexp/MatcherWrappedAsRegexpTest.java
@@ -0,0 +1,85 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.util.regexp;
+
+/**
+ * Test for the wrapped implementation of the Regexp Interface.
+ *
+ * @author Stefan Bodewig
+ */
+public class MatcherWrappedAsRegexpTest extends RegexpTest {
+
+ public MatcherWrappedAsRegexpTest(String name) {
+ super(name);
+ }
+
+ public Regexp getRegexpImplementation() {
+ RegexpMatcherFactory fac = new RegexpMatcherFactory();
+ return new MatcherWrappedAsRegexp(fac.newRegexpMatcher());
+ }
+
+ /**
+ * Jakarta Regexp fails for "default" mode.
+ */
+ protected void doEndTest2(String text) {
+ RegexpMatcherFactory fac = new RegexpMatcherFactory();
+ RegexpMatcher m = fac.newRegexpMatcher();
+ if (m.getClass().getName().equals("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher")) {
+ // ignore
+ } else {
+ super.doEndTest2(text);
+ }
+ }
+}
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java b/src/testcases/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java
index 3c4158a03..e253b239c 100644
--- a/src/testcases/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java
+++ b/src/testcases/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java
@@ -72,6 +72,8 @@ public abstract class RegexpMatcherTest extends TestCase {
public abstract RegexpMatcher getImplementation();
+ protected final RegexpMatcher getReg() {return reg;}
+
public RegexpMatcherTest(String name) {
super(name);
}
diff --git a/src/testcases/org/apache/tools/ant/util/regexp/RegexpTest.java b/src/testcases/org/apache/tools/ant/util/regexp/RegexpTest.java
new file mode 100644
index 000000000..3af558778
--- /dev/null
+++ b/src/testcases/org/apache/tools/ant/util/regexp/RegexpTest.java
@@ -0,0 +1,100 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowlegement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowlegement may appear in the software itself,
+ * if and wherever such third-party acknowlegements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Group.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ */
+
+package org.apache.tools.ant.util.regexp;
+
+/**
+ * Tests for all implementations of the Regexp interface.
+ *
+ * @author Stefan Bodewig
+ */
+public abstract class RegexpTest extends RegexpMatcherTest {
+
+ private static final String test = "abcdefg-abcdefg";
+ private static final String pattern = "ab([^d]*)d([^f]*)f";
+
+ public RegexpTest(String name) {
+ super(name);
+ }
+
+ public final RegexpMatcher getImplementation() {
+ return getRegexpImplementation();
+ }
+
+ public abstract Regexp getRegexpImplementation();
+
+ public void testSubstitution() {
+ Regexp reg = (Regexp) getReg();
+ reg.setPattern(pattern);
+ assertTrue(reg.matches(test));
+ assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f",
+ Regexp.MATCH_DEFAULT));
+ }
+
+ public void testReplaceFirstSubstitution() {
+ Regexp reg = (Regexp) getReg();
+ reg.setPattern(pattern);
+ assertTrue(reg.matches(test));
+ assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f",
+ Regexp.REPLACE_FIRST));
+ }
+
+ public void testReplaceAllSubstitution() {
+ Regexp reg = (Regexp) getReg();
+ reg.setPattern(pattern);
+ assertTrue(reg.matches(test));
+ assertEquals("abedcfg-abedcfg", reg.substitute(test, "ab\\2d\\1f",
+ Regexp.REPLACE_ALL));
+ }
+}