1 18 package org.apache.tools.ant.util.regexp; 19 20 import org.apache.tools.ant.BuildException; 21 import org.apache.tools.ant.Project; 22 import org.apache.tools.ant.util.JavaEnvUtils; 23 24 30 public class RegexpFactory extends RegexpMatcherFactory { 31 32 33 public RegexpFactory() { 34 } 35 36 41 public Regexp newRegexp() throws BuildException { 42 return (Regexp) newRegexp(null); 43 } 44 45 52 public Regexp newRegexp(Project p) throws BuildException { 53 String systemDefault = null; 54 if (p == null) { 55 systemDefault = System.getProperty("ant.regexp.regexpimpl"); 56 } else { 57 systemDefault = p.getProperty("ant.regexp.regexpimpl"); 58 } 59 60 if (systemDefault != null) { 61 return createRegexpInstance(systemDefault); 62 } 65 66 Throwable cause = null; 67 68 try { 69 testAvailability("java.util.regex.Matcher"); 70 return createRegexpInstance("org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"); 71 } catch (BuildException be) { 72 cause = orCause(cause, be, JavaEnvUtils.getJavaVersionNumber() < 14); 73 } 74 75 try { 76 testAvailability("org.apache.oro.text.regex.Pattern"); 77 return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaOroRegexp"); 78 } catch (BuildException be) { 79 cause = orCause(cause, be, true); 80 } 81 82 try { 83 testAvailability("org.apache.regexp.RE"); 84 return createRegexpInstance("org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"); 85 } catch (BuildException be) { 86 cause = orCause(cause, be, true); 87 } 88 89 throw new BuildException( 90 "No supported regular expression matcher found" 91 + (cause != null ? ": " + cause : ""), cause); 92 } 93 94 104 protected Regexp createRegexpInstance(String classname) 105 throws BuildException { 106 107 RegexpMatcher m = createInstance(classname); 108 if (m instanceof Regexp) { 109 return (Regexp) m; 110 } else { 111 throw new BuildException(classname + " doesn't implement the Regexp interface"); 112 } 113 } 114 115 } 116 | Popular Tags |