Skip to content

Commit

Permalink
[JENKINS-21223] Broken differences in build summary for failed builds
Browse files Browse the repository at this point in the history
- Publishing the SLOCCount report will be skipped if the build fails, no data are stored for it and no data are displayed in build summary.
- SloccountBuildAction.getPreviousAction() updated to search an action with valid data in a loop through previous builds. Builds that failed are skipped since they contain no data.
- Unused imports removed.
  • Loading branch information
mixalturek committed Jan 4, 2014
1 parent b7c0907 commit 6371a72
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
2 changes: 0 additions & 2 deletions src/main/java/hudson/plugins/sloccount/ReportSummary.java
@@ -1,8 +1,6 @@
package hudson.plugins.sloccount;

import hudson.plugins.sloccount.model.Language;
import hudson.plugins.sloccount.model.SloccountLanguageStatistics;
import hudson.plugins.sloccount.model.SloccountReport;
import hudson.plugins.sloccount.util.StringUtil;

import java.io.Serializable;
Expand Down
35 changes: 23 additions & 12 deletions src/main/java/hudson/plugins/sloccount/SloccountBuildAction.java
Expand Up @@ -3,7 +3,6 @@
import hudson.model.AbstractBuild;
import hudson.model.Action;
import hudson.plugins.sloccount.model.SloccountLanguageStatistics;
import hudson.plugins.sloccount.model.SloccountReport;

import java.io.Serializable;
import java.util.List;
Expand Down Expand Up @@ -86,18 +85,30 @@ SloccountResult getPreviousResult(){
return previousResult;
}

/**
* Get the previous valid action.
*
* @return the action or null
*/
SloccountBuildAction getPreviousAction(){

if(this.build != null){

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

if(previousBuild != null){

return previousBuild.getAction(SloccountBuildAction.class);
}
}
return null;
if(this.build == null){
return null;
}

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

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

if (action != null) {
return action;
}

previousBuild = previousBuild.getPreviousBuild();
}

return null;
}

AbstractBuild<?,?> getBuild(){
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/hudson/plugins/sloccount/SloccountPublisher.java
Expand Up @@ -8,7 +8,6 @@
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.plugins.sloccount.model.SloccountPublisherReport;
import hudson.plugins.sloccount.model.SloccountReport;
import hudson.plugins.sloccount.model.SloccountParser;
import hudson.remoting.VirtualChannel;
import hudson.tasks.BuildStepMonitor;
Expand Down Expand Up @@ -58,30 +57,28 @@ protected boolean canContinue(final Result result) {

@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener){
FilePath workspace = build.getWorkspace();
PrintStream logger = listener.getLogger();

if (!canContinue(build.getResult())) {
logger.println("[SLOCCount] Skipping results publication since the build is not successful");
return true;
}

SloccountParser parser = new SloccountParser(this.getRealEncoding(), this.getRealPattern(), logger);
SloccountPublisherReport report;

try{
if(this.canContinue(build.getResult())){
report = workspace.act(parser);
}else{
// generate an empty report
// TODO: Replace this empty report with the last valid one?
report = new SloccountPublisherReport();
}
report = build.getWorkspace().act(parser);
}catch(IOException ioe){
ioe.printStackTrace(logger);
return false;

}catch(InterruptedException ie){
ie.printStackTrace(logger);
return false;
}

SloccountResult result = new SloccountResult(report.getStatistics(),
getRealEncoding(), null, build);
getRealEncoding(), null, build);

SloccountBuildAction buildAction = new SloccountBuildAction(build, result);

Expand Down

0 comments on commit 6371a72

Please sign in to comment.