1 18 23 24 package org.apache.tools.ant.taskdefs.optional.perforce; 25 26 import java.io.File ; 27 import java.util.Vector ; 28 29 import org.apache.tools.ant.Project; 30 import org.apache.tools.ant.BuildException; 31 import org.apache.tools.ant.DirectoryScanner; 32 import org.apache.tools.ant.types.FileSet; 33 34 54 public class P4Add extends P4Base { 55 private static final int DEFAULT_CMD_LENGTH = 450; 56 private int changelist; 57 private String addCmd = ""; 58 private Vector filesets = new Vector (); 59 private int cmdLength = DEFAULT_CMD_LENGTH; 60 61 69 70 public void setCommandlength(int len) throws BuildException { 71 if (len <= 0) { 72 throw new BuildException("P4Add: Commandlength should be a positive number"); 73 } 74 this.cmdLength = len; 75 } 76 77 86 public void setChangelist(int changelist) throws BuildException { 87 if (changelist <= 0) { 88 throw new BuildException("P4Add: Changelist# should be a positive number"); 89 } 90 this.changelist = changelist; 91 } 92 93 98 public void addFileset(FileSet set) { 99 filesets.addElement(set); 100 } 101 102 107 public void execute() throws BuildException { 108 if (P4View != null) { 109 addCmd = P4View; 110 } 111 P4CmdOpts = (changelist > 0) ? ("-c " + changelist) : ""; 112 113 StringBuffer filelist = new StringBuffer (); 114 115 for (int i = 0; i < filesets.size(); i++) { 116 FileSet fs = (FileSet) filesets.elementAt(i); 117 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 118 119 String [] srcFiles = ds.getIncludedFiles(); 120 if (srcFiles != null) { 121 for (int j = 0; j < srcFiles.length; j++) { 122 File f = new File (ds.getBasedir(), srcFiles[j]); 123 filelist.append(" ").append('"').append(f.getAbsolutePath()).append('"'); 124 if (filelist.length() > cmdLength) { 125 execP4Add(filelist); 126 filelist = new StringBuffer (); 127 } 128 } 129 if (filelist.length() > 0) { 130 execP4Add(filelist); 131 } 132 } else { 133 log("No files specified to add!", Project.MSG_WARN); 134 } 135 } 136 } 137 138 private void execP4Add(StringBuffer list) { 139 log("Execing add " + P4CmdOpts + " " + addCmd + list, Project.MSG_INFO); 140 execP4Command("-s add " + P4CmdOpts + " " + addCmd + list, new SimpleP4OutputHandler(this)); 141 } 142 } 143 | Popular Tags |