KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > cruisecontrol > bootstrappers > StarTeamBootstrapper


1 /********************************************************************************
2  * CruiseControl, a Continuous Integration Toolkit
3  * Copyright (c) 2001-2003, ThoughtWorks, Inc.
4  * 651 W Washington Ave. Suite 600
5  * Chicago, IL 60661 USA
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * + Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * + Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  *
20  * + Neither the name of ThoughtWorks, Inc., CruiseControl, nor the
21  * names of its contributors may be used to endorse or promote
22  * products derived from this software without specific prior
23  * written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  ********************************************************************************/

37 package net.sourceforge.cruisecontrol.bootstrappers;
38
39 import com.starbase.starteam.commandline.StarTeamCmd;
40 import net.sourceforge.cruisecontrol.Bootstrapper;
41 import net.sourceforge.cruisecontrol.CruiseControlException;
42 import net.sourceforge.cruisecontrol.util.ValidationHelper;
43 import net.sourceforge.cruisecontrol.util.Commandline;
44
45 /**
46  * Since we rely on our build.xml to handle updating our source code, there has
47  * always been a problem with what happens when the build.xml file itself
48  * changes. Previous workarounds have included writing a wrapper build.xml that
49  * will check out the "real" build.xml. This class is a substitute for that
50  * practice.
51  *
52  * The StarTeamBootstrapper will handle updating a multiple space delimited files from StarTeam before the
53  * build begins.
54  *
55  * Usage:
56  *
57  * <starteambootstrapper username=""
58  * password=""
59  * server=""
60  * port=""
61  * project=""
62  * view=""
63  * folder=""
64  * files=""
65  * localfolder=""/>
66  */

67 public class StarTeamBootstrapper implements Bootstrapper {
68
69     private String JavaDoc username;
70     private String JavaDoc password;
71     private String JavaDoc servername;
72     private String JavaDoc serverport;
73     private String JavaDoc projectname;
74     private String JavaDoc viewname;
75     private String JavaDoc foldername;
76     private String JavaDoc localfoldername;
77     private String JavaDoc filenames;
78
79     public StarTeamBootstrapper() {
80     }
81
82     public void setUsername(String JavaDoc name) {
83         username = name;
84     }
85
86     public void setPassword(String JavaDoc passwd) {
87         password = passwd;
88     }
89
90     public void setServer(String JavaDoc server) {
91         servername = server;
92     }
93
94     public void setPort(String JavaDoc port) {
95         serverport = port;
96     }
97
98     public void setProject(String JavaDoc project) {
99         projectname = project;
100     }
101
102     public void setView(String JavaDoc view) {
103         viewname = view;
104     }
105
106     public void setFolder(String JavaDoc folder) {
107         foldername = folder;
108     }
109
110     public void setLocalFolder(String JavaDoc localfolder) {
111         localfoldername = localfolder;
112     }
113
114     public void setFiles(String JavaDoc files) {
115         filenames = files;
116     }
117
118     public void bootstrap() throws CruiseControlException {
119         Commandline args = buildCheckoutCommand();
120         int retVal = StarTeamCmd.run(args.getCommandline());
121         if (retVal != 0) {
122             throw new CruiseControlException("Error executing StarTeam checkout command: " + args.toString());
123         }
124     }
125
126     public void validate() throws CruiseControlException {
127         ValidationHelper.assertFalse(filenames == null
128             || username == null
129             || password == null
130             || servername == null
131             || serverport == null
132             || projectname == null
133             || viewname == null
134             || foldername == null,
135             "'files', 'username', 'password','server', 'port', 'project', 'view' and 'folder'"
136               + " are all required for StarTeamBootstrapper");
137     }
138
139     private Commandline buildCheckoutCommand() {
140         Commandline commandLine = new Commandline();
141         commandLine.createArgument().setValue("co");
142         commandLine.createArgument().setValue("-p");
143         commandLine.createArgument().setValue(
144             username
145                 + ':'
146                 + password
147                 + '@'
148                 + servername
149                 + ':'
150                 + serverport
151                 + '/'
152                 + projectname
153                 + '/'
154                 + viewname
155                 + '/'
156                 + foldername);
157         if (localfoldername != null) {
158             commandLine.createArgument().setValue("-fp");
159             commandLine.createArgument().setValue(localfoldername);
160         }
161         commandLine.createArgument().setValue("-o");
162         commandLine.createArgument().setValue("-x");
163         commandLine.createArgument().setLine(filenames);
164         return commandLine;
165     }
166
167     public String JavaDoc toString() {
168         return buildCheckoutCommand().toString();
169     }
170
171     public static void main(String JavaDoc[] args) throws CruiseControlException {
172         StarTeamBootstrapper bootstrapper = new StarTeamBootstrapper();
173         bootstrapper.setUsername("ccuser");
174         bootstrapper.setPassword("ccuser");
175         bootstrapper.setServer("starteamserver");
176         bootstrapper.setPort("4001");
177         bootstrapper.setProject("ProjectName");
178         bootstrapper.setView("ViewName");
179         bootstrapper.setFolder("src/folder");
180         bootstrapper.setLocalFolder("checkoutfolder");
181         bootstrapper.setFiles("build.properties build.xml");
182         System.out.println(bootstrapper);
183         bootstrapper.bootstrap();
184     }
185 }
186
Popular Tags