FileDocCategorySizeDatePackage
CCCheckout.javaAPI DocApache Ant 1.7014936Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.clearcase

CCCheckout

public class CCCheckout extends ClearCase
Performs ClearCase checkout.

The following attributes are interpreted:
Attribute Values Required
viewpath Path to the ClearCase view file or directory that the command will operate on No
reserved Specifies whether to check out the file as reserved or not Yes
out Creates a writable file under a different filename No
nodata Checks out the file but does not create an editable file containing its data No
branch Specify a branch to check out the file to No
version Allows checkout of a version other than main latest No
nowarn Suppress warning messages No
comment Specify a comment. Only one of comment or cfile may be used. No
commentfile Specify a file containing a comment. Only one of comment or cfile may be used. No
notco Fail if it's already checked out to the current view. Set to false to ignore it. No
failonerr Throw an exception if the command fails. Default is true No

Fields Summary
private boolean
mReserved
private String
mOut
private boolean
mNdata
private String
mBranch
private boolean
mVersion
private boolean
mNwarn
private String
mComment
private String
mCfile
private boolean
mNotco
public static final String
FLAG_RESERVED
-reserved flag -- check out the file as reserved
public static final String
FLAG_UNRESERVED
-reserved flag -- check out the file as unreserved
public static final String
FLAG_OUT
-out flag -- create a writable file under a different filename
public static final String
FLAG_NODATA
-ndata flag -- checks out the file but does not create an editable file containing its data
public static final String
FLAG_BRANCH
-branch flag -- checks out the file on a specified branch
public static final String
FLAG_VERSION
-version flag -- allows checkout of a version that is not main latest
public static final String
FLAG_NOWARN
-nwarn flag -- suppresses warning messages
public static final String
FLAG_COMMENT
-c flag -- comment to attach to the file
public static final String
FLAG_COMMENTFILE
-cfile flag -- file containing a comment to attach to the file
public static final String
FLAG_NOCOMMENT
-nc flag -- no comment is specified
Constructors Summary
Methods Summary
private voidcheckOptions(org.apache.tools.ant.types.Commandline cmd)
Check the command line options.

        // ClearCase items
        if (getReserved()) {
            // -reserved
            cmd.createArgument().setValue(FLAG_RESERVED);
        } else {
            // -unreserved
            cmd.createArgument().setValue(FLAG_UNRESERVED);
        }

        if (getOut() != null) {
            // -out
            getOutCommand(cmd);
        } else {
            if (getNoData()) {
                // -ndata
                cmd.createArgument().setValue(FLAG_NODATA);
            }

        }

        if (getBranch() != null) {
            // -branch
            getBranchCommand(cmd);
        } else {
            if (getVersion()) {
                // -version
                cmd.createArgument().setValue(FLAG_VERSION);
            }

        }

        if (getNoWarn()) {
            // -nwarn
            cmd.createArgument().setValue(FLAG_NOWARN);
        }

        if (getComment() != null) {
            // -c
            getCommentCommand(cmd);
        } else {
            if (getCommentFile() != null) {
                // -cfile
                getCommentFileCommand(cmd);
            } else {
                cmd.createArgument().setValue(FLAG_NOCOMMENT);
            }
        }

        // viewpath
        cmd.createArgument().setValue(getViewPath());

        // Print out info about the notco option
        // System.out.println( "Notco: " + (getNotco() ? "yes" : "no") );
    
public voidexecute()
Executes the task.

Builds a command line to execute cleartool and then calls Exec's run method to execute the command line.

throws
BuildException if the command fails and failonerr is set to true


                                           
         
        Commandline commandLine = new Commandline();
        Project aProj = getProject();
        int result = 0;

        // Default the viewpath to basedir if it is not specified
        if (getViewPath() == null) {
            setViewPath(aProj.getBaseDir().getPath());
        }

        // build the command line from what we got the format is
        // cleartool checkout [options...] [viewpath ...]
        // as specified in the CLEARTOOL.EXE help
        commandLine.setExecutable(getClearToolCommand());
        commandLine.createArgument().setValue(COMMAND_CHECKOUT);

        checkOptions(commandLine);
        /*
         * If configured to not care about whether the element is
         * already checked out to the current view.
         * Then check to see if it is checked out.
         */
        if (!getNotco() && lsCheckout()) {
            getProject().log("Already checked out in this view: "
                    + getViewPathBasename(), Project.MSG_VERBOSE);
            return;
        }
        if (!getFailOnErr()) {
            getProject().log("Ignoring any errors that occur for: "
                    + getViewPathBasename(), Project.MSG_VERBOSE);
        }
        result = run(commandLine);
        if (Execute.isFailure(result) && getFailOnErr()) {
            String msg = "Failed executing: " + commandLine.toString();
            throw new BuildException(msg, getLocation());
        }
    
public java.lang.StringgetBranch()
Get branch name

return
String containing the name of the branch

        return mBranch;
    
private voidgetBranchCommand(org.apache.tools.ant.types.Commandline cmd)
Get the 'branch' command

