Search in sources :

Example 6 with AgentOptions

use of org.jacoco.core.runtime.AgentOptions in project jacoco by jacoco.

the class CoverageTransformerTest method setup.

@Before
public void setup() {
    recorder = new ExceptionRecorder();
    options = new AgentOptions();
    classLoader = getClass().getClassLoader();
    protectionDomain = getClass().getProtectionDomain();
    runtime = new StubRuntime();
}
Also used : AgentOptions(org.jacoco.core.runtime.AgentOptions) Before(org.junit.Before)

Example 7 with AgentOptions

use of org.jacoco.core.runtime.AgentOptions in project jacoco by jacoco.

the class FileOutputTest method testWriteData.

@Test
public void testWriteData() throws Exception {
    File destFile = folder.newFile("jacoco.exec");
    AgentOptions options = new AgentOptions();
    options.setDestfile(destFile.getAbsolutePath());
    FileOutput controller = new FileOutput();
    controller.startup(options, new RuntimeData());
    controller.writeExecutionData(false);
    controller.shutdown();
    assertTrue("Execution data file should be created", destFile.exists());
    assertTrue("Execution data file should have contents", destFile.length() > 0);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) File(java.io.File) FileOutput(org.jacoco.agent.rt.internal.output.FileOutput) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Example 8 with AgentOptions

use of org.jacoco.core.runtime.AgentOptions in project jacoco by jacoco.

the class FileOutputTest method testCreateDestFileOnStartup.

@Test
public void testCreateDestFileOnStartup() throws Exception {
    File destFile = folder.newFile("jacoco.exec");
    AgentOptions options = new AgentOptions();
    options.setDestfile(destFile.getAbsolutePath());
    FileOutput controller = new FileOutput();
    controller.startup(options, new RuntimeData());
    assertTrue("Execution data file should be created", destFile.exists());
    assertEquals("Execution data file should be empty", 0, destFile.length());
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) File(java.io.File) FileOutput(org.jacoco.agent.rt.internal.output.FileOutput) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Example 9 with AgentOptions

use of org.jacoco.core.runtime.AgentOptions in project jacoco by jacoco.

the class AbstractAgentMojo method createAgentOptions.

AgentOptions createAgentOptions() {
    final AgentOptions agentOptions = new AgentOptions();
    agentOptions.setDestfile(getDestFile().getAbsolutePath());
    if (append != null) {
        agentOptions.setAppend(append.booleanValue());
    }
    if (getIncludes() != null && !getIncludes().isEmpty()) {
        final String agentIncludes = StringUtils.join(getIncludes().iterator(), ":");
        agentOptions.setIncludes(agentIncludes);
    }
    if (getExcludes() != null && !getExcludes().isEmpty()) {
        final String agentExcludes = StringUtils.join(getExcludes().iterator(), ":");
        agentOptions.setExcludes(agentExcludes);
    }
    if (exclClassLoaders != null) {
        agentOptions.setExclClassloader(exclClassLoaders);
    }
    if (inclBootstrapClasses != null) {
        agentOptions.setInclBootstrapClasses(inclBootstrapClasses.booleanValue());
    }
    if (inclNoLocationClasses != null) {
        agentOptions.setInclNoLocationClasses(inclNoLocationClasses.booleanValue());
    }
    if (sessionId != null) {
        agentOptions.setSessionId(sessionId);
    }
    if (dumpOnExit != null) {
        agentOptions.setDumpOnExit(dumpOnExit.booleanValue());
    }
    if (output != null) {
        agentOptions.setOutput(output);
    }
    if (address != null) {
        agentOptions.setAddress(address);
    }
    if (port != null) {
        agentOptions.setPort(port.intValue());
    }
    if (classDumpDir != null) {
        agentOptions.setClassDumpDir(classDumpDir.getAbsolutePath());
    }
    if (jmx != null) {
        agentOptions.setJmx(jmx.booleanValue());
    }
    return agentOptions;
}
Also used : AgentOptions(org.jacoco.core.runtime.AgentOptions)

Example 10 with AgentOptions

use of org.jacoco.core.runtime.AgentOptions in project jacoco by jacoco.

the class AgentTest method startup_should_log_exception.

@Test
public void startup_should_log_exception() throws Exception {
    final Exception expected = new Exception();
    Agent agent = new Agent(options, this) {

        @Override
        IAgentOutput createAgentOutput() {
            return new IAgentOutput() {

                public void startup(AgentOptions options, RuntimeData data) throws Exception {
                    throw expected;
                }

                public void shutdown() {
                }

                public void writeExecutionData(boolean reset) {
                }
            };
        }
    };
    agent.startup();
    assertSame(expected, loggedException);
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) IAgentOutput(org.jacoco.agent.rt.internal.output.IAgentOutput) IOException(java.io.IOException) InstanceNotFoundException(javax.management.InstanceNotFoundException) AgentOptions(org.jacoco.core.runtime.AgentOptions) Test(org.junit.Test)

Aggregations

AgentOptions (org.jacoco.core.runtime.AgentOptions)11 RuntimeData (org.jacoco.core.runtime.RuntimeData)7 Test (org.junit.Test)5 IOException (java.io.IOException)4 Before (org.junit.Before)4 FileOutput (org.jacoco.agent.rt.internal.output.FileOutput)3 File (java.io.File)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 ExceptionRecorder (org.jacoco.agent.rt.internal.ExceptionRecorder)2 IAgentOutput (org.jacoco.agent.rt.internal.output.IAgentOutput)2 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 MockSocket (org.jacoco.agent.rt.internal.output.MockSocketConnection.MockSocket)1 IRuntime (org.jacoco.core.runtime.IRuntime)1 RemoteControlReader (org.jacoco.core.runtime.RemoteControlReader)1 RemoteControlWriter (org.jacoco.core.runtime.RemoteControlWriter)1