|
| 1 | +// Copyright 2020 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package com.google.firebase.gradle.plugins.measurement.coverage |
| 16 | + |
| 17 | +import com.google.firebase.gradle.plugins.FirebaseLibraryExtension |
| 18 | +import com.google.firebase.gradle.plugins.FirebaseLibraryPlugin |
| 19 | +import org.gradle.api.Plugin |
| 20 | +import org.gradle.api.Project |
| 21 | +import org.gradle.api.tasks.testing.Test |
| 22 | +import org.gradle.testing.jacoco.tasks.JacocoReport |
| 23 | + |
| 24 | +class CheckCoveragePlugin implements Plugin<Project> { |
| 25 | + |
| 26 | + @Override |
| 27 | + void apply(Project project) { |
| 28 | + project.configure(project.subprojects) { sub -> |
| 29 | + apply plugin: 'jacoco' |
| 30 | + |
| 31 | + def reportsDir = "${buildDir}/reports/jacoco" |
| 32 | + jacoco { |
| 33 | + toolVersion = '0.8.5' |
| 34 | + reportsDir = reportsDir |
| 35 | + } |
| 36 | + |
| 37 | + plugins.withType(FirebaseLibraryPlugin.class) { |
| 38 | + |
| 39 | + sub.tasks.withType(Test) { |
| 40 | + jacoco { |
| 41 | + excludes = ['jdk.internal.*'] |
| 42 | + includeNoLocationClasses = true |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + sub.task('checkCoverage', type: JacocoReport) { |
| 47 | + dependsOn 'check' |
| 48 | + description 'Generates JaCoCo check coverage report.' |
| 49 | + group 'verification' |
| 50 | + |
| 51 | + def excludes = [ |
| 52 | + '**/R.class', |
| 53 | + '**/R$*.class', |
| 54 | + '**/BuildConfig.*', |
| 55 | + '**/proto/**', |
| 56 | + '**Manifest*.*' |
| 57 | + ] |
| 58 | + classDirectories = files([ |
| 59 | + fileTree(dir: "$buildDir/intermediates/javac/release", excludes: excludes), |
| 60 | + fileTree(dir: "$buildDir/tmp/kotlin-classes/release", excludes: excludes), |
| 61 | + ]) |
| 62 | + sourceDirectories = files(['src/main/java', 'src/main/kotlin']) |
| 63 | + executionData = fileTree(dir: "$buildDir", includes: ['jacoco/*.exec']) |
| 64 | + |
| 65 | + def firebaseLibrary = sub.extensions.getByType(FirebaseLibraryExtension.class) |
| 66 | + def artifactId = firebaseLibrary.artifactId.get() |
| 67 | + reports { |
| 68 | + html.destination file("${reportsDir}/${artifactId}/html") |
| 69 | + xml { |
| 70 | + enabled true |
| 71 | + destination file("${reportsDir}/${artifactId}.xml") |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + outputs.upToDateWhen { false } |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments