diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-12-19 18:36:12 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2013-12-19 18:36:12 +0100 |
commit | 9f4ef8dcffb3acbcd066ec073d87de65eeb06b48 (patch) | |
tree | bafe193d49c408a7b101345756d4ef327653d678 | |
parent | 7bbf8ffd29bb35515b449965271d79ea540d248e (diff) | |
download | jacoco-9f4ef8dcffb3acbcd066ec073d87de65eeb06b48.tar.gz |
Keep ASM API version at central place to simplify migration to ASM 5.
15 files changed, 49 insertions, 34 deletions
diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/ClassInstrumenterTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/ClassInstrumenterTest.java index a28dfcb3..fe5c2df5 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/ClassInstrumenterTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/ClassInstrumenterTest.java @@ -13,13 +13,13 @@ package org.jacoco.core.internal.instr; import static org.junit.Assert.assertNull; +import org.jacoco.core.JaCoCo; import org.jacoco.core.runtime.IRuntime; import org.jacoco.core.runtime.LoggerRuntime; import org.junit.Before; import org.junit.Test; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; /** * Unit tests for {@link ClassInstrumenter}. @@ -34,7 +34,7 @@ public class ClassInstrumenterTest { public void setup() { runtime = new LoggerRuntime(); instrumenter = new ClassInstrumenter(123, runtime, new ClassVisitor( - Opcodes.ASM4) { + JaCoCo.ASM_API_VERSION) { }); } @@ -55,7 +55,7 @@ public class ClassInstrumenterTest { @Test public void testNoMethodVisitor() { instrumenter = new ClassInstrumenter(123, runtime, new ClassVisitor( - Opcodes.ASM4) { + JaCoCo.ASM_API_VERSION) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { diff --git a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/FrameTrackerTest.java b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/FrameTrackerTest.java index 879e94a3..c3a89cd6 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/internal/instr/FrameTrackerTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/internal/instr/FrameTrackerTest.java @@ -14,6 +14,7 @@ package org.jacoco.core.internal.instr; import static org.junit.Assert.assertEquals; import static org.objectweb.asm.Opcodes.*; +import org.jacoco.core.JaCoCo; import org.jacoco.core.instr.MethodRecorder; import org.junit.After; import org.junit.Before; @@ -68,7 +69,7 @@ public class FrameTrackerTest { @After public void verify() { MethodRecorder actual = new MethodRecorder(); - MethodVisitor noLabels = new MethodVisitor(Opcodes.ASM4, + MethodVisitor noLabels = new MethodVisitor(JaCoCo.ASM_API_VERSION, actual.getVisitor()) { @Override public void visitLabel(Label label) { diff --git a/org.jacoco.core.test/src/org/jacoco/core/runtime/RuntimeTestBase.java b/org.jacoco.core.test/src/org/jacoco/core/runtime/RuntimeTestBase.java index 05f80432..ed07fe46 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/runtime/RuntimeTestBase.java +++ b/org.jacoco.core.test/src/org/jacoco/core/runtime/RuntimeTestBase.java @@ -16,6 +16,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import org.jacoco.core.JaCoCo; import org.jacoco.core.internal.instr.InstrSupport; import org.jacoco.core.test.TargetLoader; import org.junit.After; @@ -66,7 +67,7 @@ public abstract class RuntimeTestBase { public void testNoLocalVariablesInDataAccessor() throws InstantiationException, IllegalAccessException { runtime.generateDataAccessor(1001, "Target", 5, new MethodVisitor( - Opcodes.ASM4) { + JaCoCo.ASM_API_VERSION) { @Override public void visitVarInsn(int opcode, int var) { fail("No usage of local variables allowed."); diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/ClassFileVersionsTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/ClassFileVersionsTest.java index 6b5d2bfc..eec18b47 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/ClassFileVersionsTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/ClassFileVersionsTest.java @@ -27,6 +27,7 @@ import static org.objectweb.asm.Opcodes.V1_7; import java.io.IOException; +import org.jacoco.core.JaCoCo; import org.jacoco.core.instr.Instrumenter; import org.jacoco.core.runtime.IRuntime; import org.jacoco.core.runtime.SystemPropertiesRuntime; @@ -35,7 +36,6 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; /** * Test class inserted stackmap frames for different class file versions. @@ -89,23 +89,24 @@ public class ClassFileVersionsTest { private void assertFrames(byte[] source, boolean expected) { final boolean[] hasFrames = new boolean[] { false }; - new ClassReader(source).accept(new ClassVisitor(Opcodes.ASM4) { - - @Override - public MethodVisitor visitMethod(int access, String name, - String desc, String signature, String[] exceptions) { - return new MethodVisitor(Opcodes.ASM4) { + new ClassReader(source).accept( + new ClassVisitor(JaCoCo.ASM_API_VERSION) { @Override - public void visitFrame(int type, int nLocal, - Object[] local, int nStack, Object[] stack) { - hasFrames[0] = true; - } + public MethodVisitor visitMethod(int access, String name, + String desc, String signature, String[] exceptions) { + return new MethodVisitor(JaCoCo.ASM_API_VERSION) { - }; - } + @Override + public void visitFrame(int type, int nLocal, + Object[] local, int nStack, Object[] stack) { + hasFrames[0] = true; + } + + }; + } - }, 0); + }, 0); assertEquals(Boolean.valueOf(expected), Boolean.valueOf(hasFrames[0])); } diff --git a/org.jacoco.core.test/src/org/jacoco/core/test/validation/FramesTest.java b/org.jacoco.core.test/src/org/jacoco/core/test/validation/FramesTest.java index f5ac4f5e..c2ef33c9 100644 --- a/org.jacoco.core.test/src/org/jacoco/core/test/validation/FramesTest.java +++ b/org.jacoco.core.test/src/org/jacoco/core/test/validation/FramesTest.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import org.jacoco.core.JaCoCo; import org.jacoco.core.instr.Instrumenter; import org.jacoco.core.runtime.IRuntime; import org.jacoco.core.runtime.SystemPropertiesRuntime; @@ -51,7 +52,7 @@ public class FramesTest { */ private static class MaxStackEliminator extends ClassVisitor { public MaxStackEliminator(ClassVisitor cv) { - super(Opcodes.ASM4, cv); + super(JaCoCo.ASM_API_VERSION, cv); } @Override @@ -59,7 +60,7 @@ public class FramesTest { String signature, String[] exceptions) { final MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); - return new MethodVisitor(Opcodes.ASM4, mv) { + return new MethodVisitor(JaCoCo.ASM_API_VERSION, mv) { @Override public void visitMaxs(int maxStack, int maxLocals) { super.visitMaxs(-1, maxLocals); @@ -87,7 +88,7 @@ public class FramesTest { ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); // Adjust Version to 1.6 to enable frames: - rc.accept(new ClassVisitor(Opcodes.ASM4, cw) { + rc.accept(new ClassVisitor(JaCoCo.ASM_API_VERSION, cw) { @Override public void visit(int version, int access, String name, diff --git a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java index b51937be..d2f262ba 100644 --- a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java +++ b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java @@ -13,6 +13,8 @@ package org.jacoco.core; import java.util.ResourceBundle; +import org.objectweb.asm.Opcodes; + /** * Static Meta information about JaCoCo. */ @@ -27,6 +29,9 @@ public final class JaCoCo { /** Name of the runtime package of this build */ public static final String RUNTIMEPACKAGE; + /** ASM API version */ + public static final int ASM_API_VERSION = Opcodes.ASM4; + static { final ResourceBundle bundle = ResourceBundle .getBundle("org.jacoco.core.jacoco"); diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java index 937328aa..2fe3e3d7 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.jacoco.core.internal.flow; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -80,7 +81,7 @@ public class ClassProbesAdapter extends ClassVisitor implements * instance to delegate to */ public ClassProbesAdapter(final ClassProbesVisitor cv) { - super(Opcodes.ASM4, cv); + super(JaCoCo.ASM_API_VERSION, cv); this.cv = cv; } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesVisitor.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesVisitor.java index ff796edb..49a78242 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesVisitor.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesVisitor.java @@ -11,8 +11,8 @@ *******************************************************************************/ package org.jacoco.core.internal.flow; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.ClassVisitor; -import org.objectweb.asm.Opcodes; /** * A {@link ClassVisitor} with additional methods to get probe insertion @@ -34,7 +34,7 @@ public abstract class ClassProbesVisitor extends ClassVisitor { * optional next visitor in chain */ public ClassProbesVisitor(final ClassVisitor cv) { - super(Opcodes.ASM4, cv); + super(JaCoCo.ASM_API_VERSION, cv); } /** diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelFlowAnalyzer.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelFlowAnalyzer.java index b325e8a3..7007c94c 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelFlowAnalyzer.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/LabelFlowAnalyzer.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.jacoco.core.internal.flow; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -59,7 +60,7 @@ public final class LabelFlowAnalyzer extends MethodVisitor { * Create new instance. */ public LabelFlowAnalyzer() { - super(Opcodes.ASM4); + super(JaCoCo.ASM_API_VERSION); } @Override 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 60b64b66..5d681445 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 @@ -11,6 +11,7 @@ *******************************************************************************/ package org.jacoco.core.internal.flow; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -35,7 +36,7 @@ public final class MethodProbesAdapter extends MethodVisitor { */ public MethodProbesAdapter(final MethodProbesVisitor probesVisitor, final IProbeIdGenerator idGenerator) { - super(Opcodes.ASM4, probesVisitor); + super(JaCoCo.ASM_API_VERSION, probesVisitor); this.probesVisitor = probesVisitor; this.idGenerator = idGenerator; } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesVisitor.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesVisitor.java index fba48122..fd4b281a 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesVisitor.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/MethodProbesVisitor.java @@ -11,9 +11,9 @@ *******************************************************************************/ package org.jacoco.core.internal.flow; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; /** * A {@link MethodVisitor} with additional methods to get probe insertion @@ -35,7 +35,7 @@ public abstract class MethodProbesVisitor extends MethodVisitor { * optional next visitor in chain */ public MethodProbesVisitor(final MethodVisitor mv) { - super(Opcodes.ASM4, mv); + super(JaCoCo.ASM_API_VERSION, mv); } /** diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/DuplicateFrameEliminator.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/DuplicateFrameEliminator.java index 81384e55..8c3f46b0 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/instr/DuplicateFrameEliminator.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/DuplicateFrameEliminator.java @@ -11,10 +11,10 @@ *******************************************************************************/ package org.jacoco.core.internal.instr; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; -import org.objectweb.asm.Opcodes; /** * Eliminates consecutive stackmap frame definitions which causes ASM to create @@ -27,7 +27,7 @@ class DuplicateFrameEliminator extends MethodVisitor { private boolean instruction; public DuplicateFrameEliminator(final MethodVisitor mv) { - super(Opcodes.ASM4, mv); + super(JaCoCo.ASM_API_VERSION, mv); instruction = true; } diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/FrameTracker.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/FrameTracker.java index 1ff58b5c..ced09d26 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/instr/FrameTracker.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/FrameTracker.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.jacoco.core.internal.instr; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Handle; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; @@ -33,7 +34,7 @@ class FrameTracker extends MethodVisitor implements IFrameInserter { public FrameTracker(final String owner, final int access, final String name, final String desc, final MethodVisitor mv) { - super(Opcodes.ASM4, mv); + super(JaCoCo.ASM_API_VERSION, mv); this.owner = owner; local = new Object[8]; localSize = 0; diff --git a/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java b/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java index 2db2d39f..95d56c7d 100644 --- a/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java +++ b/org.jacoco.core/src/org/jacoco/core/internal/instr/ProbeInserter.java @@ -11,6 +11,7 @@ *******************************************************************************/ package org.jacoco.core.internal.instr; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; @@ -47,7 +48,7 @@ class ProbeInserter extends MethodVisitor implements IProbeInserter { */ ProbeInserter(final int access, final String desc, final MethodVisitor mv, final IProbeArrayStrategy arrayStrategy) { - super(Opcodes.ASM4, mv); + super(JaCoCo.ASM_API_VERSION, mv); this.arrayStrategy = arrayStrategy; int pos = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0; for (final Type t : Type.getArgumentTypes(desc)) { diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java b/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java index a5eb37b7..d8416ec1 100644 --- a/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java +++ b/org.jacoco.core/src/org/jacoco/core/runtime/ModifiedSystemClassRuntime.java @@ -19,6 +19,7 @@ import java.lang.instrument.Instrumentation; import java.lang.reflect.Field; import java.security.ProtectionDomain; +import org.jacoco.core.JaCoCo; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.ClassWriter; @@ -155,7 +156,7 @@ public class ModifiedSystemClassRuntime extends AbstractRuntime { final String accessFieldName) { final ClassReader reader = new ClassReader(source); final ClassWriter writer = new ClassWriter(reader, 0); - reader.accept(new ClassVisitor(Opcodes.ASM4, writer) { + reader.accept(new ClassVisitor(JaCoCo.ASM_API_VERSION, writer) { @Override public void visitEnd() { |