org.pitest.aggregate.CodeSourceAggregator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pitest-aggregator Show documentation
Show all versions of pitest-aggregator Show documentation
Aggregates the output of report XML documents into a new combined HTML report
package org.pitest.aggregate;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.ClassFilter;
import org.pitest.classpath.ClassPath;
import org.pitest.classpath.ClassPathRoot;
import org.pitest.classpath.CodeSource;
import org.pitest.classpath.DirectoryClassPathRoot;
import org.pitest.classpath.PathFilter;
import org.pitest.classpath.ProjectClassPaths;
import org.pitest.functional.FCollection;
import org.pitest.functional.prelude.Prelude;
import org.pitest.mutationtest.config.DefaultCodePathPredicate;
import org.pitest.mutationtest.config.DefaultDependencyPathPredicate;
import org.pitest.mutationtest.config.SettingsFactory;
import org.pitest.util.Glob;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.function.Function;
import java.util.function.Predicate;
class CodeSourceAggregator {
private final Collection compiledCodeDirectories;
private final SettingsFactory settings;
CodeSourceAggregator(SettingsFactory settings, Collection compiledCodeDirectories) {
this.settings = settings;
this.compiledCodeDirectories = Collections.unmodifiableCollection(compiledCodeDirectories);
}
public CodeSource createCodeSource() {
return settings.createCodeSource(createProjectClassPaths());
}
public ProjectClassPaths createProjectClassPaths() {
final ClassPath classPath = new ClassPath(this.compiledCodeDirectories);
final Predicate classPredicate = createClassPredicate();
final Predicate pathPredicate = new DefaultCodePathPredicate();
return new ProjectClassPaths(classPath, new ClassFilter(classPredicate, classPredicate),
new PathFilter(pathPredicate, Prelude.not(new DefaultDependencyPathPredicate())));
}
private Predicate createClassPredicate() {
final Collection classes = new HashSet<>();
for (final File buildOutputDirectory : this.compiledCodeDirectories) {
if (buildOutputDirectory.exists()) {
final DirectoryClassPathRoot dcRoot = new DirectoryClassPathRoot(buildOutputDirectory);
classes.addAll(FCollection.map(dcRoot.classNames(), toPredicate()));
}
}
return Prelude.or(FCollection.map(classes, Glob.toGlobPredicate()));
}
private Function toPredicate() {
return a -> ClassName.fromString(a).getPackage().asJavaName() + ".*";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy