-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration options for report-path and message #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,15 @@ class PrintCoveragePlugin implements Plugin<Project> { | |
} | ||
|
||
def extension = target.extensions.create('printcoverage', PrintCoverageExtension, target) | ||
|
||
Task task = target.tasks.create('printCoverage', PrintCoverageTask) { | ||
coverageType = extension.coverageType | ||
reportFile = extension.reportFile | ||
message = extension.message | ||
} | ||
|
||
target.ext.PrintCoverage = PrintCoverageTask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allows to reference the PrintCoverageTask in build-scripts without having to use the fully qualified class name: |
||
|
||
task.dependsOn(target.tasks.withType(JacocoReport)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,23 @@ import org.gradle.api.DefaultTask | |
import org.gradle.api.GradleException | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.Optional | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
class PrintCoverageTask extends DefaultTask { | ||
|
||
@Input | ||
@Optional | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional inputs with defaults handled in the task to allow custom task definitions extending this task with minimal configuration |
||
final Property<String> coverageType = project.objects.property(String) | ||
|
||
@Input | ||
@Optional | ||
final Property<String> reportFile = project.objects.property(String) | ||
|
||
@Input | ||
@Optional | ||
final Property<String> message = project.objects.property(String) | ||
|
||
PrintCoverageTask() { | ||
setDescription('Prints code coverage for gitlab.') | ||
setGroup('coverage') | ||
|
@@ -22,16 +32,20 @@ class PrintCoverageTask extends DefaultTask { | |
slurper.setFeature('http://apache.org/xml/features/disallow-doctype-decl', false) | ||
slurper.setFeature('http://apache.org/xml/features/nonvalidating/load-external-dtd', false) | ||
|
||
File jacocoTestReport = new File("${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml") | ||
File jacocoTestReport = new File(reportFile.getOrElse("${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml")) | ||
if (!jacocoTestReport.exists()) { | ||
logger.error('Jacoco test report is missing.') | ||
throw new GradleException('Jacoco test report is missing.') | ||
} | ||
|
||
def finalCoverageType = coverageType.getOrElse('INSTRUCTION') | ||
def finalMessage = message.getOrElse('Coverage: %s%%') | ||
def report = slurper.parse(jacocoTestReport) | ||
double missed = report.counter.find { it.'@type' == coverageType.get() }[email protected]() | ||
double covered = report.counter.find { it.'@type' == coverageType.get() }[email protected]() | ||
|
||
double missed = report.counter.find { it.'@type' == finalCoverageType }[email protected]() | ||
double covered = report.counter.find { it.'@type' == finalCoverageType }[email protected]() | ||
def coverage = (100 / (missed + covered) * covered).round(2) | ||
println 'Coverage: ' + coverage + '%' | ||
|
||
println String.format(finalMessage, coverage) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults are now handled directly in the task to allow custom task definitions with minimal configuration