Skip to content

Commit cafd297

Browse files
committedJul 6, 2014
If no failing jobs, consider unstable as failures.
Fixes JENKINS-23306
1 parent d3dae0c commit cafd297

File tree

1 file changed

+64
-12
lines changed

1 file changed

+64
-12
lines changed
 

‎src/main/java/hudson/model/ProjectViewEntry.java

+64-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public class ProjectViewEntry implements IViewEntry {
2121

2222
private String name;
2323

24+
private TreeSet<IViewEntry> failing;
25+
26+
private TreeSet<IViewEntry> completelyPassing;
27+
28+
private TreeSet<IViewEntry> unstable;
29+
30+
private int jobsHashCode = -1;
31+
2432
public ProjectViewEntry(String name) {
2533
this.name = name;
2634
}
@@ -40,24 +48,68 @@ public TreeSet<IViewEntry> getClaimedBuilds() {
4048
return failing;
4149
}
4250

51+
/**
52+
* Returns passing jobs. Passing depends on the context: if there is at
53+
* least one failing job, then passing jobs also includes unstable ones. If
54+
* there's no failing job, then passing will only include stable jobs.
55+
* Unstable ones will be returned through {@link #getFailingJobs()}
56+
*
57+
* @return passing jobs (including unstable if there are jobs in failure).
58+
* @see #getFailingJobs()
59+
*/
4360
public TreeSet<IViewEntry> getPassingJobs() {
44-
TreeSet<IViewEntry> passing = new TreeSet<IViewEntry>(
45-
new EntryComparator());
46-
for (IViewEntry job : jobs) {
47-
if (!job.getBroken() && job.getFailCount() == 0)
48-
passing.add(job);
61+
62+
computePassingAndFailingJobs();
63+
64+
if (failing.size() > 0) {
65+
TreeSet<IViewEntry> aggregate = new TreeSet<IViewEntry>(
66+
new EntryComparator());
67+
aggregate.addAll(unstable);
68+
aggregate.addAll(completelyPassing);
69+
return aggregate;
4970
}
50-
return passing;
71+
return completelyPassing;
72+
}
73+
74+
/**
75+
* Returns "failing" jobs. Depending on the context: failing will be jobs in
76+
* "real" failure (i.e. "red") if there are indeed some jobs of this sort.
77+
* If there aren't, then failing jobs will be unstable ones.
78+
*
79+
* @return "failing" jobs (unstable ones if no failing job is currently
80+
* present).
81+
* @see #getPassingJobs()
82+
*/
83+
public TreeSet<IViewEntry> getFailingJobs() {
84+
computePassingAndFailingJobs();
85+
86+
if (failing.size() > 0) {
87+
return failing;
88+
}
89+
return unstable;
5190
}
5291

53-
public TreeSet<IViewEntry> getFailingJobs() {
54-
TreeSet<IViewEntry> failing = new TreeSet<IViewEntry>(
55-
new EntryComparator());
92+
/**
93+
* Computes "completelyPassing" (meaning without including unstable jobs),
94+
* unstable and failing jobs sets. If the calculation has already been made,
95+
* this method does nothing.
96+
*/
97+
private void computePassingAndFailingJobs() {
98+
if (jobsHashCode == jobs.hashCode()) {
99+
return;
100+
}
101+
completelyPassing = new TreeSet<IViewEntry>(new EntryComparator());
102+
failing = new TreeSet<IViewEntry>(new EntryComparator());
103+
unstable = new TreeSet<IViewEntry>(new EntryComparator());
56104
for (IViewEntry job : jobs) {
57-
if (job.getBroken() || job.getFailCount() > 0)
58-
failing.add(job);
105+
if (job.getBroken() || job.getFailCount() > 0) {
106+
failing.add(job);
107+
} else if (!job.getStable()) {
108+
unstable.add(job);
109+
} else {
110+
completelyPassing.add(job);
111+
}
59112
}
60-
return failing;
61113
}
62114

63115
public TreeSet<IViewEntry> getUnclaimedJobs() {

0 commit comments

Comments
 (0)
Please sign in to comment.