Skip to content

Commit

Permalink
[JENKINS-14504] sloccount churn graph
Browse files Browse the repository at this point in the history
- Plugin version 1.10 and less stored empty data set to build.xml even for builds that failed. This causes unwanted high peaks in trend with deltas.
- Builds with no data are excluded to fix the issue.
- Indentation fixed.
- Example of legacy build.xml data:

    <hudson.plugins.sloccount.SloccountBuildAction plugin="sloccount@1.10">
      <build class="build" reference="../../.."/>
      <result>
        <report>
          <files class="linked-hash-map"/>
          <lineCount>0</lineCount>
          <folders class="linked-hash-map"/>
          <languages class="linked-hash-map"/>
        </report>
        <owner class="build" reference="../../../.."/>
      </result>
    </hudson.plugins.sloccount.SloccountBuildAction>
  • Loading branch information
mixalturek committed Jan 6, 2014
1 parent 710599c commit cdf60a3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 45 deletions.
44 changes: 24 additions & 20 deletions src/main/java/hudson/plugins/sloccount/SloccountBuildAction.java
Expand Up @@ -44,7 +44,7 @@ public String getSummary(){
if(this.result != null){

retVal = ReportSummary.createReportSummary(this.result.getStatistics(),
this.getPreviousStatistics());
this.getPreviousStatistics());
}

return retVal;
Expand All @@ -56,7 +56,7 @@ public String getDetails(){

if(this.result != null){
retVal = ReportSummary.createReportSummaryDetails(this.result.getStatistics(),
this.getPreviousStatistics());
this.getPreviousStatistics());
}

return retVal;
Expand Down Expand Up @@ -85,30 +85,34 @@ SloccountResult getPreviousResult(){
return previousResult;
}

/**
* Get the previous valid action.
*
* @return the action or null
*/
/**
* Get the previous valid and non-empty action.
*
* @return the action or null
*/
SloccountBuildAction getPreviousAction(){
if(this.build == null){
return null;
}
if(this.build == null){
return null;
}

AbstractBuild<?,?> previousBuild = this.build.getPreviousBuild();
AbstractBuild<?,?> previousBuild = this.build.getPreviousBuild();

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

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

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

previousBuild = previousBuild.getPreviousBuild();
}
previousBuild = previousBuild.getPreviousBuild();
}

return null;
return null;
}

AbstractBuild<?,?> getBuild(){
Expand Down
68 changes: 43 additions & 25 deletions src/main/java/hudson/plugins/sloccount/SloccountResult.java
Expand Up @@ -30,15 +30,15 @@ public class SloccountResult implements Serializable {
private final String encoding;

public SloccountResult(List<SloccountLanguageStatistics> statistics, String encoding,
SloccountReport report, AbstractBuild<?,?> owner){
this.statistics = statistics;
SloccountReport report, AbstractBuild<?,?> owner){
this.statistics = statistics;
this.encoding = encoding;
this.report = report;
this.owner = owner;
}

public SloccountReport getReport() {
lazyLoad();
lazyLoad();
return report;
}

Expand All @@ -52,7 +52,7 @@ public AbstractBuild<?,?> getOwner() {
* @return the statistics per language
*/
public List<SloccountLanguageStatistics> getStatistics() {
convertLegacyData();
convertLegacyData();
return Collections.unmodifiableList(statistics);
}

Expand All @@ -61,38 +61,56 @@ public List<SloccountLanguageStatistics> getStatistics() {
* to the new one that uses statistics.
*/
private void convertLegacyData() {
if(statistics != null) {
return;
}
if(statistics != null) {
return;
}

statistics = new LinkedList<SloccountLanguageStatistics>();

if(report != null) {
for(Language language : report.getLanguages()){
statistics.add(new SloccountLanguageStatistics(language.getName(),
language.getLineCount(), language.getFileCount()));
}
for(Language language : report.getLanguages()){
statistics.add(new SloccountLanguageStatistics(language.getName(),
language.getLineCount(), language.getFileCount()));
}
}
}

/**
* Lazy load report data if they are not already loaded.
*/
private void lazyLoad() {
if(report != null) {
return;
}

java.io.File destDir = new java.io.File(owner.getRootDir(),
SloccountPublisher.BUILD_SUBDIR);

if (!destDir.exists()) {
report = new SloccountReport();
return;
}

SloccountParser parser = new SloccountParser(encoding, null, null);
report = parser.parseFiles(destDir.listFiles());
if(report != null) {
return;
}

java.io.File destDir = new java.io.File(owner.getRootDir(),
SloccountPublisher.BUILD_SUBDIR);

if (!destDir.exists()) {
report = new SloccountReport();
return;
}

SloccountParser parser = new SloccountParser(encoding, null, null);
report = parser.parseFiles(destDir.listFiles());
}

/**
* Check that the result is empty.
*
* @return true if the result is empty, otherwise false
*/
public boolean isEmpty() {
if(statistics != null) {
return statistics.isEmpty();
}

// Legacy data in format of sloccount plugin version 1.10 and less
if(report != null) {
return report.getLineCount() <= 0;
}

return true;
}

public SloccountResult getLanguageResult(String language){
Expand Down

0 comments on commit cdf60a3

Please sign in to comment.