From 3a226228b5432f1e21c834ea18db974d0889e866 Mon Sep 17 00:00:00 2001 From: Dong Ma Date: Tue, 27 Sep 2016 11:06:13 -0700 Subject: [PATCH] Update cppcheck plugin - update cppcheck plugin to use convert xml - update cppcheck plugin docstring - add plugin="cppcheck" attribute - add new parameters for cppcheck plugin - update test cases Change-Id: Id17f4fb082eff1ed9266f98454f1e1df2bcaca7f --- jenkins_jobs/modules/publishers.py | 133 +++++++++++++----- .../publishers/fixtures/cppcheck-complete.xml | 40 ++++++ ...ppcheck001.yaml => cppcheck-complete.yaml} | 21 ++- .../{cppcheck001.xml => cppcheck-minimal.xml} | 22 +-- .../publishers/fixtures/cppcheck-minimal.yaml | 3 + 5 files changed, 170 insertions(+), 49 deletions(-) create mode 100644 tests/publishers/fixtures/cppcheck-complete.xml rename tests/publishers/fixtures/{cppcheck001.yaml => cppcheck-complete.yaml} (53%) rename tests/publishers/fixtures/{cppcheck001.xml => cppcheck-minimal.xml} (58%) create mode 100644 tests/publishers/fixtures/cppcheck-minimal.yaml diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index 60a49da28..bedbc64a7 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -2081,65 +2081,122 @@ def cppcheck(registry, xml_parent, data): Cppcheck result publisher Requires the Jenkins :jenkins-wiki:`Cppcheck Plugin `. - :arg str pattern: file pattern for cppcheck xml report + :arg str pattern: File pattern for cppcheck xml report (required) + :arg bool ignoreblankfiles: Ignore blank files (default false) + :arg bool allow-no-report: Do not fail the build if the Cppcheck report + is not found (default false) + :arg dict thresholds: + :thresholds: Configure the build status and health. A build is + considered as unstable or failure if the new or total number + of issues exceeds the specified thresholds. The build health + is also determined by thresholds. If the actual number of issues + is between the provided thresholds, then the build health is + interpolated. + * **unstable** (`str`): Total number unstable threshold (default '') + * **new-unstable** (`str`): New number unstable threshold (default '') + * **failure** (`str`): Total number failure threshold (default '') + * **new-failure** (`str`): New number failure threshold (default '') + * **healthy** (`str`): Healthy threshold (default '') + * **unhealthy** (`str`): Unhealthy threshold (default '') + :arg dict severity: + :severity: Determines which severity of issues should be considered + when evaluating the build status and health, default all true + * **error** (`bool`): Severity error (default true) + * **warning** (`bool`): Severity warning (default true) + * **style** (`bool`): Severity style (default true) + * **performance** (`bool`): Severity performance (default true) + * **information** (`bool`): Severity information (default true) + * **nocategory** (`bool`): Severity nocategory (default true) + * **portability** (`bool`): Severity portability (default true) + :arg dict graph: + :graph: Graph configuration + * **xysize** (`array`): Chart width and height (default [500, 200]) + * **num-builds-in-graph** (`int`): Builds number in graph (default 0) + :arg dict display + :display: which errors to display, default only sum + * **sum** (`bool`): Display sum of all issues (default true) + * **error** (`bool`): Display errors (default false) + * **warning** (`bool`): Display warnings (default false) + * **style** (`bool`): Display style (default false) + * **performance** (`bool`): Display performance (default false) + * **information** (`bool`): Display information (default false) + * **nocategory** (`bool`): Display no category (default false) + * **portability** (`bool`): Display portability (default false) - for more optional parameters see the example + Minimal Example: - Example: + .. literalinclude:: + /../../tests/publishers/fixtures/cppcheck-minimal.yaml + :language: yaml - .. literalinclude:: /../../tests/publishers/fixtures/cppcheck001.yaml + Full Example: + .. literalinclude:: + /../../tests/publishers/fixtures/cppcheck-complete.yaml :language: yaml """ + cppextbase = XML.SubElement(xml_parent, 'org.jenkinsci.plugins.cppcheck.' 'CppcheckPublisher') + cppextbase.set('plugin', 'cppcheck') cppext = XML.SubElement(cppextbase, 'cppcheckConfig') - XML.SubElement(cppext, 'pattern').text = data['pattern'] - XML.SubElement(cppext, 'ignoreBlankFiles').text = \ - str(data.get('ignoreblankfiles', False)).lower() + mappings = [ + ('pattern', 'pattern', None), + ('ignoreblankfiles', 'ignoreBlankFiles', False), + ('allow-no-report', 'allowNoReport', False) + ] + helpers.convert_mapping_to_xml(cppext, data, mappings, fail_required=True) csev = XML.SubElement(cppext, 'configSeverityEvaluation') thrsh = data.get('thresholds', {}) - XML.SubElement(csev, 'threshold').text = str(thrsh.get('unstable', '')) - XML.SubElement(csev, 'newThreshold').text = \ - str(thrsh.get('new-unstable', '')) - XML.SubElement(csev, 'failureThreshold').text = \ - str(thrsh.get('failure', '')) - XML.SubElement(csev, 'newFailureThreshold').text = \ - str(thrsh.get('new-failure', '')) - XML.SubElement(csev, 'healthy').text = str(thrsh.get('healthy', '')) - XML.SubElement(csev, 'unHealthy').text = str(thrsh.get('unhealthy', '')) + thrsh_mappings = [ + ('unstable', 'threshold', ''), + ('new-unstable', 'newThreshold', ''), + ('failure', 'failureThreshold', ''), + ('new-failure', 'newFailureThreshold', ''), + ('healthy', 'healthy', ''), + ('unhealthy', 'unHealthy', '') + ] + helpers.convert_mapping_to_xml( + csev, thrsh, thrsh_mappings, fail_required=True) sev = thrsh.get('severity', {}) - XML.SubElement(csev, 'severityError').text = \ - str(sev.get('error', True)).lower() - XML.SubElement(csev, 'severityWarning').text = \ - str(sev.get('warning', True)).lower() - XML.SubElement(csev, 'severityStyle').text = \ - str(sev.get('style', True)).lower() - XML.SubElement(csev, 'severityPerformance').text = \ - str(sev.get('performance', True)).lower() - XML.SubElement(csev, 'severityInformation').text = \ - str(sev.get('information', True)).lower() + sev_mappings = [ + ('error', 'severityError', True), + ('warning', 'severityWarning', True), + ('style', 'severityStyle', True), + ('performance', 'severityPerformance', True), + ('information', 'severityInformation', True), + ('nocategory', 'severityNoCategory', True), + ('portability', 'severityPortability', True) + ] + helpers.convert_mapping_to_xml( + csev, sev, sev_mappings, fail_required=True) graph = data.get('graph', {}) cgraph = XML.SubElement(cppext, 'configGraph') x, y = graph.get('xysize', [500, 200]) XML.SubElement(cgraph, 'xSize').text = str(x) XML.SubElement(cgraph, 'ySize').text = str(y) + graph_mapping = [ + ('num-builds-in-graph', 'numBuildsInGraph', 0) + ] + helpers.convert_mapping_to_xml( + cgraph, graph, graph_mapping, fail_required=True) + gdisplay = graph.get('display', {}) - XML.SubElement(cgraph, 'displayAllErrors').text = \ - str(gdisplay.get('sum', True)).lower() - XML.SubElement(cgraph, 'displayErrorSeverity').text = \ - str(gdisplay.get('error', False)).lower() - XML.SubElement(cgraph, 'displayWarningSeverity').text = \ - str(gdisplay.get('warning', False)).lower() - XML.SubElement(cgraph, 'displayStyleSeverity').text = \ - str(gdisplay.get('style', False)).lower() - XML.SubElement(cgraph, 'displayPerformanceSeverity').text = \ - str(gdisplay.get('performance', False)).lower() - XML.SubElement(cgraph, 'displayInformationSeverity').text = \ - str(gdisplay.get('information', False)).lower() + gdisplay_mappings = [ + ('sum', 'displayAllErrors', True), + ('error', 'displayErrorSeverity', False), + ('warning', 'displayWarningSeverity', False), + ('style', 'displayStyleSeverity', False), + ('performance', 'displayPerformanceSeverity', False), + ('information', 'displayInformationSeverity', False), + ('nocategory', 'displayNoCategorySeverity', False), + ('portability', 'displayPortabilitySeverity', False) + ] + helpers.convert_mapping_to_xml( + cgraph, gdisplay, gdisplay_mappings, fail_required=True) def logparser(registry, xml_parent, data): diff --git a/tests/publishers/fixtures/cppcheck-complete.xml b/tests/publishers/fixtures/cppcheck-complete.xml new file mode 100644 index 000000000..9932d1d4a --- /dev/null +++ b/tests/publishers/fixtures/cppcheck-complete.xml @@ -0,0 +1,40 @@ + + + + + + **/cppcheck.xml + true + true + + 5 + 5 + 7 + 3 + 5 + 10 + false + false + false + false + false + false + false + + + 600 + 300 + 10 + false + true + true + true + true + true + true + true + + + + + diff --git a/tests/publishers/fixtures/cppcheck001.yaml b/tests/publishers/fixtures/cppcheck-complete.yaml similarity index 53% rename from tests/publishers/fixtures/cppcheck001.yaml rename to tests/publishers/fixtures/cppcheck-complete.yaml index 34408a7b7..b18ba5a34 100644 --- a/tests/publishers/fixtures/cppcheck001.yaml +++ b/tests/publishers/fixtures/cppcheck-complete.yaml @@ -2,20 +2,35 @@ publishers: - cppcheck: pattern: "**/cppcheck.xml" # the rest is optional + ignoreblankfiles: true + allow-no-report: true # build status (new) error count thresholds thresholds: unstable: 5 new-unstable: 5 failure: 7 new-failure: 3 + healthy: 5 + unhealthy: 10 # severities which count towards the threshold, default all true severity: - error: true - warning: true + error: false + warning: false + style: false + performance: false information: false + nocategory: false + portability: false graph: - xysize: [500, 200] + xysize: [600, 300] + num-builds-in-graph: 10 # which errors to display, default only sum display: sum: false error: true + warning: true + style: true + performance: true + information: true + nocategory: true + portability: true diff --git a/tests/publishers/fixtures/cppcheck001.xml b/tests/publishers/fixtures/cppcheck-minimal.xml similarity index 58% rename from tests/publishers/fixtures/cppcheck001.xml rename to tests/publishers/fixtures/cppcheck-minimal.xml index 65b310329..ff5084b69 100644 --- a/tests/publishers/fixtures/cppcheck001.xml +++ b/tests/publishers/fixtures/cppcheck-minimal.xml @@ -1,32 +1,38 @@ - + **/cppcheck.xml false + false - 5 - 5 - 7 - 3 + + + + true true true true - false + true + true + true 500 200 - false - true + 0 + true + false false false false false + false + false diff --git a/tests/publishers/fixtures/cppcheck-minimal.yaml b/tests/publishers/fixtures/cppcheck-minimal.yaml new file mode 100644 index 000000000..b7482813d --- /dev/null +++ b/tests/publishers/fixtures/cppcheck-minimal.yaml @@ -0,0 +1,3 @@ +publishers: + - cppcheck: + pattern: "**/cppcheck.xml"