Example 2

Run Emma instrumentation of the classes in bin (compiled from source files in src) and put the instrumented classes in bin_instr and the metadata file in the temporary files directory tmpDir. Run two programs that are analyzed for code coverage. Merge the data from the two runs and generate a text report. Note: merging data files is perhaps most useful for hundreds of data files. In this example, the two data files could as well have been fed directly into the report task.

JavaScript

enableTaskPackage("com.vladium.emma"); // Instrument the class files new EmmaInstrumentationTF(). addClasspathEntry(bin). setMetadataFile(new FutureFile(tmpDir, "coverage.em")). addSource(bin). setTarget(bin_instr).run(); // The first program that is analyzed for coverage. This could for instance be a // unit test run. Use the EmmaExternalJavaTaskDecorator to enable Emma coverage // analysis. new JavaTF(). addDecorator( new EmmaExternalJavaTaskDecorator(). setRtControl(false). setCoverageOutFile(new FutureFile(tmpDir, "coverage1.ec")). setCoverageMerge(false). setVerbosityLevel(EmmaVerbosityLevel.QUIET)). addClasspathEntry(bin_instr). // This is the main class of the first program to run. setClassToRun("Test1"). run(); // The second program new JavaTF(). addDecorator( new EmmaExternalJavaTaskDecorator(). setRtControl(false). setCoverageOutFile(new FutureFile(tmpDir, "coverage2.ec")). setCoverageMerge(false). setVerbosityLevel(EmmaVerbosityLevel.QUIET)). addClasspathEntry(bin_instr). // This is the main class of the second program to run. setClassToRun("pkg.Test2"). run(); // Merge coverage data new EmmaMergeTF(). addMetadataFile(Directories.getFile(tmpDir, "coverage.em")). addCoverageDataFiles(Directories.getAllFilesMatching(tmpDir, "*.ec")). setTarget(new FutureFile(tmpDir, "coverage.es")).run(); // Create a text report from the analysis results new EmmaReportTF(). addSource(Directories.getFile(tmpDir, "coverage.es")). addOutputFile(EmmaReportFormat.TEXT, new FutureFile(tmpDir, "emma.txt")). addSourceDirectory(src).run();


* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.