Skip to content

Commit

Permalink
Merge pull request #14 from arturdm/feature/add-xml-html-switches
Browse files Browse the repository at this point in the history
Add switches to enable/disable report types
  • Loading branch information
arturdm committed Nov 29, 2015
2 parents af4143f + 284f069 commit 29685fd
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* Make it possible to use the plugin with Java 7
* Provide default name patterns for classes to be excluded from report generation.
Currently, these patterns include *Android*, *Dagger 2* and *Butter Knife* generated classes.
* Allow user to toggle report generation for specified type
(e.g. `jacocoAndroidUnitTestReport { csv.enabled true }`).

## Version 0.1.0 *(2015-09-13)*
* Initial release
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ publishing {
plugin(MavenPublication) {
from components.java

artifact sourcesJar {
classifier "sources"
}
artifact sourcesJar
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ class JacocoAndroidPlugin implements Plugin<ProjectInternal> {
reportTask.classDirectories =
project.fileTree(dir: classesDir, excludes: project.jacocoAndroidUnitTestReport.excludes)
reportTask.reports {
xml.enabled true
csv.enabled project.jacocoAndroidUnitTestReport.csv.enabled
html.enabled project.jacocoAndroidUnitTestReport.html.enabled
xml.enabled project.jacocoAndroidUnitTestReport.xml.enabled
}
reportTask
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ class JacocoAndroidUnitTestReportExtension {
static Closure<Collection<String>> defaultExcludesFactory = { defaultExcludes }

Collection<String> excludes
ReportConfiguration csv
ReportConfiguration html
ReportConfiguration xml

JacocoAndroidUnitTestReportExtension(Collection<String> excludes) {
this.excludes = excludes
this.csv = new ReportConfiguration(false)
this.html = new ReportConfiguration(true)
this.xml = new ReportConfiguration(true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dicedmelon.gradle.jacoco.android

public class ReportConfiguration {

private boolean enabled

ReportConfiguration(boolean enabled) {
this.enabled = enabled
}

public boolean isEnabled() {
enabled
}

public void enabled(boolean enabled) {
this.enabled = enabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,46 @@ class JacocoAndroidPluginSpec extends Specification {
assertAllJacocoReportTasksExclude(['default exclude', 'some exclude'])
}

def assertAllJacocoReportTasksExclude(Collection<String> strings) {
project.tasks.withType(JacocoReport).each {
assert strings.containsAll(it.classDirectories.patternSet.excludes as Collection<String>)
@Unroll
def "should use extension's #report configuration"() {
when:
configureAsLibraryAndApplyPlugin(project)
project.jacocoAndroidUnitTestReport."$report".enabled true
project.evaluate()

then:
eachJacocoReportTask {
assert it.reports."$report".enabled == true
}

where:
report << ['csv', 'html', 'xml']
}

def "should apply which reports to build by default"() {
when:
configureAsLibraryAndApplyPlugin(project)
project.evaluate()

then:
eachJacocoReportTask {
assert it.reports."$report".enabled == enabled
}

where:
report | enabled
'csv' | false
'html' | true
'xml' | true
}

def eachJacocoReportTask(Closure closure) {
project.tasks.withType(JacocoReport).each(closure)
}

def assertAllJacocoReportTasksExclude(Collection<String> excludes) {
eachJacocoReportTask {
assert excludes.containsAll(it.classDirectories.patternSet.excludes as Collection<String>)
}
}
}

0 comments on commit 29685fd

Please sign in to comment.