KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > CMSynergyBootstrapper


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.bootstrappers;
38
39 import java.io.File JavaDoc;
40
41 import net.sourceforge.cruisecontrol.Bootstrapper;
42 import net.sourceforge.cruisecontrol.CruiseControlException;
43 import net.sourceforge.cruisecontrol.sourcecontrols.CMSynergy;
44 import net.sourceforge.cruisecontrol.util.ManagedCommandline;
45 import net.sourceforge.cruisecontrol.util.ValidationHelper;
46
47 import org.apache.log4j.Logger;
48
49 /**
50  * The CMSynergyBootstrapper will reconfigure the project (and
51  * by default all subprojects) in order to pull in the latest changes.
52  * <p>
53  * If you do not wish to reconfigure subprojects, please set the
54  * recurse attribute to false.
55  *
56  * @author <a HREF="mailto:rjmpsmith@gmail.com">Robert J. Smith</a>
57  */

58 public class CMSynergyBootstrapper implements Bootstrapper {
59
60     /**
61      * The CM Synergy executable used for executing commands. If not set,
62      * we will use the default value "ccm".
63      */

64     private String JavaDoc ccmExe;
65     
66     /**
67      * The CM Synergy project spec (2 part name) of the project we will
68      * use as a template to determine if any new tasks have been completed.
69      */

70     private String JavaDoc projectSpec;
71     
72     /**
73      * If set to true, all subprojects will also be reconfigured.
74      */

75     private boolean recurse = true;
76
77     /**
78      * The file which contains the mapping between CM Synergy session names
79      * and IDs.
80      */

81     private File JavaDoc sessionFile;
82     
83     /**
84      * The given name of the CM Synergy session to use.
85      */

86     private String JavaDoc sessionName;
87     
88     /**
89      * The logger for this class
90      */

91     private static final Logger LOG = Logger.getLogger(CMSynergyBootstrapper.class);
92
93     /**
94      * Sets the name of the CM Synergy executable to use when issuing
95      * commands.
96      *
97      * @param ccmExe the name of the CM Synergy executable
98      */

99     public void setCcmExe(String JavaDoc ccmExe) {
100         this.ccmExe = ccmExe;
101     }
102     
103     /**
104      * Sets the CM Synergy project you wish to reconfigure
105      *
106      * @param projectSpec
107      * The project spec (in 2 part name format).
108      */

109     public void setProject(String JavaDoc projectSpec) {
110         this.projectSpec = projectSpec;
111     }
112         
113     /**
114      * Sets the value of the recurse attribute. If set to true, all subprojects
115      * will be reconfigured.
116      *
117      * @param recurse
118      */

119     public void setRecurse(boolean recurse) {
120         this.recurse = recurse;
121     }
122     
123     /**
124      * Sets the file which contains the mapping between CM Synergy session names
125      * and IDs. This file should be in the standard properties file format. Each
126      * line should map one name to a CM Synergy session ID (as returned by the
127      * "ccm status" command).
128      * <p>
129      * example:
130      * <br><br>
131      * session1=localhost:65024:192.168.1.17
132      *
133      * @param sessionFile
134      * The session file
135      */

136     public void setSessionFile(String JavaDoc sessionFile) {
137         this.sessionFile = new File JavaDoc(sessionFile);
138     }
139     
140     /**
141      * Sets the name of the CM Synergy session to use with this plugin. This
142      * name should appear in the specified session file.
143      *
144      * @param sessionName
145      * The session name
146      *
147      * @see #setSessionFile(String)
148      */

149     public void setSessionName(String JavaDoc sessionName) {
150         this.sessionName = sessionName;
151     }
152  
153     /* (non-Javadoc)
154      * @see net.sourceforge.cruisecontrol.Bootstrapper#bootstrap()
155      */

156     public void bootstrap() {
157         
158         LOG.info("Reconfiguring project \"" + projectSpec + "\".");
159
160         // Create a managed command line
161
ManagedCommandline cmd = CMSynergy.createCcmCommand(
162                 ccmExe, sessionName, sessionFile);
163         cmd.createArgument().setValue("reconfigure");
164         cmd.createArgument().setValue("-project");
165         cmd.createArgument().setValue(projectSpec);
166         if (recurse) {
167             cmd.createArgument().setValue("-recurse");
168         }
169
170         try {
171             cmd.execute();
172             cmd.assertExitCode(0);
173         } catch (Exception JavaDoc e) {
174             LOG.error(
175                 "Could not reconfigure the project \"" + projectSpec + "\"." ,
176                 e);
177         }
178     }
179
180     /* (non-Javadoc)
181      * @see net.sourceforge.cruisecontrol.Bootstrapper#validate()
182      */

183     public void validate() throws CruiseControlException {
184         // We must know which project to reconfigure
185
ValidationHelper.assertIsSet(projectSpec, "project", this.getClass());
186     }
187 }
188
Popular Tags