Skip to content

Commit

Permalink
JENKINS-22016: Create Graph for matrix summary page
Browse files Browse the repository at this point in the history
  • Loading branch information
evandy0 committed May 4, 2016
1 parent f636de3 commit 712d3e3
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -29,7 +29,7 @@
<groupId>org.tap4j</groupId>
<artifactId>tap</artifactId>
<name>Jenkins TAP Plugin</name>
<version>1.26-EVANDY</version>
<version>1.26.1-EVANDY</version>
<packaging>hpi</packaging>

<licenses>
Expand Down
99 changes: 86 additions & 13 deletions src/main/java/org/tap4j/plugin/TapProjectAction.java
Expand Up @@ -26,6 +26,8 @@
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.model.Job;
import hudson.matrix.MatrixProject;
import hudson.util.ChartUtil;
import hudson.util.DataSetBuilder;
import hudson.util.RunList;
Expand All @@ -50,6 +52,24 @@
public class TapProjectAction extends AbstractTapProjectAction {

private AbstractProject<?, ?> project;

protected class Result {
public int numPassed;
public int numFailed;
public int numSkipped;

public Result() {
numPassed = 0;
numFailed = 0;
numSkipped = 0;
}

public void add(Result r) {
numPassed += r.numPassed;
numFailed += r.numFailed;
numSkipped += r.numSkipped;
}
}

/**
* Used to figure out if we need to regenerate the graphs or not. Only used
Expand Down Expand Up @@ -150,14 +170,36 @@ protected JFreeChart createGraph() {
*/
public boolean isGraphActive() {
AbstractBuild<?, ?> build = getProject().getLastBuild();
AbstractProject<?,?> p = getProject();
// in order to have a graph, we must have at least two points.
int numPoints = 0;
while (numPoints < 2) {
if (build == null) {
return false;
}
if (build.getAction(getBuildActionClass()) != null) {
numPoints++;
if( p instanceof MatrixProject )
{
MatrixProject mp = (MatrixProject) p;

for (Job j : mp.getAllJobs()) {
if (j != mp) { //getAllJobs includes the parent job too, so skip that
Run<?,?> sub = j.getBuild(build.getId());
if(sub != null) {
// Not all builds are on all sub-projects
if (sub.getAction(getBuildActionClass()) != null) {
//data for at least 1 sub-job on this build
numPoints++;
break; // go look at the next build now
}
}
}
}
}
else
{
if (build.getAction(getBuildActionClass()) != null) {
numPoints++;
}
}
build = build.getPreviousBuild();
}
Expand Down Expand Up @@ -206,23 +248,54 @@ private boolean newGraphNotNeeded( final StaplerRequest req, StaplerResponse rsp

protected void populateDataSetBuilder(DataSetBuilder<String, ChartUtil.NumberOnlyBuildLabel> dataset ) {

AbstractProject<?, ?> p = getProject();

for (Run<?, ?> build = getProject().getLastBuild(); build != null; build = build.getPreviousBuild()) {
ChartUtil.NumberOnlyBuildLabel label = new ChartUtil.NumberOnlyBuildLabel((Run<?, ?>) build);
TapBuildAction action = build.getAction(getBuildActionClass());
if (action != null) {
TapResult report = action.getResult();
report.tally();

dataset.add(report.getPassed(), "Passed",
label);
dataset.add(report.getFailed(), "Failed",
label);
dataset.add(report.getSkipped(),
"Skipped", label);

Result r = new Result();

if( p instanceof MatrixProject )
{
MatrixProject mp = (MatrixProject) p;

for (Job j : mp.getAllJobs()) {
if (j != mp) { //getAllJobs includes the parent job too, so skip that
Run<?,?> sub = j.getBuild(build.getId());
if(sub != null) {
// Not all builds are on all sub-projects
r.add(summarizeBuild(sub));
}
}
}
}
else
{
r = summarizeBuild(build);
}

dataset.add(r.numPassed, "Passed", label);
dataset.add(r.numFailed, "Failed", label);
dataset.add(r.numSkipped, "Skipped", label);
}
}

protected Result summarizeBuild(Run<?,?> b)
{
Result r = new Result();

TapBuildAction action = b.getAction(getBuildActionClass());
if (action != null) {
TapResult report = action.getResult();
report.tally();

r.numPassed = report.getPassed();
r.numFailed = report.getFailed();
r.numSkipped = report.getSkipped();
}

return r;
}
/**
* Getter for property 'graphWidth'.
*
Expand Down

0 comments on commit 712d3e3

Please sign in to comment.