diff --git a/core/src/main/java/hudson/triggers/TimerTrigger.java b/core/src/main/java/hudson/triggers/TimerTrigger.java index 1925f00b9088555351d68f8e97f1ad00f4b73f51..c2a3ee4574cb07e9c460c79b5ade86d9f5f6c6bd 100644 --- a/core/src/main/java/hudson/triggers/TimerTrigger.java +++ b/core/src/main/java/hudson/triggers/TimerTrigger.java @@ -34,7 +34,10 @@ import hudson.scheduler.CronTabList; import hudson.scheduler.Hash; import hudson.util.FormValidation; import java.text.DateFormat; +import java.util.ArrayList; import java.util.Calendar; +import java.util.Collection; + import org.kohsuke.stapler.AncestorInPath; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; @@ -83,22 +86,32 @@ public class TimerTrigger extends Trigger { public FormValidation doCheckSpec(@QueryParameter String value, @AncestorInPath Item item) { try { CronTabList ctl = CronTabList.create(fixNull(value), item != null ? Hash.from(item.getFullName()) : null); - String msg = ctl.checkSanity(); - if(msg!=null) return FormValidation.warning(msg); - Calendar prev = ctl.previous(); - Calendar next = ctl.next(); - if (prev != null && next != null) { - DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); - return FormValidation.ok(Messages.TimerTrigger_would_last_have_run_at_would_next_run_at(fmt.format(prev.getTime()), fmt.format(next.getTime()))); - } else { - return FormValidation.warning(Messages.TimerTrigger_no_schedules_so_will_never_run()); - } + Collection validations = new ArrayList<>(); + updateValidationsForSanity(validations, ctl); + updateValidationsForNextRun(validations, ctl); + return FormValidation.aggregate(validations); } catch (ANTLRException e) { if (value.trim().indexOf('\n')==-1 && value.contains("**")) return FormValidation.error(Messages.TimerTrigger_MissingWhitespace()); return FormValidation.error(e.getMessage()); } } + + private void updateValidationsForSanity(Collection validations, CronTabList ctl) { + String msg = ctl.checkSanity(); + if(msg!=null) validations.add(FormValidation.warning(msg)); + } + + private void updateValidationsForNextRun(Collection validations, CronTabList ctl) { + Calendar prev = ctl.previous(); + Calendar next = ctl.next(); + if (prev != null && next != null) { + DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); + validations.add(FormValidation.ok(Messages.TimerTrigger_would_last_have_run_at_would_next_run_at(fmt.format(prev.getTime()), fmt.format(next.getTime())))); + } else { + validations.add(FormValidation.warning(Messages.TimerTrigger_no_schedules_so_will_never_run())); + } + } } public static class TimerTriggerCause extends Cause {