Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 159   Methods: 4
NCLOC: 43   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JspCompilerAdapterFactory.java 75% 30.8% 25% 38.1%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2001-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.optional.jsp.compilers;
 55   
 
 56   
 import org.apache.tools.ant.AntClassLoader;
 57   
 import org.apache.tools.ant.BuildException;
 58   
 import org.apache.tools.ant.Task;
 59   
 import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler;
 60   
 import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler;
 61   
 
 62   
 
 63   
 /**
 64   
  * Creates the necessary compiler adapter, given basic criteria.
 65   
  *
 66   
  * @author <a href="mailto:jayglanville@home.com">J D Glanville</a>
 67   
  * @author Matthew Watson <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
 68   
  * @author Steve Loughran
 69   
  */
 70   
 public class JspCompilerAdapterFactory {
 71   
 
 72   
     /** This is a singleton -- can't create instances!! */
 73  0
     private JspCompilerAdapterFactory() {
 74   
     }
 75   
 
 76   
     /**
 77   
      * Based on the parameter passed in, this method creates the necessary
 78   
      * factory desired.
 79   
      *
 80   
      * The current mapping for compiler names are as follows:
 81   
      * <ul><li>jasper = jasper compiler (the default)
 82   
      * <li><i>a fully quallified classname</i> = the name of a jsp compiler
 83   
      * adapter
 84   
      * </ul>
 85   
      *
 86   
      * @param compilerType either the name of the desired compiler, or the
 87   
      * full classname of the compiler's adapter.
 88   
      * @param task a task to log through.
 89   
      * @throws BuildException if the compiler type could not be resolved into
 90   
      * a compiler adapter.
 91   
      */
 92  0
     public static JspCompilerAdapter getCompiler(String compilerType, Task task)
 93   
         throws BuildException {
 94  0
         return getCompiler(compilerType, task,
 95   
                            task.getProject().createClassLoader(null));
 96   
     }
 97   
 
 98   
     /**
 99   
      * Based on the parameter passed in, this method creates the necessary
 100   
      * factory desired.
 101   
      *
 102   
      * The current mapping for compiler names are as follows:
 103   
      * <ul><li>jasper = jasper compiler (the default)
 104   
      * <li><i>a fully quallified classname</i> = the name of a jsp compiler
 105   
      * adapter
 106   
      * </ul>
 107   
      *
 108   
      * @param compilerType either the name of the desired compiler, or the
 109   
      * full classname of the compiler's adapter.
 110   
      * @param task a task to log through.
 111   
      * @param loader AntClassLoader with which the compiler should be loaded
 112   
      * @throws BuildException if the compiler type could not be resolved into
 113   
      * a compiler adapter.
 114   
      */
 115  9
     public static JspCompilerAdapter getCompiler(String compilerType, Task task,
 116   
                                                  AntClassLoader loader)
 117   
         throws BuildException {
 118   
 
 119  9
         if (compilerType.equalsIgnoreCase("jasper")) {
 120   
             //tomcat4.0 gets the old mangler
 121  2
             return new JasperC(new JspNameMangler());
 122   
         }
 123  7
         if (compilerType.equalsIgnoreCase("jasper41")) {
 124   
             //tomcat4.1 gets the new one
 125  7
             return new JasperC(new Jasper41Mangler());
 126   
         }
 127  0
         return resolveClassName(compilerType, loader);
 128   
     }
 129   
 
 130   
     /**
 131   
      * Tries to resolve the given classname into a compiler adapter.
 132   
      * Throws a fit if it can't.
 133   
      *
 134   
      * @param className The fully qualified classname to be created.
 135   
      * @param classloader Classloader with which to load the class
 136   
      * @throws BuildException This is the fit that is thrown if className
 137   
      * isn't an instance of JspCompilerAdapter.
 138   
      */
 139  0
     private static JspCompilerAdapter resolveClassName(String className,
 140   
                                                        AntClassLoader classloader)
 141   
         throws BuildException {
 142  0
         try {
 143  0
             Class c = classloader.findClass(className);
 144  0
             Object o = c.newInstance();
 145  0
             return (JspCompilerAdapter) o;
 146   
         } catch (ClassNotFoundException cnfe) {
 147  0
             throw new BuildException(className + " can\'t be found.", cnfe);
 148   
         } catch (ClassCastException cce) {
 149  0
             throw new BuildException(className + " isn\'t the classname of "
 150   
                                      + "a compiler adapter.", cce);
 151   
         } catch (Throwable t) {
 152   
             // for all other possibilities
 153  0
             throw new BuildException(className + " caused an interesting "
 154   
                                      + "exception.", t);
 155   
         }
 156   
     }
 157   
 
 158   
 }
 159