Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-31830] Added support for rcov publisher as part of the RubyM…
…etrics Reports Plugin
  • Loading branch information
v1v committed Dec 21, 2015
1 parent d03ebf3 commit d0d9d59
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 0 deletions.
@@ -0,0 +1,9 @@
job('example') {
publishers {
rcov {
reportDirectory('folder')
totalCoverage(80, 50, 0)
codeCoverage(80, 50, 0)
}
}
}
Expand Up @@ -1899,6 +1899,31 @@ class PublisherContext extends AbstractExtensibleContext {
}
}

/**
* Parses rcov html report files and shows it in Jenkins with a trend graph.
*
* @since 1.42
*/
@RequiresPlugin(id = 'rubyMetrics', minimumVersion = '1.6.3')
void rcov(@DslContext(RcovContext) Closure closure) {
RcovContext context = new RcovContext()
ContextHelper.executeInContext(closure, context)

publisherNodes << new NodeBuilder().'hudson.plugins.rubyMetrics.rcov.RcovPublisher' {
reportDir(context.reportDirectory ?: '')
targets {
context.entries.each { String key, RcovContext.MetricEntry entry ->
'hudson.plugins.rubyMetrics.rcov.model.MetricTarget' {
metric(key)
healthy(entry.healthy.toString())
unhealthy(entry.unhealthy.toString())
unstable(entry.unstable.toString())
}
}
}
}
}

@SuppressWarnings('NoDef')
private static addStaticAnalysisContext(def nodeBuilder, StaticAnalysisContext context) {
nodeBuilder.with {
Expand Down
@@ -0,0 +1,51 @@
package javaposse.jobdsl.dsl.helpers.publisher

import groovy.transform.Canonical
import javaposse.jobdsl.dsl.Context

class RcovContext implements Context {
private static final VALID_TYPES = ['TOTAL_COVERAGE', 'CODE_COVERAGE']

final Map<String, MetricEntry> entries = VALID_TYPES.collectEntries { [it, createEntry()] }
String reportDirectory

/**
* Resolves class names to source file names.
*/
void reportDirectory(String reportDirectory) {
this.reportDirectory = reportDirectory
}

/**
* Configure health reporting thresholds for the total coverage.
*/
void totalCoverage(int healthy, int unhealthy, int unstable) {
addEntry('TOTAL_COVERAGE', healthy, unhealthy, unstable)
}

/**
* Configure health reporting thresholds for the code coverage.
*/
void codeCoverage(int healthy, int unhealthy, int unstable) {
addEntry('CODE_COVERAGE', healthy, unhealthy, unstable)
}

private static createEntry(int healthy = 80, int unhealthy = 0, int unstable = 0) {
new MetricEntry(
healthy: healthy ?: 80,
unhealthy: unhealthy ?: 0,
unstable: unstable ?: 0,
)
}

private addEntry(String key, int healthy, int unhealthy, int unstable) {
entries[key] = createEntry(healthy, unhealthy, unstable)
}

@Canonical
static class MetricEntry {
int healthy
int unhealthy
int unstable
}
}
Expand Up @@ -5792,4 +5792,75 @@ class PublisherContextSpec extends Specification {
where:
value << [true, false]
}

def 'call rcov with no options'() {
when:
context.rcov {
}

then:
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'hudson.plugins.rubyMetrics.rcov.RcovPublisher'
children().size() == 2
reportDir[0].value().empty
with(targets[0]) {
children().size() == 2
with(children()[0]) {
name() == 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget'
children().size() == 4
metric[0].value() == 'TOTAL_COVERAGE'
healthy[0].value() == '80'
unhealthy[0].value() == '0'
unstable[0].value() == '0'
}
with(children()[1]) {
name() == 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget'
children().size() == 4
metric[0].value() == 'CODE_COVERAGE'
healthy[0].value() == '80'
unhealthy[0].value() == '0'
unstable[0].value() == '0'
}
}
}
1 * jobManagement.requireMinimumPluginVersion('rubyMetrics', '1.6.3')
}

def 'call rcov with all options'() {
when:
context.rcov {
reportDirectory('folder')
totalCoverage(90, 50, 10)
codeCoverage(91, 51, 11)
}

then:
context.publisherNodes.size() == 1
with(context.publisherNodes[0]) {
name() == 'hudson.plugins.rubyMetrics.rcov.RcovPublisher'
children().size() == 2
reportDir[0].value() == 'folder'
with(targets[0]) {
children().size() == 2
with(children()[0]) {
name() == 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget'
children().size() == 4
metric[0].value() == 'TOTAL_COVERAGE'
healthy[0].value() == '90'
unhealthy[0].value() == '50'
unstable[0].value() == '10'
}
with(children()[1]) {
name() == 'hudson.plugins.rubyMetrics.rcov.model.MetricTarget'
children().size() == 4
metric[0].value() == 'CODE_COVERAGE'
healthy[0].value() == '91'
unhealthy[0].value() == '51'
unstable[0].value() == '11'
}
}
}
1 * jobManagement.requireMinimumPluginVersion('rubyMetrics', '1.6.3')
}
}

0 comments on commit d0d9d59

Please sign in to comment.