@@ -1,7 +1,7 @@
/*
/*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
@@ -9,7 +9,7 @@
* are met:
* are met:
*
*
* 1. Redistributions of source code must retain the above copyright
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* notice, this list of conditions and the following disclaimer.
*
*
* 2. Redistributions in binary form must reproduce the above copyright
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* notice, this list of conditions and the following disclaimer in
@@ -17,15 +17,15 @@
* distribution.
* distribution.
*
*
* 3. The end-user documentation included with the redistribution, if
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
* if and wherever such third-party acknowlegements normally appear.
*
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
* permission, please contact apache@apache.org.
*
*
* 5. Products derived from this software may not be called "Apache"
* 5. Products derived from this software may not be called "Apache"
@@ -54,26 +54,27 @@
*/
*/
package org.apache.tools.ant.taskdefs.optional.starteam;
package org.apache.tools.ant.taskdefs.optional.starteam;
import com.starbase.starteam.ServerException;
import com.starbase.starteam.vts.comm.CommandException;
import java.util.StringTokenizer;
import com.starbase.starteam.Server;
import com.starbase.starteam.StarTeamFinder;
import com.starbase.starteam.User;
import com.starbase.starteam.View;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.Task;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
/**
* Common super class for all StarTeam tasks.
* At this level of the hierarchy we are concerned only with obtaining a
* connection to the StarTeam server. The subclass <code>TreeBasedTask</code>,
* also abstract defines the tree-walking behavior common to many subtasks.
*
* @see TreeBasedTask
* @author <a href="mailto:jcyip@thoughtworks.com">Jason Yip</a>
* @version 1.1
* @author <a href="mailto:stevec@ignitesports.com">Steve Cohen</a>
*/
/**
* Common super class for all StarTeam tasks.
* At this level of the hierarchy we are concerned only with obtaining a
* connection to the StarTeam server. The subclass <code>TreeBasedTask</code>,
* also abstract defines the tree-walking behavior common to many subtasks.
*
* @see TreeBasedTask
* @author <a href="mailto:jcyip@thoughtworks.com">Jason Yip</a>
* @version 1.1
* @author <a href="mailto:stevec@ignitesports.com">Steve Cohen</a>
*/
public abstract class StarTeamTask extends Task {
public abstract class StarTeamTask extends Task {
@@ -109,144 +110,150 @@ public abstract class StarTeamTask extends Task {
*/
*/
private String viewname;
private String viewname;
/////////////////////////////////////////////////////////
// GET/SET methods.
/**
*The starteam server through which all activities will be done.
*/
private Server server = null;
/////////////////////////////////////////////////////////
// GET/SET methods.
// Setters, of course are where ant user passes in values.
// Setters, of course are where ant user passes in values.
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/**
/**
* Set the name of StarTeamServer
* Set the name of StarTeamServer
*
*
* @param servername a <code>String</code> value
* @param servername a <code>String</code> value
* @see setURL()
* @see # setURL(String )
*/
*/
public void setServername(String servername) {
public void setServername(String servername) {
this.servername = servername;
this.servername = servername;
}
}
/**
/**
* returns the name of the StarTeamServer
* returns the name of the StarTeamServer
*
*
* @return the name of the StarTeam server
* @return the name of the StarTeam server
* @see getURL()
* @see # getURL()
*/
*/
public String getServername() {
public String getServername() {
return this.servername;
return this.servername;
}
}
/**
/**
* set the port number of the StarTeam connection
* set the port number of the StarTeam connection
*
*
* @param serverport port number to be set
* @param serverport port number to be set
* @see setURL()
* @see # setURL(String )
*/
*/
public void setServerport(String serverport) {
public void setServerport(String serverport) {
this.serverport = serverport;
this.serverport = serverport;
}
}
/**
/**
* returns the port number of the StarTeam connection
* returns the port number of the StarTeam connection
*
*
* @return the port number of the StarTeam connection
* @return the port number of the StarTeam connection
* @see getURL()
* @see # getURL()
*/
*/
public String getServerport() {
public String getServerport() {
return this.serverport;
return this.serverport;
}
}
/**
/**
* set the name of the StarTeam project to be acted on
* set the name of the StarTeam project to be acted on
*
*
* @param projectname the name of the StarTeam project to be acted on
* @param projectname the name of the StarTeam project to be acted on
* @see setURL()
* @see # setURL(String )
*/
*/
public void setProjectname(String projectname) {
public void setProjectname(String projectname) {
this.projectname = projectname;
this.projectname = projectname;
}
}
/**
/**
* returns the name of the StarTeam project to be acted on
* returns the name of the StarTeam project to be acted on
*
*
* @return the name of the StarTeam project to be acted on
* @return the name of the StarTeam project to be acted on
* @see getURL()
* @see # getURL()
*/
*/
public String getProjectname() {
public String getProjectname() {
return this.projectname;
return this.projectname;
}
}
/**
/**
* set the name of the StarTeam view to be acted on
* set the name of the StarTeam view to be acted on
*
*
* @param projectname the name of the StarTeam view to be acted on
* @param projectname the name of the StarTeam view to be acted on
* @see setURL()
* @see # setURL(String )
*/
*/
public void setViewname(String viewname) {
public void setViewname(String viewname) {
this.viewname = viewname;
this.viewname = viewname;
}
}
/**
/**
* returns the name of the StarTeam view to be acted on
* returns the name of the StarTeam view to be acted on
*
*
* @return the name of the StarTeam view to be acted on
* @return the name of the StarTeam view to be acted on
* @see getURL()
*/ public String getViewname() {
return this.viewname;
* @see #getURL()
*/
public String getViewname() {
return this.viewname;
}
}
/**
/**
* This is a convenience method for setting the server name, server port,
* This is a convenience method for setting the server name, server port,
* project name and project folder at one shot.
* project name and project folder at one shot.
*
*
* @param url a <code>String</code> of the form
* @param url a <code>String</code> of the form
* "servername:portnum/project/view"
* "servername:portnum/project/view"
* @see setServerame()
* @see setServerport()
* @see setProjectname()
* @see setViewname()
* @see # setServern ame(String )
* @see # setServerport(String )
* @see # setProjectname(String )
* @see # setViewname(String )
*/
*/
public void setURL(String url) {
public void setURL(String url) {
StringTokenizer t = new StringTokenizer(url, "/");
if (t.hasMoreTokens()) {
String unpw = t.nextToken();
int pos = unpw.indexOf(":");
if (pos > 0) {
this.servername = unpw.substring(0, pos);
this.serverport = unpw.substring(pos+ 1);
if (t.hasMoreTokens()) {
this.projectname= t.nextToken();
if (t.hasMoreTokens()) {
this.viewname = t.nextToken();
}
}
}
}
StringTokenizer t = new StringTokenizer(url, "/");
if (t.hasMoreTokens()) {
String unpw = t.nextToken();
int pos = unpw.indexOf(":");
if (pos > 0) {
this.servername = unpw.substring(0, pos);
this.serverport = unpw.substring(pos + 1);
if (t.hasMoreTokens()) {
this.projectname = t.nextToken();
if (t.hasMoreTokens()) {
this.viewname = t.nextToken();
}
}
}
}
}
}
/**
/**
* convenience method returns whole URL at once
* convenience method returns whole URL at once
* returns
* returns
* as a single string
* as a single string
*/
*/
/**
/**
* a convenience method which returns the whole StarTeam
* a convenience method which returns the whole StarTeam
* connection information as a single URL string of
* connection information as a single URL string of
*
*
* @return a <code>String</code> of the form
* @return a <code>String</code> of the form
* "servername:portnum/project/view"
* "servername:portnum/project/view"
* @see getServername()
* @see getServerport()
* @see getProjectname()
* @see getViewname()
* @see # getServername()
* @see # getServerport()
* @see # getProjectname()
* @see # getViewname()
*/
*/
public String getURL() {
public String getURL() {
return
this.servername + ":" +
this.serverport + "/" +
this.projectname + "/" +
((null== this.viewname)?"":this.viewname);
return
this.servername + ":" +
this.serverport + "/" +
this.projectname + "/" +
((null == this.viewname)?"":this.viewname);
}
}
/**
/**
* set the name of the StarTeam user, needed for the connection
* set the name of the StarTeam user, needed for the connection
*
*
@@ -255,7 +262,7 @@ public abstract class StarTeamTask extends Task {
public void setUserName(String userName) {
public void setUserName(String userName) {
this.userName = userName;
this.userName = userName;
}
}
/**
/**
* returns the name of the StarTeam user
* returns the name of the StarTeam user
*
*
@@ -273,7 +280,7 @@ public abstract class StarTeamTask extends Task {
public void setPassword(String password) {
public void setPassword(String password) {
this.password = password;
this.password = password;
}
}
/**
/**
* returns the password used for login
* returns the password used for login
*
*
@@ -282,6 +289,67 @@ public abstract class StarTeamTask extends Task {
public String getPassword() {
public String getPassword() {
return this.password;
return this.password;
}
}
/**
* returns a reference to the server which may be used for informational
* purposes by subclasses.
*
* @return a reference to the server
*/
protected Server getServer() {
return this.server;
}
/**
* Derived classes must override <code>createSnapshotView</code>
* defining the kind of configured view appropriate to its task.
*
* @param rawview the unconfigured <code>View</code>
* @return the snapshot <code>View</code> appropriately configured.
*/
protected abstract View createSnapshotView(View rawview);
/**
* All subclasses will call on this method to open the view needed for
* processing. This method also saves a reference to the
* <code>Server</code> that may be accessed for information at various
* points in the process.
*
* @return the <code>View</code> that will be used for processing.
* @see #createSnapshotView(View)
* @see #getServer()
*/
protected View openView() throws BuildException {
View view =
StarTeamFinder.openView(getUserName() + ":"
+ getPassword()
+ "@" + getURL());
if (null == view) {
throw new BuildException("Cannot find view" + getURL() +
" in repository()");
}
View snapshot = createSnapshotView(view);
this.server = snapshot.getServer();
return snapshot;
}
/**
* Returns the name of the user with the supplied ID or a blank string
* if user not found.
*
* @param userID a user's ID
* @return the name of the user with ID userID
*/
protected String getUserName(int userID) {
User u = this.server.getUser(userID);
if (null == u) {
return "";
}
return u.getName();
}
}
}