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 b0fa23e57..f0b758afa 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.util.regexp; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.JavaEnvUtils; /*** * Regular expression factory, which will create Regexp objects. The @@ -61,28 +62,31 @@ public class RegexpFactory extends RegexpMatcherFactory { // load a different implementation? } + Throwable cause = null; + try { testAvailability("java.util.regex.Matcher"); return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14); } try { testAvailability("org.apache.oro.text.regex.Pattern"); return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, true); } try { testAvailability("org.apache.regexp.RE"); return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, true); } - throw new BuildException("No supported regular expression matcher found"); + throw new BuildException("No supported regular expression matcher found" + + (cause != null ? ": " + cause : ""), cause); } /** diff --git a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java index 1a8c5a35c..1c2ff1662 100644 --- a/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java +++ b/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java @@ -21,6 +21,7 @@ import org.apache.tools.ant.Project; import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.util.ClasspathUtils; +import org.apache.tools.ant.util.JavaEnvUtils; /** * Simple Factory Class that produces an implementation of @@ -69,30 +70,41 @@ public class RegexpMatcherFactory { // load a different implementation? } + Throwable cause = null; + try { testAvailability("java.util.regex.Matcher"); return createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14); } try { testAvailability("org.apache.oro.text.regex.Pattern"); return createInstance("org.apache.tools.ant.util.regexp.JakartaOroMatcher"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, true); } try { testAvailability("org.apache.regexp.RE"); return createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher"); } catch (BuildException be) { - // ignore + cause = orCause(cause, be, true); } - throw new BuildException("No supported regular expression matcher found"); + throw new BuildException("No supported regular expression matcher found" + + (cause != null ? ": " + cause : ""), cause); } + static Throwable orCause(Throwable deflt, BuildException be, boolean ignoreCnfe) { + if (deflt != null) { + return deflt; + } + Throwable t = be.getException(); + return ignoreCnfe && t instanceof ClassNotFoundException ? null : t; + } + /** * Create an instance of a matcher from a classname. *