1/* Copyright (C) 2003 Vladimir Roubtsov. All rights reserved. 2 * 3 * This program and the accompanying materials are made available under 4 * the terms of the Common Public License v1.0 which accompanies this distribution, 5 * and is available at http://www.eclipse.org/legal/cpl-v10.html 6 * 7 * $Id: reportTask.java,v 1.1.1.1.2.1 2004/07/08 10:52:11 vlad_r Exp $ 8 */ 9package com.vladium.emma.report; 10 11import org.apache.tools.ant.BuildException; 12import org.apache.tools.ant.types.Path; 13import org.apache.tools.ant.types.Reference; 14 15import com.vladium.util.IProperties; 16import com.vladium.emma.ant.FileTask; 17import com.vladium.emma.ant.SuppressableTask; 18import com.vladium.emma.report.ReportCfg.Element_HTML; 19import com.vladium.emma.report.ReportCfg.Element_LCOV; 20import com.vladium.emma.report.ReportCfg.Element_TXT; 21import com.vladium.emma.report.ReportCfg.Element_XML; 22 23// ---------------------------------------------------------------------------- 24/** 25 * @author Vlad Roubtsov, (C) 2003 26 */ 27public 28final class reportTask extends FileTask implements IReportProperties, IReportEnums 29{ 30 public reportTask (final SuppressableTask parent) 31 { 32 super (parent); 33 } 34 35 public void init () throws BuildException 36 { 37 super.init (); 38 39 m_reportCfg = new ReportCfg (getProject (), this); 40 } 41 42 43 public void execute () throws BuildException 44 { 45 if (isEnabled ()) 46 { 47 final String [] reportTypes = m_reportCfg.getReportTypes (); 48 49 if ((reportTypes == null) || (reportTypes.length == 0)) // no "txt" default for report processor 50 throw (BuildException) newBuildException (getTaskName () 51 + ": no report types specified: provide at least one of <txt>, <html>, <lcov>, <xml> nested elements", location).fillInStackTrace (); 52 53 String [] files = getDataPath (true); 54 if ((files == null) || (files.length == 0)) 55 throw (BuildException) newBuildException (getTaskName () 56 + ": no valid input data files have been specified", location).fillInStackTrace (); 57 58 final Path srcpath = m_reportCfg.getSourcepath (); 59 60 // combine report and all generic settings: 61 final IProperties settings; 62 { 63 final IProperties taskSettings = getTaskSettings (); 64 final IProperties reportSettings = m_reportCfg.getReportSettings (); 65 66 // named report settings override generic named settings and file 67 // settings have lower priority than any explicitly named overrides: 68 settings = IProperties.Factory.combine (reportSettings, taskSettings); 69 } 70 71 final ReportProcessor processor = ReportProcessor.create (); 72 73 processor.setDataPath (files); files = null; 74 processor.setSourcePath (srcpath != null ? srcpath.list () : null); 75 processor.setReportTypes (reportTypes); 76 processor.setPropertyOverrides (settings); 77 78 processor.run (); 79 } 80 } 81 82 83 // sourcepath attribute/element: 84 85 public void setSourcepath (final Path path) 86 { 87 m_reportCfg.setSourcepath (path); 88 } 89 90 public void setSourcepathRef (final Reference ref) 91 { 92 m_reportCfg.setSourcepathRef (ref); 93 } 94 95 public Path createSourcepath () 96 { 97 return m_reportCfg.createSourcepath (); 98 } 99 100 101 // generator elements: 102 103 public Element_TXT createTxt () 104 { 105 return m_reportCfg.createTxt (); 106 } 107 108 public Element_LCOV createLcov () 109 { 110 return m_reportCfg.createLcov (); 111 } 112 113 public Element_HTML createHtml () 114 { 115 return m_reportCfg.createHtml (); 116 } 117 118 public Element_XML createXml () 119 { 120 return m_reportCfg.createXml (); 121 } 122 123 124 // report properties [defaults for all report types]: 125 126 public void setUnits (final UnitsTypeAttribute units) 127 { 128 m_reportCfg.setUnits (units); 129 } 130 131 public void setDepth (final DepthAttribute depth) 132 { 133 m_reportCfg.setDepth (depth); 134 } 135 136 public void setColumns (final String columns) 137 { 138 m_reportCfg.setColumns (columns); 139 } 140 141 public void setSort (final String sort) 142 { 143 m_reportCfg.setSort (sort); 144 } 145 146 public void setMetrics (final String metrics) 147 { 148 m_reportCfg.setMetrics (metrics); 149 } 150 151 // not supported anymore: 152 153// public void setOutdir (final File dir) 154// { 155// m_reportCfg.setOutdir (dir); 156// } 157// 158// public void setDestdir (final File dir) 159// { 160// m_reportCfg.setDestdir (dir); 161// } 162 163 // should not be set at the global level: 164 165// public void setOutfile (final String fileName) 166// { 167// m_reportCfg.setOutfile (fileName); 168// } 169 170 public void setEncoding (final String encoding) 171 { 172 m_reportCfg.setEncoding (encoding); 173 } 174 175 // protected: ............................................................. 176 177 // package: ............................................................... 178 179 // private: ............................................................... 180 181 182 private ReportCfg m_reportCfg; 183 184} // end of class 185// ---------------------------------------------------------------------------- 186