Class AbstractInstrumenter

java.lang.Object
org.hibernate.bytecode.buildtime.AbstractInstrumenter
All Implemented Interfaces:
Instrumenter
Direct Known Subclasses:
CGLIBInstrumenter, JavassistInstrumenter

public abstract class AbstractInstrumenter extends Object implements Instrumenter
Provides the basic templating of how instrumentation should occur.
  • Field Details

  • Constructor Details

    • AbstractInstrumenter

      public AbstractInstrumenter(Logger logger, Instrumenter.Options options)
      Creates the basic instrumentation strategy.
      Parameters:
      logger - The bridge to the environment's logging system.
      options - User-supplied options.
  • Method Details

    • getClassDescriptor

      protected abstract ClassDescriptor getClassDescriptor(byte[] byecode) throws Exception
      Given the bytecode of a java class, retrieve the descriptor for that class.
      Parameters:
      byecode - The class bytecode.
      Returns:
      The class's descriptor
      Throws:
      Exception - Indicates problems access the bytecode.
    • getClassTransformer

      protected abstract ClassTransformer getClassTransformer(ClassDescriptor descriptor, Set classNames)
      Create class transformer for the class.
      Parameters:
      descriptor - The descriptor of the class to be instrumented.
      classNames - The names of all classes to be instrumented; the "pipeline" if you will.
      Returns:
      The transformer for the given class; may return null to indicate that transformation should be skipped (ala already instrumented).
    • execute

      public void execute(Set files)
      The main instrumentation entry point. Given a set of files, perform instrumentation on each discovered class file.
      Specified by:
      execute in interface Instrumenter
      Parameters:
      files - The files.
    • isClassFile

      protected final boolean isClassFile(File file) throws IOException
      Does this file represent a compiled class?
      Parameters:
      file - The file to check.
      Returns:
      True if the file is a class; false otherwise.
      Throws:
      IOException - Indicates problem access the file.
    • isJarFile

      protected final boolean isJarFile(File file) throws IOException
      Does this file represent a zip file of some format?
      Parameters:
      file - The file to check.
      Returns:
      True if the file is n archive; false otherwise.
      Throws:
      IOException - Indicates problem access the file.
    • checkMagic

      protected final boolean checkMagic(File file, long magic) throws IOException
      Throws:
      IOException
    • processFile

      protected void processFile(File file, Set classNames) throws Exception
      Actually process the file by applying instrumentation transformations to any classes it contains.

      Again, just like with collectClassNames(java.io.File, java.util.Set) this method can handle both class and archive files.

      Parameters:
      file - The file to process.
      classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
      Throws:
      Exception - Indicates an issue either access files or applying the transformations.
    • processClassFile

      protected void processClassFile(File file, Set classNames) throws Exception
      Process a class file. Delegated to from processFile(java.io.File, java.util.Set) in the case of a class file.
      Parameters:
      file - The class file to process.
      classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
      Throws:
      Exception - Indicates an issue either access files or applying the transformations.
    • processJarFile

      protected void processJarFile(File file, Set classNames) throws Exception
      Process an archive file. Delegated to from processFile(java.io.File, java.util.Set) in the case of an archive file.
      Parameters:
      file - The archive file to process.
      classNames - The 'pipeline' of classes to be processed. Only actually populated when the user specifies to perform extended instrumentation.
      Throws:
      Exception - Indicates an issue either access files or applying the transformations.