FileDocCategorySizeDatePackage
MSVSS.javaAPI DocApache Ant 1.7025320Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.vss

MSVSS

public abstract class MSVSS extends org.apache.tools.ant.Task implements MSVSSConstants
A base class for creating tasks for executing commands on Visual SourceSafe.

The class extends the 'exec' task as it operates by executing the ss.exe program supplied with SourceSafe. By default the task expects ss.exe to be in the path, you can override this be specifying the ssdir attribute.

This class provides set and get methods for 'login' and 'vsspath' attributes. It also contains constants for the flags that can be passed to SS.

Fields Summary
private String
ssDir
private String
vssLogin
private String
vssPath
private String
serverPath
private String
version
Version
private String
date
Date
private String
label
Label
private String
autoResponse
Auto response
private String
localPath
Local path
private String
comment
Comment
private String
fromLabel
From label
private String
toLabel
To label
private String
outputFileName
Output file name
private String
user
User
private String
fromDate
From date
private String
toDate
To date
private String
style
History style
private boolean
quiet
Quiet defaults to false
private boolean
recursive
Recursive defaults to false
private boolean
writable
Writable defaults to false
private boolean
failOnError
Fail on error defaults to true
private boolean
getLocalCopy
Get local copy for checkout defaults to true
private int
numDays
Number of days offset for History
private DateFormat
dateFormat
Date format for History
private CurrentModUpdated
timestamp
Timestamp for retreived files
private WritableFiles
writableFiles
Behaviour for writable files
Constructors Summary
Methods Summary
abstract org.apache.tools.ant.types.CommandlinebuildCmdLine()
Each sub-class must implemnt this method and return the constructed command line to be executed. It is up to the sub-task to determine the required attrubutes and their order.

return
The Constructed command line.

private java.lang.StringcalcDate(java.lang.String startDate, int daysToAdd)
Calculates the start date for version comparison.

Calculates the date numDay days earlier than startdate.

param
startDate The start date.
param
daysToAdd The number of days to add.
return
The calculated date.
throws
ParseException

        Calendar calendar = new GregorianCalendar();
        Date currentDate = dateFormat.parse(startDate);
        calendar.setTime(currentDate);
        calendar.add(Calendar.DATE, daysToAdd);
        return dateFormat.format(calendar.getTime());
    
public voidexecute()
Executes the task.
Builds a command line to execute ss.exe and then calls Exec's run method to execute the command line.

throws
BuildException if the command cannot execute.

        int result = 0;
        Commandline commandLine = buildCmdLine();
        result = run(commandLine);
        if (Execute.isFailure(result) && getFailOnError()) {
            String msg = "Failed executing: " + formatCommandLine(commandLine)
                     + " With a return code of " + result;
            throw new BuildException(msg, getLocation());
        }
    
private java.lang.StringformatCommandLine(org.apache.tools.ant.types.Commandline cmd)
Changes the password to '***' so it isn't displayed on screen if the build fails

param
cmd The command line to clean
return
The command line as a string with out the password

        StringBuffer sBuff = new StringBuffer(cmd.toString());
        int indexUser = sBuff.substring(0).indexOf(FLAG_LOGIN);
        if (indexUser > 0) {
            int indexPass = sBuff.substring(0).indexOf(",", indexUser);
            int indexAfterPass = sBuff.substring(0).indexOf(" ", indexPass);

            for (int i = indexPass + 1; i < indexAfterPass; i++) {
                sBuff.setCharAt(i, '*");
            }
        }
        return sBuff.toString();
    
protected java.lang.StringgetAutoresponse()
Gets the auto response string. This can be Y "-I-Y" or N "-I-N".

return
The default value "-I-" if autoresponse is not set.

        if (autoResponse == null) {
            return FLAG_AUTORESPONSE_DEF;
        } else if (autoResponse.equalsIgnoreCase("Y")) {
            return FLAG_AUTORESPONSE_YES;
        } else if (autoResponse.equalsIgnoreCase("N")) {
            return FLAG_AUTORESPONSE_NO;
        } else {
            return FLAG_AUTORESPONSE_DEF;
        }
    
protected java.lang.StringgetComment()
Gets the comment string. "-Ccomment text"

return
A comment of "-" if comment is not set.

        return comment != null ? FLAG_COMMENT + comment : FLAG_COMMENT + "-";
    
private booleangetFailOnError()
Gets the value of the fail on error flag.

return
True if the FailOnError flag has been set or if 'writablefiles=skip'.

        return getWritableFiles().equals(WRITABLE_SKIP) ? false : failOnError;
    
public java.lang.StringgetFileTimeStamp()
Gets the value set for the FileTimeStamp. if it equals "current" then we return -GTC if it equals "modified" then we return -GTM if it equals "updated" then we return -GTU otherwise we return -GTC

return
The default file time flag, if not set.

        if (timestamp == null) {
            return "";
        } else if (timestamp.getValue().equals(TIME_MODIFIED)) {
            return FLAG_FILETIME_MODIFIED;
        } else if (timestamp.getValue().equals(TIME_UPDATED)) {
            return FLAG_FILETIME_UPDATED;
        } else {
            return FLAG_FILETIME_DEF;
        }
    
protected java.lang.StringgetGetLocalCopy()
Builds and returns the -G- flag if required.

return
An empty string if get local copy is true.

        return (!getLocalCopy) ? FLAG_NO_GET : "";
    
protected java.lang.StringgetLabel()
Gets the label string. "-Lbuild1" Max label length is 32 chars

return
An empty string if label is not set.

        String shortLabel = "";
        if (label != null && label.length() > 0) {
                shortLabel = FLAG_LABEL + getShortLabel();
        }
        return shortLabel;
    
protected java.lang.StringgetLocalpath()
Gets the localpath string. "-GLc:\source"

The localpath is created if it didn't exist.

return
An empty string if localpath is not set.

        String lclPath = ""; //set to empty str if no local path return
        if (localPath != null) {
            //make sure m_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());
            }
            lclPath = FLAG_OVERRIDE_WORKING_DIR + localPath;
        }
        return lclPath;
    
