001/* 002 * The Apache Software License, Version 1.1 003 * 004 * Copyright (C) 2000-2002 The Apache Software Foundation. All rights 005 * reserved. 006 * Copyright (C) 2003 jcoverage ltd. 007 * Copyright (C) 2005 Mark Doliner 008 * Copyright (C) 2005 Jeremy Thomerson 009 * Copyright (C) 2005 Grzegorz Lukasik 010 * 011 * Redistribution and use in source and binary forms, with or without 012 * modification, are permitted provided that the following conditions 013 * are met: 014 * 015 * 1. Redistributions of source code must retain the above copyright 016 * notice, this list of conditions and the following disclaimer. 017 * 018 * 2. Redistributions in binary form must reproduce the above copyright 019 * notice, this list of conditions and the following disclaimer in 020 * the documentation and/or other materials provided with the 021 * distribution. 022 * 023 * 3. The end-user documentation included with the redistribution, if 024 * any, must include the following acknowlegement: 025 * "This product includes software developed by the 026 * Apache Software Foundation (http://www.apache.org/)." 027 * Alternately, this acknowlegement may appear in the software itself, 028 * if and wherever such third-party acknowlegements normally appear. 029 * 030 * 4. The names "Ant" and "Apache Software 031 * Foundation" must not be used to endorse or promote products derived 032 * from this software without prior written permission. For written 033 * permission, please contact apache@apache.org. 034 * 035 * 5. Products derived from this software may not be called "Apache" 036 * nor may "Apache" appear in their names without prior written 037 * permission of the Apache Group. 038 * 039 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 040 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 041 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 042 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 043 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 044 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 045 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 046 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 047 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 048 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 049 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 050 * SUCH DAMAGE. 051 * ==================================================================== 052 * 053 * This software consists of voluntary contributions made by many 054 * individuals on behalf of the Apache Software Foundation. For more 055 * information on the Apache Software Foundation, please see 056 * <http://www.apache.org/>. 057 */ 058 059package net.sourceforge.cobertura.ant; 060 061import java.io.File; 062import java.io.IOException; 063 064import net.sourceforge.cobertura.util.CommandLineBuilder; 065 066import org.apache.tools.ant.BuildException; 067import org.apache.tools.ant.Project; 068 069/** 070 * Generate a coverage report based on coverage data generated 071 * by instrumented classes. 072 */ 073public class ReportTask extends CommonMatchingTask 074{ 075 076 private String dataFile = null; 077 private String format = "html"; 078 private File destDir; 079 private String srcDir; 080 private String encoding; 081 082 public ReportTask() { 083 super("net.sourceforge.cobertura.reporting.Main"); 084 } 085 086 public void execute() throws BuildException { 087 CommandLineBuilder builder = null; 088 try { 089 builder = new CommandLineBuilder(); 090 if (dataFile != null) 091 builder.addArg("--datafile", dataFile); 092 if (destDir != null) 093 builder.addArg("--destination", destDir.getAbsolutePath()); 094 if (format != null) 095 builder.addArg("--format", format); 096 if (encoding != null) 097 builder.addArg("--encoding", encoding); 098 if (srcDir != null) 099 builder.addArg(srcDir); 100 createArgumentsForFilesets(builder); 101 102 builder.saveArgs(); 103 } catch (IOException ioe) { 104 getProject().log("Error creating commands file.", Project.MSG_ERR); 105 throw new BuildException("Unable to create the commands file.", ioe); 106 } 107 108 // Execute GPL licensed code in separate virtual machine 109 getJava().createArg().setValue("--commandsfile"); 110 getJava().createArg().setValue(builder.getCommandLineFile()); 111 AntUtil.transferCoberturaDataFileProperty(getJava()); 112 if (getJava().executeJava() != 0) { 113 throw new BuildException( 114 "Error running reports. See messages above."); 115 } 116 117 builder.dispose(); 118 } 119 120 public void setDataFile(String dataFile) { 121 this.dataFile = dataFile; 122 } 123 124 public void setDestDir(File destDir) { 125 this.destDir = destDir; 126 } 127 128 public void setFormat(String format) { 129 this.format = format; 130 } 131 132 public void setEncoding(String encoding) { 133 this.encoding = encoding; 134 } 135 136 public void setSrcDir(String dir) { 137 srcDir = dir; 138 } 139}