Class Agent

java.lang.Object
org.jacoco.agent.rt.internal.Agent
All Implemented Interfaces:
IAgent

public class Agent extends Object implements IAgent
The agent manages the life cycle of JaCoCo runtime.
  • Field Details

  • Constructor Details

    • Agent

      Agent(AgentOptions options, IExceptionLogger logger)
      Creates a new agent with the given agent options.
      Parameters:
      options - agent options
      logger - logger used by this agent
  • Method Details

    • getInstance

      public static Agent getInstance(AgentOptions options) throws Exception
      Returns a global instance which is already started. If the method is called the first time the instance is created with the given options.
      Parameters:
      options - options to configure the instance
      Returns:
      global instance
      Throws:
      Exception - in case something cannot be initialized
    • getInstance

      public static Agent getInstance() throws IllegalStateException
      Returns a global instance which is already started. If a agent has not been initialized before this method will fail.
      Returns:
      global instance
      Throws:
      IllegalStateException - if no Agent has been started yet
    • getData

      public RuntimeData getData()
      Returns the runtime data object created by this agent
      Returns:
      runtime data for this agent instance
    • startup

      public void startup() throws Exception
      Initializes this agent.
      Throws:
      Exception - in case something cannot be initialized
    • shutdown

      public void shutdown()
      Shutdown the agent again.
    • createAgentOutput

      IAgentOutput createAgentOutput()
      Create output implementation as given by the agent options.
      Returns:
      configured controller implementation
    • createSessionId

      private String createSessionId()
    • getVersion

      public String getVersion()
      Description copied from interface: IAgent
      Returns version of JaCoCo.
      Specified by:
      getVersion in interface IAgent
      Returns:
      version of JaCoCo
    • getSessionId

      public String getSessionId()
      Description copied from interface: IAgent
      Returns current a session identifier.
      Specified by:
      getSessionId in interface IAgent
      Returns:
      current session identifier
    • setSessionId

      public void setSessionId(String id)
      Description copied from interface: IAgent
      Sets a session identifier.
      Specified by:
      setSessionId in interface IAgent
      Parameters:
      id - new session identifier
    • reset

      public void reset()
      Description copied from interface: IAgent
      Resets all coverage information.
      Specified by:
      reset in interface IAgent
    • getExecutionData

      public byte[] getExecutionData(boolean reset)
      Description copied from interface: IAgent
      Returns current execution data.
      Specified by:
      getExecutionData in interface IAgent
      Parameters:
      reset - if true the current execution data is cleared afterwards
      Returns:
      dump of current execution data in JaCoCo binary format
    • dump

      public void dump(boolean reset) throws IOException
      Description copied from interface: IAgent
      Triggers a dump of the current execution data through the configured output.
      Specified by:
      dump in interface IAgent
      Parameters:
      reset - if true the current execution data is cleared afterwards
      Throws:
      IOException - if the output can't write execution data