hudson.plugins.PerfPublisher.ReportsDiff Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of perfpublisher Show documentation
Show all versions of perfpublisher Show documentation
The PerfPublisher plug-in scans for xml tests reports defined in the administration panel and generates trend graphs, computes stats and underline regressions and modifications. The xml files must be generated by your own testing tool.
package hudson.plugins.PerfPublisher;
import java.awt.Color;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.ui.RectangleInsets;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import hudson.model.ModelObject;
import hudson.model.AbstractBuild;
import hudson.model.Result;
import hudson.plugins.PerfPublisher.Report.Report;
import hudson.plugins.PerfPublisher.Report.ReportContainer;
import hudson.plugins.PerfPublisher.Report.Test;
import hudson.util.ChartUtil;
import hudson.util.ColorPalette;
import hudson.util.DataSetBuilder;
import hudson.util.ShiftedCategoryAxis;
import hudson.util.ChartUtil.NumberOnlyBuildLabel;
/**
* This class is dedicated to the report diff display
* it prepares and generate the content of the diff
* @see hudson.model.ModelObject
* @author gbossert
*
*/
public class ReportsDiff implements ModelObject {
private final AbstractBuild, ?> _owner;
/**
* The 2 reports to compare
*/
private ReportContainer report1;
private ReportContainer report2;
private ReportContainer report3;
/**
* The 3 builds numbers
*/
private int nb_build1;
private int nb_build2;
private int nb_build3;
/**
* Activate or not the short diff
*/
private boolean shortDiff;
/**
* The stappler request
*/
private String link;
/**
* The constructor
* @param owner
* @param shortDiff activate or not the short display
* @param nb_build1 number of the first build
* @param report1 first report
* @param nb_build2 number of the second build
* @param report2 second report
* @param nb_build3 number of the third build
* @param report3 third report
*/
public ReportsDiff(final AbstractBuild, ?> owner, StaplerRequest request, int nb_build1, ReportContainer report1, int nb_build2, ReportContainer report2, int nb_build3, ReportContainer report3) {
this._owner = owner;
this.report1 = report1;
this.report2 = report2;
this.report3 = report3;
this.nb_build1 = nb_build1;
this.nb_build2 = nb_build2;
this.nb_build3 = nb_build3;
this.link="?build1="+this.nb_build1+"&build2="+this.nb_build2;
if (this.nb_build3==0) {
this.link+="&build3=none";
} else {
this.link+="&build3="+this.nb_build3;
}
// Activate or not the short display
this.shortDiff = false;
if (request.getParameter("short")!=null && request.getParameter("short").equals("yes")) {
this.shortDiff = true;
this.link+="&short=no";
} else {
this.link+="&short=yes";
}
}
/**
* Getter for the first build number
* @return the first build number
*/
public String getBuild1Number() {
return ""+nb_build1;
}
/**
* Getter for the second build number
* @return the second build number
*/
public String getBuild2Number() {
return ""+nb_build2;
}
/**
* Getter for the third build number
* @return the third build number
*/
public String getBuild3Number() {
return ""+nb_build3;
}
/**
* Getter for the first report
* @return the first report
*/
public ReportContainer getReport1() {
return this.report1;
}
/**
* Getter for the tests list of the first report
* @return all the tests from the first report
*/
public List getReport1Tests() {
return this.report1.getTests();
}
/**
* Getter for the second report
* @return the second report
*/
public ReportContainer getReport2() {
return this.report2;
}
/**
* Getter for the tests of the second report
* @return all the tests from the second report
*/
public List getReport2Tests() {
return this.report2.getTests();
}
/**
* Getter for the third report
* @return the third report
*/
public ReportContainer getReport3() {
return this.report3;
}
public List getReport3Tests() {
return this.report3.getTests();
}
public String getHtmlTestsDiff() {
String style="Threecolumn";
if (nb_build3==0) {
style="Twocolumn";
}
StringBuilder strb = new StringBuilder();
strb.append("");
strb.append("Build number");
strb.append("Build "+this.nb_build1+"");
strb.append("Build "+this.nb_build2+"");
if (nb_build3!=0) strb.append("Build "+this.nb_build3+"");
strb.append("");
strb.append("");
strb.append("Build date");
strb.append(""+this._owner.getProject().getBuildByNumber(nb_build1).getTimestampString2()+"");
strb.append(""+this._owner.getProject().getBuildByNumber(nb_build2).getTimestampString2()+"");
if (nb_build3!=0) strb.append(""+this._owner.getProject().getBuildByNumber(nb_build3).getTimestampString2()+"");
strb.append("");
strb.append("");
strb.append("Number of executed tests");
strb.append(""+this.report1.getNumberOfExecutedTest()+"");
strb.append(""+this.report2.getNumberOfExecutedTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getNumberOfExecutedTest()+"");
strb.append("");
strb.append("");
strb.append("Number of not executed tests");
strb.append(""+this.report1.getNumberOfNotExecutedTest()+"");
strb.append(""+this.report2.getNumberOfNotExecutedTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getNumberOfNotExecutedTest()+"");
strb.append("");
strb.append("");
strb.append("Number of succeeded tests");
strb.append(""+this.report1.getNumberOfPassedTest()+"");
strb.append(""+this.report2.getNumberOfPassedTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getNumberOfPassedTest()+"");
strb.append("");
strb.append("");
strb.append("Number of failed tests");
strb.append(""+this.report1.getNumberOfFailedTest()+"");
strb.append(""+this.report2.getNumberOfFailedTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getNumberOfFailedTest()+"");
strb.append("");
strb.append("");
strb.append("Compile time (Average/Number of measures)");
strb.append(""+this.report1.getAverageOfCompileTime()+"/"+this.report1.getNumberOfCompileTimeTest()+"");
strb.append(""+this.report2.getAverageOfCompileTime()+"/"+this.report2.getNumberOfCompileTimeTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getAverageOfCompileTime()+"/"+this.report3.getNumberOfCompileTimeTest()+"");
strb.append("");
strb.append("");
strb.append("Execution time (Average/Number of measures)");
strb.append(""+this.report1.getAverageOfExecutionTime()+"/"+this.report1.getNumberOfExecutionTimeTest()+"");
strb.append(""+this.report2.getAverageOfExecutionTime()+"/"+this.report2.getNumberOfExecutionTimeTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getAverageOfExecutionTime()+"/"+this.report3.getNumberOfExecutionTimeTest()+"");
strb.append("");
strb.append("");
strb.append("Performance (Average/Number of measures)");
strb.append(""+this.report1.getAverageOfPerformance()+"/"+this.report1.getNumberOfPerformanceTest()+"");
strb.append(""+this.report2.getAverageOfPerformance()+"/"+this.report2.getNumberOfPerformanceTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getAverageOfPerformance()+"/"+this.report3.getNumberOfPerformanceTest()+"");
strb.append("");
strb.append("");
strb.append("Performance (Average/Number of measures)");
strb.append(""+this.report1.getAverageOfPerformance()+"/"+this.report1.getNumberOfPerformanceTest()+"");
strb.append(""+this.report2.getAverageOfPerformance()+"/"+this.report2.getNumberOfPerformanceTest()+"");
if (nb_build3!=0) strb.append(""+this.report3.getAverageOfPerformance()+"/"+this.report3.getNumberOfPerformanceTest()+"");
strb.append("
");
strb.append("");
strb.append("NOT EXECUTED");
strb.append("TIMED OUT");
strb.append("FAILED");
strb.append("SUCCESSFULL");
strb.append("DOESN'T EXIST");
strb.append("");
if (this.shortDiff) {
strb.append("Display the full diff");
} else {
strb.append("Display the short diff");
}
strb.append("");
strb.append("");
/**
* if short display :
* Get all the tests executed in the three builds
* else
* Get all the changed status tests in the three builds
*/
ArrayList global_test = new ArrayList();
global_test.addAll(this.report1.getTests());
for (int i=0; ix";
if (!test1.isExecuted()) {
color1="grey";
} else {
if (test1.isHasTimedOut()) {
color1 = "yellow";
} else {
if (test1.isSuccessfull()) {
color1="green";
} else { color1="red"; }
}
}
}
if (this.report2.getTestWithName(global_test.get(i).getName()) != null) {
Test test2 = this.report2.getTestWithName(global_test.get(i).getName());
txt2="x";
if (!test2.isExecuted()) {
color2="grey";
} else {
if (test2.isHasTimedOut()) {
color2 = "yellow";
} else {
if (test2.isSuccessfull()) {
color2="green";
} else { color2="red"; }
}
}
}
if (nb_build3!=0) {
if (this.report3.getTestWithName(global_test.get(i).getName()) != null) {
Test test3 = this.report3.getTestWithName(global_test.get(i).getName());
txt3="x";
if (!test3.isExecuted()) {
color3="grey";
} else {
if (test3.isHasTimedOut()) {
color3 = "yellow";
} else {
if (test3.isSuccessfull()) {
color3="green";
} else { color3="red"; }
}
}
}
if (shortDiff && (color1!=color2 || color1!=color3 || color2!=color3)) {
strb.append("");
strb.append(""+global_test.get(i).getName()+"");
strb.append(" "+txt1+" ");
strb.append(" "+txt2+" ");
strb.append(" "+txt3+" ");
strb.append("\n");
} else if (!shortDiff) {
strb.append("");
strb.append(""+global_test.get(i).getName()+"");
strb.append(" "+txt1+" ");
strb.append(" "+txt2+" ");
strb.append(" "+txt3+" ");
strb.append("\n");
}
} else {
if (shortDiff && (color1!=color2)) {
strb.append("");
strb.append(""+global_test.get(i).getName()+"");
strb.append(" "+txt1+" ");
strb.append(" "+txt2+" ");
strb.append("\n");
} else if (!shortDiff) {
strb.append("");
strb.append(""+global_test.get(i).getName()+"");
strb.append(" "+txt1+" ");
strb.append(" "+txt2+" ");
strb.append("\n");
}
}
}
return strb.toString();
}
public AbstractBuild, ?> getOwner() {
return _owner;
}
public String getDisplayName() {
return "Reports diff.";
}
}