001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001-2007, 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.util.Commandline;
043: import net.sourceforge.cruisecontrol.util.EnvCommandline;
044: import net.sourceforge.cruisecontrol.util.ValidationHelper;
045:
046: import org.apache.log4j.Logger;
047:
048: public class VssBootstrapper implements Bootstrapper {
049:
050: private static final Logger LOG = Logger
051: .getLogger(VssBootstrapper.class);
052:
053: private String ssDir;
054: private String serverPath;
055:
056: private String vssPath;
057: private String localDirectory;
058: private String login;
059:
060: public void bootstrap() throws CruiseControlException {
061: generateCommandLine().executeAndWait(LOG);
062: }
063:
064: public void validate() throws CruiseControlException {
065: ValidationHelper
066: .assertTrue(vssPath != null && localDirectory != null,
067: "VssBootstrapper has required attributes vssPath and localDirectory");
068:
069: File localDirForFile = new File(localDirectory);
070: ValidationHelper.assertTrue(localDirForFile.exists(),
071: "file path attribute value " + localDirectory
072: + " must specify an existing directory.");
073:
074: ValidationHelper
075: .assertTrue(
076: localDirForFile.isDirectory(),
077: "file path attribute value "
078: + localDirectory
079: + " must specify an existing directory, not a file.");
080:
081: setLocalDirectory(localDirForFile.getAbsolutePath());
082: }
083:
084: private String getExecutable() {
085: String executable = "";
086: if (ssDir != null) {
087: executable = ssDir;
088: if (ssDir.charAt(ssDir.length() - 1) != '\\') {
089: executable += '\\';
090: }
091: }
092: executable += "ss.exe";
093: return executable;
094: }
095:
096: Commandline generateCommandLine() {
097: EnvCommandline command = new EnvCommandline();
098: command.setExecutable(getExecutable());
099: command.createArgument("get");
100:
101: if (serverPath != null) {
102: command.setVariable("SSDIR", serverPath);
103: }
104:
105: // check for leading "$", to be argument-compatible with other tasks
106: if (vssPath != null) {
107: String pathPrefix = vssPath.startsWith("$") ? "" : "$";
108: command.createArgument('"' + pathPrefix + vssPath + '"');
109: }
110: command.createArgument("-GL\"" + localDirectory + '"');
111: command.createArgument("-I-N");
112: if (login != null) {
113: command.createArgument("-Y" + login);
114: }
115:
116: return command;
117: }
118:
119: /**
120: * Required.
121: *
122: * @param vssPath
123: * fully qualified VSS path to the file ($/Project/subproject/filename.ext)
124: */
125: public void setVssPath(String vssPath) {
126: this .vssPath = vssPath;
127: }
128:
129: /**
130: * Optional.
131: *
132: * @param ssDir
133: * Path to the directory containing ss.exe. Assumes that ss.exe is in the path by default.
134: */
135: public void setSsDir(String ssDir) {
136: this .ssDir = ssDir;
137: }
138:
139: /**
140: * Optional.
141: *
142: * @param serverPath
143: * The path to the directory containing the srcsafe.ini file.
144: */
145: public void setServerPath(String serverPath) {
146: this .serverPath = serverPath;
147: }
148:
149: /**
150: * Required.
151: *
152: * @param localDirectory
153: * fully qualified path for the destination directory (c:\directory\subdirectory\)
154: */
155: public void setLocalDirectory(String localDirectory) {
156: this .localDirectory = localDirectory;
157: }
158:
159: /**
160: * Optional.
161: *
162: * @param login
163: * vss login information in the form username,password\
164: */
165: public void setLogin(String login) {
166: this.login = login;
167: }
168: }
|