package org.apache.tools.ant.taskdefs.optional.starteam;

import org.apache.tools.ant.BuildException;

import com.starbase.starteam.Server;
import com.starbase.starteam.ServerException;

/**
 * This module implements a log on to a StarTeam server using the
 * cached credentials.  You must already logged onto the server
 * and have the StarTeam Taskbar running.
 *  
 * @author John Ballment
 *
 */

public class StarTeamAutoLogOn implements StarTeamLogOnProvider {

	/**
	 * LogOn method uses the StarTeam cached credentials to initiate a log on to the specified server instance.
	 *  
	 * @param task
	 * @param server
	 * @throws ServerException
	 * @output task.username is updated with the user from the cached credentials.
	 */
	public void LogOn(StarTeamTask task, Server server) throws ServerException {
		try {
			server.autoLogOn();
		} catch (ServerException e) {
			throw new BuildException("Unable to log onto server because " + e.getErrorMessage());
		}
		task.setUserName(server.getMyUserAccount().getLogOnName());
	}

}
