Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-6876] Create a dash-board view portlet that shows the SLOC o…
…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
Showing
9 changed files
with
199 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
Languages=Sprachen | ||
Files=Dateien | ||
Lines=Zeilen | ||
Total=Total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,4 @@ | ||
Languages=\u8a00\u8a9e | ||
Files=\u30d5\u30a1\u30a4\u30eb | ||
Lines=\u884c | ||
Total=\u5408\u8a08 |