diff --git a/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/order/ByStatus.java b/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/order/ByStatus.java index 1ed146141..573c016ae 100644 --- a/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/order/ByStatus.java +++ b/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/order/ByStatus.java @@ -1,7 +1,5 @@ package com.smartcodeltd.jenkinsci.plugins.buildmonitor.order; -import hudson.model.AbstractBuild; -import hudson.model.AbstractProject; import hudson.model.Job; import hudson.model.Result; import hudson.model.Run; @@ -11,33 +9,33 @@ public class ByStatus implements Comparator> { @Override public int compare(Job a, Job b) { - return bothProjectsHaveBuildHistory(a, b) ? - compareLastBuilds(a, b) : - compareProjects(a, b); + return bothProjectsHaveBuildHistory(a, b) + ? compareRecentlyCompletedBuilds(a, b) + : compareProjects(a, b); } // -- private boolean bothProjectsHaveBuildHistory(Job a, Job b) { - return a.getLastBuild() != null && b.getLastBuild() != null; + return a.getLastCompletedBuild() != null && b.getLastCompletedBuild() != null; } private int compareProjects(Job a, Job b) { - Run lastBuildOfA = a.getLastBuild(); - Run lastBuildOfB = b.getLastBuild(); + Run recentBuildOfA = a.getLastCompletedBuild(); + Run recentBuildOfB = b.getLastCompletedBuild(); - if (lastBuildOfA == null && lastBuildOfB != null) { + if (recentBuildOfA == null && recentBuildOfB != null) { return -1; - } else if (lastBuildOfA != null && lastBuildOfB == null) { + } else if (recentBuildOfA != null && recentBuildOfB == null) { return 1; } else { return 0; } } - private int compareLastBuilds(Job a, Job b) { - Result lastResultOfA = a.getLastBuild().getResult(); - Result lastResultOfB = b.getLastBuild().getResult(); + private int compareRecentlyCompletedBuilds(Job a, Job b) { + Result lastResultOfA = a.getLastCompletedBuild().getResult(); + Result lastResultOfB = b.getLastCompletedBuild().getResult(); if (lastResultOfA.isWorseThan(lastResultOfB)) { return -1; @@ -47,4 +45,4 @@ private int compareLastBuilds(Job a, Job b) { return 0; } } -} +} \ No newline at end of file