param
cmd containing the command line string with or without the branch flag and name appended

        if (getBranch() != null) {
            /* Had to make two separate commands here because if a space is
               inserted between the flag and the value, it is treated as a
               Windows filename with a space and it is enclosed in double
               quotes ("). This breaks clearcase.
            */
            cmd.createArgument().setValue(FLAG_BRANCH);
            cmd.createArgument().setValue(getBranch());
        }
    
public java.lang.StringgetComment()
Get comment string

return
String containing the comment

        return mComment;
    
private voidgetCommentCommand(org.apache.tools.ant.types.Commandline cmd)
Get the 'comment' command

param
cmd containing the command line string with or without the comment flag and string appended

        if (getComment() != null) {
            /* Had to make two separate commands here because if a space is
               inserted between the flag and the value, it is treated as a
               Windows filename with a space and it is enclosed in double
               quotes ("). This breaks clearcase.
            */
            cmd.createArgument().setValue(FLAG_COMMENT);
            cmd.createArgument().setValue(getComment());
        }
    
public java.lang.StringgetCommentFile()
Get comment file

return
String containing the path to the comment file

        return mCfile;
    
private voidgetCommentFileCommand(org.apache.tools.ant.types.Commandline cmd)
Get the 'cfile' command

param
cmd containing the command line string with or without the cfile flag and file appended

        if (getCommentFile() != null) {
            /* Had to make two separate commands here because if a space is
               inserted between the flag and the value, it is treated as a
               Windows filename with a space and it is enclosed in double
               quotes ("). This breaks clearcase.
            */
            cmd.createArgument().setValue(FLAG_COMMENTFILE);
            cmd.createArgument().setValue(getCommentFile());
        }
    
public booleangetNoData()
Get nodata flag status

return
boolean containing status of ndata flag

        return mNdata;
    
public booleangetNoWarn()
Get nowarn flag status

return
boolean containing status of nwarn flag

        return mNwarn;
    
public booleangetNotco()
Get notco flag status

return
boolean containing status of notco flag
since
ant 1.6.1

        return mNotco;
    
public java.lang.StringgetOut()
Get out file

return
String containing the path to the out file

        return mOut;
    
private voidgetOutCommand(org.apache.tools.ant.types.Commandline cmd)
Get the 'out' command

param
cmd containing the command line string with or without the out flag and path appended

        if (getOut() != null) {
            /* Had to make two separate commands here because if a space is
               inserted between the flag and the value, it is treated as a
               Windows filename with a space and it is enclosed in double
               quotes ("). This breaks clearcase.
            */
            cmd.createArgument().setValue(FLAG_OUT);
            cmd.createArgument().setValue(getOut());
        }
    
public booleangetReserved()
Get reserved flag status

return
boolean containing status of reserved flag

        return mReserved;
    
public booleangetVersion()
Get version flag status

return
boolean containing status of version flag

        return mVersion;
    
private booleanlsCheckout()
Check to see if the element is checked out in the current view.

        Commandline cmdl = new Commandline();
        String result;

        // build the command line from what we got the format is
        // cleartool lsco [options...] [viewpath ...]
        // as specified in the CLEARTOOL.EXE help
        cmdl.setExecutable(getClearToolCommand());
        cmdl.createArgument().setValue(COMMAND_LSCO);
        cmdl.createArgument().setValue("-cview");
        cmdl.createArgument().setValue("-short");
        cmdl.createArgument().setValue("-d");
        // viewpath
        cmdl.createArgument().setValue(getViewPath());

        result = runS(cmdl);

        // System.out.println( "lsCheckout: " + result );

        return (result != null && result.length() > 0) ? true : false;
    
public voidsetBranch(java.lang.String branch)
Specify a branch to check out the file to.

param
branch the name of the branch

        mBranch = branch;
    
public voidsetComment(java.lang.String comment)
Sets the comment string.

param
comment the comment string

        mComment = comment;
    
public voidsetCommentFile(java.lang.String cfile)
Specifies a file containing a comment.

param
cfile the path to the comment file

        mCfile = cfile;
    
public voidsetNoData(boolean ndata)
If true, checks out the file but does not create an editable file containing its data.

param
ndata the status to set the flag to

        mNdata = ndata;
    
public voidsetNoWarn(boolean nwarn)
If true, warning messages are suppressed.

param
nwarn the status to set the flag to

        mNwarn = nwarn;
    
public voidsetNotco(boolean notco)
If true, checkout fails if the element is already checked out to the current view.

param
notco the status to set the flag to
since
ant 1.6.1

        mNotco = notco;
    
public voidsetOut(java.lang.String outf)
Creates a writable file under a different filename.

param
outf the path to the out file

        mOut = outf;
    
public voidsetReserved(boolean reserved)
If true, checks out the file as reserved.

param
reserved the status to set the flag to

        mReserved = reserved;
    
public voidsetVersion(boolean version)
If true, allows checkout of a version other than main latest.

param
version the status to set the flag to

        mVersion = version;