protected java.lang.StringgetLogin()
Gets the login string. This can be user and password, "-Yuser,password" or just user "-Yuser".

return
An empty string if login is not set.

        return vssLogin != null ? FLAG_LOGIN + vssLogin : "";
    
protected java.lang.StringgetOutput()
Gets the output file string. "-Ooutput.file"

return
An empty string if user is not set.

        return outputFileName != null ? FLAG_OUTPUT + outputFileName : "";
    
protected java.lang.StringgetQuiet()
Gets the quiet string. -O-

return
An empty string if quiet is not set or is false.

        return quiet ? FLAG_QUIET : "";
    
protected java.lang.StringgetRecursive()
Gets the recursive string. "-R"

return
An empty string if recursive is not set or is false.

        return recursive ? FLAG_RECURSION : "";
    
protected java.lang.StringgetSSCommand()
Gets the sscommand string. "ss" or "c:\path\to\ss"

return
The path to ss.exe or just ss if sscommand is not set.

        if (ssDir == null) {
            return SS_EXE;
        }
        return ssDir.endsWith(File.separator) ? ssDir + SS_EXE : ssDir
                 + File.separator + SS_EXE;
    
private java.lang.StringgetShortLabel()
Return at most the 30 first chars of the label, logging a warning message about the truncation

return
at most the 30 first chars of the label

        String shortLabel;
        if (label !=  null && label.length() > 31) {
            shortLabel = this.label.substring(0, 30);
            log("Label is longer than 31 characters, truncated to: " + shortLabel,
                Project.MSG_WARN);
        } else {
            shortLabel = label;
        }
        return shortLabel;
    
protected java.lang.StringgetStyle()
Gets the style string. "-Lbuild1"

return
An empty string if label is not set.

        return style != null ? style : "";
    
protected java.lang.StringgetUser()
Gets the user string. "-Uusername"

return
An empty string if user is not set.

        return user != null ? FLAG_USER + user : "";
    
protected java.lang.StringgetVersion()
Gets the version string.

return
An empty string if a version is not set.

        return version != null ? FLAG_VERSION + version : "";
    
protected java.lang.StringgetVersionDate()
Gets the Version date string.

return
An empty string if neither Todate or from date are set.
throws
BuildException if there is an error.

        if (fromDate == null && toDate == null
            && numDays == Integer.MIN_VALUE) {
            return "";
        }
        if (fromDate != null && toDate != null) {
            return FLAG_VERSION_DATE + toDate + VALUE_FROMDATE + fromDate;
        } else if (toDate != null && numDays != Integer.MIN_VALUE) {
            try {
                return FLAG_VERSION_DATE + toDate + VALUE_FROMDATE
                        + calcDate(toDate, numDays);
            } catch (ParseException ex) {
                String msg = "Error parsing date: " + toDate;
                throw new BuildException(msg, getLocation());
            }
        } else if (fromDate != null && numDays != Integer.MIN_VALUE) {
            try {
                return FLAG_VERSION_DATE + calcDate(fromDate, numDays)
                        + VALUE_FROMDATE + fromDate;
            } catch (ParseException ex) {
                String msg = "Error parsing date: " + fromDate;
                throw new BuildException(msg, getLocation());
            }
        } else {
            return fromDate != null ? FLAG_VERSION + VALUE_FROMDATE
                    + fromDate : FLAG_VERSION_DATE + toDate;
        }
    
