1 9 package com.vladium.emma; 10 11 import java.io.File ; 12 13 import com.vladium.util.IProperties; 14 import com.vladium.util.Strings; 15 import com.vladium.emma.ant.*; 16 import com.vladium.emma.instr.FilterCfg; 17 import com.vladium.emma.instr.FilterCfg.filterElement; 18 import com.vladium.emma.report.ReportCfg; 19 import com.vladium.emma.report.IReportEnums.DepthAttribute; 20 import com.vladium.emma.report.IReportEnums.UnitsTypeAttribute; 21 import com.vladium.emma.report.ReportCfg.Element_HTML; 22 import com.vladium.emma.report.ReportCfg.Element_TXT; 23 import com.vladium.emma.report.ReportCfg.Element_XML; 24 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.Project; 27 import org.apache.tools.ant.taskdefs.Java; 28 import org.apache.tools.ant.types.Commandline; 29 import org.apache.tools.ant.types.Path; 30 import org.apache.tools.ant.types.Reference; 31 32 36 public 37 class emmajavaTask extends Java 38 { 39 41 42 public void init () throws BuildException 43 { 44 super.init (); 45 46 m_verbosityCfg = new VerbosityCfg (); 47 m_genericCfg = new GenericCfg (this); 48 m_filterCfg = new FilterCfg (this); 49 m_reportCfg = new ReportCfg (project, this); 50 setEnabled (true); 51 } 52 53 54 public void execute () throws BuildException 55 { 56 log (IAppConstants.APP_VERBOSE_BUILD_ID, Project.MSG_VERBOSE); 57 58 if (getClasspath () == null) 59 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 60 + ": this task requires 'classpath' attribute to be set", location).fillInStackTrace (); 61 62 63 if (isEnabled ()) 64 { 65 if (m_forkUserOverride && ! m_fork) 67 log (getTaskName () + ": 'fork=\"false\"' attribute setting ignored (this task always forks)", Project.MSG_WARN); 68 69 super.setFork (true); 71 final Path libClasspath = m_libClasspath; 73 if ((libClasspath != null) && (libClasspath.size () > 0)) 74 { 75 super.createClasspath ().append (libClasspath); 76 } 77 78 super.setClassname ("emmarun"); 80 81 { 83 { 85 String reportTypes = Strings.toListForm (m_reportCfg.getReportTypes (), ','); 86 if ((reportTypes == null) || (reportTypes.length () == 0)) reportTypes = "txt"; 87 88 super.createArg ().setValue ("-r"); 89 super.createArg ().setValue (reportTypes); 90 } 91 92 { 94 if (m_scanCoveragePath) 95 { 96 super.createArg ().setValue ("-f"); 97 } 98 } 99 100 { 102 if (m_dumpSessionData) 103 { 104 super.createArg ().setValue ("-raw"); 105 106 if (m_outFile != null) 107 { 108 super.createArg ().setValue ("-out"); 109 super.createArg ().setValue (m_outFile.getAbsolutePath ()); 110 } 111 112 if (m_outFileMerge != null) 113 { 114 super.createArg ().setValue ("-merge"); 115 super.createArg ().setValue (m_outFileMerge.booleanValue () ? "y" : "n"); 116 } 117 } 118 else 119 { 120 if (m_outFile != null) 121 log (getTaskName () + ": output file attribute ignored ('fullmetadata=\"true\"' not specified)", Project.MSG_WARN); 122 123 if (m_outFileMerge != null) 124 log (getTaskName () + ": merge attribute setting ignored ('fullmetadata=\"true\"' not specified)", Project.MSG_WARN); 125 } 126 } 127 128 { 130 final String [] specs = m_filterCfg.getFilterSpecs (); 131 if ((specs != null) && (specs.length > 0)) 132 { 133 super.createArg ().setValue ("-ix"); 134 super.createArg ().setValue (Strings.toListForm (specs, ',')); 135 } 136 } 137 138 { 140 final Path srcpath = m_reportCfg.getSourcepath (); 141 if (srcpath != null) 142 { 143 super.createArg ().setValue ("-sp"); 144 super.createArg ().setValue (Strings.toListForm (srcpath.list (), ',')); 145 } 146 } 147 148 { 150 final IProperties reportSettings = m_reportCfg.getReportSettings (); 151 final IProperties genericSettings = m_genericCfg.getGenericSettings (); 152 153 final IProperties fileSettings = m_genericCfg.getFileSettings (); 156 157 final IProperties verbositySettings = m_verbosityCfg.getSettings (); 160 161 final IProperties settings = IProperties.Factory.combine (reportSettings, 166 IProperties.Factory.combine (verbositySettings, 167 IProperties.Factory.combine (genericSettings, 168 fileSettings))); 169 170 final String [] argForm = settings.toAppArgsForm ("-D"); 171 if (argForm.length > 0) 172 { 173 for (int a = 0; a < argForm.length; ++ a) 174 super.createArg ().setValue (argForm [a]); 175 } 176 } 177 } 178 179 181 super.createArg ().setValue ("-cp"); 183 super.createArg ().setPath (getClasspath ()); 184 185 if (getClassname () != null) 187 super.createArg ().setValue (getClassname ()); 188 else if (getJar () != null) 189 { 190 super.createArg ().setValue ("-jar"); 191 super.createArg ().setValue (getJar ().getAbsolutePath ()); 192 } 193 else 194 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 195 + "either 'jar' or 'classname' attribute must be set", location).fillInStackTrace (); 196 197 if (m_appArgs != null) 199 { 200 final String [] args = m_appArgs.getArguments (); 201 for (int a = 0; a < args.length; ++ a) 202 { 203 super.createArg ().setValue (args [a]); } 205 } 206 } 207 else 208 { 209 super.setFork (m_fork); 211 212 214 super.createClasspath ().append (getClasspath ()); 217 if (getClassname () != null) 219 super.setClassname (getClassname ()); 220 else if (getJar () != null) 221 super.setJar (getJar ()); 222 else 223 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 224 + "either 'jar' or 'classname' attribute must be set", location).fillInStackTrace (); 225 226 if (m_appArgs != null) 228 { 229 final String [] args = m_appArgs.getArguments (); 230 for (int a = 0; a < args.length; ++ a) 231 { 232 super.createArg ().setValue (args [a]); } 234 } 235 } 236 237 super.execute (); 238 } 239 240 241 242 244 public void setClassname (final String classname) 245 { 246 if (getJar () != null) 247 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 248 + "'jar' and 'classname' attributes cannot be set at the same time", location).fillInStackTrace (); 249 250 m_classname = classname; 251 } 252 253 public void setJar (final File file) 254 { 255 if (getClassname () != null) 256 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 257 + "'jar' and 'classname' attributes cannot be set at the same time", location).fillInStackTrace (); 258 259 m_jar = file; 260 } 261 262 263 public void setClasspath (final Path path) 264 { 265 if (m_classpath == null) 266 m_classpath = path; 267 else 268 m_classpath.append (path); 269 } 270 271 public void setClasspathRef (final Reference ref) 272 { 273 createClasspath ().setRefid (ref); 274 } 275 276 public Path createClasspath () 277 { 278 if (m_classpath == null) 279 m_classpath = new Path (project); 280 281 return m_classpath.createPath (); 282 } 283 284 288 public void setArgs (final String args) 289 { 290 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 291 + ": disallows using <java>'s deprecated 'args' attribute", location).fillInStackTrace (); 292 } 293 294 297 public final void setFork (final boolean fork) 298 { 299 m_fork = fork; 300 m_forkUserOverride = true; 301 } 302 303 306 public final Commandline.Argument createArg () 307 { 308 if (m_appArgs == null) 309 m_appArgs = new Commandline (); 310 311 return m_appArgs.createArgument (); 312 } 313 314 316 318 319 321 public void setEnabled (final boolean enabled) 322 { 323 m_enabled = enabled; 324 } 325 326 328 public final void setProperties (final File file) 329 { 330 m_genericCfg.setProperties (file); 331 } 332 333 335 public final PropertyElement createProperty () 336 { 337 return m_genericCfg.createProperty (); 338 } 339 340 342 public void setVerbosity (final VerbosityCfg.VerbosityAttribute verbosity) 343 { 344 m_verbosityCfg.setVerbosity (verbosity); 345 } 346 347 349 public void setVerbosityfilter (final String filter) 350 { 351 m_verbosityCfg.setVerbosityfilter (filter); 352 } 353 354 356 public final void setLibclasspath (final Path classpath) 357 { 358 if (m_libClasspath == null) 359 m_libClasspath = classpath; 360 else 361 m_libClasspath.append (classpath); 362 } 363 364 public final void setLibclasspathRef (final Reference ref) 365 { 366 if (m_libClasspath == null) 367 m_libClasspath = new Path (project); 368 369 m_libClasspath.createPath ().setRefid (ref); 370 } 371 372 374 public void setFullmetadata (final boolean full) 375 { 376 m_scanCoveragePath = full; } 378 379 381 public void setDumpsessiondata (final boolean dump) 382 { 383 m_dumpSessionData = dump; 384 } 385 386 388 390 public void setSessiondatafile (final File file) 391 { 392 if (m_outFile != null) 393 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 394 + ": session data file attribute already set", location).fillInStackTrace (); 395 396 m_outFile = file; 397 } 398 399 public void setOutfile (final File file) 400 { 401 if (m_outFile != null) 402 throw (BuildException) SuppressableTask.newBuildException (getTaskName () 403 + ": session data file attribute already set", location).fillInStackTrace (); 404 405 m_outFile = file; 406 } 407 408 426 427 429 public void setMerge (final boolean merge) 430 { 431 m_outFileMerge = merge ? Boolean.TRUE : Boolean.FALSE; 432 } 433 434 436 public final void setFilter (final String filter) 437 { 438 m_filterCfg.setFilter (filter); 439 } 440 441 public final filterElement createFilter () 442 { 443 return m_filterCfg.createFilter (); 444 } 445 446 447 449 451 public final void setSourcepath (final Path path) 452 { 453 m_reportCfg.setSourcepath (path); 454 } 455 456 public final void setSourcepathRef (final Reference ref) 457 { 458 m_reportCfg.setSourcepathRef (ref); 459 } 460 461 public final Path createSourcepath () 462 { 463 return m_reportCfg.createSourcepath (); 464 } 465 466 467 469 public final Element_TXT createTxt () 470 { 471 return m_reportCfg.createTxt (); 472 } 473 474 public final Element_HTML createHtml () 475 { 476 return m_reportCfg.createHtml (); 477 } 478 479 public final Element_XML createXml () 480 { 481 return m_reportCfg.createXml (); 482 } 483 484 485 487 public final void setUnits (final UnitsTypeAttribute units) 488 { 489 m_reportCfg.setUnits (units); 490 } 491 492 public final void setDepth (final DepthAttribute depth) 493 { 494 m_reportCfg.setDepth (depth); 495 } 496 497 public final void setColumns (final String columns) 498 { 499 m_reportCfg.setColumns (columns); 500 } 501 502 public final void setSort (final String sort) 503 { 504 m_reportCfg.setSort (sort); 505 } 506 507 public final void setMetrics (final String metrics) 508 { 509 m_reportCfg.setMetrics (metrics); 510 } 511 512 514 524 526 531 public void setEncoding (final String encoding) 532 { 533 m_reportCfg.setEncoding (encoding); 534 } 535 536 538 539 protected String getClassname () 540 { 541 return m_classname; 542 } 543 544 protected File getJar () 545 { 546 return m_jar; 547 } 548 549 protected Path getClasspath () 550 { 551 return m_classpath; 552 } 553 554 556 protected boolean isEnabled () 557 { 558 return m_enabled; 559 } 560 561 563 565 567 private Path m_classpath; 568 private String m_classname; 569 private File m_jar; 570 private Commandline m_appArgs; 571 private boolean m_fork, m_forkUserOverride; 572 573 575 private boolean m_enabled; 576 private Path m_libClasspath; 577 private VerbosityCfg m_verbosityCfg; 578 private GenericCfg m_genericCfg; 579 private FilterCfg m_filterCfg; 580 private ReportCfg m_reportCfg; 581 private boolean m_scanCoveragePath; private boolean m_dumpSessionData; private File m_outFile; 584 private Boolean m_outFileMerge; 585 586 } | Popular Tags |