Search in sources :

Example 1 with JacocoAgentBuilder

use of com.teamscale.jacoco.agent.options.JacocoAgentBuilder in project teamscale-jacoco-agent by cqse.

the class AgentBase method premain.

/**
 * Called by the actual premain method once the agent is isolated from the rest of the application.
 */
public static void premain(String options, Instrumentation instrumentation) throws Exception {
    AgentOptions agentOptions;
    DelayedLogger delayedLogger = new DelayedLogger();
    try {
        agentOptions = AgentOptionsParser.parse(options, delayedLogger);
    } catch (AgentOptionParseException e) {
        try (LoggingUtils.LoggingResources ignored = initializeFallbackLogging(options, delayedLogger)) {
            delayedLogger.error("Failed to parse agent options: " + e.getMessage(), e);
            System.err.println("Failed to parse agent options: " + e.getMessage());
            // we perform actual logging output after writing to console to
            // ensure the console is reached even in case of logging issues
            // (see TS-23151). We use the Agent class here (same as below)
            Logger logger = LoggingUtils.getLogger(Agent.class);
            delayedLogger.logTo(logger);
            throw e;
        }
    }
    loggingResources = LoggingUtils.initializeLogging(agentOptions.getLoggingConfig());
    Logger logger = LoggingUtils.getLogger(Agent.class);
    delayedLogger.logTo(logger);
    HttpUtils.setShouldValidateSsl(agentOptions.shouldValidateSsl());
    logger.info("Starting JaCoCo's agent");
    JacocoAgentBuilder agentBuilder = new JacocoAgentBuilder(agentOptions);
    org.jacoco.agent.rt.internal_3570298.PreMain.premain(agentBuilder.createJacocoAgentOptions(), instrumentation);
    AgentBase agent = agentBuilder.createAgent(instrumentation);
    agent.registerShutdownHook();
}
Also used : LoggingResources(com.teamscale.jacoco.agent.util.LoggingUtils.LoggingResources) AgentOptionParseException(com.teamscale.jacoco.agent.options.AgentOptionParseException) JacocoAgentBuilder(com.teamscale.jacoco.agent.options.JacocoAgentBuilder) Logger(org.slf4j.Logger) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions)

Aggregations

AgentOptionParseException (com.teamscale.jacoco.agent.options.AgentOptionParseException)1 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)1 JacocoAgentBuilder (com.teamscale.jacoco.agent.options.JacocoAgentBuilder)1 LoggingResources (com.teamscale.jacoco.agent.util.LoggingUtils.LoggingResources)1 Logger (org.slf4j.Logger)1