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();
}
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()));
}
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;
}
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();
}
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;
}
};
}
Aggregations