Package org.jacoco.core.instr
Class Instrumenter
- java.lang.Object
-
- org.jacoco.core.instr.Instrumenter
-
public class Instrumenter extends java.lang.ObjectSeveral APIs to instrument Java class definitions for coverage tracing.
-
-
Field Summary
Fields Modifier and Type Field Description private IExecutionDataAccessorGeneratoraccessorGeneratorprivate SignatureRemoversignatureRemover
-
Constructor Summary
Constructors Constructor Description Instrumenter(IExecutionDataAccessorGenerator runtime)Creates a new instance based on the given runtime.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcopy(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)private static longcrc(byte[] data)private intfilterOrInstrument(java.io.InputStream in, java.io.OutputStream out, java.lang.String name, java.lang.String entryName)private byte[]instrument(byte[] source)byte[]instrument(byte[] buffer, java.lang.String name)Creates a instrumented version of the given class if possible.voidinstrument(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)Creates a instrumented version of the given class file.byte[]instrument(java.io.InputStream input, java.lang.String name)Creates a instrumented version of the given class if possible.intinstrumentAll(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)Creates a instrumented version of the given resource depending on its type.private java.io.IOExceptioninstrumentError(java.lang.String name, java.lang.Exception cause)private intinstrumentGzip(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)private intinstrumentPack200(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)private intinstrumentZip(java.io.InputStream input, java.io.OutputStream output, java.lang.String name)private java.util.zip.ZipEntrynextEntry(java.util.zip.ZipInputStream input, java.lang.String location)private intread(java.io.InputStream input, byte[] buffer, java.lang.String name)voidsetRemoveSignatures(boolean flag)Determines whether signatures should be removed from JAR files.
-
-
-
Field Detail
-
accessorGenerator
private final IExecutionDataAccessorGenerator accessorGenerator
-
signatureRemover
private final SignatureRemover signatureRemover
-
-
Constructor Detail
-
Instrumenter
public Instrumenter(IExecutionDataAccessorGenerator runtime)
Creates a new instance based on the given runtime.- Parameters:
runtime- runtime used by the instrumented classes
-
-
Method Detail
-
setRemoveSignatures
public void setRemoveSignatures(boolean flag)
Determines whether signatures should be removed from JAR files. This is typically necessary as instrumentation modifies the class files and therefore invalidates existing JAR signatures. Default istrue.- Parameters:
flag-trueif signatures should be removed
-
instrument
private byte[] instrument(byte[] source)
-
instrument
public byte[] instrument(byte[] buffer, java.lang.String name) throws java.io.IOExceptionCreates a instrumented version of the given class if possible.- Parameters:
buffer- definition of the classname- a name used for exception messages- Returns:
- instrumented definition
- Throws:
java.io.IOException- if the class can't be instrumented
-
instrument
public byte[] instrument(java.io.InputStream input, java.lang.String name) throws java.io.IOExceptionCreates a instrumented version of the given class if possible. The providedInputStreamis not closed by this method.- Parameters:
input- stream to read class definition fromname- a name used for exception messages- Returns:
- instrumented definition
- Throws:
java.io.IOException- if reading data from the stream fails or the class can't be instrumented
-
instrument
public void instrument(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOExceptionCreates a instrumented version of the given class file. The providedInputStreamandOutputStreaminstances are not closed by this method.- Parameters:
input- stream to read class definition fromoutput- stream to write the instrumented version of the class toname- a name used for exception messages- Throws:
java.io.IOException- if reading data from the stream fails or the class can't be instrumented
-
instrumentError
private java.io.IOException instrumentError(java.lang.String name, java.lang.Exception cause)
-
instrumentAll
public int instrumentAll(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOExceptionCreates a instrumented version of the given resource depending on its type. Class files and the content of archive files are instrumented. All other files are copied without modification. The providedInputStreamandOutputStreaminstances are not closed by this method.- Parameters:
input- stream to contents fromoutput- stream to write the instrumented version of the contentsname- a name used for exception messages- Returns:
- number of instrumented classes
- Throws:
java.io.IOException- if reading data from the stream fails or a class can't be instrumented
-
instrumentZip
private int instrumentZip(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
filterOrInstrument
private int filterOrInstrument(java.io.InputStream in, java.io.OutputStream out, java.lang.String name, java.lang.String entryName) throws java.io.IOException- Throws:
java.io.IOException
-
crc
private static long crc(byte[] data)
-
nextEntry
private java.util.zip.ZipEntry nextEntry(java.util.zip.ZipInputStream input, java.lang.String location) throws java.io.IOException- Throws:
java.io.IOException
-
instrumentGzip
private int instrumentGzip(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
instrumentPack200
private int instrumentPack200(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
copy
private void copy(java.io.InputStream input, java.io.OutputStream output, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
read
private int read(java.io.InputStream input, byte[] buffer, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
-