Search in sources :

Example 1 with GenerateCodeCoverageReportStep

use of com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep in project buck by facebook.

the class TestRunning method getReportCommand.

/**
   * Returns the ShellCommand object that is supposed to generate a code coverage report from data
   * obtained during the test run. This method will also generate a set of source paths to the class
   * files tested during the test run.
   */
private static Step getReportCommand(ImmutableSet<JavaLibrary> rulesUnderTest, DefaultJavaPackageFinder defaultJavaPackageFinder, JavaRuntimeLauncher javaRuntimeLauncher, ProjectFilesystem filesystem, SourcePathResolver sourcePathResolver, SourcePathRuleFinder ruleFinder, Path outputDirectory, CoverageReportFormat format, String title, boolean useIntermediateClassesDir, Optional<String> coverageIncludes, Optional<String> coverageExcludes) {
    ImmutableSet.Builder<String> srcDirectories = ImmutableSet.builder();
    ImmutableSet.Builder<Path> pathsToJars = ImmutableSet.builder();
    // Add all source directories of java libraries that we are testing to -sourcepath.
    for (JavaLibrary rule : rulesUnderTest) {
        ImmutableSet<String> sourceFolderPath = getPathToSourceFolders(rule, sourcePathResolver, ruleFinder, defaultJavaPackageFinder);
        if (!sourceFolderPath.isEmpty()) {
            srcDirectories.addAll(sourceFolderPath);
        }
        Path classesItem = null;
        if (useIntermediateClassesDir) {
            classesItem = DefaultJavaLibrary.getClassesDir(rule.getBuildTarget(), filesystem);
        } else {
            SourcePath path = rule.getSourcePathToOutput();
            if (path != null) {
                classesItem = sourcePathResolver.getRelativePath(path);
            }
        }
        if (classesItem == null) {
            continue;
        }
        pathsToJars.add(classesItem);
    }
    return new GenerateCodeCoverageReportStep(javaRuntimeLauncher, filesystem, srcDirectories.build(), pathsToJars.build(), outputDirectory, format, title, coverageIncludes, coverageExcludes);
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) GenerateCodeCoverageReportStep(com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep)

Aggregations

DefaultJavaLibrary (com.facebook.buck.jvm.java.DefaultJavaLibrary)1 GenerateCodeCoverageReportStep (com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep)1 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)1 SourcePath (com.facebook.buck.rules.SourcePath)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Path (java.nio.file.Path)1