001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001, ThoughtWorks, Inc.
004: * 651 W Washington Ave. Suite 500
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.util.HashMap;
039: import java.util.Map;
040:
041: import net.sourceforge.cruisecontrol.Bootstrapper;
042: import net.sourceforge.cruisecontrol.CruiseControlException;
043: import net.sourceforge.cruisecontrol.util.ValidationHelper;
044: import net.sourceforge.cruisecontrol.builders.ExecBuilder;
045:
046: import org.apache.log4j.Logger;
047: import org.jdom.Attribute;
048: import org.jdom.Element;
049:
050: public class ExecBootstrapper implements Bootstrapper {
051:
052: private static final Logger LOG = Logger
053: .getLogger(ExecBootstrapper.class);
054: private final ExecBuilder delegate = new ExecBuilder();
055:
056: /**
057: * Called after the configuration is read to make sure that all the mandatory parameters
058: * were specified..
059: *
060: * @throws CruiseControlException if there was a configuration error.
061: */
062: public void validate() throws CruiseControlException {
063: // assert with this classname in error message, otherwise delegate classname is used
064: ValidationHelper.assertIsSet(delegate.getCommand(), "command",
065: this .getClass());
066:
067: delegate.validate();
068: }
069:
070: public void bootstrap() throws CruiseControlException {
071:
072: final Map properties = new HashMap();
073: // Run ExecuteBuilder
074: final Element result = delegate.build(properties, null);
075: if (result == null) {
076: LOG.error("ExecBootstrapper failed.\n\n");
077: throw new CruiseControlException(
078: "ExecBootstrapper failed with null result");
079: }
080:
081: final Attribute error = result.getAttribute("error");
082: if (error == null) {
083: LOG.info("ExecBootstrapper successful.");
084: } else {
085: LOG.error("ExecBootstrapper failed.\n\n" + error.getValue()
086: + "\n");
087: throw new CruiseControlException(
088: "ExecBootstrapper failed: " + error.getValue());
089: }
090: }
091:
092: /**
093: * Sets build timeout in seconds.
094: *
095: * @param timeout long build timeout
096: */
097: public void setTimeout(long timeout) {
098: delegate.setTimeout(timeout);
099: }
100:
101: /**
102: * Sets the command to execute
103: *
104: * @param cmd the command to execute
105: */
106: public void setCommand(String cmd) {
107: delegate.setCommand(cmd);
108: }
109:
110: /**
111: * Sets the arguments for the command to execute
112: *
113: * @param args arguments for the command to execute
114: */
115: public void setArgs(String args) {
116: delegate.setArgs(args);
117: }
118:
119: /**
120: * Sets the error string to search for in the command output
121: *
122: * @param errStr the error string to search for in the command output
123: */
124: public void setErrorStr(String errStr) {
125: delegate.setErrorStr(errStr);
126: }
127:
128: /**
129: * Sets the working directory where the command is to be executed
130: *
131: * @param dir the directory where the command is to be executed
132: */
133: public void setWorkingDir(String dir) {
134: delegate.setWorkingDir(dir);
135: }
136: }
|