Skip to content
Permalink
Browse files
[FIXED JENKINS-9309] sloccount trend report only works up to last fai…
…led build (second version)
  • Loading branch information
Karsten Brandt authored and Karsten Brandt committed Jun 6, 2012
1 parent ba86876 commit 92f5ca9855f4bbf65f95c61b4ab9ca1e606c6f37
Showing 4 changed files with 92 additions and 59 deletions.
@@ -19,40 +19,45 @@ private ReportSummary(){
public static String createReportSummary(SloccountReport report, SloccountReport previous){
StringBuilder builder = new StringBuilder();

builder.append("<a href=\"" + SloccountBuildAction.URL_NAME + "\">");
builder.append(report.getLineCountString());
if(previous != null){
if((report != null)&&(previous != null)){

builder.append("<a href=\"" + SloccountBuildAction.URL_NAME + "\">");
builder.append(report.getLineCountString());
printDifference(report.getLineCount(), previous.getLineCount(), builder);
}
builder.append(" lines</a> in ");
builder.append(report.getFileCountString());
if(previous != null){

builder.append(" lines</a> in ");
builder.append(report.getFileCountString());
printDifference(report.getFileCount(), previous.getFileCount(), builder);
}
builder.append(" files and ");
builder.append(report.getLanguageCountString());
if(previous != null){

builder.append(" files and ");
builder.append(report.getLanguageCountString());
printDifference(report.getLanguageCount(), previous.getLanguageCount(), builder);
}
builder.append(" languages.");

builder.append(" languages.");
}

return builder.toString();
}

public static String createReportSummaryDetails(SloccountReport report, SloccountReport previous){

StringBuilder builder = new StringBuilder();

for(Language language : report.getLanguages()){
Language previousLanguage = null;
if(previous != null){
if((report != null)&&(previous != null)){

for(Language language : report.getLanguages()){

Language previousLanguage = null;
previousLanguage = previous.getLanguage(language.getName());

appendLanguageDetails(language, previousLanguage, builder);
}
appendLanguageDetails(language, previousLanguage, builder);
}

return builder.toString();
}

public static void appendLanguageDetails(Language language, Language previous, StringBuilder builder){
private static void appendLanguageDetails(Language language, Language previous, StringBuilder builder){
builder.append("<li>");
builder.append("<a href=\"");
builder.append(SloccountBuildAction.URL_NAME);
@@ -35,11 +35,26 @@ public String getUrlName() {
}

public String getSummary(){
return ReportSummary.createReportSummary(result.getReport(), this.getPreviousReport());

String retVal = "";

if(this.result != null){

retVal = ReportSummary.createReportSummary(this.result.getReport(), this.getPreviousReport());
}

return retVal;
}

public String getDetails(){
return ReportSummary.createReportSummaryDetails(result.getReport(), this.getPreviousReport());

String retVal = "";

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

return retVal;
}

public SloccountResult getResult(){
@@ -66,9 +81,15 @@ SloccountResult getPreviousResult(){
}

SloccountBuildAction getPreviousAction(){
AbstractBuild<?,?> previousBuild = this.build.getPreviousBuild();
if(previousBuild != null){
return previousBuild.getAction(SloccountBuildAction.class);

if(this.build != null){

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

if(previousBuild != null){

return previousBuild.getAction(SloccountBuildAction.class);
}
}
return null;
}
@@ -77,25 +77,29 @@ public final boolean hasValidResults() {
if (build != null) {

SloccountBuildAction resultAction = build.getAction(SloccountBuildAction.class);
int nbr_results = 0;

do{

SloccountResult result = resultAction.getResult();

if(result != null){

nbr_results++;

if(nbr_results > 1){

return true;
}
}

resultAction = resultAction.getPreviousAction();

}while(resultAction != null);

if (resultAction != null) {

int nbr_results = 0;

do{

SloccountResult result = resultAction.getResult();

if(result != null){

nbr_results++;

if(nbr_results > 1){

return true;
}
}

resultAction = resultAction.getPreviousAction();

}while(resultAction != null);
}
}

return false;
@@ -47,29 +47,32 @@ protected boolean canContinue(final Result result) {
@Override
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener){

SloccountResult result = null;

if(this.canContinue(build.getResult())){
SloccountResult result;

FilePath workspace = build.getWorkspace();
PrintStream logger = listener.getLogger();
SloccountParser parser = new SloccountParser(this.getRealEncoding(), this.getRealPattern(), logger);
SloccountReport report;
FilePath workspace = build.getWorkspace();
PrintStream logger = listener.getLogger();
SloccountParser parser = new SloccountParser(this.getRealEncoding(), this.getRealPattern(), logger);
SloccountReport report;

try{
try{
if(this.canContinue(build.getResult())){
report = workspace.act(parser);

}catch(IOException ioe){
ioe.printStackTrace(logger);
return false;

}catch(InterruptedException ie){
ie.printStackTrace(logger);
return false;
}else{
// generate an empty report
// TODO: Replace this empty report with the last valid one?
report = new SloccountReport();
}

}catch(IOException ioe){
ioe.printStackTrace(logger);
return false;

result = new SloccountResult(report, build);
}catch(InterruptedException ie){
ie.printStackTrace(logger);
return false;
}

result = new SloccountResult(report, build);

SloccountBuildAction buildAction = new SloccountBuildAction(build, result);

0 comments on commit 92f5ca9

Please sign in to comment.