Coverage Report - net.sourceforge.cobertura.ant.ReportTask
 
Classes in this File Line Coverage Branch Coverage Complexity
ReportTask
89%
31/35
60%
6/10
2.333
 
 1  
 /*
 2  
  * The Apache Software License, Version 1.1
 3  
  *
 4  
  * Copyright (C) 2000-2002 The Apache Software Foundation.  All rights
 5  
  * reserved.
 6  
  * Copyright (C) 2003 jcoverage ltd.
 7  
  * Copyright (C) 2005 Mark Doliner
 8  
  * Copyright (C) 2005 Jeremy Thomerson
 9  
  * Copyright (C) 2005 Grzegorz Lukasik
 10  
  *
 11  
  * Redistribution and use in source and binary forms, with or without
 12  
  * modification, are permitted provided that the following conditions
 13  
  * are met:
 14  
  *
 15  
  * 1. Redistributions of source code must retain the above copyright
 16  
  *    notice, this list of conditions and the following disclaimer.
 17  
  *
 18  
  * 2. Redistributions in binary form must reproduce the above copyright
 19  
  *    notice, this list of conditions and the following disclaimer in
 20  
  *    the documentation and/or other materials provided with the
 21  
  *    distribution.
 22  
  *
 23  
  * 3. The end-user documentation included with the redistribution, if
 24  
  *    any, must include the following acknowlegement:
 25  
  *       "This product includes software developed by the
 26  
  *        Apache Software Foundation (http://www.apache.org/)."
 27  
  *    Alternately, this acknowlegement may appear in the software itself,
 28  
  *    if and wherever such third-party acknowlegements normally appear.
 29  
  *
 30  
  * 4. The names "Ant" and "Apache Software
 31  
  *    Foundation" must not be used to endorse or promote products derived
 32  
  *    from this software without prior written permission. For written
 33  
  *    permission, please contact apache@apache.org.
 34  
  *
 35  
  * 5. Products derived from this software may not be called "Apache"
 36  
  *    nor may "Apache" appear in their names without prior written
 37  
  *    permission of the Apache Group.
 38  
  *
 39  
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 40  
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 41  
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 42  
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 43  
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 44  
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 45  
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 46  
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 47  
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 48  
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 49  
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 50  
  * SUCH DAMAGE.
 51  
  * ====================================================================
 52  
  *
 53  
  * This software consists of voluntary contributions made by many
 54  
  * individuals on behalf of the Apache Software Foundation.  For more
 55  
  * information on the Apache Software Foundation, please see
 56  
  * <http://www.apache.org/>.
 57  
  */
 58  
 
 59  
 package net.sourceforge.cobertura.ant;
 60  
 
 61  
 import java.io.File;
 62  
 import java.io.IOException;
 63  
 
 64  
 import net.sourceforge.cobertura.util.CommandLineBuilder;
 65  
 
 66  
 import org.apache.tools.ant.BuildException;
 67  
 import org.apache.tools.ant.Project;
 68  
 
 69  
 /**
 70  
  * Generate a coverage report based on coverage data generated 
 71  
  * by instrumented classes.
 72  
  */
 73  
 public class ReportTask extends CommonMatchingTask
 74  
 {
 75  
 
 76  8
         private String dataFile = null;
 77  8
         private String format = "html";
 78  
         private File destDir;
 79  
         private String srcDir;
 80  
 
 81  
         public ReportTask() {
 82  8
                 super("net.sourceforge.cobertura.reporting.Main");
 83  8
         }
 84  
         
 85  
         public void execute() throws BuildException {
 86  8
                 CommandLineBuilder builder = null;
 87  
                 try {
 88  8
                         builder = new CommandLineBuilder();
 89  8
                         if (dataFile != null)
 90  8
                                 builder.addArg("--datafile", dataFile);
 91  8
                         if (destDir != null)
 92  8
                                 builder.addArg("--destination", destDir.getAbsolutePath());
 93  8
                         if (format != null)
 94  8
                                 builder.addArg("--format", format);
 95  8
                         if (srcDir != null)
 96  4
                                 builder.addArg(srcDir);
 97  
 
 98  8
                         createArgumentsForFilesets(builder);
 99  
 
 100  8
                         builder.saveArgs();
 101  0
                 } catch (IOException ioe) {
 102  0
                         getProject().log("Error creating commands file.", Project.MSG_ERR);
 103  0
                         throw new BuildException("Unable to create the commands file.", ioe);
 104  8
                 }
 105  
 
 106  
                 // Execute GPL licensed code in separate virtual machine
 107  8
                 getJava().createArg().setValue("--commandsfile");
 108  8
                 getJava().createArg().setValue(builder.getCommandLineFile());
 109  8
                 AntUtil.transferCoberturaDataFileProperty(getJava());
 110  8
                 if (getJava().executeJava() != 0) {
 111  0
                         throw new BuildException(
 112  
                                         "Error running reports. See messages above.");
 113  
                 }
 114  
 
 115  8
                 builder.dispose();
 116  8
         }
 117  
 
 118  
         public void setDataFile(String dataFile) {
 119  8
                 this.dataFile = dataFile;
 120  8
         }
 121  
 
 122  
         public void setDestDir(File destDir) {
 123  8
                 this.destDir = destDir;
 124  8
         }
 125  
 
 126  
         public void setFormat(String format) {
 127  4
                 this.format = format;
 128  4
         }
 129  
         
 130  
         public void setSrcDir(String dir) {
 131  4
                 srcDir = dir;
 132  4
         }
 133  
 }