Search in sources :

Example 6 with Instrumenter

use of org.jacoco.core.instr.Instrumenter in project jacoco by jacoco.

the class CyclomaticComplexityTest method instrument.

private void instrument(final Class<? extends Target> clazz) throws Exception {
    bytes = TargetLoader.getClassDataAsBytes(clazz);
    final byte[] instrumented = new Instrumenter(runtime).instrument(bytes, "TestTarget");
    final TargetLoader loader = new TargetLoader();
    target = (Target) loader.add(clazz, instrumented).newInstance();
}
Also used : TargetLoader(org.jacoco.core.test.TargetLoader) Instrumenter(org.jacoco.core.instr.Instrumenter)

Example 7 with Instrumenter

use of org.jacoco.core.instr.Instrumenter in project jacoco by jacoco.

the class InstrumentTask method execute.

@Override
public void execute() throws BuildException {
    if (destdir == null) {
        throw new BuildException("Destination directory must be supplied", getLocation());
    }
    int total = 0;
    final Instrumenter instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator());
    instrumenter.setRemoveSignatures(removesignatures);
    final Iterator<?> resourceIterator = files.iterator();
    while (resourceIterator.hasNext()) {
        final Resource resource = (Resource) resourceIterator.next();
        if (resource.isDirectory()) {
            continue;
        }
        total += instrument(instrumenter, resource);
    }
    log(format("Instrumented %s classes to %s", Integer.valueOf(total), destdir.getAbsolutePath()));
}
Also used : Resource(org.apache.tools.ant.types.Resource) OfflineInstrumentationAccessGenerator(org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator) BuildException(org.apache.tools.ant.BuildException) Instrumenter(org.jacoco.core.instr.Instrumenter)

Example 8 with Instrumenter

use of org.jacoco.core.instr.Instrumenter in project jacoco by jacoco.

the class Instrument method execute.

@Override
public int execute(final PrintWriter out, final PrintWriter err) throws IOException {
    final File absoluteDest = dest.getAbsoluteFile();
    instrumenter = new Instrumenter(new OfflineInstrumentationAccessGenerator());
    int total = 0;
    for (final File s : source) {
        if (s.isFile()) {
            total += instrument(s, new File(absoluteDest, s.getName()));
        } else {
            total += instrumentRecursive(s, absoluteDest);
        }
    }
    out.printf("[INFO] %s classes instrumented to %s.%n", Integer.valueOf(total), absoluteDest);
    return 0;
}
Also used : OfflineInstrumentationAccessGenerator(org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator) Instrumenter(org.jacoco.core.instr.Instrumenter) File(java.io.File)

Example 9 with Instrumenter

use of org.jacoco.core.instr.Instrumenter in project jacoco by jacoco.

the class ExecuteInstrumentedCodeScenario method getInstrumentedCallable.

@Override
@SuppressWarnings("unchecked")
protected Callable<Void> getInstrumentedCallable() throws Exception {
    ClassReader reader = new ClassReader(TargetLoader.getClassData(target));
    IRuntime runtime = new LoggerRuntime();
    runtime.startup(new RuntimeData());
    final Instrumenter instr = new Instrumenter(runtime);
    final byte[] instrumentedBuffer = instr.instrument(reader);
    final TargetLoader loader = new TargetLoader();
    return (Callable<Void>) loader.add(target, instrumentedBuffer).newInstance();
}
Also used : RuntimeData(org.jacoco.core.runtime.RuntimeData) LoggerRuntime(org.jacoco.core.runtime.LoggerRuntime) TargetLoader(org.jacoco.core.test.TargetLoader) ClassReader(org.objectweb.asm.ClassReader) Instrumenter(org.jacoco.core.instr.Instrumenter) Callable(java.util.concurrent.Callable) IRuntime(org.jacoco.core.runtime.IRuntime)

Example 10 with Instrumenter

use of org.jacoco.core.instr.Instrumenter in project jacoco by jacoco.

the class InstrumentationTimeScenario method getInstrumentedCallable.

@Override
protected Callable<Void> getInstrumentedCallable() throws Exception {
    final byte[] bytes = TargetLoader.getClassDataAsBytes(target);
    final Instrumenter instr = new Instrumenter(new LoggerRuntime());
    return new Callable<Void>() {

        public Void call() throws Exception {
            for (int i = 0; i < count; i++) {
                instr.instrument(bytes, "TestTarget");
            }
            return null;
        }
    };
}
Also used : LoggerRuntime(org.jacoco.core.runtime.LoggerRuntime) Instrumenter(org.jacoco.core.instr.Instrumenter) Callable(java.util.concurrent.Callable)

Aggregations

Instrumenter (org.jacoco.core.instr.Instrumenter)12 IRuntime (org.jacoco.core.runtime.IRuntime)6 LoggerRuntime (org.jacoco.core.runtime.LoggerRuntime)4 OfflineInstrumentationAccessGenerator (org.jacoco.core.runtime.OfflineInstrumentationAccessGenerator)4 SystemPropertiesRuntime (org.jacoco.core.runtime.SystemPropertiesRuntime)3 ClassReader (org.objectweb.asm.ClassReader)3 File (java.io.File)2 InputStream (java.io.InputStream)2 Callable (java.util.concurrent.Callable)2 RuntimeData (org.jacoco.core.runtime.RuntimeData)2 TargetLoader (org.jacoco.core.test.TargetLoader)2 JarCreator (com.google.devtools.build.buildjar.jarhelper.JarCreator)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 BuildException (org.apache.tools.ant.BuildException)1 Resource (org.apache.tools.ant.types.Resource)1