提交 f97b5b33 编写于 作者: J Jesse Glick

Show the user examples of when a cron tab list should actually run.

上级 ce1df7d3
......@@ -55,6 +55,8 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=rfe>
Cron-style trigger configuration will now display expected prior and subsequent run times.
<li class=bug>
Incorrect filtering of build queue and executors widgets after 1.514.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-20500">issue 20500</a>)
......
......@@ -24,10 +24,12 @@
package hudson.scheduler;
import antlr.ANTLRException;
import java.util.Calendar;
import java.util.Collection;
import java.util.Vector;
import javax.annotation.CheckForNull;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
/**
* {@link CronTab} list (logically OR-ed).
......@@ -89,4 +91,29 @@ public final class CronTabList {
}
return new CronTabList(r);
}
@Restricted(NoExternalUse.class) // just for form validation
public @CheckForNull Calendar previous() {
Calendar nearest = null;
for (CronTab tab : tabs) {
Calendar scheduled = tab.floor(Calendar.getInstance());
if (nearest == null || nearest.before(scheduled)) {
nearest = scheduled;
}
}
return nearest;
}
@Restricted(NoExternalUse.class) // just for form validation
public @CheckForNull Calendar next() {
Calendar nearest = null;
for (CronTab tab : tabs) {
Calendar scheduled = tab.ceil(Calendar.getInstance());
if (nearest == null || nearest.after(scheduled)) {
nearest = scheduled;
}
}
return nearest;
}
}
......@@ -23,19 +23,21 @@
*/
package hudson.triggers;
import antlr.ANTLRException;
import hudson.Extension;
import static hudson.Util.fixNull;
import hudson.model.BuildableItem;
import hudson.model.Cause;
import hudson.model.Item;
import hudson.scheduler.CronTabList;
import hudson.scheduler.Hash;
import hudson.util.FormValidation;
import hudson.Extension;
import java.text.DateFormat;
import java.util.Calendar;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import antlr.ANTLRException;
/**
* {@link Trigger} that runs a job periodically.
*
......@@ -64,18 +66,26 @@ public class TimerTrigger extends Trigger<BuildableItem> {
}
// backward compatibility
public FormValidation doCheck(@QueryParameter String value) {
return doCheckSpec(value);
public FormValidation doCheck(@QueryParameter String value, @AncestorInPath Item item) {
return doCheckSpec(value, item);
}
/**
* Performs syntax check.
*/
public FormValidation doCheckSpec(@QueryParameter String value) {
public FormValidation doCheckSpec(@QueryParameter String value, @AncestorInPath Item item) {
try {
String msg = CronTabList.create(fixNull(value)).checkSanity();
CronTabList ctl = CronTabList.create(fixNull(value), item != null ? Hash.from(item.getFullName()) : null);
String msg = ctl.checkSanity();
if(msg!=null) return FormValidation.warning(msg);
return FormValidation.ok();
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());
}
} catch (ANTLRException e) {
if (value.trim().indexOf('\n')==-1 && value.contains("**"))
return FormValidation.error(Messages.TimerTrigger_MissingWhitespace());
......
......@@ -26,5 +26,7 @@ SCMTrigger.BuildAction.DisplayName=Polling Log
SCMTrigger.SCMTriggerCause.ShortDescription=Started by an SCM change
TimerTrigger.DisplayName=Build periodically
TimerTrigger.MissingWhitespace=You appear to be missing whitespace between * and *.
TimerTrigger.no_schedules_so_will_never_run=No schedules so will never run
TimerTrigger.TimerTriggerCause.ShortDescription=Started by timer
Trigger.init=Initializing timer for triggers
\ No newline at end of file
TimerTrigger.would_last_have_run_at_would_next_run_at=Would last have run at {0}; would next run at {1}.
Trigger.init=Initializing timer for triggers
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册