public BuildTimelineWidget(RunList<?> builds) { this.builds = builds.limit(20); // TODO instead render lazily }
/** * Return only the most recent builds. * <em>Warning:</em> this method mutates the original list and then returns it. * @param n a count * @return the n most recent builds * @since 1.507 */ public RunList<R> limit(final int n) { return limit(new CountingPredicate<R>() { public boolean apply(int index, R input) { return index<n; } }); }
/** * Filter the list by timestamp. * * {@code s<=;e}. * <em>Warning:</em> this method mutates the original list and then returns it. */ public RunList<R> byTimestamp(final long start, final long end) { return limit(new CountingPredicate<R>() { public boolean apply(int index, R r) { return start<=r.getTimeInMillis(); } }).filter(new Predicate<R>() { public boolean apply(R r) { return r.getTimeInMillis()<end; } }); }
/** * Reduce the size of the list by only leaving relatively new ones. * This also removes on-going builds, as RSS cannot be used to publish information * if it changes. * <em>Warning:</em> this method mutates the original list and then returns it. */ public RunList<R> newBuilds() { GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_YEAR, -7); final long t = cal.getTimeInMillis(); // can't publish on-going builds return filter(new Predicate<R>() { public boolean apply(R r) { return !r.isBuilding(); } }) // put at least 10 builds, but otherwise ignore old builds .limit(new CountingPredicate<R>() { public boolean apply(int index, R r) { return index < 10 || r.getTimeInMillis() >= t; } }); } }
/** * Gets the read-only view of the recent builds. * * @since 1.485 */ @Exported(name="builds") public RunList<RunT> getNewBuilds() { return getBuilds().limit(100); }
public BuildTimelineWidget(RunList<?> builds) { this.builds = builds.limit(20); // TODO instead render lazily }
/** * Return only the most recent builds. * <em>Warning:</em> this method mutates the original list and then returns it. * @param n a count * @return the n most recent builds * @since 1.507 */ public RunList<R> limit(final int n) { return limit(new CountingPredicate<R>() { public boolean apply(int index, R input) { return index<n; } }); }
/** * Filter the list by timestamp. * * {@code s<=;e}. * <em>Warning:</em> this method mutates the original list and then returns it. */ public RunList<R> byTimestamp(final long start, final long end) { return limit(new CountingPredicate<R>() { public boolean apply(int index, R r) { return start<=r.getTimeInMillis(); } }).filter(new Predicate<R>() { public boolean apply(R r) { return r.getTimeInMillis()<end; } }); }
/** * Reduce the size of the list by only leaving relatively new ones. * This also removes on-going builds, as RSS cannot be used to publish information * if it changes. * <em>Warning:</em> this method mutates the original list and then returns it. */ public RunList<R> newBuilds() { GregorianCalendar cal = new GregorianCalendar(); cal.add(Calendar.DAY_OF_YEAR, -7); final long t = cal.getTimeInMillis(); // can't publish on-going builds return filter(new Predicate<R>() { public boolean apply(R r) { return !r.isBuilding(); } }) // put at least 10 builds, but otherwise ignore old builds .limit(new CountingPredicate<R>() { public boolean apply(int index, R r) { return index < 10 || r.getTimeInMillis() >= t; } }); } }
/** * Gets the read-only view of the recent builds. * * @since 1.485 */ @Exported(name="builds") public RunList<RunT> getNewBuilds() { return getBuilds().limit(100); }
@Override public boolean shouldClearAll(@Nonnull Run<?,?> build) { if (build instanceof WorkflowRun) { WorkflowRun r = (WorkflowRun)build; WorkflowJob j = r.getParent(); PreserveStashesJobProperty prop = j.getProperty(PreserveStashesJobProperty.class); if (prop != null) { int bc = prop.getBuildCount(); if (bc > 0) { for (WorkflowRun recentRun : j.getBuilds().completedOnly().limit(bc)) { if (recentRun != null && recentRun.equals(r)) { return false; } } } } } return true; } }
@Override public void onCompleted(Run<?,?> r, TaskListener listener) { if (r instanceof WorkflowRun) { WorkflowJob j = ((WorkflowRun) r).getParent(); PreserveStashesJobProperty prop = j.getProperty(PreserveStashesJobProperty.class); if (prop != null && prop.getBuildCount() > 0) { // The "+1" is to ensure that we look at one more than the maximum possible number of builds with saved stashes. for (WorkflowRun build : j.getBuilds().completedOnly().limit(MAX_SAVED_STASHES + 1)) { try { StashManager.maybeClearAll(build); } catch (IOException x) { LOGGER.log(Level.WARNING, "failed to clean up stashes from " + build, x); } } } } } }