Skip to content
Permalink
Browse files
[JENKINS-21258] Graphical artefacts in the trend graphs
- If a language newly appears/disappears in/from SLOCCount report the trend graphs will contain graphical artifacts. The issue is visible mainly in the delta trend but it is (and always was) present in the absolute one too. The code doesn't consider that currently processed build may contain different languages than the previous and next ones.
- The issue fixed by adding zero or negative lines count for all known languages that are not present in the particular build but may be present in the previous or next ones.
  • Loading branch information
mixalturek committed Jan 7, 2014
1 parent cdf60a3 commit b214b258df66a1671271be14a24d0391ea8c57aa
Showing 2 changed files with 57 additions and 7 deletions.
@@ -4,7 +4,9 @@
import hudson.plugins.sloccount.util.StringUtil;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
*
@@ -165,4 +167,21 @@ static SloccountLanguageStatistics getLanguage(List<SloccountLanguageStatistics>

return new SloccountLanguageStatistics(name, 0, 0);
}

/**
* Get names of all languages.
*
* @param statistics the source statistics
* @return the names
*/
static List<String> getAllLanguages(List<SloccountLanguageStatistics> statistics)
{
List<String> languages = new LinkedList<String>();

for(SloccountLanguageStatistics it : statistics) {
languages.add(it.getName());
}

return languages;
}
}
@@ -7,7 +7,9 @@

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

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
@@ -66,20 +68,30 @@ strLines, buildDataset(action), PlotOrientation.VERTICAL,

private static CategoryDataset buildDataset(SloccountBuildAction lastAction){
DataSetBuilder<String, NumberOnlyBuildLabel> builder = new DataSetBuilder<String, NumberOnlyBuildLabel>();
Set<String> allLanguages = new HashSet<String>();

SloccountBuildAction action = lastAction;
do{
while(action != null){
SloccountResult result = action.getResult();
if(result != null){
NumberOnlyBuildLabel buildLabel = new NumberOnlyBuildLabel(action.getBuild());

allLanguages.addAll(ReportSummary.getAllLanguages(result.getStatistics()));
Set<String> remainingLanguages = new HashSet<String>(allLanguages);

for(SloccountLanguageStatistics l : result.getStatistics()){
builder.add(l.getLineCount(), l.getName(), buildLabel);
remainingLanguages.remove(l.getName());
}

for(String language : remainingLanguages) {
// Language disappeared
builder.add(0, language, buildLabel);
}
}

action = action.getPreviousAction();
}while(action != null);
}

return builder.build();
}
@@ -123,29 +135,48 @@ strLinesDelta, buildDatasetDelta(action), PlotOrientation.VERTICAL,

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

Set<String> allLanguages = new HashSet<String>();
SloccountBuildAction action = lastAction;


// Initial languages from the first action
if(action != null && action.getResult() != null) {
allLanguages.addAll(ReportSummary.getAllLanguages(
action.getResult().getStatistics()));
}

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();
}

allLanguages.addAll(ReportSummary.getAllLanguages(previousStatistics));
Set<String> remainingLanguages = new HashSet<String>(allLanguages);

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

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

remainingLanguages.remove(current.getName());
}

for(String language : remainingLanguages) {
SloccountLanguageStatistics previous
= ReportSummary.getLanguage(previousStatistics, language);

// Language disappeared (current - previous = 0 - previous)
builder.add(-previous.getLineCount(), language, buildLabel);
}
}

0 comments on commit b214b25

Please sign in to comment.