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 net.sourceforge.cruisecontrol.Bootstrapper;
039: import net.sourceforge.cruisecontrol.CruiseControlException;
040: import net.sourceforge.cruisecontrol.util.Commandline;
041: import net.sourceforge.cruisecontrol.util.ValidationHelper;
042:
043: import org.apache.log4j.Logger;
044:
045: /**
046: * Since we rely on our build.xml to handle updating our source code, there has always been a problem with what happens
047: * when the build.xml file itself changes. Previous workarounds have included writing a wrapper build.xml that will
048: * check out the "real" build.xml. This class is a substitute for that practice. The ClearCaseBootstrapper will handle
049: * updating a single file from ClearCase before the build begins. Usage: <clearcasebootstrapper file=""
050: * viewpath=""/>
051: */
052: public class ClearCaseBootstrapper implements Bootstrapper {
053:
054: private static final Logger LOG = Logger
055: .getLogger(ClearCaseBootstrapper.class);
056:
057: private String filename;
058: private String viewpath;
059:
060: public void setViewpath(String path) {
061: viewpath = path;
062: }
063:
064: public void setFile(String name) {
065: filename = name;
066: }
067:
068: /**
069: * Update the specified file.
070: */
071: public void bootstrap() throws CruiseControlException {
072: buildUpdateCommand().executeAndWait(LOG);
073: }
074:
075: public void validate() throws CruiseControlException {
076: ValidationHelper.assertIsSet(filename, "file", this .getClass());
077: }
078:
079: protected Commandline buildUpdateCommand() {
080: Commandline commandLine = new Commandline();
081: commandLine.setExecutable("cleartool");
082:
083: commandLine.createArgument("update");
084: commandLine.createArgument("-force");
085: commandLine.createArguments("-log", isWindows() ? "NUL"
086: : "/dev/null");
087: commandLine.createArgument(getFullPathFileName());
088:
089: return commandLine;
090: }
091:
092: private String getFullPathFileName() {
093: return viewpath == null ? filename : new StringBuffer(viewpath)
094: .append("/").append(filename).toString();
095: }
096:
097: protected boolean isWindows() {
098: return getOsName().indexOf("Windows") >= 0;
099: }
100:
101: protected String getOsName() {
102: return System.getProperty("os.name");
103: }
104:
105: }
|