KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.Serializable JavaDoc;
40 import java.util.ArrayList JavaDoc;
41 import java.util.Collections JavaDoc;
42 import java.util.List JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.Properties JavaDoc;
45 import java.util.Iterator JavaDoc;
46
47 import net.sourceforge.cruisecontrol.util.ValidationHelper;
48
49 /**
50  * A plugin that represents the project node
51  * @author <a HREF="mailto:jerome@coffeebreaks.org">Jerome Lacoste</a>
52  */

53 public class ProjectConfig implements Serializable JavaDoc {
54
55     private String JavaDoc name;
56     private boolean buildAfterFailed = true;
57     private CCDateFormat dateFormat;
58
59     private Bootstrappers bootstrappers;
60     private LabelIncrementer labelIncrementer;
61     private Listeners listeners;
62     private Log log;
63     private ModificationSet modificationSet;
64     private Publishers publishers;
65     private Schedule schedule;
66
67     private Map JavaDoc properties;
68
69     /**
70      * Called after the configuration is read to make sure that all the mandatory parameters
71      * were specified..
72      *
73      * @throws CruiseControlException if there was a configuration error.
74      */

75     public void validate() throws CruiseControlException {
76         if (dateFormat != null) {
77              dateFormat.validate();
78         }
79         ValidationHelper.assertTrue(schedule != null, "project requires a schedule");
80
81         if (bootstrappers != null) {
82             bootstrappers.validate();
83         }
84
85         if (listeners != null) {
86             listeners.validate();
87         }
88
89         if (log != null) {
90             log.validate();
91         }
92
93         if (modificationSet != null) {
94             modificationSet.validate();
95         }
96
97         if (schedule != null) {
98             schedule.validate();
99         }
100
101         if (publishers != null) {
102             publishers.validate();
103         }
104     }
105
106     public void setName(String JavaDoc name) {
107         this.name = name;
108     }
109
110     // TODO think about how to turn properties into plugins
111
void setProperties(Map JavaDoc properties) {
112         this.properties = properties;
113     }
114
115     public void setBuildAfterFailed(boolean buildAfterFailed) {
116         this.buildAfterFailed = buildAfterFailed;
117     }
118
119     public void add(CCDateFormat dateFormat) {
120         this.dateFormat = dateFormat;
121     }
122
123     public void add(ModificationSet modificationSet) {
124         this.modificationSet = modificationSet;
125     }
126
127     public void add(Bootstrappers bootstrappers) {
128         this.bootstrappers = bootstrappers;
129     }
130
131     public void add(Listeners listeners) {
132         this.listeners = listeners;
133     }
134
135     public void add(Publishers publishers) {
136         this.publishers = publishers;
137     }
138
139     public void add(Schedule schedule) {
140         this.schedule = schedule;
141     }
142
143     public void add(Log log) {
144         this.log = log;
145     }
146
147     public void add(LabelIncrementer labelIncrementer) {
148         this.labelIncrementer = labelIncrementer;
149     }
150
151     public CCDateFormat getDateFormat() { return dateFormat; }
152     
153     public boolean shouldBuildAfterFailed() { return buildAfterFailed; }
154
155     public Log getLog() { return log; }
156
157     public List JavaDoc getBootstrappers() {
158       return bootstrappers == null ? Collections.EMPTY_LIST : bootstrappers.getBootstrappers();
159     }
160
161     public List JavaDoc getListeners() { return listeners == null ? Collections.EMPTY_LIST : listeners.getListeners(); }
162
163     public List JavaDoc getPublishers() { return publishers == null ? Collections.EMPTY_LIST : publishers.getPublishers(); }
164
165     public ModificationSet getModificationSet() { return modificationSet; }
166
167     public Schedule getSchedule() { return schedule; }
168
169     public LabelIncrementer getLabelIncrementer() { return labelIncrementer; }
170
171     public String JavaDoc getName() { return name; }
172
173     // TODO: keep as Map ??
174
public Properties JavaDoc getProperties() {
175         Properties JavaDoc props = new Properties JavaDoc();
176         props.putAll(properties);
177         return props;
178     }
179     
180     public static class Bootstrappers {
181         private List JavaDoc bootstrappers = new ArrayList JavaDoc();
182         public void add(Bootstrapper bootstrapper) {
183             bootstrappers.add(bootstrapper);
184         }
185         public List JavaDoc getBootstrappers() { return bootstrappers; }
186
187         public void validate() throws CruiseControlException {
188             for (Iterator JavaDoc iterator = bootstrappers.iterator(); iterator.hasNext();) {
189                 Bootstrapper nextBootstrapper = (Bootstrapper) iterator.next();
190                 nextBootstrapper.validate();
191             }
192         }
193     }
194
195     public static class Listeners {
196         private List JavaDoc listeners = new ArrayList JavaDoc();
197         public void add(Listener listener) {
198             listeners.add(listener);
199         }
200         public List JavaDoc getListeners() { return listeners; }
201
202         public void validate() throws CruiseControlException {
203             for (Iterator JavaDoc iterator = listeners.iterator(); iterator.hasNext();) {
204                 Listener nextListener = (Listener) iterator.next();
205                 nextListener.validate();
206             }
207         }
208     }
209
210     public static class Publishers {
211         private List JavaDoc publishers = new ArrayList JavaDoc();
212         public void add(Publisher publisher) {
213             publishers.add(publisher);
214         }
215         public List JavaDoc getPublishers() { return publishers; }
216
217         public void validate() throws CruiseControlException {
218             for (Iterator JavaDoc iterator = publishers.iterator(); iterator.hasNext();) {
219                 Publisher nextPublisher = (Publisher) iterator.next();
220                 nextPublisher.validate();
221             }
222
223         }
224     }
225 }
226
Popular Tags