Class Instrumenter

java.lang.Object
org.jacoco.core.instr.Instrumenter

public class Instrumenter extends Object
Several APIs to instrument Java class definitions for coverage tracing.
  • Field Details

  • Constructor Details

    • Instrumenter

      public Instrumenter(IExecutionDataAccessorGenerator runtime)
      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 is true.
      Parameters:
      flag - true if signatures should be removed
    • instrument

      private byte[] instrument(byte[] source)
    • instrument

      public byte[] instrument(byte[] buffer, String name) throws IOException
      Creates a instrumented version of the given class if possible.
      Parameters:
      buffer - definition of the class
      name - a name used for exception messages
      Returns:
      instrumented definition
      Throws:
      IOException - if the class can't be instrumented
    • instrument

      public byte[] instrument(InputStream input, String name) throws IOException
      Creates a instrumented version of the given class if possible. The provided InputStream is not closed by this method.
      Parameters:
      input - stream to read class definition from
      name - 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

      public void instrument(InputStream input, OutputStream output, String name) throws IOException
      Creates a instrumented version of the given class file. The provided InputStream and OutputStream instances are not closed by this method.
      Parameters:
      input - stream to read class definition from
      output - stream to write the instrumented version of the class to
      name - a name used for exception messages
      Throws:
      IOException - if reading data from the stream fails or the class can't be instrumented
    • instrumentError

      private IOException instrumentError(String name, Exception cause)
    • instrumentAll

      public int instrumentAll(InputStream input, OutputStream output, String name) throws IOException
      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 provided InputStream and OutputStream instances are not closed by this method.
      Parameters:
      input - stream to contents from
      output - stream to write the instrumented version of the contents
      name - 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

      private int instrumentZip(InputStream input, OutputStream output, String name) throws IOException
      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

      private ZipEntry nextEntry(ZipInputStream input, String location) throws IOException
      Throws:
      IOException
    • instrumentGzip

      private int instrumentGzip(InputStream input, OutputStream output, String name) throws IOException
      Throws:
      IOException
    • instrumentPack200

      private int instrumentPack200(InputStream input, OutputStream output, String name) throws IOException
      Throws:
      IOException
    • copy

      private void copy(InputStream input, OutputStream output, String name) throws IOException
      Throws:
      IOException
    • read

      private int read(InputStream input, byte[] buffer, String name) throws IOException
      Throws:
      IOException