net.sourceforge.cobertura.instrument

Class Main


public class Main
extends java.lang.Object

Add coverage instrumentation to existing classes.

What does that mean, exactly?

It means Cobertura will look at each class you give it. It loads the bytecode into memory. For each line of source, Cobertura adds a few extra instructions. These instructions do the following:

  1. Get an instance of the ProjectData class.
  2. Call a method in this ProjectData class that increments a counter for this line of code.

After every line in a class has been "instrumented," Cobertura edits the bytecode for the class one more time and adds "implements net.sourceforge.cobertura.coveragedata.HasBeenInstrumented" This is basically just a flag used internally by Cobertura to determine whether a class has been instrumented or not, so as not to instrument the same class twice.

Field Summary

private ClassPattern
classPattern
private File
destinationDirectory
private Collection
ignoreRegexes
private static Logger
logger
private ProjectData
projectData

Method Summary

private void
addInstrumentation(CoberturaFile coberturaFile)
private void
addInstrumentationToArchive(Archive archive)
private void
addInstrumentationToArchive(CoberturaFile archive)
private boolean
addInstrumentationToArchive(CoberturaFile file, InputStream archive, OutputStream output)
private boolean
addInstrumentationToArchive(CoberturaFile file, ZipInputStream archive, ZipOutputStream output)
private void
addInstrumentationToSingleClass(File file)
private static boolean
isClass(ZipEntry entry)
static void
main(String[] args)
private void
parseArguments(String[] args)

Field Details

classPattern

private ClassPattern classPattern

destinationDirectory

private File destinationDirectory

ignoreRegexes

private Collection ignoreRegexes

logger

private static final Logger logger

projectData

private ProjectData projectData

Method Details

addInstrumentation

private void addInstrumentation(CoberturaFile coberturaFile)

addInstrumentationToArchive

private void addInstrumentationToArchive(Archive archive)
            throws Exception

addInstrumentationToArchive

private void addInstrumentationToArchive(CoberturaFile archive)

addInstrumentationToArchive

private boolean addInstrumentationToArchive(CoberturaFile file,
                                            InputStream archive,
                                            OutputStream output)
            throws Exception

addInstrumentationToArchive

private boolean addInstrumentationToArchive(CoberturaFile file,
                                            ZipInputStream archive,
                                            ZipOutputStream output)
            throws Exception

addInstrumentationToSingleClass

private void addInstrumentationToSingleClass(File file)

isClass

private static boolean isClass(ZipEntry entry)
Parameters:
entry - A zip entry.
Returns:
True if the specified entry has "class" as its extension, false otherwise.

main

public static void main(String[] args)

parseArguments

private void parseArguments(String[] args)