Skip to content
Permalink
Browse files

JENKINS-32499 BuildGraph doesn't show up if there is a null run

And also moving the FlowDownStreamRunDeclarer.java to buildgraph-view
from build-flow-plugin as this file functionality related to buildgraph
  • Loading branch information...
pskumar448 committed May 7, 2016
1 parent 38cb290 commit f368bf106afe3763b20768dbe53f31f9ff3205ec
Showing with 60 additions and 0 deletions.
  1. +7 −0 pom.xml
  2. +53 −0 src/main/java/org/jenkinsci/plugins/buildgraphview/FlowDownStreamRunDeclarer.java
@@ -55,6 +55,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.cloudbees.plugins</groupId>
<artifactId>build-flow-plugin</artifactId>
<version>0.18</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@@ -0,0 +1,53 @@
package org.jenkinsci.plugins.buildgraphview;

import com.cloudbees.plugins.flow.FlowCause;
import com.cloudbees.plugins.flow.FlowRun;
import com.cloudbees.plugins.flow.JobInvocation;
import hudson.Extension;
import hudson.model.Run;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutionException;

/**
* @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
*/
@Extension(optional = true)
public class FlowDownStreamRunDeclarer extends DownStreamRunDeclarer {

@Override
public List<Run> getDownStream(Run r) throws ExecutionException, InterruptedException {

if (r instanceof FlowRun) {
FlowRun f = (FlowRun) r;
return getOutgoingEdgeRuns(f, f.getStartJob());
}

List<Run> runs = Collections.emptyList();
FlowCause cause = (FlowCause) r.getCause(FlowCause.class);
FlowRun f;
while (runs.isEmpty() && cause != null) {
f = cause.getFlowRun();
runs = getOutgoingEdgeRuns(f, cause.getAssociatedJob());
cause = (FlowCause) cause.getFlowRun().getCause(FlowCause.class);
}

return runs;
}

private List<Run> getOutgoingEdgeRuns(FlowRun f, JobInvocation start) throws ExecutionException, InterruptedException {
Set<FlowRun.JobEdge> edges = f.getJobsGraph().outgoingEdgesOf(start);
List<Run> runs = new ArrayList<Run>(edges.size());
for (FlowRun.JobEdge edge : edges) {
JobInvocation targetJobEdge = edge.getTarget();
Run run = targetJobEdge.getBuild();
if (run != null) {
runs.add(run);
}
}
return runs;
}
}

0 comments on commit f368bf1

Please sign in to comment.
You can’t perform that action at this time.