Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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 b214b25
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
19 changes: 19 additions & 0 deletions src/main/java/hudson/plugins/sloccount/ReportSummary.java
Expand Up @@ -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;

/**
*
Expand Down Expand Up @@ -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;
}
}
45 changes: 38 additions & 7 deletions src/main/java/hudson/plugins/sloccount/SloccountChartBuilder.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit b214b25

Please sign in to comment.