001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 200 E. Randolph, 25th Floor
005: * Chicago, IL 60601 USA
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package net.sourceforge.cruisecontrol.bootstrappers;
037:
038: import java.io.File;
039:
040: import net.sourceforge.cruisecontrol.Bootstrapper;
041: import net.sourceforge.cruisecontrol.CruiseControlException;
042: import net.sourceforge.cruisecontrol.sourcecontrols.CMSynergy;
043: import net.sourceforge.cruisecontrol.util.ManagedCommandline;
044: import net.sourceforge.cruisecontrol.util.ValidationHelper;
045:
046: import org.apache.log4j.Logger;
047:
048: /**
049: * The CMSynergyBootstrapper will reconfigure the project (and
050: * by default all subprojects) in order to pull in the latest changes.
051: * <p>
052: * If you do not wish to reconfigure subprojects, please set the
053: * recurse attribute to false.
054: *
055: * @author <a href="mailto:rjmpsmith@gmail.com">Robert J. Smith</a>
056: */
057: public class CMSynergyBootstrapper implements Bootstrapper {
058:
059: /**
060: * The CM Synergy executable used for executing commands. If not set,
061: * we will use the default value "ccm".
062: */
063: private String ccmExe;
064:
065: /**
066: * The CM Synergy project spec (2 part name) of the project we will
067: * use as a template to determine if any new tasks have been completed.
068: */
069: private String projectSpec;
070:
071: /**
072: * If set to true, all subprojects will also be reconfigured.
073: */
074: private boolean recurse = true;
075:
076: /**
077: * The file which contains the mapping between CM Synergy session names
078: * and IDs.
079: */
080: private File sessionFile;
081:
082: /**
083: * The given name of the CM Synergy session to use.
084: */
085: private String sessionName;
086:
087: /**
088: * The logger for this class
089: */
090: private static final Logger LOG = Logger
091: .getLogger(CMSynergyBootstrapper.class);
092:
093: /**
094: * Sets the name of the CM Synergy executable to use when issuing
095: * commands.
096: *
097: * @param ccmExe the name of the CM Synergy executable
098: */
099: public void setCcmExe(String 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 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 sessionFile) {
137: this .sessionFile = new File(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 sessionName) {
150: this .sessionName = sessionName;
151: }
152:
153: public void bootstrap() throws CruiseControlException {
154: LOG.info("Reconfiguring project \"" + projectSpec + "\".");
155:
156: // Create a managed command line
157: ManagedCommandline cmd = CMSynergy.createCcmCommand(ccmExe,
158: sessionName, sessionFile);
159: cmd.createArgument("reconfigure");
160: cmd.createArguments("-project", projectSpec);
161: if (recurse) {
162: cmd.createArgument("-recurse");
163: }
164:
165: try {
166: cmd.execute();
167: cmd.assertExitCode(0);
168: } catch (Exception e) {
169: throw new CruiseControlException(
170: "Could not reconfigure the project \""
171: + projectSpec + "\".", e);
172: }
173: }
174:
175: /* (non-Javadoc)
176: * @see net.sourceforge.cruisecontrol.Bootstrapper#validate()
177: */
178: public void validate() throws CruiseControlException {
179: // We must know which project to reconfigure
180: ValidationHelper.assertIsSet(projectSpec, "project", this
181: .getClass());
182: }
183: }
|