Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 175   Methods: 4
NCLOC: 80   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JasperC.java 60% 84.4% 100% 81.4%
 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   
 
 55   
 package org.apache.tools.ant.taskdefs.optional.jsp.compilers;
 56   
 
 57   
 import java.io.File;
 58   
 import org.apache.tools.ant.BuildException;
 59   
 import org.apache.tools.ant.Project;
 60   
 import org.apache.tools.ant.taskdefs.Java;
 61   
 import org.apache.tools.ant.taskdefs.optional.jsp.JspC;
 62   
 import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler;
 63   
 import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler;
 64   
 import org.apache.tools.ant.types.CommandlineJava;
 65   
 import org.apache.tools.ant.types.Path;
 66   
 
 67   
 /**
 68   
  * The implementation of the jasper compiler.
 69   
  * This is a cut-and-paste of the original Jspc task.
 70   
  *
 71   
  * @author Matthew Watson <a href="mailto:mattw@i3sp.com">mattw@i3sp.com</a>
 72   
  * @author steve loughran
 73   
  * @since ant1.5
 74   
  */
 75   
 public class JasperC extends DefaultJspCompilerAdapter {
 76   
 
 77   
 
 78   
     /**
 79   
      * what produces java classes from .jsp files
 80   
      */
 81   
     JspMangler mangler;
 82   
 
 83  9
     public JasperC(JspMangler mangler) {
 84  9
         this.mangler = mangler;
 85   
     }
 86   
 
 87   
     /**
 88   
      * our execute method
 89   
      */
 90  6
     public boolean execute()
 91   
         throws BuildException {
 92  6
         getJspc().log("Using jasper compiler", Project.MSG_VERBOSE);
 93  6
         CommandlineJava cmd = setupJasperCommand();
 94   
 
 95   
 
 96  6
         try {
 97   
             // Create an instance of the compiler, redirecting output to
 98   
             // the project log
 99  6
             Java java = (Java) (getProject().createTask("java"));
 100  6
             if (getJspc().getClasspath() != null) {
 101  0
                 getProject().log("using user supplied classpath: "+getJspc().getClasspath(),
 102   
                     Project.MSG_DEBUG);
 103  0
                 java.setClasspath(getJspc().getClasspath()
 104   
                                   .concatSystemClasspath("ignore"));
 105   
             } else {
 106  6
                 Path classpath=new Path(getProject());
 107  6
                 classpath=classpath.concatSystemClasspath("only");
 108  6
                 getProject().log("using system classpath: "+classpath, Project.MSG_DEBUG);
 109  6
                 java.setClasspath(classpath);
 110   
             }
 111  6
             java.setDir(getProject().getBaseDir());
 112  6
             java.setClassname("org.apache.jasper.JspC");
 113   
             //this is really irritating; we need a way to set stuff
 114  6
             String args[] = cmd.getJavaCommand().getArguments();
 115  6
             for (int i = 0; i < args.length; i++) {
 116  38
                 java.createArg().setValue(args[i]);
 117   
             }
 118  6
             java.setFailonerror(getJspc().getFailonerror());
 119   
             //we are forking here to be sure that if JspC calls
 120   
             //System.exit() it doesn't halt the build
 121  6
             java.setFork(true);
 122  6
             java.setTaskName("jasperc");
 123  6
             java.execute();
 124  0
             return true;
 125   
         } catch (Exception ex) {
 126  6
             if (ex instanceof BuildException) {
 127  6
                 throw (BuildException) ex;
 128   
             } else {
 129  0
                 throw new BuildException("Error running jsp compiler: ",
 130   
                                          ex, getJspc().getLocation());
 131   
             }
 132   
         } finally {
 133  6
             getJspc().deleteEmptyJavaFiles();
 134   
         }
 135   
     }
 136   
     
 137   
 
 138   
     
 139   
     /**
 140   
      * build up a command line
 141   
      * @return a command line for jasper
 142   
      */
 143  6
     private CommandlineJava setupJasperCommand() {
 144  6
         CommandlineJava cmd = new CommandlineJava();
 145  6
         JspC jspc = getJspc();
 146  6
         addArg(cmd, "-d", jspc.getDestdir());
 147  6
         addArg(cmd, "-p", jspc.getPackage());
 148  6
         addArg(cmd, "-v" + jspc.getVerbose());
 149  6
         addArg(cmd, "-uriroot", jspc.getUriroot());
 150  6
         addArg(cmd, "-uribase", jspc.getUribase());
 151  6
         addArg(cmd, "-ieplugin", jspc.getIeplugin());
 152  6
         addArg(cmd, "-webinc", jspc.getWebinc());
 153  6
         addArg(cmd, "-webxml", jspc.getWebxml());        
 154  6
         addArg(cmd, "-die9");
 155   
 
 156  6
         if (jspc.isMapped()){
 157  0
             addArg(cmd, "-mapped");
 158   
         }       
 159  6
         if (jspc.getWebApp() != null) {
 160  0
             File dir = jspc.getWebApp().getDirectory();
 161  0
             addArg(cmd, "-webapp", dir);
 162   
         }
 163  6
         logAndAddFilesToCompile(getJspc(), getJspc().getCompileList(), cmd);
 164  6
         return cmd;
 165   
     }
 166   
 
 167   
     /**
 168   
      * @return an instance of the mangler this compiler uses
 169   
      */
 170   
 
 171  9
     public JspMangler createMangler() {
 172  9
         return mangler;
 173   
     }
 174   
 }
 175