Skip to content
Permalink
Browse files
[JENKINS-21223] Broken differences in build summary for failed builds
- 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 6371a727476c7b7a394e0fa4267bc82b9d74ec4a
Showing 3 changed files with 31 additions and 25 deletions.
@@ -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;
@@ -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;
@@ -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(){
@@ -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;
@@ -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);

0 comments on commit 6371a72

Please sign in to comment.