Merge "Update JaCoCo plugin"

This commit is contained in:
Jenkins 2017-03-28 19:03:14 +00:00 committed by Gerrit Code Review
commit 2260a3006b
7 changed files with 115 additions and 38 deletions

View File

@ -1006,18 +1006,17 @@ def jacoco(registry, xml_parent, data):
Requires the Jenkins :jenkins-wiki:`JaCoCo Plugin <JaCoCo+Plugin>`.
:arg str exec-pattern: This is a file name pattern that can be used to
locate the jacoco report files (default
``**/**.exec``)
locate the jacoco report files (default '**/**.exec')
:arg str class-pattern: This is a file name pattern that can be used
to locate class files (default ``**/classes``)
to locate class files (default '**/classes')
:arg str source-pattern: This is a file name pattern that can be used
to locate source files (default ``**/src/main/java``)
to locate source files (default '**/src/main/java')
:arg bool update-build-status: Update the build according to the results
(default false)
(default false)
:arg str inclusion-pattern: This is a file name pattern that can be used
to include certain class files (optional)
to include certain class files (default '')
:arg str exclusion-pattern: This is a file name pattern that can be used
to exclude certain class files (optional)
to exclude certain class files (default '')
:arg dict targets:
:targets: (instruction, branch, complexity, line, method, class)
@ -1025,26 +1024,30 @@ def jacoco(registry, xml_parent, data):
* **healthy** (`int`): Healthy threshold (default 0)
* **unhealthy** (`int`): Unhealthy threshold (default 0)
Example:
Minimal Example:
.. literalinclude:: /../../tests/publishers/fixtures/jacoco001.yaml
.. literalinclude:: /../../tests/publishers/fixtures/jacoco-minimal.yaml
:language: yaml
Full Example:
.. literalinclude:: /../../tests/publishers/fixtures/jacoco-complete.yaml
:language: yaml
"""
jacoco = XML.SubElement(xml_parent,
'hudson.plugins.jacoco.JacocoPublisher')
XML.SubElement(jacoco, 'execPattern').text = data.get(
'exec-pattern', '**/**.exec')
XML.SubElement(jacoco, 'classPattern').text = data.get(
'class-pattern', '**/classes')
XML.SubElement(jacoco, 'sourcePattern').text = data.get(
'source-pattern', '**/src/main/java')
XML.SubElement(jacoco, 'changeBuildStatus').text = data.get(
'update-build-status', False)
XML.SubElement(jacoco, 'inclusionPattern').text = data.get(
'inclusion-pattern', '')
XML.SubElement(jacoco, 'exclusionPattern').text = data.get(
'exclusion-pattern', '')
jacoco.set('plugin', 'jacoco')
mappings = [
('exec-pattern', 'execPattern', '**/**.exec'),
('class-pattern', 'classPattern', '**/classes'),
('source-pattern', 'sourcePattern', '**/src/main/java'),
('update-build-status', 'changeBuildStatus', False),
('inclusion-pattern', 'inclusionPattern', ''),
('exclusion-pattern', 'exclusionPattern', ''),
]
helpers.convert_mapping_to_xml(jacoco, data, mappings, fail_required=True)
itemsList = ['instruction',
'branch',
@ -1053,21 +1056,28 @@ def jacoco(registry, xml_parent, data):
'method',
'class']
for item in data['targets']:
item_name = next(iter(item.keys()))
if item_name not in itemsList:
raise JenkinsJobsException("item entered is not valid must be "
"one of: %s" % ",".join(itemsList))
item_values = item.get(item_name, 0)
if 'targets' in data:
for item in data['targets']:
item_name = next(iter(item.keys()))
if item_name not in itemsList:
raise InvalidAttributeError('targets', item_name, itemsList)
XML.SubElement(jacoco,
'maximum' +
item_name.capitalize() +
'Coverage').text = str(item_values.get('healthy', 0))
XML.SubElement(jacoco,
'minimum' +
item_name.capitalize() +
'Coverage').text = str(item_values.get('unhealthy', 0))
item_values = item[item_name]
if item_values:
XML.SubElement(jacoco,
'maximum' +
item_name.capitalize() +
'Coverage').text = str(
item_values.get('healthy', 0))
XML.SubElement(jacoco,
'minimum' +
item_name.capitalize() +
'Coverage').text = str(
item_values.get('unhealthy', 0))
else:
raise MissingAttributeError(
['healthy', 'unhealthy'],
'publishers.jacoco.targets.' + item_name)
def ftp(registry, xml_parent, data):

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.jacoco.JacocoPublisher plugin="jacoco">
<execPattern>**/**.exec</execPattern>
<classPattern>**/classes</classPattern>
<sourcePattern>**/src/main/java</sourcePattern>
<changeBuildStatus>true</changeBuildStatus>
<inclusionPattern>**/*.class</inclusionPattern>
<exclusionPattern>**/*Test*.class</exclusionPattern>
<maximumInstructionCoverage>7</maximumInstructionCoverage>
<minimumInstructionCoverage>1</minimumInstructionCoverage>
<maximumBranchCoverage>8</maximumBranchCoverage>
<minimumBranchCoverage>2</minimumBranchCoverage>
<maximumComplexityCoverage>9</maximumComplexityCoverage>
<minimumComplexityCoverage>3</minimumComplexityCoverage>
<maximumLineCoverage>10</maximumLineCoverage>
<minimumLineCoverage>4</minimumLineCoverage>
<maximumMethodCoverage>11</maximumMethodCoverage>
<minimumMethodCoverage>5</minimumMethodCoverage>
<maximumClassCoverage>12</maximumClassCoverage>
<minimumClassCoverage>6</minimumClassCoverage>
</hudson.plugins.jacoco.JacocoPublisher>
</publishers>
</project>

View File

@ -0,0 +1,27 @@
publishers:
- jacoco:
exec-pattern: '**/**.exec'
class-pattern: '**/classes'
source-pattern: '**/src/main/java'
update-build-status: true
inclusion-pattern: '**/*.class'
exclusion-pattern: '**/*Test*.class'
targets:
- instruction:
healthy: 7
unhealthy: 1
- branch:
healthy: 8
unhealthy: 2
- complexity:
healthy: 9
unhealthy: 3
- line:
healthy: 10
unhealthy: 4
- method:
healthy: 11
unhealthy: 5
- class:
healthy: 12
unhealthy: 6

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.jacoco.JacocoPublisher plugin="jacoco">
<execPattern>**/**.exec</execPattern>
<classPattern>**/classes</classPattern>
<sourcePattern>**/src/main/java</sourcePattern>
<changeBuildStatus>false</changeBuildStatus>
<inclusionPattern/>
<exclusionPattern/>
</hudson.plugins.jacoco.JacocoPublisher>
</publishers>
</project>

View File

@ -0,0 +1,2 @@
publishers:
- jacoco

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<publishers>
<hudson.plugins.jacoco.JacocoPublisher>
<hudson.plugins.jacoco.JacocoPublisher plugin="jacoco">
<execPattern>**/**.exec</execPattern>
<classPattern>**/classes</classPattern>
<sourcePattern>**/src/main/java</sourcePattern>
<changeBuildStatus/>
<changeBuildStatus>true</changeBuildStatus>
<inclusionPattern/>
<exclusionPattern/>
<maximumBranchCoverage>10</maximumBranchCoverage>

View File

@ -3,7 +3,7 @@ publishers:
exec-pattern: "**/**.exec"
class-pattern: "**/classes"
source-pattern: "**/src/main/java"
status-update: true
update-build-status: true
targets:
- branch:
healthy: 10