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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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.scheduler;
25
26 import antlr.ANTLRException;
27
28 import java.util.Calendar;
29 import java.util.Collection;
30 import java.util.Vector;
31
32 /**
33 * {@link CronTab} list (logically OR-ed).
34 *
35 * @author Kohsuke Kawaguchi
36 */
37 public final class CronTabList {
38 private final Vector<CronTab> tabs;
39
40 public CronTabList(Collection<CronTab> tabs) {
41 this.tabs = new Vector<CronTab>(tabs);
42 }
43
44 /**
45 * Returns true if the given calendar matches
46 */
47 public synchronized boolean check(Calendar cal) {
48 for (CronTab tab : tabs) {
49 if(tab.check(cal))
50 return true;
51 }
52 return false;
53 }
54
55 /**
56 * Checks if this crontab entry looks reasonable,
57 * and if not, return an warning message.
58 *
59 * <p>
60 * The point of this method is to catch syntactically correct
61 * but semantically suspicious combinations, like
62 * "* 0 * * *"
63 */
64 public String checkSanity() {
65 for (CronTab tab : tabs) {
66 String s = tab.checkSanity();
67 if(s!=null) return s;
68 }
69 return null;
70 }
71
72 public static CronTabList create(String format) throws ANTLRException {
73 return create(format,null);
74 }
75
76 public static CronTabList create(String format, Hash hash) throws ANTLRException {
77 Vector<CronTab> r = new Vector<CronTab>();
78 int lineNumber = 0;
79 for (String line : format.split("\\r?\\n")) {
80 lineNumber++;
81 line = line.trim();
82 if(line.length()==0 || line.startsWith("#"))
83 continue; // ignorable line
84 try {
85 r.add(new CronTab(line,lineNumber,hash));
86 } catch (ANTLRException e) {
87 throw new ANTLRException(Messages.CronTabList_InvalidInput(line,e.toString()),e);
88 }
89 }
90 return new CronTabList(r);
91 }
92 }
93