Add FindBugs plugin support

- Add reporters test module
- Move build_trends_publisher to helpers module now that there is
  multiple modules using the function

https://wiki.jenkins-ci.org/display/JENKINS/FindBugs+Plugin

Change-Id: Ic537279ff875589b41823f6f5324feb61ed7054e
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
This commit is contained in:
Thanh Ha 2015-02-07 02:22:09 -05:00
parent be8def7829
commit 849ca49eff
No known key found for this signature in database
GPG Key ID: B0CB27E00DA095AA
10 changed files with 300 additions and 66 deletions

View File

@ -1,5 +1,87 @@
# Copyright 2015 Thanh Ha
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import xml.etree.ElementTree as XML
from jenkins_jobs.errors import JenkinsJobsException
def build_trends_publisher(plugin_name, xml_element, data):
"""Helper to create various trend publishers.
"""
def append_thresholds(element, data, only_totals):
"""Appends the status thresholds.
"""
for status in ['unstable', 'failed']:
status_data = data.get(status, {})
limits = [
('total-all', 'TotalAll'),
('total-high', 'TotalHigh'),
('total-normal', 'TotalNormal'),
('total-low', 'TotalLow')]
if only_totals is False:
limits.extend([
('new-all', 'NewAll'),
('new-high', 'NewHigh'),
('new-normal', 'NewNormal'),
('new-low', 'NewLow')])
for key, tag_suffix in limits:
tag_name = status + tag_suffix
XML.SubElement(element, tag_name).text = str(
status_data.get(key, ''))
# Tuples containing: setting name, tag name, default value
settings = [
('healthy', 'healthy', ''),
('unhealthy', 'unHealthy', ''),
('health-threshold', 'thresholdLimit', 'low'),
('plugin-name', 'pluginName', plugin_name),
('default-encoding', 'defaultEncoding', ''),
('can-run-on-failed', 'canRunOnFailed', False),
('use-stable-build-as-reference', 'useStableBuildAsReference', False),
('use-delta-values', 'useDeltaValues', False),
('thresholds', 'thresholds', {}),
('should-detect-modules', 'shouldDetectModules', False),
('dont-compute-new', 'dontComputeNew', True),
('do-not-resolve-relative-paths', 'doNotResolveRelativePaths', False),
('pattern', 'pattern', '')]
thresholds = ['low', 'normal', 'high']
for key, tag_name, default in settings:
xml_config = XML.SubElement(xml_element, tag_name)
config_value = data.get(key, default)
if key == 'thresholds':
append_thresholds(
xml_config,
config_value,
data.get('dont-compute-new', True))
elif key == 'health-threshold' and config_value not in thresholds:
raise JenkinsJobsException("health-threshold must be one of %s" %
", ".join(thresholds))
else:
if isinstance(default, bool):
xml_config.text = str(config_value).lower()
else:
xml_config.text = str(config_value)
def config_file_provider_settings(xml_parent, data):
settings = {

View File

@ -29,6 +29,7 @@ the build is complete.
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.modules import hudson_model
from jenkins_jobs.modules.helpers import build_trends_publisher
from jenkins_jobs.errors import JenkinsJobsException
import logging
import sys
@ -3745,72 +3746,6 @@ def valgrind(parser, xml_parent, data):
data.get('publish-if-failed', False)).lower()
def build_trends_publisher(plugin_name, xml_element, data):
"""Helper to create various trend publishers.
"""
def append_thresholds(element, data, only_totals):
"""Appends the status thresholds.
"""
for status in ['unstable', 'failed']:
status_data = data.get(status, {})
limits = [
('total-all', 'TotalAll'),
('total-high', 'TotalHigh'),
('total-normal', 'TotalNormal'),
('total-low', 'TotalLow')]
if only_totals is False:
limits.extend([
('new-all', 'NewAll'),
('new-high', 'NewHigh'),
('new-normal', 'NewNormal'),
('new-low', 'NewLow')])
for key, tag_suffix in limits:
tag_name = status + tag_suffix
XML.SubElement(element, tag_name).text = str(
status_data.get(key, ''))
# Tuples containing: setting name, tag name, default value
settings = [
('healthy', 'healthy', ''),
('unhealthy', 'unHealthy', ''),
('health-threshold', 'thresholdLimit', 'low'),
('plugin-name', 'pluginName', plugin_name),
('default-encoding', 'defaultEncoding', ''),
('can-run-on-failed', 'canRunOnFailed', False),
('use-stable-build-as-reference', 'useStableBuildAsReference', False),
('use-delta-values', 'useDeltaValues', False),
('thresholds', 'thresholds', {}),
('should-detect-modules', 'shouldDetectModules', False),
('dont-compute-new', 'dontComputeNew', True),
('do-not-resolve-relative-paths', 'doNotResolveRelativePaths', False),
('pattern', 'pattern', '')]
thresholds = ['low', 'normal', 'high']
for key, tag_name, default in settings:
xml_config = XML.SubElement(xml_element, tag_name)
config_value = data.get(key, default)
if key == 'thresholds':
append_thresholds(
xml_config,
config_value,
data.get('dont-compute-new', True))
elif key == 'health-threshold' and config_value not in thresholds:
raise JenkinsJobsException("health-threshold must be one of %s" %
", ".join(thresholds))
else:
if isinstance(default, bool):
xml_config.text = str(config_value).lower()
else:
xml_config.text = str(config_value)
def pmd(parser, xml_parent, data):
"""yaml: pmd
Publish trend reports with PMD.

View File

@ -34,6 +34,7 @@ Example::
import xml.etree.ElementTree as XML
import jenkins_jobs.modules.base
from jenkins_jobs.modules.helpers import build_trends_publisher
from jenkins_jobs.errors import JenkinsJobsException
@ -69,6 +70,83 @@ def email(parser, xml_parent, data):
XML.SubElement(mailer, 'perModuleEmail').text = 'true'
def findbugs(parser, xml_parent, data):
"""yaml: findbugs
FindBugs reporting for builds
Requires the Jenkins :jenkins-wiki:`FindBugs Plugin
<FindBugs+Plugin>`.
:arg bool rank-priority: Use rank as priority (default: false)
:arg str include-files: Comma separated list of files to include.
(Optional)
:arg str exclude-files: Comma separated list of files to exclude.
(Optional)
:arg bool can-run-on-failed: Weather or not to run plug-in on failed builds
(default: false)
:arg int healthy: Sunny threshold (optional)
:arg int unhealthy: Stormy threshold (optional)
:arg str health-threshold: Threshold priority for health status
('low', 'normal' or 'high', defaulted to 'low')
:arg bool dont-compute-new: If set to false, computes new warnings based on
the reference build (default true)
:arg bool use-delta-values: Use delta for new warnings. (Default: false)
:arg bool use-previous-build-as-reference: If set then the number of new
warnings will always be calculated based on the previous build. Otherwise
the reference build. (Default: false)
:arg bool use-stable-build-as-reference: The number of new warnings will be
calculated based on the last stable build, allowing reverts of unstable
builds where the number of warnings was decreased. (default false)
:arg dict thresholds:
:thresholds:
* **unstable** (`dict`)
:unstable: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
* **failed** (`dict`)
:failed: * **total-all** (`int`)
* **total-high** (`int`)
* **total-normal** (`int`)
* **total-low** (`int`)
* **new-all** (`int`)
* **new-high** (`int`)
* **new-normal** (`int`)
* **new-low** (`int`)
Minimal Example:
.. literalinclude:: /../../tests/reporters/fixtures/findbugs-minimal.yaml
Full Example:
.. literalinclude:: /../../tests/reporters/fixtures/findbugs01.yaml
"""
findbugs = XML.SubElement(xml_parent,
'hudson.plugins.findbugs.FindBugsReporter')
findbugs.set('plugin', 'findbugs')
# General Options
rank_priority = str(data.get('rank-priority', False)).lower()
XML.SubElement(findbugs, 'isRankActivated').text = rank_priority
include_files = data.get('include-files', '')
XML.SubElement(findbugs, 'includePattern').text = include_files
exclude_files = data.get('exclude-files', '')
XML.SubElement(findbugs, 'excludePattern').text = exclude_files
use_previous_build = str(data.get('use-previous-build-as-reference',
False)).lower()
XML.SubElement(findbugs,
'usePreviousBuildAsReference').text = use_previous_build
build_trends_publisher('[FINDBUGS] ', findbugs, data)
class Reporters(jenkins_jobs.modules.base.Base):
sequence = 55

View File

@ -73,6 +73,7 @@ jenkins_jobs.builders =
trigger-builds=jenkins_jobs.modules.builders:trigger_builds
jenkins_jobs.reporters =
email=jenkins_jobs.modules.reporters:email
findbugs=jenkins_jobs.modules.reporters:findbugs
jenkins_jobs.properties =
authenticated-build=jenkins_jobs.modules.properties:authenticated_build
authorization=jenkins_jobs.modules.properties:authorization

View File

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<maven2-moduleset>
<reporters>
<hudson.plugins.findbugs.FindBugsReporter plugin="findbugs">
<isRankActivated>false</isRankActivated>
<includePattern/>
<excludePattern/>
<usePreviousBuildAsReference>false</usePreviousBuildAsReference>
<healthy/>
<unHealthy/>
<thresholdLimit>low</thresholdLimit>
<pluginName>[FINDBUGS] </pluginName>
<defaultEncoding/>
<canRunOnFailed>false</canRunOnFailed>
<useStableBuildAsReference>false</useStableBuildAsReference>
<useDeltaValues>false</useDeltaValues>
<thresholds>
<unstableTotalAll/>
<unstableTotalHigh/>
<unstableTotalNormal/>
<unstableTotalLow/>
<failedTotalAll/>
<failedTotalHigh/>
<failedTotalNormal/>
<failedTotalLow/>
</thresholds>
<shouldDetectModules>false</shouldDetectModules>
<dontComputeNew>true</dontComputeNew>
<doNotResolveRelativePaths>false</doNotResolveRelativePaths>
<pattern/>
</hudson.plugins.findbugs.FindBugsReporter>
</reporters>
</maven2-moduleset>

View File

@ -0,0 +1,3 @@
project-type: maven
reporters:
- findbugs

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<maven2-moduleset>
<reporters>
<hudson.plugins.findbugs.FindBugsReporter plugin="findbugs">
<isRankActivated>true</isRankActivated>
<includePattern>f,d,e,.*</includePattern>
<excludePattern>a,c,d,.*</excludePattern>
<usePreviousBuildAsReference>true</usePreviousBuildAsReference>
<healthy>80</healthy>
<unHealthy>10</unHealthy>
<thresholdLimit>high</thresholdLimit>
<pluginName>[FINDBUGS] </pluginName>
<defaultEncoding/>
<canRunOnFailed>true</canRunOnFailed>
<useStableBuildAsReference>true</useStableBuildAsReference>
<useDeltaValues>true</useDeltaValues>
<thresholds>
<unstableTotalAll>90</unstableTotalAll>
<unstableTotalHigh>80</unstableTotalHigh>
<unstableTotalNormal>50</unstableTotalNormal>
<unstableTotalLow>20</unstableTotalLow>
<unstableNewAll>95</unstableNewAll>
<unstableNewHigh>85</unstableNewHigh>
<unstableNewNormal>55</unstableNewNormal>
<unstableNewLow>25</unstableNewLow>
<failedTotalAll>80</failedTotalAll>
<failedTotalHigh>70</failedTotalHigh>
<failedTotalNormal>40</failedTotalNormal>
<failedTotalLow>10</failedTotalLow>
<failedNewAll>85</failedNewAll>
<failedNewHigh>75</failedNewHigh>
<failedNewNormal>45</failedNewNormal>
<failedNewLow>15</failedNewLow>
</thresholds>
<shouldDetectModules>false</shouldDetectModules>
<dontComputeNew>false</dontComputeNew>
<doNotResolveRelativePaths>false</doNotResolveRelativePaths>
<pattern/>
</hudson.plugins.findbugs.FindBugsReporter>
</reporters>
</maven2-moduleset>

View File

@ -0,0 +1,34 @@
project-type: maven
reporters:
- findbugs:
rank-priority: true
include-files: 'f,d,e,.*'
exclude-files: 'a,c,d,.*'
can-run-on-failed: true
healthy: 80
unhealthy: 10
use-delta-values: true
health-threshold: 'high'
thresholds:
unstable:
total-all: 90
total-high: 80
total-normal: 50
total-low: 20
new-all: 95
new-high: 85
new-normal: 55
new-low: 25
failed:
total-all: 80
total-high: 70
total-normal: 40
total-low: 10
new-all: 85
new-high: 75
new-normal: 45
new-low: 15
dont-compute-new: false
use-delta-values: true
use-previous-build-as-reference: true
use-stable-build-as-reference: true

View File

@ -0,0 +1,27 @@
#!/usr/bin/env python
#
# Copyright 2015 Thanh Ha
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
from testtools import TestCase
from testscenarios.testcase import TestWithScenarios
from jenkins_jobs.modules import reporters
from tests.base import get_scenarios, BaseTestCase
class TestCaseModuleReporters(TestWithScenarios, TestCase, BaseTestCase):
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
scenarios = get_scenarios(fixtures_path)
klass = reporters.Reporters