File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\triggers\TimerTrigger.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Jean-Baptiste Quenot, Martin Eigenbrodt
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.triggers;
25
26 import static hudson.Util.fixNull;
27 import hudson.model.BuildableItem;
28 import hudson.model.Cause;
29 import hudson.model.Item;
30 import hudson.scheduler.CronTabList;
31 import hudson.util.FormValidation;
32 import hudson.Extension;
33
34 import org.kohsuke.stapler.DataBoundConstructor;
35 import org.kohsuke.stapler.QueryParameter;
36
37 import antlr.ANTLRException;
38
39 /**
40 * {@link Trigger} that runs a job periodically.
41 *
42 * @author Kohsuke Kawaguchi
43 */
44 public class TimerTrigger extends Trigger<BuildableItem> {
45
46 @DataBoundConstructor
47 public TimerTrigger(String spec) throws ANTLRException {
48 super(spec);
49 }
50
51 @Override
52 public void run() {
53 job.scheduleBuild(0, new TimerTriggerCause());
54 }
55
56 @Extension
57 public static class DescriptorImpl extends TriggerDescriptor {
58 public boolean isApplicable(Item item) {
59 return item instanceof BuildableItem;
60 }
61
62 public String getDisplayName() {
63 return Messages.TimerTrigger_DisplayName();
64 }
65
66 // backward compatibility
67 public FormValidation doCheck(@QueryParameter String value) {
68 return doCheckSpec(value);
69 }
70
71 /**
72 * Performs syntax check.
73 */
74 public FormValidation doCheckSpec(@QueryParameter String value) {
75 try {
76 String msg = CronTabList.create(fixNull(value)).checkSanity();
77 if(msg!=null) return FormValidation.warning(msg);
78 return FormValidation.ok();
79 } catch (ANTLRException e) {
80 if (value.trim().indexOf('\n')==-1 && value.contains("**"))
81 return FormValidation.error(Messages.TimerTrigger_MissingWhitespace());
82 return FormValidation.error(e.getMessage());
83 }
84 }
85 }
86
87 public static class TimerTriggerCause extends Cause {
88 @Override
89 public String getShortDescription() {
90 return Messages.TimerTrigger_TimerTriggerCause_ShortDescription();
91 }
92
93 @Override
94 public boolean equals(Object o) {
95 return o instanceof TimerTriggerCause;
96 }
97
98 @Override
99 public int hashCode() {
100 return 5;
101 }
102 }
103 }
104