diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-01-04 17:46:18 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2015-01-04 17:46:18 +0100 |
commit | d31ce3dcc90dead13a1ca8acb0d7a5bfe99e61d6 (patch) | |
tree | 232dcdbb44ebf4784999fcb5139f3721d5fd4c30 | |
parent | 0092055e81f99968780cc7ad347d44c056ec4ff5 (diff) | |
parent | 834d1556e4a1051621909f705a6ac94eaa6d7248 (diff) | |
download | jacoco-d31ce3dcc90dead13a1ca8acb0d7a5bfe99e61d6.tar.gz |
Merge remote-tracking branch 'allenhair/master'
-rw-r--r-- | jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec | bin | 24 -> 24 bytes | |||
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec | bin | 42 -> 42 bytes | |||
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec | 2 | ||||
-rw-r--r-- | org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec | 2 | ||||
-rw-r--r-- | org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java | 52 | ||||
-rw-r--r-- | org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java | 2 | ||||
-rw-r--r-- | org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java | 24 |
7 files changed, 79 insertions, 3 deletions
diff --git a/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec Binary files differindex 31cad96f..b3396529 100644 --- a/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec +++ b/jacoco-maven-plugin.test/it/it-report-nomatch/nomatch.exec diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec Binary files differindex ef7d62ae..66d78df2 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/nomatch.exec diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec index b9c3ab93..2e87d6ca 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample1.exec @@ -1 +1 @@ -ÀÀ
\ No newline at end of file +ÀÀ
\ No newline at end of file diff --git a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec index b9c3ab93..2e87d6ca 100644 --- a/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec +++ b/org.jacoco.ant.test/src/org/jacoco/ant/data/sample2.exec @@ -1 +1 @@ -ÀÀ
\ No newline at end of file +ÀÀ
\ No newline at end of file diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java index ea329632..5590323f 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/flow/MethodProbesAdapterTest.java @@ -312,6 +312,58 @@ public class MethodProbesAdapterTest implements IProbeIdGenerator { expectedVisitor.visitTableSwitchInsn(0, 1, label, labels); } + @Test + public void testVisitTryCatchBlockNoProbe() { + Label start = new Label(); + Label end = new Label(); + Label handler = new Label(); + + adapter.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + adapter.visitLabel(start); + + expectedVisitor.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + expectedVisitor.visitLabel(start); + } + + @Test + public void testVisitTryCatchBlockWithProbe() { + Label target = new Label(); + LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); + Label end = new Label(); + Label handler = new Label(); + Label start = new Label(); + + adapter.visitTryCatchBlock(target, end, handler, "java/lang/Exception"); + adapter.visitLabel(target); + + expectedVisitor.visitTryCatchBlock(start, end, handler, "java/lang/Exception"); + expectedVisitor.visitLabel(start); + expectedVisitor.visitProbe(1000); + expectedVisitor.visitLabel(target); + } + + @Test + public void testVisitMultipleTryCatchBlocksWithProbe() { + Label target = new Label(); + LabelInfo.setSuccessor(target); + LabelInfo.setTarget(target); + Label end = new Label(); + Label handler1 = new Label(); + Label handler2 = new Label(); + Label start = new Label(); + + adapter.visitTryCatchBlock(target, end, handler1, "java/lang/Exception"); + adapter.visitTryCatchBlock(target, end, handler2, "java/io/IOException"); + adapter.visitLabel(target); + + expectedVisitor.visitTryCatchBlock(start, end, handler1, "java/lang/Exception"); + expectedVisitor.visitTryCatchBlock(start, end, handler2, "java/io/IOException"); + expectedVisitor.visitLabel(start); + expectedVisitor.visitProbe(1000); + expectedVisitor.visitLabel(target); + } + // === IProbeIdGenerator === public int nextId() { diff --git a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java index f064f907..1d0157da 100644 --- a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java +++ b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataWriter.java @@ -24,7 +24,7 @@ public class ExecutionDataWriter implements ISessionInfoVisitor, IExecutionDataVisitor { /** File format version, will be incremented for each incompatible change. */ - public static final char FORMAT_VERSION = 0x1006; + public static final char FORMAT_VERSION = 0x1007; /** Magic number in header for file format identification. */ public static final char MAGIC_NUMBER = 0xC0C0; diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java index 6d44bc5a..2fe7e315 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesAdapter.java @@ -17,6 +17,9 @@ import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; import org.objectweb.asm.commons.AnalyzerAdapter; +import java.util.HashMap; +import java.util.Map; + /** * Adapter that creates additional visitor events for probes to be inserted into * a method. @@ -29,6 +32,8 @@ public final class MethodProbesAdapter extends MethodVisitor { private AnalyzerAdapter analyzer; + private Map<Label, Label> tryCatchProbeLabels = new HashMap<Label, Label>(); + /** * Create a new adapter instance. * @@ -56,8 +61,27 @@ public final class MethodProbesAdapter extends MethodVisitor { } @Override + public void visitTryCatchBlock(Label start, final Label end, + final Label handler, final String type) { + // If a probe will be inserted before the start label, we'll need to use a + // different label for the try-catch block. + if (tryCatchProbeLabels.containsKey(start)) { + start = tryCatchProbeLabels.get(start); + } else if (LabelInfo.isMultiTarget(start) && LabelInfo.isSuccessor(start)) { + Label probeLabel = new Label(); + LabelInfo.setSuccessor(probeLabel); + tryCatchProbeLabels.put(start, probeLabel); + start = probeLabel; + } + probesVisitor.visitTryCatchBlock(start, end, handler, type); + } + + @Override public void visitLabel(final Label label) { if (LabelInfo.isMultiTarget(label) && LabelInfo.isSuccessor(label)) { + if (tryCatchProbeLabels.containsKey(label)) { + probesVisitor.visitLabel(tryCatchProbeLabels.get(label)); + } probesVisitor.visitProbe(idGenerator.nextId()); } probesVisitor.visitLabel(label); |