Class Instrumenter
java.lang.Object
org.jacoco.core.instr.Instrumenter
Several APIs to instrument Java class definitions for coverage tracing.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final IExecutionDataAccessorGeneratorprivate final SignatureRemover -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance based on the given runtime. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcopy(InputStream input, OutputStream output, String name) private static longcrc(byte[] data) private intfilterOrInstrument(InputStream in, OutputStream out, String name, String entryName) private byte[]instrument(byte[] source) byte[]instrument(byte[] buffer, String name) Creates a instrumented version of the given class if possible.voidinstrument(InputStream input, OutputStream output, String name) Creates a instrumented version of the given class file.byte[]instrument(InputStream input, String name) Creates a instrumented version of the given class if possible.intinstrumentAll(InputStream input, OutputStream output, String name) Creates a instrumented version of the given resource depending on its type.private IOExceptioninstrumentError(String name, Exception cause) private intinstrumentGzip(InputStream input, OutputStream output, String name) private intinstrumentPack200(InputStream input, OutputStream output, String name) private intinstrumentZip(InputStream input, OutputStream output, String name) private ZipEntrynextEntry(ZipInputStream input, String location) private intread(InputStream input, byte[] buffer, String name) voidsetRemoveSignatures(boolean flag) Determines whether signatures should be removed from JAR files.
-
Field Details
-
accessorGenerator
-
signatureRemover
-
-
Constructor Details
-
Instrumenter
Creates a new instance based on the given runtime.- Parameters:
runtime- runtime used by the instrumented classes
-
-
Method Details
-
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
Creates 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:
IOException- if the class can't be instrumented
-
instrument
Creates 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:
IOException- if reading data from the stream fails or the class can't be instrumented
-
instrument
Creates 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:
IOException- if reading data from the stream fails or the class can't be instrumented
-
instrumentError
-
instrumentAll
Creates 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:
IOException- if reading data from the stream fails or a class can't be instrumented
-
instrumentZip
- Throws:
IOException
-
filterOrInstrument
private int filterOrInstrument(InputStream in, OutputStream out, String name, String entryName) throws IOException - Throws:
IOException
-
crc
private static long crc(byte[] data) -
nextEntry
- Throws:
IOException
-
instrumentGzip
- Throws:
IOException
-
instrumentPack200
private int instrumentPack200(InputStream input, OutputStream output, String name) throws IOException - Throws:
IOException
-
copy
- Throws:
IOException
-
read
- Throws:
IOException
-