1 18 package org.apache.tools.ant.taskdefs.optional.starteam; 19 20 import com.starbase.starteam.BuildNumber; 21 import com.starbase.starteam.Server; 22 import com.starbase.starteam.StarTeamFinder; 23 import com.starbase.starteam.TypeNames; 24 import com.starbase.starteam.User; 25 import com.starbase.starteam.View; 26 import java.util.StringTokenizer ; 27 import org.apache.tools.ant.BuildException; 28 import org.apache.tools.ant.Project; 29 import org.apache.tools.ant.Task; 30 31 40 41 public abstract class StarTeamTask extends Task { 42 43 45 48 private String userName; 49 50 53 private String password; 54 55 58 private String servername; 59 60 63 private String serverport; 64 65 68 private String projectname; 69 70 73 private String viewname; 74 75 78 private Server server = null; 79 80 private void logStarteamVersion() { 81 log("StarTeam version: " 82 + BuildNumber.getDisplayString(), Project.MSG_VERBOSE); 83 } 84 85 86 91 97 public final void setServername(String servername) { 98 this.servername = servername; 99 } 100 101 107 public final String getServername() { 108 return this.servername; 109 } 110 111 117 public final void setServerport(String serverport) { 118 this.serverport = serverport; 119 } 120 121 127 public final String getServerport() { 128 return this.serverport; 129 } 130 131 138 public final void setProjectname(String projectname) { 139 this.projectname = projectname; 140 } 141 142 148 public final String getProjectname() { 149 return this.projectname; 150 } 151 152 159 public final void setViewname(String viewname) { 160 this.viewname = viewname; 161 } 162 163 169 public final String getViewname() { 170 return this.viewname; 171 } 172 173 174 186 public final void setURL(String url) { 187 StringTokenizer t = new StringTokenizer (url, "/"); 188 if (t.hasMoreTokens()) { 189 String unpw = t.nextToken(); 190 int pos = unpw.indexOf(":"); 191 if (pos > 0) { 192 this.servername = unpw.substring(0, pos); 193 this.serverport = unpw.substring(pos + 1); 194 if (t.hasMoreTokens()) { 195 this.projectname = t.nextToken(); 196 if (t.hasMoreTokens()) { 197 this.viewname = t.nextToken(); 198 } 199 } 200 } 201 } 202 } 203 204 209 220 public final String getURL() { 221 return this.servername + ":" 222 + this.serverport + "/" 223 + this.projectname + "/" 224 + ((null == this.viewname) ? "" : this.viewname); 225 } 226 227 233 protected final String getViewURL() { 234 return getUserName() + ":" + getPassword() + "@" + getURL(); 235 } 236 241 public final void setUserName(String userName) { 242 this.userName = userName; 243 } 244 245 250 public final String getUserName() { 251 return this.userName; 252 } 253 254 259 public final void setPassword(String password) { 260 this.password = password; 261 } 262 263 268 public final String getPassword() { 269 return this.password; 270 } 271 272 278 protected final Server getServer() { 279 return this.server; 280 } 281 282 286 protected final void disconnectFromServer() { 287 if (null != this.server) { 288 this.server.disconnect(); 289 log("successful disconnect from StarTeam Server " + servername, 290 Project.MSG_VERBOSE); 291 } 292 } 293 294 299 protected final TypeNames getTypeNames() { 300 return this.server.getTypeNames(); 301 } 302 310 protected abstract View createSnapshotView(View rawview) 311 throws BuildException; 312 313 324 protected View openView() throws BuildException { 325 326 logStarteamVersion(); 327 View view = null; 328 try { 329 view = StarTeamFinder.openView(getViewURL()); 330 } catch (Exception e) { 331 throw new BuildException( 332 "Failed to connect to " + getURL(), e); 333 } 334 335 if (null == view) { 336 throw new BuildException("Cannot find view" + getURL() 337 + " in repository()"); 338 } 339 340 View snapshot = createSnapshotView(view); 341 log("Connected to StarTeam view " + getURL(), 342 Project.MSG_VERBOSE); 343 this.server = snapshot.getServer(); 344 return snapshot; 345 } 346 347 354 protected final String getUserName(int userID) { 355 User u = this.server.getUser(userID); 356 if (null == u) { 357 return ""; 358 } 359 return u.getName(); 360 } 361 362 } 363 | Popular Tags |