FileDocCategorySizeDatePackage
SOS.javaAPI DocApache Ant 1.7014010Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.sos

SOS

public abstract class SOS extends org.apache.tools.ant.Task implements SOSCmd
A base class for creating tasks for executing commands on SourceOffSite. These tasks were inspired by the VSS tasks.

Fields Summary
private String
sosCmdDir
private String
sosUsername
private String
sosPassword
private String
projectPath
private String
vssServerPath
private String
sosServerPath
private String
sosHome
private String
localPath
private String
version
private String
label
private String
comment
private String
filename
private boolean
noCompress
private boolean
noCache
private boolean
recursive
private boolean
verbose
protected org.apache.tools.ant.types.Commandline
commandLine
Commandline to be executed.
Constructors Summary
Methods Summary
abstract org.apache.tools.ant.types.CommandlinebuildCmdLine()
Subclasses implement the logic required to construct the command line.

return
The command line to execute.

public voidexecute()
Execute the created command line.

throws
BuildException on error.

        int result = 0;
        buildCmdLine();
        result = run(commandLine);
        if (result == 255) {  // This is the exit status
            String msg = "Failed executing: " + commandLine.toString();
            throw new BuildException(msg, getLocation());
        }
    
protected java.lang.StringgetComment()
Get the comment

return
if it was set, null if not.

        return comment;
    
protected java.lang.StringgetFilename()
Get the filename to be acted upon.

return
if it was set, null if not.

        return filename;
    
protected java.lang.StringgetLabel()
Get the label

return
if it was set, null if not.

        return label;
    
protected java.lang.StringgetLocalPath()
Builds and returns the working directory.

The localpath is created if it didn't exist.

return
the absolute path of the working directory.

        if (localPath == null) {
            return getProject().getBaseDir().getAbsolutePath();
        } else {
            // make sure localDir exists, create it if it doesn't
            File dir = getProject().resolveFile(localPath);
            if (!dir.exists()) {
                boolean done = dir.mkdirs();
                if (!done) {
                    String msg = "Directory " + localPath + " creation was not "
                        + "successful for an unknown reason";
                    throw new BuildException(msg, getLocation());
                }
                getProject().log("Created dir: " + dir.getAbsolutePath());
            }
            return dir.getAbsolutePath();
        }
    
protected java.lang.StringgetNoCache()
Get the NoCache flag.

return
the 'nocache' Flag if the attribute was 'true', otherwise an empty string.

        return noCache ? FLAG_NO_CACHE : "";
    
protected java.lang.StringgetNoCompress()
Get the NoCompress flag.

return
the 'nocompress' Flag if the attribute was 'true', otherwise an empty string.

        return noCompress ? FLAG_NO_COMPRESSION : "";
    
protected voidgetOptionalAttributes()
Adds the optional attributes to the command line.

        // -verbose
        commandLine.createArgument().setValue(getVerbose());
        // Disable Compression
        commandLine.createArgument().setValue(getNoCompress());
        // Path to the SourceOffSite home directory /home/user/.sos
        if (getSosHome() == null) {
            // If -soshome was not specified then we can look for nocache
            commandLine.createArgument().setValue(getNoCache());
        } else {
            commandLine.createArgument().setValue(FLAG_SOS_HOME);
            commandLine.createArgument().setValue(getSosHome());
        }
        //If a working directory was specified then add it to the command line
        if (getLocalPath() != null) {
            commandLine.createArgument().setValue(FLAG_WORKING_DIR);
            commandLine.createArgument().setValue(getLocalPath());
        }
    
protected java.lang.StringgetPassword()
Get the password

return
empty string if it wasn't set.

        return sosPassword;
    
protected java.lang.StringgetProjectPath()
Get the project path

return
if it was set, null if not.

        return projectPath;
    
protected java.lang.StringgetRecursive()
Get the 'recursive' Flag.

return
the 'recursive' Flag if the attribute was 'true', otherwise an empty string.

        return recursive ? FLAG_RECURSION : "";
    
protected voidgetRequiredAttributes()
Sets the executable and add the required attributes to the command line.

        // Get the path to the soscmd(.exe)
        commandLine.setExecutable(getSosCommand());
        // SOS server address is required
        if (getSosServerPath() == null) {
            throw new BuildException("sosserverpath attribute must be set!", getLocation());
        }
        commandLine.createArgument().setValue(FLAG_SOS_SERVER);
        commandLine.createArgument().setValue(getSosServerPath());
        // Login info is required
        if (getUsername() == null) {
            throw new BuildException("username attribute must be set!", getLocation());
        }
        commandLine.createArgument().setValue(FLAG_USERNAME);
        commandLine.createArgument().setValue(getUsername());
        // The SOS class knows that the SOS server needs the password flag,
        // even if there is no password ,so we send a " "
        commandLine.createArgument().setValue(FLAG_PASSWORD);
        commandLine.createArgument().setValue(getPassword());
        // VSS Info is required
        if (getVssServerPath() == null) {
            throw new BuildException("vssserverpath attribute must be set!", getLocation());
        }
        commandLine.createArgument().setValue(FLAG_VSS_SERVER);
        commandLine.createArgument().setValue(getVssServerPath());
        // VSS project is required
        if (getProjectPath() == null) {
            throw new BuildException("projectpath attribute must be set!", getLocation());
        }
        commandLine.createArgument().setValue(FLAG_PROJECT);
        commandLine.createArgument().setValue(getProjectPath());
    
