Skip to content
Permalink
Browse files

[JENKINS-10651] Add cppcheck to "Dashboard View"

- Cppcheck dashboard view implemented. There is a table, each job is a row and columns contain severity types.
- Plugin dashboard-view is a new optional dependency.
  • Loading branch information...
mixalturek committed Mar 9, 2014
1 parent 844874a commit c7fbdb666b47a9ada2ba34984c1ccc3802a2e627
@@ -49,6 +49,7 @@
<junit.version>4.8.2</junit.version>
<mockito.version>1.8.5</mockito.version>
<ivy.plugin.version>1.19</ivy.plugin.version>
<dashboard.view.version>2.0</dashboard.view.version>
</properties>

<dependencies>
@@ -104,6 +105,12 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>dashboard-view</artifactId>
<version>${dashboard.view.version}</version>
<optional>true</optional>
</dependency>
</dependencies>

<build>
@@ -0,0 +1,68 @@
package org.jenkinsci.plugins.cppcheck;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.view.dashboard.DashboardPortlet;

/**
* Dashboard portlet that shows a sortable table with jobs and Cppcheck
* statistics per severity type.
*
* @author Michal Turek
*/
public class CppcheckTablePortlet extends DashboardPortlet {
/**
* Constructor.
*
* @param name
* the name of the portlet
*/
@DataBoundConstructor
public CppcheckTablePortlet(String name) {
super(name);
}

/**
* Get latest available Cppcheck statistics of a job.
*
* @param job
* the job
* @return the statistics, always non-null value
*/
public CppcheckStatistics getStatistics(Job<?, ?> job) {
Run<?, ?> build = job.getLastBuild();

while(build != null){
CppcheckBuildAction action = build.getAction(CppcheckBuildAction.class);

if (action != null) {
CppcheckResult result = action.getResult();

if(result != null) {
return result.getStatistics();
}
}

build = build.getPreviousBuild();
}

return new CppcheckStatistics();
}

/**
* Extension point registration.
*
* @author Michal Turek
*/
@Extension(optional = true)
public static class CppcheckTableDescriptor extends Descriptor<DashboardPortlet> {
@Override
public String getDisplayName() {
return Messages.cppcheck_PortletName();
}
}
}
@@ -0,0 +1,17 @@
<j:jelly xmlns:j="jelly:core"
xmlns:st="jelly:stapler"
xmlns:d="jelly:define"
xmlns:dp="/hudson/plugins/view/dashboard"
xmlns:l="/lib/layout"
xmlns:t="/lib/hudson"
xmlns:f="/lib/form">

<!-- According to https://wiki.jenkins-ci.org/display/JENKINS/Dashboard+View -->
<dp:decorate portlet="${it}">
<tr><td>
<div align="center">
<st:include page="table.jelly"/>
</div>
</td></tr>
</dp:decorate>
</j:jelly>
@@ -0,0 +1,74 @@
<j:jelly xmlns:j="jelly:core"
xmlns:st="jelly:stapler"
xmlns:l="/lib/layout"
xmlns:t="/lib/hudson"
xmlns:dp="/hudson/plugins/view/dashboard">

<style type="text/css">
.cppcheckTablePortlet .number { text-align: right; }
</style>

<table class="pane sortable cppcheckTablePortlet">
<j:set var="numberTotal" value="${0}"/>
<j:set var="numberErrorSeverity" value="${0}"/>
<j:set var="numberWarningSeverity" value="${0}"/>
<j:set var="numberStyleSeverity" value="${0}"/>
<j:set var="numberPerformanceSeverity" value="${0}"/>
<j:set var="numberPortabilitySeverity" value="${0}"/>
<j:set var="numberInformationSeverity" value="${0}"/>
<j:set var="numberNoCategorySeverity" value="${0}"/>

<thead>
<tr>
<td class="pane-header">${%Job}</td>
<td class="pane-header">${%Total}</td>
<td class="pane-header">${%Error}</td>
<td class="pane-header">${%Warning}</td>
<td class="pane-header">${%Style}</td>
<td class="pane-header">${%Performance}</td>
<td class="pane-header">${%Portability}</td>
<td class="pane-header">${%Information}</td>
<td class="pane-header">${%No category}</td>
</tr>
</thead>
<tbody>
<j:forEach var="job" items="${jobs}">
<tr>
<j:set var="stats" value="${it.getStatistics(job)}" />

<td class="pane"><dp:jobLink job="${job}" /></td>
<td class="pane number">${stats.numberTotal}</td>
<td class="pane number">${stats.numberErrorSeverity}</td>
<td class="pane number">${stats.numberWarningSeverity}</td>
<td class="pane number">${stats.numberStyleSeverity}</td>
<td class="pane number">${stats.numberPerformanceSeverity}</td>
<td class="pane number">${stats.numberPortabilitySeverity}</td>
<td class="pane number">${stats.numberInformationSeverity}</td>
<td class="pane number">${stats.numberNoCategorySeverity}</td>

<j:set var="numberTotal" value="${numberTotal + stats.numberTotal}"/>
<j:set var="numberErrorSeverity" value="${numberErrorSeverity + stats.numberErrorSeverity}"/>
<j:set var="numberWarningSeverity" value="${numberWarningSeverity + stats.numberWarningSeverity}"/>
<j:set var="numberStyleSeverity" value="${numberStyleSeverity + stats.numberStyleSeverity}"/>
<j:set var="numberPerformanceSeverity" value="${numberPerformanceSeverity + stats.numberPerformanceSeverity}"/>
<j:set var="numberPortabilitySeverity" value="${numberPortabilitySeverity + stats.numberPortabilitySeverity}"/>
<j:set var="numberInformationSeverity" value="${numberInformationSeverity + stats.numberInformationSeverity}"/>
<j:set var="numberNoCategorySeverity" value="${numberNoCategorySeverity + stats.numberNoCategorySeverity}"/>
</tr>
</j:forEach>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">${%Total}</td>
<td class="pane-header number">${numberTotal}</td>
<td class="pane-header number">${numberErrorSeverity}</td>
<td class="pane-header number">${numberWarningSeverity}</td>
<td class="pane-header number">${numberStyleSeverity}</td>
<td class="pane-header number">${numberPerformanceSeverity}</td>
<td class="pane-header number">${numberPortabilitySeverity}</td>
<td class="pane-header number">${numberInformationSeverity}</td>
<td class="pane-header number">${numberNoCategorySeverity}</td>
</tr>
</tfoot>
</table>
</j:jelly>
@@ -17,3 +17,4 @@ cppcheck.Portability=Portability
cppcheck.AllErrors=All errors

cppcheck.BuildStability=Build stability for Cppcheck errors.
cppcheck.PortletName=Cppcheck Statistics

0 comments on commit c7fbdb6

Please sign in to comment.
You can’t perform that action at this time.