protected java.lang.StringgetVersionDateLabel()
Gets the version string. Returns the first specified of version "-V1.0", date "-Vd01.01.01", label "-Vlbuild1".

return
An empty string if a version, date and label are not set.

        String versionDateLabel = "";
        if (version != null) {
            versionDateLabel = FLAG_VERSION + version;
        } else if (date != null) {
            versionDateLabel = FLAG_VERSION_DATE + date;
        } else {
            // Use getShortLabel() so labels longer then 30 char are truncated
            // and the user is warned
            String shortLabel = getShortLabel();
            if (shortLabel != null && !shortLabel.equals("")) {
                versionDateLabel = FLAG_VERSION_LABEL + shortLabel;
            }
        }
        return versionDateLabel;
    
protected java.lang.StringgetVersionLabel()
Gets the version string. This can be to-from "-VLbuild2~Lbuild1", from "~Lbuild1" or to "-VLbuild2".

return
An empty string if neither tolabel or fromlabel are set.

        if (fromLabel == null && toLabel == null) {
            return "";
        }
        if (fromLabel != null && toLabel != null) {
            if (fromLabel.length() > 31) {
                fromLabel = fromLabel.substring(0, 30);
                log("FromLabel is longer than 31 characters, truncated to: "
                    + fromLabel, Project.MSG_WARN);
            }
            if (toLabel.length() > 31) {
                toLabel = toLabel.substring(0, 30);
                log("ToLabel is longer than 31 characters, truncated to: "
                    + toLabel, Project.MSG_WARN);
            }
            return FLAG_VERSION_LABEL + toLabel + VALUE_FROMLABEL + fromLabel;
        } else if (fromLabel != null) {
            if (fromLabel.length() > 31) {
                fromLabel = fromLabel.substring(0, 30);
                log("FromLabel is longer than 31 characters, truncated to: "
                    + fromLabel, Project.MSG_WARN);
            }
            return FLAG_VERSION + VALUE_FROMLABEL + fromLabel;
        } else {
            if (toLabel.length() > 31) {
                toLabel = toLabel.substring(0, 30);
                log("ToLabel is longer than 31 characters, truncated to: "
                    + toLabel, Project.MSG_WARN);
            }
            return FLAG_VERSION_LABEL + toLabel;
        }
    
protected java.lang.StringgetVsspath()
Gets the vssserverpath string.

return
null if vssserverpath is not set.

        return vssPath;
    
protected java.lang.StringgetWritable()
Gets the writable string. "-W"

return
An empty string if writable is not set or is false.

        return writable ? FLAG_WRITABLE : "";
    
public java.lang.StringgetWritableFiles()
Gets the value to determine the behaviour when encountering writable files.

return
An empty String, if not set.

        if (writableFiles == null) {
            return "";
        } else if (writableFiles.getValue().equals(WRITABLE_REPLACE)) {
            return FLAG_REPLACE_WRITABLE;
        } else if (writableFiles.getValue().equals(WRITABLE_SKIP)) {
            // ss.exe exits with '100', when files have been skipped
            // so we have to ignore the failure
            failOnError = false;
            return FLAG_SKIP_WRITABLE;
        } else {
            return "";
        }
    
private intrun(org.apache.tools.ant.types.Commandline cmd)
Sets up the required environment and executes the command line.

param
cmd The command line to execute.
return
The return code from the exec'd process.

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

            // If location of ss.ini is specified we need to set the
            // environment-variable SSDIR to this value
            if (serverPath != null) {
                String[] env = exe.getEnvironment();
                if (env == null) {
                    env = new String[0];
                }
                String[] newEnv = new String[env.length + 1];
                System.arraycopy(env, 0, newEnv, 0, env.length);
                newEnv[env.length] = "SSDIR=" + serverPath;

                exe.setEnvironment(newEnv);
            }

            exe.setAntRun(getProject());
            exe.setWorkingDirectory(getProject().getBaseDir());
            exe.setCommandline(cmd.getCommandline());
            // Use the OS launcher so we get environment variables
            exe.setVMLauncher(false);
            return exe.execute();
        } catch (IOException e) {
            throw new BuildException(e, getLocation());
        }
    
public final voidsetFailOnError(boolean failOnError)
Indicates if the build should fail if the Sourcesafe command does. Defaults to true.

param
failOnError True if task should fail on any error.

        this.failOnError = failOnError;
    
protected voidsetInternalAutoResponse(java.lang.String autoResponse)
Set the auto response attribute.

param
autoResponse the value to use.

        this.autoResponse = autoResponse;
    
