diff --git a/pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java b/pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java index b921d8f42..62ac04835 100644 --- a/pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java +++ b/pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java @@ -24,7 +24,7 @@ public DefaultCodeSource(final ProjectClassPaths classPath) { classPath.getClassPath()))); } - DefaultCodeSource(final ProjectClassPaths classPath, + public DefaultCodeSource(final ProjectClassPaths classPath, final Repository classRepository) { this.classPath = classPath; this.classRepository = classRepository; diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java index c929c3d0d..d3a7fd73e 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/CompoundMutationInterceptor.java @@ -1,6 +1,7 @@ package org.pitest.mutationtest.build; import org.pitest.bytecode.analysis.ClassTree; +import org.pitest.classpath.CodeSource; import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails; @@ -32,6 +33,11 @@ public CompoundMutationInterceptor filter(Predicate p) { .collect(Collectors.toList())); } + @Override + public void initialise(CodeSource code) { + this.children.forEach(each -> each.initialise(code)); + } + @Override public void begin(ClassTree clazz) { this.children.forEach(each -> each.begin(clazz)); diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/MutationInterceptor.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/MutationInterceptor.java index bbfe0bba7..792094ddd 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/MutationInterceptor.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/MutationInterceptor.java @@ -3,6 +3,7 @@ import java.util.Collection; import org.pitest.bytecode.analysis.ClassTree; +import org.pitest.classpath.CodeSource; import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails; @@ -10,6 +11,14 @@ public interface MutationInterceptor { InterceptorType type(); + /** + * Called once per instance prior to intercepting + * @param code Current code source + */ + default void initialise(CodeSource code) { + // noop + } + void begin(ClassTree clazz); Collection intercept(Collection mutations, Mutater m); diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java index 786984cfe..befb7d349 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/MutationCoverage.java @@ -358,6 +358,8 @@ private List buildMutationTests(CoverageDatabase coverageD .createInterceptor(this.data, coverageData, bas) .filter(interceptorFilter); + interceptor.initialise(this.code); + final MutationSource source = new MutationSource(mutationConfig, testPrioritiser, bas, interceptor); final MutationAnalyser analyser = new IncrementalAnalyser( diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java index d2bee41eb..bba98d2d2 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/build/CompoundMutationInterceptorTest.java @@ -6,6 +6,9 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.pitest.bytecode.analysis.ClassTree; +import org.pitest.classpath.CodeSource; +import org.pitest.classpath.DefaultCodeSource; +import org.pitest.classpath.ProjectClassPaths; import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails; @@ -51,6 +54,16 @@ public void setUp() { when(this.reportChild.type()).thenReturn(InterceptorType.REPORT); } + @Test + public void initialisesAllChildren() { + this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild, this.filterChild)); + final CodeSource source = new DefaultCodeSource(new ProjectClassPaths(null, null,null)); + + this.testee.initialise(source); + verify(this.modifyChild).initialise(source); + verify(this.filterChild).initialise(source); + } + @Test public void shouldNotifyAllChildrenOfNewClass() { this.testee = new CompoundMutationInterceptor(Arrays.asList(this.modifyChild,this.filterChild)); diff --git a/pitest-entry/src/test/java/org/pitest/verifier/interceptors/Verifier.java b/pitest-entry/src/test/java/org/pitest/verifier/interceptors/Verifier.java index 2b79a458c..0c53951cc 100644 --- a/pitest-entry/src/test/java/org/pitest/verifier/interceptors/Verifier.java +++ b/pitest-entry/src/test/java/org/pitest/verifier/interceptors/Verifier.java @@ -3,6 +3,8 @@ import org.objectweb.asm.tree.AbstractInsnNode; import org.pitest.bytecode.analysis.ClassTree; import org.pitest.classinfo.ClassByteArraySource; +import org.pitest.classinfo.Repository; +import org.pitest.classpath.DefaultCodeSource; import org.pitest.mutationtest.build.MutationInterceptor; import org.pitest.mutationtest.engine.Mutater; import org.pitest.mutationtest.engine.MutationDetails;