org.gradle.testing.jacoco.plugins.JacocoTaskExtension Java Examples

The following examples show how to use org.gradle.testing.jacoco.plugins.JacocoTaskExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransportPlugin.java    From transport with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void apply(Project project) {

    TransportPluginConfig extension = project.getExtensions().create("transport", TransportPluginConfig.class, project);

    project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
      project.getPlugins().apply(ScalaPlugin.class);
      project.getPlugins().apply(DistributionPlugin.class);
      project.getConfigurations().create(ShadowBasePlugin.getCONFIGURATION_NAME());

      JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
      SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(extension.mainSourceSetName);
      SourceSet testSourceSet = javaConvention.getSourceSets().getByName(extension.testSourceSetName);

      configureBaseSourceSets(project, mainSourceSet, testSourceSet);
      Defaults.DEFAULT_PLATFORMS.forEach(
          platform -> configurePlatform(project, platform, mainSourceSet, testSourceSet, extension.outputDirFile));
    });
    // Disable Jacoco for platform test tasks as it is known to cause issues with Presto and Hive tests
    project.getPlugins().withType(JacocoPlugin.class, (jacocoPlugin) -> {
        Defaults.DEFAULT_PLATFORMS.forEach(platform -> {
          project.getTasksByName(testTaskName(platform), true).forEach(task -> {
            JacocoTaskExtension jacocoExtension = task.getExtensions().findByType(JacocoTaskExtension.class);
            if (jacocoExtension != null) {
              jacocoExtension.setEnabled(false);
            }
          });
        });
    });
  }
 
Example #2
Source File: Coverage.java    From firebase-android-sdk with Apache License 2.0 4 votes vote down vote up
public static void apply(FirebaseLibraryExtension firebaseLibrary) {
  Project project = firebaseLibrary.project;
  project.apply(ImmutableMap.of("plugin", "jacoco"));
  File reportsDir = new File(project.getBuildDir(), "/reports/jacoco");
  JacocoPluginExtension jacoco = project.getExtensions().getByType(JacocoPluginExtension.class);

  jacoco.setToolVersion("0.8.5");
  jacoco.setReportsDir(reportsDir);
  project
      .getTasks()
      .withType(
          Test.class,
          test -> {
            JacocoTaskExtension testJacoco =
                test.getExtensions().getByType(JacocoTaskExtension.class);
            testJacoco.setExcludeClassLoaders(ImmutableList.of("jdk.internal.*"));
            testJacoco.setIncludeNoLocationClasses(true);
          });

  project
      .getTasks()
      .create(
          "checkCoverage",
          JacocoReport.class,
          task -> {
            task.dependsOn("check");
            task.setDescription("Generates JaCoCo check coverage report.");
            task.setGroup("verification");

            List<String> excludes =
                ImmutableList.<String>builder()
                    .add("**/R.class")
                    .add("**/R$*.class")
                    .add("**/BuildConfig.*")
                    .add("**/proto/**")
                    .add("**Manifest*.*")
                    .build();

            task.setClassDirectories(
                project.files(
                    project.fileTree(
                        ImmutableMap.of(
                            "dir",
                            project.getBuildDir() + "/intermediates/javac/release",
                            "excludes",
                            excludes)),
                    project.fileTree(
                        ImmutableMap.of(
                            "dir",
                            project.getBuildDir() + "/tmp/kotlin-classes/release",
                            "excludes",
                            excludes))));
            task.setSourceDirectories(project.files("src/main/java", "src/main/kotlin"));
            task.setExecutionData(
                project.fileTree(
                    ImmutableMap.of(
                        "dir",
                        project.getBuildDir(),
                        "includes",
                        ImmutableList.of("jacoco/*.exec"))));
            task.reports(
                reports -> {
                  reports
                      .getHtml()
                      .setDestination(
                          new File(reportsDir, firebaseLibrary.artifactId.get() + "/html"));
                  reports.getXml().setEnabled(true);
                  reports
                      .getXml()
                      .setDestination(
                          new File(reportsDir, firebaseLibrary.artifactId.get() + ".xml"));
                });
            task.getOutputs().upToDateWhen(t -> false);
          });
}