Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed JENKINS-18386, JENKINS-17597, JENKINS-17093, JENKINS-18399
- Loading branch information
jacob_robertson
committed
Jun 28, 2013
1 parent
0af7e79
commit b10005a
Showing
7 changed files
with
150 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
package hudson.views; | |||
|
|||
import hudson.Extension; | |||
import hudson.model.Descriptor; | |||
import hudson.model.Job; | |||
import hudson.model.Run; | |||
import hudson.model.TopLevelItem; | |||
import hudson.model.View; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.logging.Logger; | |||
|
|||
import org.kohsuke.stapler.DataBoundConstructor; | |||
|
|||
public class MostRecentJobsFilter extends ViewJobFilter { | |||
|
|||
private int maxToInclude; | |||
private boolean checkStartTime; | |||
|
|||
private static final transient Logger log = Logger.getLogger("MostRecentJobsFilter"); | |||
|
|||
@DataBoundConstructor | |||
public MostRecentJobsFilter(int maxToInclude, boolean checkStartTime) { | |||
this.maxToInclude = maxToInclude; | |||
this.checkStartTime = checkStartTime; | |||
} | |||
|
|||
@Override | |||
public List<TopLevelItem> filter(List<TopLevelItem> added, List<TopLevelItem> all, View filteringView) { | |||
List<TopLevelItem> filtered = new ArrayList<TopLevelItem>(added); | |||
|
|||
Collections.sort(filtered, new MostRecentJobsComparator()); | |||
|
|||
// subList was causing null-pointer, not sure why. | |||
// filtered = filtered.subList(0, maxToInclude); | |||
|
|||
int max = maxToInclude; | |||
if (max > filtered.size()) { | |||
max = filtered.size(); | |||
} | |||
List<TopLevelItem> subList = new ArrayList<TopLevelItem>(); | |||
for (int i = 0; i < max; i++) { | |||
subList.add(filtered.get(i)); | |||
} | |||
|
|||
return subList; | |||
} | |||
|
|||
@SuppressWarnings("rawtypes") | |||
private class MostRecentJobsComparator implements Comparator<TopLevelItem> { | |||
public int compare(TopLevelItem i1, TopLevelItem i2) { | |||
if (!(i1 instanceof Job)) { | |||
return -1; | |||
} | |||
if (!(i2 instanceof Job)) { | |||
return 1; | |||
} | |||
Job j1 = (Job) i1; | |||
Job j2 = (Job) i2; | |||
|
|||
Long t1 = getTime(j1); | |||
Long t2 = getTime(j2); | |||
|
|||
return t2.compareTo(t1); | |||
} | |||
} | |||
@SuppressWarnings("rawtypes") | |||
private long getTime(Job job) { | |||
Run run = job.getLastBuild(); | |||
while (run != null) { | |||
if (checkStartTime) { | |||
return run.getTimeInMillis(); | |||
} else if (!run.isBuilding()) { | |||
return run.getTimeInMillis() + run.getDuration(); | |||
} else { | |||
run = run.getPreviousBuild(); | |||
} | |||
} | |||
return Long.MIN_VALUE; | |||
} | |||
|
|||
@Extension | |||
public static class DescriptorImpl extends Descriptor<ViewJobFilter> { | |||
@Override | |||
public String getDisplayName() { | |||
return "Most Recent Jobs Filter"; | |||
} | |||
@Override | |||
public String getHelpFile() { | |||
return "/plugin/view-job-filters/most-recent-help.html"; | |||
} | |||
} | |||
|
|||
public boolean isCheckStartTime() { | |||
return checkStartTime; | |||
} | |||
|
|||
public int getMaxToInclude() { | |||
return maxToInclude; | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/resources/hudson/views/MostRecentJobsFilter/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,10 @@ | |||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" | |||
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" | |||
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project"> | |||
<f:entry title="${%Number of Jobs To Include}"> | |||
<f:textbox name="maxToInclude" field="maxToInclude" /> | |||
</f:entry> | |||
<f:entry title="${%Use job start time instead of completion time}"> | |||
<f:checkbox name="checkStartTime" field="checkStartTime"/> | |||
</f:entry> | |||
</j:jelly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters