KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > PauseBuilder


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol;
38
39 import java.util.Calendar JavaDoc;
40 import java.util.Date JavaDoc;
41
42 import net.sourceforge.cruisecontrol.util.DateUtil;
43 import net.sourceforge.cruisecontrol.util.PerDayScheduleItem;
44 import net.sourceforge.cruisecontrol.util.ValidationHelper;
45
46 /**
47  * Used by <code>Schedule</code> to define periods of time when CruiseControl
48  * should not even attempt a build. Useful for making sure CruiseControl does
49  * not run during server backup times, etc.
50  *
51  * @author Alden Almagro
52  */

53 public class PauseBuilder extends PerDayScheduleItem {
54
55     private int startTime = PerDayScheduleItem.NOT_SET;
56     private int endTime = PerDayScheduleItem.NOT_SET;
57
58     public void validate() throws CruiseControlException {
59         ValidationHelper.assertFalse(startTime < 0,
60             "'starttime' is a required attribute on PauseBuilder");
61
62         ValidationHelper.assertFalse(endTime < 0,
63             "'endtime' is a required attribute on PauseBuilder");
64
65         ValidationHelper.assertFalse(getDay() == INVALID_NAME_OF_DAY,
66             "setDay attribute on PauseBuilder requires english name for day of week (case insensitive)");
67     }
68
69     public void setStartTime(int time) {
70         startTime = time;
71     }
72
73     public void setEndTime(int time) {
74         endTime = time;
75     }
76
77     public int getStartTime() {
78         return startTime;
79     }
80
81     public int getEndTime() {
82         return endTime;
83     }
84
85     /**
86      * Determine if the build is paused at the given time.
87      *
88      * @param date Date set to current date/time
89      *
90      * @return true if the build is paused at date
91      */

92     public boolean isPaused(Date JavaDoc date) {
93         Calendar JavaDoc now = Calendar.getInstance();
94         now.setTime(date);
95         int currentDay = now.get(Calendar.DAY_OF_WEEK);
96         int currentTime = DateUtil.getTimeFromDate(date);
97
98         int builderDay = getDay();
99         boolean isValidDay = ((builderDay < 0) || (builderDay == currentDay));
100
101         if (startTime < endTime) {
102             return (
103                 startTime <= currentTime
104                     && currentTime <= endTime
105                     && isValidDay);
106         }
107
108         return (
109             (startTime <= currentTime && (builderDay < 0 || builderDay == currentDay))
110                 || (currentTime <= endTime
111                     && (builderDay < 0 || builderDay == (currentDay - 1))));
112     }
113
114 }
115
Popular Tags