-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1150 from hcoles/feature/results_interceptors
New extension points
- Loading branch information
Showing
38 changed files
with
586 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
pitest-entry/src/main/java/org/pitest/classpath/CodeSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.pitest.classpath; | ||
|
||
import org.pitest.plugin.ToolClasspathPlugin; | ||
|
||
public interface CodeSourceFactory extends ToolClasspathPlugin { | ||
CodeSource createCodeSource(ProjectClassPaths classPath); | ||
} |
85 changes: 85 additions & 0 deletions
85
pitest-entry/src/main/java/org/pitest/classpath/DefaultCodeSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package org.pitest.classpath; | ||
|
||
import org.pitest.bytecode.analysis.ClassTree; | ||
import org.pitest.classinfo.ClassInfo; | ||
import org.pitest.classinfo.ClassName; | ||
import org.pitest.classinfo.NameToClassInfo; | ||
import org.pitest.classinfo.Repository; | ||
import org.pitest.classinfo.TestToClassMapper; | ||
import org.pitest.functional.Streams; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class DefaultCodeSource implements CodeSource { | ||
private final ProjectClassPaths classPath; | ||
private final Repository classRepository; | ||
|
||
public DefaultCodeSource(final ProjectClassPaths classPath) { | ||
this(classPath, new Repository(new ClassPathByteArraySource( | ||
classPath.getClassPath()))); | ||
} | ||
|
||
DefaultCodeSource(final ProjectClassPaths classPath, | ||
final Repository classRepository) { | ||
this.classPath = classPath; | ||
this.classRepository = classRepository; | ||
} | ||
|
||
public Stream<ClassTree> codeTrees() { | ||
return this.classPath.code().stream() | ||
.map(c -> this.getBytes(c.asJavaName())) | ||
.filter(Optional::isPresent) | ||
.map(maybe -> ClassTree.fromBytes(maybe.get())); | ||
} | ||
|
||
public Set<ClassName> getCodeUnderTestNames() { | ||
return this.classPath.code().stream().collect(Collectors.toSet()); | ||
} | ||
|
||
public Stream<ClassTree> testTrees() { | ||
return this.classPath.test().stream() | ||
.map(c -> this.getBytes(c.asJavaName())) | ||
.filter(Optional::isPresent) | ||
.map(maybe -> ClassTree.fromBytes(maybe.get())) | ||
.filter(t -> !t.isAbstract()); | ||
} | ||
|
||
public ClassPath getClassPath() { | ||
return this.classPath.getClassPath(); | ||
} | ||
|
||
public Optional<ClassName> findTestee(final String className) { | ||
final TestToClassMapper mapper = new TestToClassMapper(this.classRepository); | ||
return mapper.findTestee(className); | ||
} | ||
|
||
public Collection<ClassInfo> getClassInfo(final Collection<ClassName> classes) { | ||
return classes.stream() | ||
.flatMap(nameToClassInfo()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public Optional<byte[]> fetchClassBytes(final ClassName clazz) { | ||
return this.classRepository.querySource(clazz); | ||
} | ||
|
||
@Override | ||
public Optional<ClassInfo> fetchClass(final ClassName clazz) { | ||
return this.classRepository.fetchClass(clazz); | ||
} | ||
|
||
private Function<ClassName, Stream<ClassInfo>> nameToClassInfo() { | ||
return new NameToClassInfo(this.classRepository) | ||
.andThen(Streams::fromOptional); | ||
} | ||
|
||
@Override | ||
public Optional<byte[]> getBytes(String clazz) { | ||
return fetchClassBytes(ClassName.fromString(clazz)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.