Skip to content

Commit

Permalink
Merge pull request #1941 from ChrisA89/JENKINS-9346-neaten-help-git-p…
Browse files Browse the repository at this point in the history
…arams

JENKINS-29059: Display cron run times after warnings if warnings occur.
  • Loading branch information
oleg-nenashev committed Dec 7, 2015
2 parents b8d4d2b + 4d754c4 commit 0597f3c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions core/src/main/java/hudson/triggers/TimerTrigger.java
Expand Up @@ -34,7 +34,10 @@
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;
Expand Down Expand Up @@ -83,22 +86,32 @@ public FormValidation doCheck(@QueryParameter String value, @AncestorInPath Item
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<FormValidation> 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<FormValidation> validations, CronTabList ctl) {
String msg = ctl.checkSanity();
if(msg!=null) validations.add(FormValidation.warning(msg));
}

private void updateValidationsForNextRun(Collection<FormValidation> 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 {
Expand Down

0 comments on commit 0597f3c

Please sign in to comment.