You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/11/29 12:50:14 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/util/regexp RegexpMatcherFactory.java

bodewig     00/11/29 03:50:10

  Modified:    .        bootstrap.sh build.xml
               docs     index.html
               src/main/org/apache/tools/ant/util RegexpPatternMapper.java
  Added:       src/main/org/apache/tools/ant/util/regexp
                        RegexpMatcherFactory.java
  Removed:     docs     P4desc.html
  Log:
  Moved the instantiation of the RE matcher to a factory. Users can now
  choose an implementation of there own by setting a system property.
  
  Revision  Changes    Path
  1.27      +2 -2      jakarta-ant/bootstrap.sh
  
  Index: bootstrap.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/bootstrap.sh,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- bootstrap.sh	2000/11/28 15:10:28	1.26
  +++ bootstrap.sh	2000/11/29 11:49:44	1.27
  @@ -49,10 +49,10 @@
   echo ... Compiling Ant Classes
   
   ${JAVAC} -d ${CLASSDIR} ${TOOLS}/tar/*.java
  +${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/util/regexp/RegexpMatcher.java ${TOOLS}/ant/util/regexp/RegexpMatcherFactory.java
  +${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/util/*.java
   ${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/types/*.java
   ${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/*.java
  -${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/util/regexp/RegexpMatcher.java
  -${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/util/*.java
   ${JAVAC} -d ${CLASSDIR} ${TOOLS}/ant/taskdefs/*.java
   
   echo ... Copying Required Files
  
  
  
  1.104     +2 -1      jakarta-ant/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/build.xml,v
  retrieving revision 1.103
  retrieving revision 1.104
  diff -u -r1.103 -r1.104
  --- build.xml	2000/11/28 17:06:19	1.103
  +++ build.xml	2000/11/29 11:49:45	1.104
  @@ -41,6 +41,7 @@
     <property name="build.compiler" value="classic"/>
     <property name="build.compiler.emacs" value="on"/>
     <property name="junit.fork" value="false" />
  +  <property name="javac.optimize" value="true" />
   
     <!-- =================================================================== -->
     <!-- Define a global set of patterns that can be referenced by           -->
  @@ -96,7 +97,7 @@
              destdir="${build.classes}"
              debug="on"
              deprecation="off"
  -           optimize="on" >
  +           optimize="${javac.optimize}" >
         <classpath refid="classpath" />
   
         <exclude name="**/Script.java" unless="bsf.present" />
  
  
  
  1.155     +1 -2      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.154
  retrieving revision 1.155
  diff -u -r1.154 -r1.155
  --- index.html	2000/11/27 07:54:34	1.154
  +++ index.html	2000/11/29 11:49:57	1.155
  @@ -27,7 +27,7 @@
     <li>Dave Walend (<a href="mailto:dwalend@cs.tufts.edu">dwalend@cs.tufts.edu</a>)</li>
   </ul>
   
  -<p>Version 1.3 - 2000/11/14</p>
  +<p>Version 1.3 - 2000/11/29</p>
   
   <hr>
   <h2>Table of Contents</h2>
  @@ -4550,7 +4550,6 @@
     <li><a href="junit.html">JUnit</a></li>
     <li><a href="native2ascii.html">Native2Ascii</a></li>
     <li><a href="#netrexxc">NetRexxC</a></li>
  -  <li><a href="P4desc.html">Perforce</a></li>
     <li><a href="propertyfile.html">PropertyFile</a></li>
     <li><a href="#renameexts">RenameExtensions</a></li>
     <li><a href="#script">Script</a></li>
  
  
  
  1.3       +10 -31    jakarta-ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java
  
  Index: RegexpPatternMapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/RegexpPatternMapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RegexpPatternMapper.java	2000/11/28 16:01:11	1.2
  +++ RegexpPatternMapper.java	2000/11/29 11:50:02	1.3
  @@ -56,6 +56,7 @@
   
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.util.regexp.RegexpMatcher;
  +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
   
   import java.util.Enumeration;
   import java.util.Vector;
  @@ -70,30 +71,23 @@
       protected RegexpMatcher reg = null;
       protected char[] to = null;
       protected StringBuffer result = new StringBuffer();
  -    protected Class regexpMatcherClass = null;
   
       public RegexpPatternMapper() throws BuildException {
  -        try {
  -            regexpMatcherClass = Class.forName("org.apache.tools.ant.util.regexp.JakartaOroMatcher");
  -
  -            if (regexpMatcherClass == null) {
  -                regexpMatcherClass = Class.forName("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher");
  -                 
  -            }
  -        } catch (ClassNotFoundException ce) {
  -        } catch (NoClassDefFoundError ne) {
  -        }
  -
  -        if (regexpMatcherClass == null) {
  -            throw new BuildException("No supported regular expression matcher found");
  -        }
  +        reg = (new RegexpMatcherFactory()).newRegexpMatcher();
       }
       
       /**
        * Sets the &quot;from&quot; pattern. Required.
        */
       public void setFrom(String from) throws BuildException {
  -        reg = createMatcher(from);
  +        try {
  +            reg.setPattern(from);
  +        } catch (NoClassDefFoundError e) {
  +            // depending on the implementation the actual RE won't
  +            // get instantiated in the constructor.
  +            throw new BuildException("Cannot load regular expression matcher",
  +                                     e);
  +        }
       }
   
       /**
  @@ -144,19 +138,4 @@
           return result.toString();
       }
   
  -    /**
  -     * Create an implementation of RegexpMatcher based on the classes
  -     * that can be loaded.
  -     */
  -    protected RegexpMatcher createMatcher(String pattern) 
  -        throws BuildException {
  -        try {
  -            RegexpMatcher rm = (RegexpMatcher) regexpMatcherClass.newInstance();
  -            rm.setPattern(pattern);
  -            return rm;
  -        } catch (Throwable t) {
  -            throw new BuildException(t);
  -        }
  -        
  -    }
   }
  
  
  
  1.1                  jakarta-ant/src/main/org/apache/tools/ant/util/regexp/RegexpMatcherFactory.java
  
  Index: RegexpMatcherFactory.java
  ===================================================================
  /*
   * 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
   * <http://www.apache.org/>.
   */
  
  package org.apache.tools.ant.util.regexp;
  
  import org.apache.tools.ant.BuildException;
  
  /**
   * Simple Factory Class that produces an implementation of
   * RegexpMatcher based on the system property
   * <code>ant.regexp.matcherimpl</code> and the classes
   * available.
   * 
   * <p>In a more general framework this class would be abstract and
   * have a static newInstance method.</p>
   *
   * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> 
   */
  public class RegexpMatcherFactory {
  
      public RegexpMatcherFactory() {}
  
      public RegexpMatcher newRegexpMatcher() throws BuildException {
          String systemDefault = System.getProperty("ant.regexp.matcherimpl");
          if (systemDefault != null) {
              return createInstance(systemDefault);
              // XXX     should we silently possible exceptions and try to 
              //         load a different implementation?
          }
  
          try {
              return createInstance("org.apache.tools.ant.util.regexp.JakartaOroMatcher");
          } catch (BuildException be) {}
          
          try {
              return createInstance("org.apache.tools.ant.util.regexp.JakartaRegexpMatcher");
          } catch (BuildException be) {}
  
          throw new BuildException("No supported regular expression matcher found");
     }
  
      protected RegexpMatcher createInstance(String className) 
          throws BuildException {
          try {
              Class implClass = Class.forName(className);
              return (RegexpMatcher) implClass.newInstance();
          } catch (Throwable t) {
              throw new BuildException(t);
          }
      }
  }