001: /********************************************************************************
002: * CruiseControl, a Continuous Integration Toolkit
003: * Copyright (c) 2001-2003, 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 com.starbase.starteam.commandline.StarTeamCmd;
039: import net.sourceforge.cruisecontrol.Bootstrapper;
040: import net.sourceforge.cruisecontrol.CruiseControlException;
041: import net.sourceforge.cruisecontrol.util.ValidationHelper;
042: import net.sourceforge.cruisecontrol.util.Commandline;
043:
044: /**
045: * Since we rely on our build.xml to handle updating our source code, there has
046: * always been a problem with what happens when the build.xml file itself
047: * changes. Previous workarounds have included writing a wrapper build.xml that
048: * will check out the "real" build.xml. This class is a substitute for that
049: * practice.
050: *
051: * The StarTeamBootstrapper will handle updating a multiple space delimited files from StarTeam before the
052: * build begins.
053: *
054: * Usage:
055: *
056: * <starteambootstrapper username=""
057: * password=""
058: * server=""
059: * port=""
060: * project=""
061: * view=""
062: * folder=""
063: * files=""
064: * localfolder=""/>
065: */
066: public class StarTeamBootstrapper implements Bootstrapper {
067:
068: private String username;
069: private String password;
070: private String servername;
071: private String serverport;
072: private String projectname;
073: private String viewname;
074: private String foldername;
075: private String localfoldername;
076: private String filenames;
077:
078: public StarTeamBootstrapper() {
079: }
080:
081: public void setUsername(String name) {
082: username = name;
083: }
084:
085: public void setPassword(String passwd) {
086: password = passwd;
087: }
088:
089: public void setServer(String server) {
090: servername = server;
091: }
092:
093: public void setPort(String port) {
094: serverport = port;
095: }
096:
097: public void setProject(String project) {
098: projectname = project;
099: }
100:
101: public void setView(String view) {
102: viewname = view;
103: }
104:
105: public void setFolder(String folder) {
106: foldername = folder;
107: }
108:
109: public void setLocalFolder(String localfolder) {
110: localfoldername = localfolder;
111: }
112:
113: public void setFiles(String files) {
114: filenames = files;
115: }
116:
117: public void bootstrap() throws CruiseControlException {
118: Commandline args = buildCheckoutCommand();
119: int retVal = StarTeamCmd.run(args.getCommandline());
120: if (retVal != 0) {
121: throw new CruiseControlException(
122: "Error executing StarTeam checkout command: "
123: + args.toString());
124: }
125: }
126:
127: public void validate() throws CruiseControlException {
128: ValidationHelper
129: .assertFalse(
130: filenames == null || username == null
131: || password == null
132: || servername == null
133: || serverport == null
134: || projectname == null
135: || viewname == null
136: || foldername == null,
137: "'files', 'username', 'password','server', 'port', 'project', 'view' and 'folder'"
138: + " are all required for StarTeamBootstrapper");
139: }
140:
141: private Commandline buildCheckoutCommand() {
142: Commandline commandLine = new Commandline();
143: commandLine.createArgument("co");
144: commandLine.createArgument("-p");
145: commandLine.createArgument(username + ':' + password + '@'
146: + servername + ':' + serverport + '/' + projectname
147: + '/' + viewname + '/' + foldername);
148: if (localfoldername != null) {
149: commandLine.createArguments("-fp", localfoldername);
150: }
151: commandLine.createArgument("-o");
152: commandLine.createArgument("-x");
153: commandLine.createArgument().setLine(filenames);
154: return commandLine;
155: }
156:
157: public String toString() {
158: return buildCheckoutCommand().toString();
159: }
160:
161: public static void main(String[] args)
162: throws CruiseControlException {
163: StarTeamBootstrapper bootstrapper = new StarTeamBootstrapper();
164: bootstrapper.setUsername("ccuser");
165: bootstrapper.setPassword("ccuser");
166: bootstrapper.setServer("starteamserver");
167: bootstrapper.setPort("4001");
168: bootstrapper.setProject("ProjectName");
169: bootstrapper.setView("ViewName");
170: bootstrapper.setFolder("src/folder");
171: bootstrapper.setLocalFolder("checkoutfolder");
172: bootstrapper.setFiles("build.properties build.xml");
173: System.out.println(bootstrapper);
174: bootstrapper.bootstrap();
175: }
176: }
|