| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| BuildStatMoverTask |
|
| 1.7619047619047619;1.762 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // | |
| 3 | // ObjectLab is sponsoring QALab | |
| 4 | // | |
| 5 | // Based in London, we are world leaders in the design and development | |
| 6 | // of bespoke applications for the Securities Financing markets. | |
| 7 | // | |
| 8 | // <a href="http://www.objectlab.co.uk/open">Click here to learn more</a> | |
| 9 | // ___ _ _ _ _ _ | |
| 10 | // / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 11 | // | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 12 | // | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 13 | // \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 14 | // |__/ | |
| 15 | // | |
| 16 | // http://www.ObjectLab.co.uk | |
| 17 | // --------------------------------------------------------------------------- | |
| 18 | // | |
| 19 | //QALab is released under the GNU General Public License. | |
| 20 | // | |
| 21 | //QALab: Collects QA Statistics from your build over time. | |
| 22 | //2005+, ObjectLab Ltd | |
| 23 | // | |
| 24 | //This library is free software; you can redistribute it and/or | |
| 25 | //modify it under the terms of the GNU General Public | |
| 26 | //License as published by the Free Software Foundation; either | |
| 27 | //version 2.1 of the License, or (at your option) any later version. | |
| 28 | // | |
| 29 | //This library is distributed in the hope that it will be useful, | |
| 30 | //but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 31 | //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 32 | //General Public License for more details. | |
| 33 | // | |
| 34 | //You should have received a copy of the GNU General Public | |
| 35 | //License along with this library; if not, write to the Free Software | |
| 36 | //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 37 | // | |
| 38 | //////////////////////////////////////////////////////////////////////////////// | |
| 39 | package net.objectlab.qalab.ant; | |
| 40 | ||
| 41 | import net.objectlab.qalab.parser.BuildStatMoverHandler; | |
| 42 | import net.objectlab.qalab.util.QALabTags; | |
| 43 | import net.objectlab.qalab.util.TaskLogger; | |
| 44 | ||
| 45 | import org.apache.tools.ant.BuildException; | |
| 46 | import org.apache.tools.ant.Task; | |
| 47 | import org.xml.sax.InputSource; | |
| 48 | import org.xml.sax.SAXException; | |
| 49 | ||
| 50 | import javax.xml.parsers.ParserConfigurationException; | |
| 51 | ||
| 52 | import java.io.File; | |
| 53 | import java.io.FileReader; | |
| 54 | import java.io.FileWriter; | |
| 55 | import java.io.IOException; | |
| 56 | ||
| 57 | import java.text.ParseException; | |
| 58 | ||
| 59 | /** | |
| 60 | * An Ant task to create the mover XML file given some parameters. | |
| 61 | * | |
| 62 | * @author Paramjit Rehinsi | |
| 63 | * @version $Revision: 187 $ | |
| 64 | */ | |
| 65 | 0 | public class BuildStatMoverTask extends Task implements TaskLogger { |
| 66 | /** size of the string based on ISO 8601 date format. */ | |
| 67 | private static final int MIN_DATE_SIZE = 18; | |
| 68 | ||
| 69 | /** | |
| 70 | * the inputFile, typically qalab.xml. | |
| 71 | */ | |
| 72 | 0 | private File inputFile = null; |
| 73 | ||
| 74 | /** | |
| 75 | * number of hours to define the time window from now. | |
| 76 | */ | |
| 77 | private String startTimeHoursOffset; | |
| 78 | ||
| 79 | /** | |
| 80 | * Statistic types to be taken into account | |
| 81 | * (checkstyle|findbugs|pms|simian). Or comma separated combinations. | |
| 82 | */ | |
| 83 | private String types; | |
| 84 | ||
| 85 | /** | |
| 86 | * The output XML file with ups and downs. | |
| 87 | */ | |
| 88 | private File outputXMLfile; | |
| 89 | ||
| 90 | /** | |
| 91 | * if true, no output log. | |
| 92 | */ | |
| 93 | 0 | private boolean quiet = false; |
| 94 | ||
| 95 | /** | |
| 96 | * if true, adjust for weekend ie add 48h if start time falls on a weekend. | |
| 97 | */ | |
| 98 | 0 | private boolean weekendAdjustment = false; |
| 99 | ||
| 100 | /** | |
| 101 | * Start Time Window (instead of using startTimeHoursOffset). | |
| 102 | */ | |
| 103 | 0 | private String startTimeWindow = null; |
| 104 | ||
| 105 | /** | |
| 106 | * End Time Window (instead of assuming "now"). | |
| 107 | */ | |
| 108 | 0 | private String endTimeWindow = null; |
| 109 | ||
| 110 | /** | |
| 111 | * offset in hours to determine if the stat has fallen to 0 over the last n | |
| 112 | * hours from the endDateCutoff. | |
| 113 | */ | |
| 114 | 0 | private Integer hoursOffsetForLastRun = null; |
| 115 | ||
| 116 | /** | |
| 117 | * @return true if no log enabled. | |
| 118 | */ | |
| 119 | public final boolean isQuiet() { | |
| 120 | 0 | return quiet; |
| 121 | } | |
| 122 | ||
| 123 | /** | |
| 124 | * @param noLog | |
| 125 | * true and the system will not output debug info. | |
| 126 | */ | |
| 127 | public final void setQuiet(final boolean noLog) { | |
| 128 | 0 | this.quiet = noLog; |
| 129 | 0 | } |
| 130 | ||
| 131 | /** | |
| 132 | * Method invoked by the ant framework to execute the compilation of | |
| 133 | * statistics movers withing the time window. | |
| 134 | */ | |
| 135 | public final void execute() { | |
| 136 | 0 | validate(); |
| 137 | ||
| 138 | 0 | if (!quiet) { |
| 139 | 0 | log("inputFile='" + inputFile.getPath() + "', type='" + getTypes() + "'" + " output='" + getOutputXMLfile().getPath() |
| 140 | + "' adjustForWeekend='" + isWeekendAdjustment() + "'" + " startTimeOffset='" + getStartTimeHoursOffset() | |
| 141 | + "'" + " startTimeWindow='" + getStartTimeWindow() + "'" + " endTimeWindow='" + getEndTimeWindow() + "'"); | |
| 142 | } | |
| 143 | ||
| 144 | try { | |
| 145 | 0 | final BuildStatMoverHandler handler = new BuildStatMoverHandler(new InputSource(new FileReader(getInputFile())), |
| 146 | getTypes(), new FileWriter(getOutputXMLfile()), isWeekendAdjustment(), this, quiet); | |
| 147 | ||
| 148 | 0 | if (startTimeWindow != null) { |
| 149 | 0 | handler.setStartTimeWindow(QALabTags.DEFAULT_DATETIME_FORMAT.parse(startTimeWindow)); |
| 150 | } | |
| 151 | ||
| 152 | 0 | if (endTimeWindow != null) { |
| 153 | 0 | handler.setEndTimeWindow(QALabTags.DEFAULT_DATETIME_FORMAT.parse(endTimeWindow)); |
| 154 | } | |
| 155 | ||
| 156 | 0 | if (getStartTimeHoursOffset() != null) { |
| 157 | 0 | handler.setOffsetHours(getStartTimeHoursOffset()); |
| 158 | } | |
| 159 | ||
| 160 | 0 | if (getHoursOffsetForLastRun() != null) { |
| 161 | 0 | handler.setHoursOffsetForLastRun(hoursOffsetForLastRun.intValue()); |
| 162 | } | |
| 163 | ||
| 164 | 0 | handler.process(); |
| 165 | 0 | } catch (ParserConfigurationException e) { |
| 166 | 0 | log(e.toString()); |
| 167 | 0 | } catch (SAXException e) { |
| 168 | 0 | log(e.toString()); |
| 169 | 0 | } catch (IOException e) { |
| 170 | 0 | log(e.toString()); |
| 171 | 0 | } catch (ParseException e) { |
| 172 | 0 | throw new BuildException("Date Parse issue", e); |
| 173 | 0 | } |
| 174 | 0 | } |
| 175 | ||
| 176 | /** | |
| 177 | * Do some basic parameter validation. | |
| 178 | */ | |
| 179 | private void validate() { | |
| 180 | 0 | if (inputFile == null) { |
| 181 | 0 | throw new BuildException("inputFile is mandatory"); |
| 182 | } | |
| 183 | ||
| 184 | 0 | if ((startTimeHoursOffset != null) && (startTimeWindow != null)) { |
| 185 | 0 | throw new BuildException("use startTimeHoursOffset OR " + "startTimeWindow, not both."); |
| 186 | } | |
| 187 | 0 | } |
| 188 | ||
| 189 | /** | |
| 190 | * uses the super log from the conventional Ant Task log. | |
| 191 | * | |
| 192 | * @param text | |
| 193 | * the text to log | |
| 194 | */ | |
| 195 | public final void log(final String text) { | |
| 196 | 0 | super.log(text); |
| 197 | 0 | } |
| 198 | ||
| 199 | /** | |
| 200 | * @return Return the offset time in hours. | |
| 201 | */ | |
| 202 | public final String getStartTimeHoursOffset() { | |
| 203 | 0 | return startTimeHoursOffset; |
| 204 | } | |
| 205 | ||
| 206 | /** | |
| 207 | * Set the offset time in hours to define start window. | |
| 208 | * | |
| 209 | * @param hours | |
| 210 | * offset in hours | |
| 211 | */ | |
| 212 | public final void setStartTimeHoursOffset(final String hours) { | |
| 213 | 0 | startTimeHoursOffset = hours; |
| 214 | 0 | } |
| 215 | ||
| 216 | /** | |
| 217 | * @return Return List of types handled (checkstyle|findbugs|pmd|simian). | |
| 218 | */ | |
| 219 | public final String getTypes() { | |
| 220 | 0 | return types; |
| 221 | } | |
| 222 | ||
| 223 | /** | |
| 224 | * Sets the types on which the report is based, checkstyle|findbugs|pmd | |
| 225 | * |simian can be combined in a comma separated format. | |
| 226 | * | |
| 227 | * @param type | |
| 228 | * single or multiple types. | |
| 229 | */ | |
| 230 | public final void setTypes(final String type) { | |
| 231 | 0 | this.types = type; |
| 232 | 0 | } |
| 233 | ||
| 234 | /** | |
| 235 | * @return Return the destination XML file for the up/down stats. | |
| 236 | */ | |
| 237 | public final File getOutputXMLfile() { | |
| 238 | 0 | return outputXMLfile; |
| 239 | } | |
| 240 | ||
| 241 | /** | |
| 242 | * Set the destination XML file for the up/down stats. | |
| 243 | * | |
| 244 | * @param outputFile | |
| 245 | * XML destination file. | |
| 246 | */ | |
| 247 | public final void setOutputXMLfile(final File outputFile) { | |
| 248 | 0 | outputXMLfile = outputFile; |
| 249 | 0 | } |
| 250 | ||
| 251 | /** | |
| 252 | * @return the input base file xml document, typically qalab.xml. | |
| 253 | */ | |
| 254 | public final File getInputFile() { | |
| 255 | 0 | return inputFile; |
| 256 | } | |
| 257 | ||
| 258 | /** | |
| 259 | * Set the base file xml document, typically qalab.xml. | |
| 260 | * | |
| 261 | * @param inputXML | |
| 262 | * the qalab.xml. | |
| 263 | */ | |
| 264 | public final void setInputFile(final File inputXML) { | |
| 265 | 0 | inputFile = inputXML; |
| 266 | 0 | } |
| 267 | ||
| 268 | /** | |
| 269 | * @param wkendadj | |
| 270 | * true will deduce a further 48 hours to the start window in | |
| 271 | * order to take into account weekend if the start window fell on | |
| 272 | * a Saturday or Sunday. | |
| 273 | */ | |
| 274 | public final void setWeekendAdjustment(final boolean wkendadj) { | |
| 275 | 0 | weekendAdjustment = wkendadj; |
| 276 | 0 | } |
| 277 | ||
| 278 | /** | |
| 279 | * @return true if system is supposed to adjust for weekend. | |
| 280 | */ | |
| 281 | public final boolean isWeekendAdjustment() { | |
| 282 | 0 | return weekendAdjustment; |
| 283 | } | |
| 284 | ||
| 285 | /** | |
| 286 | * @param endTime | |
| 287 | * The endTimeWindow to set. | |
| 288 | */ | |
| 289 | public final void setEndTimeWindow(final String endTime) { | |
| 290 | 0 | this.endTimeWindow = endTime.trim(); |
| 291 | ||
| 292 | 0 | if (endTimeWindow.length() < MIN_DATE_SIZE) { |
| 293 | 0 | endTimeWindow += " 00:00:00"; |
| 294 | } | |
| 295 | 0 | } |
| 296 | ||
| 297 | /** | |
| 298 | * @return Returns the endTimeWindow. | |
| 299 | */ | |
| 300 | public final String getEndTimeWindow() { | |
| 301 | 0 | return endTimeWindow; |
| 302 | } | |
| 303 | ||
| 304 | /** | |
| 305 | * @param startTime | |
| 306 | * The startTimeWindow to set. | |
| 307 | */ | |
| 308 | public final void setStartTimeWindow(final String startTime) { | |
| 309 | 0 | this.startTimeWindow = startTime.trim(); |
| 310 | ||
| 311 | 0 | if (startTimeWindow.length() < MIN_DATE_SIZE) { |
| 312 | 0 | startTimeWindow += " 00:00:00"; |
| 313 | } | |
| 314 | 0 | } |
| 315 | ||
| 316 | /** | |
| 317 | * @return Returns the startTimeWindow. | |
| 318 | */ | |
| 319 | public final String getStartTimeWindow() { | |
| 320 | 0 | return startTimeWindow; |
| 321 | } | |
| 322 | ||
| 323 | public Integer getHoursOffsetForLastRun() { | |
| 324 | 0 | return hoursOffsetForLastRun; |
| 325 | } | |
| 326 | ||
| 327 | public void setHoursOffsetForLastRun(Integer hoursOffsetForLastRun) { | |
| 328 | 0 | this.hoursOffsetForLastRun = hoursOffsetForLastRun; |
| 329 | 0 | } |
| 330 | } | |
| 331 | /* | |
| 332 | * ObjectLab is sponsoring QALab | |
| 333 | * | |
| 334 | * Based in London, we are world leaders in the design and development | |
| 335 | * of bespoke applications for the securities financing markets. | |
| 336 | * | |
| 337 | * <a href="http://www.objectlab.co.uk/open">Click here to learn more about us</a> | |
| 338 | * ___ _ _ _ _ _ | |
| 339 | * / _ \| |__ (_) ___ ___| |_| | __ _| |__ | |
| 340 | * | | | | '_ \| |/ _ \/ __| __| | / _` | '_ \ | |
| 341 | * | |_| | |_) | | __/ (__| |_| |__| (_| | |_) | | |
| 342 | * \___/|_.__// |\___|\___|\__|_____\__,_|_.__/ | |
| 343 | * |__/ | |
| 344 | * | |
| 345 | * www.ObjectLab.co.uk | |
| 346 | */ |