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>`.
|
Requires the Jenkins :jenkins-wiki:`JaCoCo Plugin <JaCoCo+Plugin>`.
|
||||||
|
|
||||||
:arg str exec-pattern: This is a file name pattern that can be used to
|
:arg str exec-pattern: This is a file name pattern that can be used to
|
||||||
locate the jacoco report files (default
|
locate the jacoco report files (default '**/**.exec')
|
||||||
``**/**.exec``)
|
|
||||||
:arg str class-pattern: This is a file name pattern that can be used
|
: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
|
: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
|
: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
|
: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
|
: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:
|
:arg dict targets:
|
||||||
|
|
||||||
:targets: (instruction, branch, complexity, line, method, class)
|
:targets: (instruction, branch, complexity, line, method, class)
|
||||||
@ -979,26 +978,30 @@ def jacoco(registry, xml_parent, data):
|
|||||||
* **healthy** (`int`): Healthy threshold (default 0)
|
* **healthy** (`int`): Healthy threshold (default 0)
|
||||||
* **unhealthy** (`int`): Unhealthy 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
|
:language: yaml
|
||||||
"""
|
"""
|
||||||
|
|
||||||
jacoco = XML.SubElement(xml_parent,
|
jacoco = XML.SubElement(xml_parent,
|
||||||
'hudson.plugins.jacoco.JacocoPublisher')
|
'hudson.plugins.jacoco.JacocoPublisher')
|
||||||
XML.SubElement(jacoco, 'execPattern').text = data.get(
|
jacoco.set('plugin', 'jacoco')
|
||||||
'exec-pattern', '**/**.exec')
|
|
||||||
XML.SubElement(jacoco, 'classPattern').text = data.get(
|
mappings = [
|
||||||
'class-pattern', '**/classes')
|
('exec-pattern', 'execPattern', '**/**.exec'),
|
||||||
XML.SubElement(jacoco, 'sourcePattern').text = data.get(
|
('class-pattern', 'classPattern', '**/classes'),
|
||||||
'source-pattern', '**/src/main/java')
|
('source-pattern', 'sourcePattern', '**/src/main/java'),
|
||||||
XML.SubElement(jacoco, 'changeBuildStatus').text = data.get(
|
('update-build-status', 'changeBuildStatus', False),
|
||||||
'update-build-status', False)
|
('inclusion-pattern', 'inclusionPattern', ''),
|
||||||
XML.SubElement(jacoco, 'inclusionPattern').text = data.get(
|
('exclusion-pattern', 'exclusionPattern', ''),
|
||||||
'inclusion-pattern', '')
|
]
|
||||||
XML.SubElement(jacoco, 'exclusionPattern').text = data.get(
|
helpers.convert_mapping_to_xml(jacoco, data, mappings, fail_required=True)
|
||||||
'exclusion-pattern', '')
|
|
||||||
|
|
||||||
itemsList = ['instruction',
|
itemsList = ['instruction',
|
||||||
'branch',
|
'branch',
|
||||||
@ -1007,21 +1010,28 @@ def jacoco(registry, xml_parent, data):
|
|||||||
'method',
|
'method',
|
||||||
'class']
|
'class']
|
||||||
|
|
||||||
for item in data['targets']:
|
if 'targets' in data:
|
||||||
item_name = next(iter(item.keys()))
|
for item in data['targets']:
|
||||||
if item_name not in itemsList:
|
item_name = next(iter(item.keys()))
|
||||||
raise JenkinsJobsException("item entered is not valid must be "
|
if item_name not in itemsList:
|
||||||
"one of: %s" % ",".join(itemsList))
|
raise InvalidAttributeError('targets', item_name, itemsList)
|
||||||
item_values = item.get(item_name, 0)
|
|
||||||
|
|
||||||
XML.SubElement(jacoco,
|
item_values = item[item_name]
|
||||||
'maximum' +
|
if item_values:
|
||||||
item_name.capitalize() +
|
XML.SubElement(jacoco,
|
||||||
'Coverage').text = str(item_values.get('healthy', 0))
|
'maximum' +
|
||||||
XML.SubElement(jacoco,
|
item_name.capitalize() +
|
||||||
'minimum' +
|
'Coverage').text = str(
|
||||||
item_name.capitalize() +
|
item_values.get('healthy', 0))
|
||||||
'Coverage').text = str(item_values.get('unhealthy', 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):
|
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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<project>
|
<project>
|
||||||
<publishers>
|
<publishers>
|
||||||
<hudson.plugins.jacoco.JacocoPublisher>
|
<hudson.plugins.jacoco.JacocoPublisher plugin="jacoco">
|
||||||
<execPattern>**/**.exec</execPattern>
|
<execPattern>**/**.exec</execPattern>
|
||||||
<classPattern>**/classes</classPattern>
|
<classPattern>**/classes</classPattern>
|
||||||
<sourcePattern>**/src/main/java</sourcePattern>
|
<sourcePattern>**/src/main/java</sourcePattern>
|
||||||
<changeBuildStatus/>
|
<changeBuildStatus>true</changeBuildStatus>
|
||||||
<inclusionPattern/>
|
<inclusionPattern/>
|
||||||
<exclusionPattern/>
|
<exclusionPattern/>
|
||||||
<maximumBranchCoverage>10</maximumBranchCoverage>
|
<maximumBranchCoverage>10</maximumBranchCoverage>
|
||||||
|
@ -3,7 +3,7 @@ publishers:
|
|||||||
exec-pattern: "**/**.exec"
|
exec-pattern: "**/**.exec"
|
||||||
class-pattern: "**/classes"
|
class-pattern: "**/classes"
|
||||||
source-pattern: "**/src/main/java"
|
source-pattern: "**/src/main/java"
|
||||||
status-update: true
|
update-build-status: true
|
||||||
targets:
|
targets:
|
||||||
- branch:
|
- branch:
|
||||||
healthy: 10
|
healthy: 10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user