Merge "cloverphp publisher"

This commit is contained in:
Jenkins 2013-12-12 04:40:00 +00:00 committed by Gerrit Code Review
commit 0007488a41
8 changed files with 194 additions and 0 deletions

View File

@ -248,6 +248,112 @@ def trigger(parser, xml_parent, data):
tcolor.text = thresholds[threshold]['color']
def cloverphp(parser, xml_parent, data):
"""yaml: cloverphp
Capture code coverage reports from PHPUnit
Requires the Jenkins `Clover PHP Plugin.
<https://wiki.jenkins-ci.org/display/JENKINS/Clover+PHP+Plugin>`_
Your job definition should pass to PHPUnit the --coverage-clover option
pointing to a file in the workspace (ex: clover-coverage.xml). The filename
has to be filled in the `xml-location` field.
:arg str xml-location: Path to the coverage XML file generated by PHPUnit
using --coverage-clover. Relative to workspace. (required)
:arg dict html: When existent, whether the plugin should generate a HTML
report. Note that PHPUnit already provide a HTML report via its
--cover-html option which can be set in your builder (optional):
* **dir** (str): Directory where HTML report will be generated relative
to workspace. (required in `html` dict).
* **archive** (bool): Whether to archive HTML reports (default True).
:arg list metric-targets: List of metric targets to reach, must be one of
**healthy**, **unhealthy** and **failing**. Each metric target can takes
two parameters:
* **method** Target for method coverage
* **statement** Target for statements coverage
Whenever a metric target is not filled in, the Jenkins plugin can fill in
defaults for you (as of v0.3.3 of the plugin the healthy target will have
method: 70 and statement: 80 if both are left empty). Jenkins Job Builder
will mimic that feature to ensure clean configuration diff.
Minimal example:
.. literalinclude:: ../../tests/publishers/fixtures/cloverphp001.yaml
Full example:
.. literalinclude:: ../../tests/publishers/fixtures/cloverphp002.yaml
"""
cloverphp = XML.SubElement(
xml_parent,
'org.jenkinsci.plugins.cloverphp.CloverPHPPublisher')
# The plugin requires clover XML file to parse
if 'xml-location' not in data:
raise JenkinsJobsException('xml-location must be set')
# Whether HTML publishing has been checked
html_publish = False
# By default, disableArchiving = false. Note that we use
# reversed logic.
html_archive = True
if 'html' in data:
html_publish = True
html_dir = data['html'].get('dir', None)
html_archive = data['html'].get('archive', html_archive)
if html_dir is None:
# No point in going further, the plugin would not work
raise JenkinsJobsException('htmldir is required in a html block')
XML.SubElement(cloverphp, 'publishHtmlReport').text = \
str(html_publish).lower()
if html_publish:
XML.SubElement(cloverphp, 'reportDir').text = html_dir
XML.SubElement(cloverphp, 'xmlLocation').text = data.get('xml-location')
XML.SubElement(cloverphp, 'disableArchiving').text = \
str(not html_archive).lower()
# Handle targets
# Plugin v0.3.3 will fill defaults for us whenever healthy targets are both
# blanks.
default_metrics = {
'healthy': {'method': 70, 'statement': 80}
}
allowed_metrics = ['healthy', 'unhealthy', 'failing']
metrics = data.get('metric-targets', [])
# list of dicts to dict
metrics = dict(kv for m in metrics for kv in m.iteritems())
# Populate defaults whenever nothing has been filled by user.
for default in default_metrics.keys():
if metrics.get(default, None) is None:
metrics[default] = default_metrics[default]
# The plugin would at least define empty targets so make sure
# we output them all in the XML regardless of what the user
# has or has not entered.
for target in allowed_metrics:
cur_target = XML.SubElement(cloverphp, target + 'Target')
for t_type in ['method', 'statement']:
val = metrics.get(target, {}).get(t_type)
if val is None or type(val) != int:
continue
if val < 0 or val > 100:
raise JenkinsJobsException(
"Publisher cloverphp metric target %s:%s = %s "
"is not in valid range 0-100." % (target, t_type, val))
XML.SubElement(cur_target, t_type + 'Coverage').text = str(val)
def coverage(parser, xml_parent, data):
"""yaml: coverage
WARNING: The coverage function is deprecated. Instead, use the

View File

@ -126,6 +126,7 @@ setuptools.setup(
'checkstyle=jenkins_jobs.modules.publishers:checkstyle',
'cifs=jenkins_jobs.modules.publishers:cifs',
'claim-build=jenkins_jobs.modules.publishers:claim_build',
'cloverphp=jenkins_jobs.modules.publishers:cloverphp',
'cobertura=jenkins_jobs.modules.publishers:cobertura',
'copy-to-master=jenkins_jobs.modules.publishers:copy_to_master',
'coverage=jenkins_jobs.modules.publishers:coverage',

View File

@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
<publishHtmlReport>false</publishHtmlReport>
<xmlLocation>build/clover.xml</xmlLocation>
<disableArchiving>false</disableArchiving>
<healthyTarget>
<methodCoverage>70</methodCoverage>
<statementCoverage>80</statementCoverage>
</healthyTarget>
<unhealthyTarget/>
<failingTarget/>
</org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
</publishers>
</project>

View File

@ -0,0 +1,4 @@
# Test for the defaults, only xml-location is required
publishers:
- cloverphp:
xml-location: 'build/clover.xml'

View File

@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
<publishHtmlReport>true</publishHtmlReport>
<reportDir>html</reportDir>
<xmlLocation>build/clover.xml</xmlLocation>
<disableArchiving>true</disableArchiving>
<healthyTarget>
<methodCoverage>80</methodCoverage>
<statementCoverage>90</statementCoverage>
</healthyTarget>
<unhealthyTarget>
<methodCoverage>40</methodCoverage>
<statementCoverage>50</statementCoverage>
</unhealthyTarget>
<failingTarget>
<methodCoverage>10</methodCoverage>
<statementCoverage>20</statementCoverage>
</failingTarget>
</org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
</publishers>
</project>

View File

@ -0,0 +1,17 @@
# Exercise all options with non defaults values
publishers:
- cloverphp:
xml-location: 'build/clover.xml'
html:
dir: 'html'
archive: false
metric-targets:
- healthy:
method: 80
statement: 90
- unhealthy:
method: 40
statement: 50
- failing:
method: 10
statement: 20

View File

@ -0,0 +1,17 @@
<?xml version="1.0" ?>
<project>
<publishers>
<org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
<publishHtmlReport>false</publishHtmlReport>
<xmlLocation>build/clover.xml</xmlLocation>
<disableArchiving>false</disableArchiving>
<healthyTarget>
<methodCoverage>77</methodCoverage>
</healthyTarget>
<unhealthyTarget>
<statementCoverage>88</statementCoverage>
</unhealthyTarget>
<failingTarget/>
</org.jenkinsci.plugins.cloverphp.CloverPHPPublisher>
</publishers>
</project>

View File

@ -0,0 +1,10 @@
# Specify only method or statement
# Does not specify failling
publishers:
- cloverphp:
xml-location: 'build/clover.xml'
metric-targets:
- healthy:
method: 77
- unhealthy:
statement: 88