Browse Source

Providing more information in case a regexp impl is unavailable for unexpected reasons.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@432728 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 19 years ago
parent
commit
136c2556cc
2 changed files with 24 additions and 8 deletions
  1. +8
    -4
      src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java
  2. +16
    -4
      src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java

+ 8
- 4
src/main/org/apache/tools/ant/util/regexp/RegexpFactory.java View File

@@ -18,6 +18,7 @@ package org.apache.tools.ant.util.regexp;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JavaEnvUtils;


/*** /***
* Regular expression factory, which will create Regexp objects. The * Regular expression factory, which will create Regexp objects. The
@@ -61,28 +62,31 @@ public class RegexpFactory extends RegexpMatcherFactory {
// load a different implementation? // load a different implementation?
} }


Throwable cause = null;

try { try {
testAvailability("java.util.regex.Matcher"); testAvailability("java.util.regex.Matcher");
return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"); return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp");
} catch (BuildException be) { } catch (BuildException be) {
// ignore
cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14);
} }


try { try {
testAvailability("org.apache.oro.text.regex.Pattern"); testAvailability("org.apache.oro.text.regex.Pattern");
return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp"); return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp");
} catch (BuildException be) { } catch (BuildException be) {
// ignore
cause = orCause(cause, be, true);
} }


try { try {
testAvailability("org.apache.regexp.RE"); testAvailability("org.apache.regexp.RE");
return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"); return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp");
} catch (BuildException be) { } 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);
} }


/** /**


+ 16
- 4
src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java View File

@@ -21,6 +21,7 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.util.ClasspathUtils; import org.apache.tools.ant.util.ClasspathUtils;
import org.apache.tools.ant.util.JavaEnvUtils;


/** /**
* Simple Factory Class that produces an implementation of * Simple Factory Class that produces an implementation of
@@ -69,30 +70,41 @@ public class RegexpMatcherFactory {
// load a different implementation? // load a different implementation?
} }


Throwable cause = null;

try { try {
testAvailability("java.util.regex.Matcher"); testAvailability("java.util.regex.Matcher");
return createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher"); return createInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpMatcher");
} catch (BuildException be) { } catch (BuildException be) {
// ignore
cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14);
} }


try { try {
testAvailability("org.apache.oro.text.regex.Pattern"); testAvailability("org.apache.oro.text.regex.Pattern");
return createInstance("org.apache.tools.ant.util.regexp.JakartaOroMatcher"); return createInstance("org.apache.tools.ant.util.regexp.JakartaOroMatcher");
} catch (BuildException be) { } catch (BuildException be) {
// ignore
cause = orCause(cause, be, true);
} }


try { try {
testAvailability("org.apache.regexp.RE"); testAvailability("org.apache.regexp.RE");
return createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher"); return createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher");
} catch (BuildException be) { } 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. * Create an instance of a matcher from a classname.
* *


Loading…
Cancel
Save