KickJava   Java API By Example, From Geeks To Geeks.

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


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
38 package net.sourceforge.cruisecontrol;
39
40 import java.util.Calendar JavaDoc;
41 import java.util.Date JavaDoc;
42 import java.util.Map JavaDoc;
43
44 import net.sourceforge.cruisecontrol.util.PerDayScheduleItem;
45 import net.sourceforge.cruisecontrol.util.ValidationHelper;
46
47 import org.jdom.Element;
48
49 public abstract class Builder extends PerDayScheduleItem implements Comparable JavaDoc {
50
51     private int time = NOT_SET;
52     private int multiple = 1;
53     private boolean multipleSet = false;
54     private String JavaDoc group = "default";
55
56     //should return log from build
57
public abstract Element build(Map JavaDoc properties) throws CruiseControlException;
58     
59     public abstract Element buildWithTarget(Map JavaDoc properties, String JavaDoc target) throws CruiseControlException;
60     
61     public void validate() throws CruiseControlException {
62         boolean timeSet = time != NOT_SET;
63
64         ValidationHelper.assertFalse(timeSet && multipleSet,
65             "Only one of 'time' or 'multiple' are allowed on builders.");
66     }
67
68     public int getTime() {
69         return time;
70     }
71
72     /**
73      * can use ScheduleItem.NOT_SET to reset.
74      * @param timeString
75      */

76     public void setTime(String JavaDoc timeString) {
77         time = Integer.parseInt(timeString);
78     }
79
80     /**
81      * can use Builder.NOT_SET to reset.
82      * @param multiple
83      */

84     public void setMultiple(int multiple) {
85         multipleSet = multiple != NOT_SET;
86         this.multiple = multiple;
87     }
88
89     public int getMultiple() {
90         boolean timeSet = time != NOT_SET;
91         if (timeSet && !multipleSet) {
92             return NOT_SET;
93         }
94         return multiple;
95     }
96
97     public String JavaDoc getGroup() {
98         return group;
99     }
100
101     public void setGroup(String JavaDoc group) {
102         this.group = group;
103     }
104
105     /**
106      * is this the correct day to be running this builder?
107      */

108     public boolean isValidDay(Date JavaDoc now) {
109         if (getDay() < 0) {
110             return true;
111         }
112
113         Calendar JavaDoc cal = Calendar.getInstance();
114         cal.setTime(now);
115         return cal.get(Calendar.DAY_OF_WEEK) == getDay();
116     }
117
118     /**
119      * used to sort builders. we're only going to care about sorting builders based on build number,
120      * so we'll sort based on the multiple attribute.
121      */

122     public int compareTo(Object JavaDoc o) {
123         Builder builder = (Builder) o;
124         Integer JavaDoc integer = new Integer JavaDoc(multiple);
125         Integer JavaDoc integer2 = new Integer JavaDoc(builder.getMultiple());
126         return integer2.compareTo(integer); //descending order
127
}
128
129 }
130
Popular Tags