Skip to content
Permalink
Browse files
[JENKINS-14504] sloccount churn graph
- Trend graph with values computed as delta between builds N and N-1 implemented.
- SLOCCount plugin now displays two graphs: absolute and delta.
- Indentation fixed.
  • Loading branch information
mixalturek committed Jan 4, 2014
1 parent 6371a72 commit 1c05513d9b5ebbf536ec7d365f81438d4bb74704
Showing 5 changed files with 141 additions and 17 deletions.
@@ -17,7 +17,7 @@ private ReportSummary(){
}

public static String createReportSummary(List<SloccountLanguageStatistics> current,
List<SloccountLanguageStatistics> previous){
List<SloccountLanguageStatistics> previous){
StringBuilder builder = new StringBuilder();

if(current != null){
@@ -55,15 +55,15 @@ public static String createReportSummary(List<SloccountLanguageStatistics> curre
}

public static String createReportSummaryDetails(List<SloccountLanguageStatistics> current,
List<SloccountLanguageStatistics> previous){
List<SloccountLanguageStatistics> previous){

StringBuilder builder = new StringBuilder();

if(current != null){

for(SloccountLanguageStatistics language : current){

SloccountLanguageStatistics previousLanguage = null;
SloccountLanguageStatistics previousLanguage = null;

if(previous != null) {
previousLanguage = getLanguage(previous, language.getName());
@@ -77,7 +77,7 @@ public static String createReportSummaryDetails(List<SloccountLanguageStatistics
}

private static void appendLanguageDetails(SloccountLanguageStatistics current,
SloccountLanguageStatistics previous, StringBuilder builder){
SloccountLanguageStatistics previous, StringBuilder builder){

String strLines = Messages.Sloccount_ReportSummary_Lines();
String strFiles = Messages.Sloccount_ReportSummary_Files();
@@ -136,7 +136,7 @@ private static int getLineCount(List<SloccountLanguageStatistics> statistics)
lineCount += it.getLineCount();
}

return lineCount;
return lineCount;
}

private static int getFileCount(List<SloccountLanguageStatistics> statistics)
@@ -147,22 +147,22 @@ private static int getFileCount(List<SloccountLanguageStatistics> statistics)
fileCount += it.getFileCount();
}

return fileCount;
return fileCount;
}

private static int getLanguageCount(List<SloccountLanguageStatistics> statistics)
{
return statistics.size();
}

private static SloccountLanguageStatistics getLanguage(List<SloccountLanguageStatistics> statistics, String name)
static SloccountLanguageStatistics getLanguage(List<SloccountLanguageStatistics> statistics, String name)
{
for(SloccountLanguageStatistics it : statistics) {
for(SloccountLanguageStatistics it : statistics) {
if(it.getName().equals(name)) {
return it;
return it;
}
}
return new SloccountLanguageStatistics(name, 0, 0);
return new SloccountLanguageStatistics(name, 0, 0);
}
}
@@ -1,14 +1,13 @@
package hudson.plugins.sloccount;

import hudson.plugins.sloccount.model.Language;
import hudson.plugins.sloccount.model.SloccountLanguageStatistics;
import hudson.plugins.sloccount.model.SloccountReport;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;
import hudson.util.DataSetBuilder;
import hudson.util.ShiftedCategoryAxis;

import java.awt.Color;
import java.io.Serializable;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
@@ -33,7 +32,9 @@ public static JFreeChart buildChart(SloccountBuildAction action){

String strLines = Messages.Sloccount_ReportSummary_Lines();

JFreeChart chart = ChartFactory.createStackedAreaChart(null, null, strLines, buildDataset(action), PlotOrientation.VERTICAL, true, false, true);
JFreeChart chart = ChartFactory.createStackedAreaChart(null, null,
strLines, buildDataset(action), PlotOrientation.VERTICAL,
true, false, true);

chart.setBackgroundPaint(Color.white);

@@ -82,4 +83,75 @@ private static CategoryDataset buildDataset(SloccountBuildAction lastAction){

return builder.build();
}

public static JFreeChart buildChartDelta(SloccountBuildAction action){

String strLinesDelta = Messages.Sloccount_ReportSummary_Lines()
+ " " + Messages.Sloccount_Trend_Delta();

JFreeChart chart = ChartFactory.createStackedAreaChart(null, null,
strLinesDelta, buildDatasetDelta(action), PlotOrientation.VERTICAL,
true, false, true);

chart.setBackgroundPaint(Color.white);

CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.WHITE);
plot.setOutlinePaint(null);
plot.setForegroundAlpha(0.8f);
plot.setRangeGridlinesVisible(true);
plot.setRangeGridlinePaint(Color.black);

CategoryAxis domainAxis = new ShiftedCategoryAxis(null);
plot.setDomainAxis(domainAxis);
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
domainAxis.setCategoryMargin(0.0);

NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

// crop extra space around the graph
plot.setInsets(new RectangleInsets(0, 0, 0, 5.0));

SloccountAreaRenderer renderer = new SloccountAreaRenderer(action.getUrlName());
plot.setRenderer(renderer);

return chart;
}

private static CategoryDataset buildDatasetDelta(SloccountBuildAction lastAction){
DataSetBuilder<String, NumberOnlyBuildLabel> builder = new DataSetBuilder<String, NumberOnlyBuildLabel>();

SloccountBuildAction action = lastAction;

while(action != null){
SloccountBuildAction previousAction = action.getPreviousAction();
SloccountResult result = action.getResult();
List<SloccountLanguageStatistics> previousStatistics = null;

if(result != null){
NumberOnlyBuildLabel buildLabel = new NumberOnlyBuildLabel(action.getBuild());

if(previousAction != null && previousAction.getResult() != null){
previousStatistics = previousAction.getResult().getStatistics();
} else {
// This will produce zero delta for the first build
previousStatistics = result.getStatistics();
}

for(SloccountLanguageStatistics current : result.getStatistics()){
SloccountLanguageStatistics previous = ReportSummary.getLanguage(previousStatistics, current.getName());

builder.add(current.getLineCount() - previous.getLineCount(),
current.getName(), buildLabel);
}
}

action = previousAction;
};

return builder.build();
}
}
@@ -54,8 +54,8 @@ public void doIndex(final StaplerRequest request, final StaplerResponse response
if (build != null) {
response.sendRedirect2(String.format("../%d/%s", build.getNumber(), SloccountBuildAction.URL_NAME));
}else{
// Click to the link in menu on the job page before the first build
response.sendRedirect2("..");
// Click to the link in menu on the job page before the first build
response.sendRedirect2("..");
}
}

@@ -154,4 +154,51 @@ public void doTrend(final StaplerRequest request, final StaplerResponse response
CHART_WIDTH,
CHART_HEIGHT);
}

/**
* Display the trend delta map. Delegates to the the associated
* {@link ResultAction}.
*
* @param request
* Stapler request
* @param response
* Stapler response
* @throws IOException
* in case of an error
*/
public void doTrendDeltaMap(final StaplerRequest request, final StaplerResponse response) throws IOException {
AbstractBuild<?,?> lastBuild = this.getLastFinishedBuild();
SloccountBuildAction lastAction = lastBuild.getAction(SloccountBuildAction.class);

ChartUtil.generateClickableMap(
request,
response,
SloccountChartBuilder.buildChartDelta(lastAction),
CHART_WIDTH,
CHART_HEIGHT);
}

/**
* Display the trend delta graph. Delegates to the the associated
* {@link ResultAction}.
*
* @param request
* Stapler request
* @param response
* Stapler response
* @throws IOException
* in case of an error in
* {@link ResultAction#doGraph(StaplerRequest, StaplerResponse, int)}
*/
public void doTrendDelta(final StaplerRequest request, final StaplerResponse response) throws IOException {
AbstractBuild<?,?> lastBuild = this.getLastFinishedBuild();
SloccountBuildAction lastAction = lastBuild.getAction(SloccountBuildAction.class);

ChartUtil.generateGraph(
request,
response,
SloccountChartBuilder.buildChartDelta(lastAction),
CHART_WIDTH,
CHART_HEIGHT);
}
}
@@ -8,4 +8,6 @@ Sloccount.ReportSummary.Lines=lines of code
Sloccount.ReportSummary.Files=files
Sloccount.ReportSummary.and=and
Sloccount.ReportSummary.in=in
Sloccount.ReportSummary.Languages=languages
Sloccount.ReportSummary.Languages=languages

Sloccount.Trend.Delta=(delta)
@@ -8,6 +8,9 @@
<div>
<img src="${from.urlName}/trend" lazymap="${from.urlName}/trendMap"/>
</div>
<div>
<img src="${from.urlName}/trendDelta" lazymap="${from.urlName}/trendDeltaMap"/>
</div>
</div>
</j:if>
</j:jelly>

0 comments on commit 1c05513

Please sign in to comment.