protected java.lang.StringgetSosCommand()
Get the executable to run. Add the path if it was specifed in the build file

return
the executable to run.

        if (sosCmdDir == null) {
            return COMMAND_SOS_EXE;
        } else {
            return sosCmdDir + File.separator + COMMAND_SOS_EXE;
        }
    
protected java.lang.StringgetSosHome()
Get the SOS home directory.

return
if it was set, null if not.

        return sosHome;
    
protected java.lang.StringgetSosServerPath()
Get the SOS serve path.

return
if it was set, null if not.

        return sosServerPath;
    
protected java.lang.StringgetUsername()
Get the username

return
if it was set, null if not.

        return sosUsername;
    
protected java.lang.StringgetVerbose()
Get the 'verbose' Flag.

return
the 'verbose' Flag if the attribute was 'true', otherwise an empty string.

        return verbose ? FLAG_VERBOSE : "";
    
protected java.lang.StringgetVersion()
Get the version

return
if it was set, null if not.

        return version;
    
protected java.lang.StringgetVssServerPath()
Get the VSS server path

return
if it was set, null if not.

        return vssServerPath;
    
protected intrun(org.apache.tools.ant.types.Commandline cmd)
Execute the created command line.

param
cmd The command line to run.
return
int the exit code.
throws
BuildException

        try {
            Execute exe = new Execute(new LogStreamHandler(this,
                    Project.MSG_INFO,
                    Project.MSG_WARN));

            exe.setAntRun(getProject());
            exe.setWorkingDirectory(getProject().getBaseDir());
            exe.setCommandline(cmd.getCommandline());
            exe.setVMLauncher(false);  // Use the OS VM launcher so we get environment variables
            return exe.execute();
        } catch (java.io.IOException e) {
            throw new BuildException(e, getLocation());
        }
    
protected voidsetInternalComment(java.lang.String text)
Set the comment text.

param
text the comment text to use.

        comment = text;
    
protected voidsetInternalFilename(java.lang.String file)
Set the file name.

param
file the filename to use.

        filename = file;
    
protected voidsetInternalLabel(java.lang.String text)
Set the label.

param
text the label to use.

        label = text;
    
protected voidsetInternalRecursive(boolean recurse)
Set the recursive flag.

param
recurse if true use the recursive flag on the command line.

        recursive = recurse;
    
protected voidsetInternalVersion(java.lang.String text)
Set the version.

param
text the version to use.

        version = text;
    
public final voidsetLocalPath(org.apache.tools.ant.types.Path path)
Override the working directory and get to the specified path.

param
path The new localPath value.

        localPath = path.toString();
    
public final voidsetNoCache(boolean nocache)
Flag to disable the cache when set. Required if SOSHOME is set as an environment variable. Defaults to false.

param
nocache True to disable caching.

    // CheckStyle:VisibilityModifier ON

                                    
         
        noCache = nocache;
    
public final voidsetNoCompress(boolean nocompress)
Flag to disable compression when set. Defaults to false.

param
nocompress True to disable compression.

        noCompress = nocompress;
    
public final voidsetPassword(java.lang.String password)
The SourceSafe password.

param
password The new password value.

        sosPassword = password;
    
public final voidsetProjectPath(java.lang.String projectpath)
The SourceSafe project path.

param
projectpath The new projectpath value.
ant.attribute
group="required"

        if (projectpath.startsWith(SOSCmd.PROJECT_PREFIX)) {
            projectPath = projectpath;
        } else {
            projectPath = SOSCmd.PROJECT_PREFIX + projectpath;
        }
    
public final voidsetSosCmd(java.lang.String dir)
The directory where soscmd(.exe) is located. soscmd must be on the path if omitted.

param
dir The new sosCmd value.

        sosCmdDir = FileUtils.translatePath(dir);
    
public final voidsetSosHome(java.lang.String sosHome)
Path to the SourceOffSite home directory.

param
sosHome The new sosHome value.

        this.sosHome = sosHome;
    
public final voidsetSosServerPath(java.lang.String sosServerPath)
The address and port of SourceOffSite Server, for example 192.168.0.1:8888.

param
sosServerPath The new sosServerPath value.
ant.attribute
group="required"

        this.sosServerPath = sosServerPath;
    
public final voidsetUsername(java.lang.String username)
The SourceSafe username.

param
username The new username value.
ant.attribute
group="required"

        sosUsername = username;
    
public voidsetVerbose(boolean verbose)
Enable verbose output. Defaults to false.

param
verbose True for verbose output.

        this.verbose = verbose;
    
public final voidsetVssServerPath(java.lang.String vssServerPath)
The path to the location of the ss.ini file.

param
vssServerPath The new vssServerPath value.
ant.attribute
group="required"

        this.vssServerPath = vssServerPath;