Update JaCoCo plugin
- update JaCoCo plugin to use convert_mapping_to_xml - fix status-update to update-build-status - add minimal and full test Change-Id: Iff936c93544416ab7759ccfabb7e284fc99e8e7c Signed-off-by: Kien Ha <kienha9922@gmail.com> Signed-off-by: Ryo Tagami <rtagami@airstrip.jp>
This commit is contained in:
parent
7e3edde3dc
commit
6b938fbd9d
@ -960,18 +960,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)
|
||||
@ -979,26 +978,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',
|
||||
@ -1007,21 +1010,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):
|
||||
|
25
tests/publishers/fixtures/jacoco-complete.xml
Normal file
25
tests/publishers/fixtures/jacoco-complete.xml
Normal 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>
|
27
tests/publishers/fixtures/jacoco-complete.yaml
Normal file
27
tests/publishers/fixtures/jacoco-complete.yaml
Normal 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
|
13
tests/publishers/fixtures/jacoco-minimal.xml
Normal file
13
tests/publishers/fixtures/jacoco-minimal.xml
Normal 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>
|
2
tests/publishers/fixtures/jacoco-minimal.yaml
Normal file
2
tests/publishers/fixtures/jacoco-minimal.yaml
Normal file
@ -0,0 +1,2 @@
|
||||
publishers:
|
||||
- jacoco
|
@ -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>
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user