FileDocCategorySizeDatePackage
P4Add.javaAPI DocApache Ant 1.705352Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.optional.perforce

P4Add

public class P4Add extends P4Base
Adds specified files to Perforce. Example Usage:
FunctionCommand
Add files using P4USER, P4PORT and P4CLIENT settings specified <P4add
P4view="//projects/foo/main/source/..."
P4User="fbloggs"
P4Port="km01:1666"
P4Client="fbloggsclient">
<fileset basedir="dir" includes="**/*.java">
</p4add>
Add files using P4USER, P4PORT and P4CLIENT settings defined in environment <P4add P4view="//projects/foo/main/source/..." />
<fileset basedir="dir" includes="**/*.java">
</p4add>
Specify the length of command line arguments to pass to each invocation of p4 <p4add Commandlength="450">
ant.task
category="scm"

Fields Summary
private static final int
DEFAULT_CMD_LENGTH
private int
changelist
private String
addCmd
private Vector
filesets
private int
cmdLength
Constructors Summary
Methods Summary
public voidaddFileset(org.apache.tools.ant.types.FileSet set)
Add a fileset whose files will be added to Perforce.

param
set the FileSet that one wants to add to Perforce Source Control.

        filesets.addElement(set);
    
private voidexecP4Add(java.lang.StringBuffer list)

        log("Execing add " + P4CmdOpts + " " + addCmd + list, Project.MSG_INFO);
        execP4Command("-s add " + P4CmdOpts + " " + addCmd + list, new SimpleP4OutputHandler(this));
    
public voidexecute()
Run the task.

throws
BuildException if the execution of the Perforce command fails.

        if (P4View != null) {
            addCmd = P4View;
        }
        P4CmdOpts = (changelist > 0) ? ("-c " + changelist) : "";

        StringBuffer filelist = new StringBuffer();

        for (int i = 0; i < filesets.size(); i++) {
            FileSet fs = (FileSet) filesets.elementAt(i);
            DirectoryScanner ds = fs.getDirectoryScanner(getProject());

            String[] srcFiles = ds.getIncludedFiles();
            if (srcFiles != null) {
                for (int j = 0; j < srcFiles.length; j++) {
                    File f = new File(ds.getBasedir(), srcFiles[j]);
                    filelist.append(" ").append('"").append(f.getAbsolutePath()).append('"");
                    if (filelist.length() > cmdLength) {
                        execP4Add(filelist);
                        filelist = new StringBuffer();
                    }
                }
                if (filelist.length() > 0) {
                    execP4Add(filelist);
                }
            } else {
                log("No files specified to add!", Project.MSG_WARN);
            }
        }
    
public voidsetChangelist(int changelist)
If specified the open files are associated with the specified pending changelist number; otherwise the open files are associated with the default changelist.

param
changelist the change list number.
throws
BuildException if trying to set a change list number <=0.

        if (changelist <= 0) {
            throw new BuildException("P4Add: Changelist# should be a positive number");
        }
        this.changelist = changelist;
    
public voidsetCommandlength(int len)
Set the maximum length of the commandline when calling Perforce to add the files. Defaults to 450, higher values mean faster execution, but also possible failures.

param
len maximum length of command line default is 450.
throws
BuildException if trying to set the command line length to 0 or less.


                                                                       

          
        if (len <= 0) {
            throw new BuildException("P4Add: Commandlength should be a positive number");
        }
        this.cmdLength = len;