Skip to content

Commit

Permalink
[JENKINS-6876] Create a dash-board view portlet that shows the SLOC o…
Browse files Browse the repository at this point in the history
…f the selected projectes

[JENKINS-12166] add a sloccount portlet to dashboard

- Optional dependency to dashboard-view added.
- SLOCCount dashboard-view portlet implemented. It displays a sortable table with number of lines, files and languages for each job.
- Programming language specific data were not added to the table because there can be many of them which would break the layout. The [job x language] table would have both many rows and many columns.
- Germal and Japanese localization blindly copied from other jelly files.
  • Loading branch information
mixalturek committed Jan 26, 2014
1 parent d0af8c1 commit 807cda1
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 3 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Expand Up @@ -52,9 +52,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- None -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>dashboard-view</artifactId>
<version>2.0</version>
<optional>true</optional>
</dependency>
</dependencies>

<repositories>
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/hudson/plugins/sloccount/SloccountResult.java
Expand Up @@ -51,7 +51,7 @@ public AbstractBuild<?,?> getOwner() {
/**
* Get the statistics.
*
* @return the statistics
* @return the statistics, always non-null value
*/
public SloccountReportStatistics getStatistics() {
convertLegacyData();
Expand All @@ -61,6 +61,10 @@ public SloccountReportStatistics getStatistics() {
/**
* Convert legacy data in format of sloccount plugin version 1.10
* to the new one that uses statistics.
*
* If statistics are null for any reason, the object will be created.
* Statistics will be always non-null after this method is called (side
* effect).
*/
private void convertLegacyData() {
if(statistics != null) {
Expand Down
@@ -0,0 +1,84 @@
package hudson.plugins.sloccount.dashboard;

import java.util.LinkedList;

import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.sloccount.Messages;
import hudson.plugins.sloccount.SloccountBuildAction;
import hudson.plugins.sloccount.SloccountResult;
import hudson.plugins.sloccount.model.SloccountLanguageStatistics;
import hudson.plugins.sloccount.model.SloccountReportStatistics;
import hudson.plugins.sloccount.util.StringUtil;
import hudson.plugins.view.dashboard.DashboardPortlet;

/**
* Dashboard portlet that shows a table with jobs and size of their code base.
*
* @author Michal Turek
*/
public class SloccountTablePortlet extends DashboardPortlet {
/**
* Constructor.
*
* @param name
* the name of the portlet
*/
@DataBoundConstructor
public SloccountTablePortlet(String name) {
super(name);
}

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

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

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

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

build = build.getPreviousBuild();
}

return new SloccountReportStatistics(new LinkedList<SloccountLanguageStatistics>());
}

/**
* Format an integer to contain a thousands separator.
*
* @return the formatted string
*/
public String grouping(int value) {
return StringUtil.grouping(value);
}

/**
* Extension point registration.
*
* @author Michal Turek
*/
@Extension(optional = true)
public static class SloccountTableDescriptor extends Descriptor<DashboardPortlet> {
@Override
public String getDisplayName() {
return Messages.Sloccount_Portlet_Name();
}
}
}
@@ -1,5 +1,7 @@
package hudson.plugins.sloccount.model;

import hudson.plugins.sloccount.util.StringUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -75,6 +77,33 @@ public int getLanguageCount() {
return statistics.size();
}

/**
* Get total lines count.
*
* @return the lines count
*/
public String getLineCountString() {
return StringUtil.grouping(getLineCount());
}

/**
* Get total files count.
*
* @return the files count
*/
public String getFileCountString() {
return StringUtil.grouping(getFileCount());
}

/**
* Get total files count.
*
* @return the files count
*/
public String getLanguageCountString() {
return StringUtil.grouping(getLanguageCount());
}

/**
* Get language statistics for a concrete language.
*
Expand Down
Expand Up @@ -5,3 +5,5 @@ Sloccount.ProjectAction.Name=SLOCCount
Sloccount.Trend.Name=SLOCCount Trend
Sloccount.Trend.Lines=lines
Sloccount.Trend.Delta=(delta)

Sloccount.Portlet.Name=SLOCCount
@@ -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,47 @@
<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">
.sloccountTablePortlet .number { text-align: right; }
</style>

<table class="pane sortable sloccountTablePortlet">
<j:set var="totalLines" value="${0}"/>
<j:set var="totalFiles" value="${0}"/>

<thead>
<tr>
<td class="pane-header">${%Job}</td>
<td class="pane-header">${%Lines}</td>
<td class="pane-header">${%Files}</td>
<td class="pane-header">${%Languages}</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" data="${stats.lineCount}">${stats.lineCountString}</td>
<td class="pane number" data="${stats.fileCount}">${stats.fileCountString}</td>
<td class="pane number" data="${stats.languageCount}">${stats.languageCountString}</td>

<j:set var="totalLines" value="${totalLines + stats.lineCount}"/>
<j:set var="totalFiles" value="${totalFiles + stats.fileCount}"/>
</tr>
</j:forEach>
</tbody>
<tfoot>
<tr class="sortbottom">
<td class="pane-header">${%Total}</td>
<td class="pane-header number" data="${totalLines}">${it.grouping(totalLines)}</td>
<td class="pane-header number" data="${totalFiles}">${it.grouping(totalFiles)}</td>
<td class="pane-header number" data="0">-</td>
</tr>
</tfoot>
</table>
</j:jelly>
@@ -0,0 +1,4 @@
Languages=Sprachen
Files=Dateien
Lines=Zeilen
Total=Total
@@ -0,0 +1,4 @@
Languages=\u8a00\u8a9e
Files=\u30d5\u30a1\u30a4\u30eb
Lines=\u884c
Total=\u5408\u8a08

0 comments on commit 807cda1

Please sign in to comment.