diff options
author | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2014-03-23 17:03:43 +0100 |
---|---|---|
committer | Marc R. Hoffmann <hoffmann@mountainminds.com> | 2014-03-23 17:04:32 +0100 |
commit | 82b13485562ca4a212b7499920f85f22cf9f294b (patch) | |
tree | e2c63952fea873ce3032c8685fa80d4cc98b2522 | |
parent | d65d20d8af92dcf1fbd1728ab2999813aef5e906 (diff) | |
download | jacoco-82b13485562ca4a212b7499920f85f22cf9f294b.tar.gz |
GitHub #35: Better interoperability with JMockit.
6 files changed, 14 insertions, 67 deletions
diff --git a/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java b/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java index 031221db..15e3d1a5 100644 --- a/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java +++ b/org.jacoco.agent.rt.test/src/org/jacoco/agent/rt/internal/CoverageTransformerTest.java @@ -148,9 +148,8 @@ public class CoverageTransformerTest { CoverageTransformer t = createTransformer(); // Just pick any non-system class outside our namespace final Class<?> target = JaCoCo.class; - t.transform(classLoader, target.getName(), target, null, - getClassData(target)); - runtime.assertDisconnected(target); + assertNull(t.transform(classLoader, target.getName(), target, null, + getClassData(target))); } private CoverageTransformer createTransformer() { @@ -173,8 +172,6 @@ public class CoverageTransformerTest { private static class StubRuntime extends AbstractRuntime { - private Class<?> disconnected; - public StubRuntime() { } @@ -186,15 +183,6 @@ public class CoverageTransformerTest { public void shutdown() { } - @Override - public void disconnect(Class<?> type) throws Exception { - this.disconnected = type; - } - - public void assertDisconnected(Class<?> expected) { - assertEquals(expected, disconnected); - } - } } diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java index b5ed7e18..78d7b5e5 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/CoverageTransformer.java @@ -32,8 +32,6 @@ public class CoverageTransformer implements ClassFileTransformer { AGENT_PREFIX = toVMName(name.substring(0, name.lastIndexOf('.'))); } - private final IRuntime runtime; - private final Instrumenter instrumenter; private final IExceptionLogger logger; @@ -58,7 +56,6 @@ public class CoverageTransformer implements ClassFileTransformer { */ public CoverageTransformer(final IRuntime runtime, final AgentOptions options, final IExceptionLogger logger) { - this.runtime = runtime; this.instrumenter = new Instrumenter(runtime); this.logger = logger; // Class names will be reported in VM notation: @@ -73,17 +70,17 @@ public class CoverageTransformer implements ClassFileTransformer { final ProtectionDomain protectionDomain, final byte[] classfileBuffer) throws IllegalClassFormatException { + if (classBeingRedefined != null) { + // We do not support class retransformation. + return null; + } + if (!filter(loader, classname)) { return null; } try { classFileDumper.dump(classname, classfileBuffer); - if (classBeingRedefined != null) { - // For redefined classes we must clear the execution data - // reference as probes might have changed. - runtime.disconnect(classBeingRedefined); - } return instrumenter.instrument(classfileBuffer, classname); } catch (final Exception ex) { final IllegalClassFormatException wrapper = new IllegalClassFormatException( 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 77877679..9dfb7090 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 @@ -12,7 +12,6 @@ package org.jacoco.core.runtime; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -98,24 +97,6 @@ public abstract class RuntimeTestBase { assertTrue(data[1]); } - @Test - public void testDisconnect() throws Exception { - final ITarget target = generateAndInstantiateClass(1001); - target.a(); - runtime.disconnect(target.getClass()); - assertNull(target.get()); - data.collect(storage, storage, false); - storage.assertSize(1); - final boolean[] data = storage.getData(1001).getProbes(); - assertTrue(data[0]); - } - - @Test - public void testDisconnectInterface() throws Exception { - // No effect: - runtime.disconnect(ITarget.class); - } - /** * Creates a new class with the given id, loads this class and instantiates * it. The constructor of the generated class will request the probe array diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/AbstractRuntime.java b/org.jacoco.core/src/org/jacoco/core/runtime/AbstractRuntime.java index c0d48b95..fe28a20c 100644 --- a/org.jacoco.core/src/org/jacoco/core/runtime/AbstractRuntime.java +++ b/org.jacoco.core/src/org/jacoco/core/runtime/AbstractRuntime.java @@ -11,11 +11,8 @@ *******************************************************************************/ package org.jacoco.core.runtime; -import java.lang.reflect.Field; import java.util.Random; -import org.jacoco.core.internal.instr.InstrSupport; - /** * Base {@link IRuntime} implementation. */ @@ -24,15 +21,6 @@ public abstract class AbstractRuntime implements IRuntime { /** access to the runtime data */ protected RuntimeData data; - public void disconnect(final Class<?> type) throws Exception { - if (!type.isInterface()) { - final Field dataField = type - .getDeclaredField(InstrSupport.DATAFIELD_NAME); - dataField.setAccessible(true); - dataField.set(null, null); - } - } - /** * Subclasses must call this method when overwriting it. */ diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/IRuntime.java b/org.jacoco.core/src/org/jacoco/core/runtime/IRuntime.java index 626e0f7c..0b96c25b 100644 --- a/org.jacoco.core/src/org/jacoco/core/runtime/IRuntime.java +++ b/org.jacoco.core/src/org/jacoco/core/runtime/IRuntime.java @@ -34,18 +34,4 @@ public interface IRuntime extends IExecutionDataAccessorGenerator { */ public void shutdown(); - /** - * Clears the execution data buffered in the given instrumented type. It - * forces the class to re-connect to the runtime the next time it is - * executed. This method is used by the agent and is required when a class - * has been redefined. Note that a call to this method does not actually - * reset the data that is already stored in the runtime. - * - * @param type - * class to clear - * @throws Exception - * if clearing the data is not possible - */ - public void disconnect(final Class<?> type) throws Exception; - } diff --git a/org.jacoco.doc/docroot/doc/changes.html b/org.jacoco.doc/docroot/doc/changes.html index 4b57d7d7..ffe9bcda 100644 --- a/org.jacoco.doc/docroot/doc/changes.html +++ b/org.jacoco.doc/docroot/doc/changes.html @@ -20,6 +20,13 @@ <h2>Snapshot Build @qualified.bundle.version@ (@build.date@)</h2> +<h3>Fixed Bugs</h3> +<ul> + <li>Better interoperability with JMockit, analysis and fix contributed by Rogério + Liesenfeld (GitHub <a href="https://github.com/jacoco/jacoco/issues/35">#35</a> + and (GitHub <a href="https://github.com/jacoco/jacoco/issues/54">#54</a>).</li> +</ul> + <h2>Release 0.7.0 (2014/03/18)</h2> <h3>New Features</h3> |