protected voidsetInternalComment(java.lang.String comment)
Set the internal comment attribute.

param
comment the value to use.

        this.comment = comment;
    
protected voidsetInternalDate(java.lang.String date)
Set the date attribute.

param
date the value to use.

        this.date = date;
    
protected voidsetInternalDateFormat(java.text.DateFormat dateFormat)
Set the date format attribute.

param
dateFormat the value to use.

        this.dateFormat = dateFormat;
    
protected voidsetInternalFailOnError(boolean failOnError)
Set the failOnError attribute.

param
failOnError the value to use.

        this.failOnError = failOnError;
    
protected voidsetInternalFileTimeStamp(org.apache.tools.ant.taskdefs.optional.vss.MSVSS$CurrentModUpdated timestamp)
Set the timestamp attribute.

param
timestamp the value to use.

        this.timestamp = timestamp;
    
protected voidsetInternalFromDate(java.lang.String fromDate)
Set the from date attribute.

param
fromDate the value to use.

        this.fromDate = fromDate;
    
protected voidsetInternalFromLabel(java.lang.String fromLabel)
Set the from label attribute.

param
fromLabel the value to use.

        this.fromLabel = fromLabel;
    
protected voidsetInternalGetLocalCopy(boolean getLocalCopy)
Set the getLocalCopy attribute.

param
getLocalCopy the value to use.

        this.getLocalCopy = getLocalCopy;
    
protected voidsetInternalLabel(java.lang.String label)
Set the label attribute.

param
label the value to use.

        this.label = label;
    
protected voidsetInternalLocalPath(java.lang.String localPath)
Set the local path comment attribute.

param
localPath the value to use.

        this.localPath = localPath;
    
protected voidsetInternalNumDays(int numDays)
Set the num days attribute.

param
numDays the value to use.

        this.numDays = numDays;
    
protected voidsetInternalOutputFilename(java.lang.String outputFileName)
Set the outputFileName comment attribute.

param
outputFileName the value to use.

        this.outputFileName = outputFileName;
    
protected voidsetInternalQuiet(boolean quiet)
Set the quiet attribute.

param
quiet the value to use.

        this.quiet = quiet;
    
protected voidsetInternalRecursive(boolean recursive)
Set the recursive attribute.

param
recursive the value to use.

        this.recursive = recursive;
    
protected voidsetInternalStyle(java.lang.String style)
Set the style attribute.

param
style the value to use.

        this.style = style;
    
protected voidsetInternalToDate(java.lang.String toDate)
Set the to date attribute.

param
toDate the value to use.

        this.toDate = toDate;
    
protected voidsetInternalToLabel(java.lang.String toLabel)
Set the to label attribute.

param
toLabel the value to use.

        this.toLabel = toLabel;
    
protected voidsetInternalUser(java.lang.String user)
Set the user attribute.

param
user the value to use.

        this.user = user;
    
protected voidsetInternalVersion(java.lang.String version)
Set the version attribute.

param
version the value to use.

        this.version = version;
    
protected voidsetInternalWritable(boolean writable)
Set the writable attribute.

param
writable the value to use.

        this.writable = writable;
    
protected voidsetInternalWritableFiles(org.apache.tools.ant.taskdefs.optional.vss.MSVSS$WritableFiles writableFiles)
Set the writableFiles attribute.

param
writableFiles the value to use.

        this.writableFiles = writableFiles;
    
public final voidsetLogin(java.lang.String vssLogin)
Login to use when accessing VSS, formatted as "username,password".

You can omit the password if your database is not password protected. If you have a password and omit it, Ant will hang.

param
vssLogin The login string to use.

        this.vssLogin = vssLogin;
    
public final voidsetServerpath(java.lang.String serverPath)
Directory where srssafe.ini resides.

param
serverPath The path to the VSS server.

        this.serverPath = serverPath;
    
public final voidsetSsdir(java.lang.String dir)
Directory where ss.exe resides. By default the task expects it to be in the PATH.

param
dir The directory containing ss.exe.


                                              
      

                                
         
        this.ssDir = FileUtils.translatePath(dir);
    
public final voidsetVsspath(java.lang.String vssPath)
SourceSafe path which specifies the project/file(s) you wish to perform the action on.

A prefix of 'vss://' will be removed if specified.

param
vssPath The VSS project path.
ant.attribute
group="required"

        String projectPath;
        if (vssPath.startsWith("vss://")) { //$NON-NLS-1$
            projectPath = vssPath.substring(5);
        } else {
            projectPath = vssPath;
        }

        if (projectPath.startsWith(PROJECT_PREFIX)) {
            this.vssPath = projectPath;
        } else {
            this.vssPath = PROJECT_PREFIX + projectPath;
        }