1 package hudson.triggers; 2 3 import antlr.ANTLRException; 4 import static hudson.Util.fixNull; 5 import hudson.model.Descriptor; 6 import hudson.model.BuildableItem; 7 import hudson.model.Item; 8 import hudson.scheduler.CronTabList; 9 import hudson.util.FormFieldValidator; 10 import org.kohsuke.stapler.StaplerRequest; 11 import org.kohsuke.stapler.StaplerResponse; 12 13 import javax.servlet.ServletException ; 14 import java.io.IOException ; 15 16 21 public class TimerTrigger extends Trigger<BuildableItem> { 22 public TimerTrigger(String cronTabSpec) throws ANTLRException { 23 super(cronTabSpec); 24 } 25 26 protected void run() { 27 job.scheduleBuild(); 28 } 29 30 public TriggerDescriptor getDescriptor() { 31 return DESCRIPTOR; 32 } 33 34 public static final TriggerDescriptor DESCRIPTOR = new DescriptorImpl(); 35 36 public static class DescriptorImpl extends TriggerDescriptor { 37 public DescriptorImpl() { 38 super(TimerTrigger.class); 39 } 40 41 public boolean isApplicable(Item item) { 42 return item instanceof BuildableItem; 43 } 44 45 public String getDisplayName() { 46 return "Build periodically"; 47 } 48 49 public String getHelpFile() { 50 return "/help/project-config/timer.html"; 51 } 52 53 56 public void doCheck(StaplerRequest req, StaplerResponse rsp) throws IOException , ServletException { 57 new FormFieldValidator(req,rsp,true) { 58 protected void check() throws IOException , ServletException { 59 try { 60 CronTabList.create(fixNull(request.getParameter("value"))); 61 ok(); 62 } catch (ANTLRException e) { 63 error(e.getMessage()); 64 } 65 } 66 }.process(); 67 } 68 69 public Trigger newInstance(StaplerRequest req) throws FormException { 70 try { 71 return new TimerTrigger(req.getParameter("timer_spec")); 72 } catch (ANTLRException e) { 73 throw new FormException(e.toString(),e,"timer_spec"); 74 } 75 } 76 } 77 } 78 | Popular Tags |