1 package hudson.util; 2 3 import hudson.model.Job; 4 import hudson.model.Result; 5 import hudson.model.Run; 6 import hudson.model.View; 7 import hudson.model.Item; 8 9 import java.util.ArrayList ; 10 import java.util.Calendar ; 11 import java.util.Collection ; 12 import java.util.Collections ; 13 import java.util.GregorianCalendar ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 22 public class RunList extends ArrayList <Run> { 23 24 public RunList() { 25 } 26 27 public RunList(Job<?,?> j) { 28 addAll(j.getBuilds()); 29 } 30 31 public RunList(View view) { 32 for (Item item : view.getItems()) 33 for (Job<?,?> j : item.getAllJobs()) 34 addAll(j.getBuilds()); 35 Collections.sort(this,Run.ORDER_BY_DATE); 36 } 37 38 public RunList(Collection <? extends Job> jobs) { 39 for (Job<?,?> j : jobs) 40 addAll(j.getBuilds()); 41 Collections.sort(this,Run.ORDER_BY_DATE); 42 } 43 44 public static RunList fromRuns(Collection <? extends Run> runs) { 45 RunList r = new RunList(); 46 r.addAll(runs); 47 return r; 48 } 49 50 53 public RunList failureOnly() { 54 for (Iterator <Run> itr = iterator(); itr.hasNext();) { 55 Run r = itr.next(); 56 if(r.getResult()==Result.SUCCESS) 57 itr.remove(); 58 } 59 return this; 60 } 61 62 65 public RunList regressionOnly() { 66 for (Iterator <Run> itr = iterator(); itr.hasNext();) { 67 Run r = itr.next(); 68 if(!r.getBuildStatusSummary().isWorse) 69 itr.remove(); 70 } 71 return this; 72 } 73 74 79 public RunList newBuilds() { 80 GregorianCalendar threshold = new GregorianCalendar (); 81 threshold.add(Calendar.DAY_OF_YEAR,-7); 82 83 int count=0; 84 85 for (Iterator <Run> itr = iterator(); itr.hasNext();) { 86 Run r = itr.next(); 87 if(r.isBuilding()) { 88 itr.remove(); 90 continue; 91 } 92 if(count<10) { 94 count++; 95 continue; 96 } 97 if(r.getTimestamp().before(threshold)) 99 itr.remove(); 100 } 101 return this; 102 } 103 } 104 | Popular Tags |