1 18 23 24 package org.apache.tools.ant.taskdefs.optional.perforce; 25 26 27 import java.io.File ; 28 import java.util.Vector ; 29 import java.util.ArrayList ; 30 31 import org.apache.tools.ant.Project; 32 import org.apache.tools.ant.BuildException; 33 import org.apache.tools.ant.DirectoryScanner; 34 import org.apache.tools.ant.types.FileSet; 35 36 53 public class P4Fstat extends P4Base { 54 55 private int changelist; 56 private String addCmd = ""; 57 private Vector filesets = new Vector (); 58 private static final int DEFAULT_CMD_LENGTH = 300; 59 private int cmdLength = DEFAULT_CMD_LENGTH; 60 private static final int SHOW_ALL = 0; 61 private static final int SHOW_EXISTING = 1; 62 private static final int SHOW_NON_EXISTING = 2; 63 private int show = SHOW_NON_EXISTING; 64 private FStatP4OutputHandler handler; 65 private StringBuffer filelist; 66 private int fileNum = 0; 67 private int doneFileNum = 0; 68 private boolean debug = false; 69 70 private static final String EXISTING_HEADER 71 = "Following files exist in perforce"; 72 private static final String NONEXISTING_HEADER 73 = "Following files do not exist in perforce"; 74 75 85 public void setShowFilter(String filter) { 86 if (filter.equalsIgnoreCase("all")) { 87 show = SHOW_ALL; 88 } else if (filter.equalsIgnoreCase("existing")) { 89 show = SHOW_EXISTING; 90 } else if (filter.equalsIgnoreCase("non-existing")) { 91 show = SHOW_NON_EXISTING; 92 } else { 93 throw new BuildException("P4Fstat: ShowFilter should be one of: " 94 + "all, existing, non-existing"); 95 } 96 } 97 98 103 public void setChangelist(int changelist) throws BuildException { 104 if (changelist <= 0) { 105 throw new BuildException("P4FStat: Changelist# should be a " 106 + "positive number"); 107 } 108 this.changelist = changelist; 109 } 110 111 115 public void addFileset(FileSet set) { 116 filesets.addElement(set); 117 } 118 119 123 public void execute() throws BuildException { 124 handler = new FStatP4OutputHandler(this); 125 if (P4View != null) { 126 addCmd = P4View; 127 } 128 P4CmdOpts = (changelist > 0) ? ("-c " + changelist) : ""; 129 130 filelist = new StringBuffer (); 131 132 for (int i = 0; i < filesets.size(); i++) { 133 FileSet fs = (FileSet) filesets.elementAt(i); 134 DirectoryScanner ds = fs.getDirectoryScanner(getProject()); 135 136 String [] srcFiles = ds.getIncludedFiles(); 137 fileNum = srcFiles.length; 138 139 if (srcFiles != null) { 140 for (int j = 0; j < srcFiles.length; j++) { 141 File f = new File (ds.getBasedir(), srcFiles[j]); 142 filelist.append(" ").append('"').append(f.getAbsolutePath()).append('"'); 143 doneFileNum++; 144 if (filelist.length() > cmdLength) { 145 146 execP4Fstat(filelist); 147 filelist = new StringBuffer (); 148 } 149 } 150 if (filelist.length() > 0) { 151 execP4Fstat(filelist); 152 } 153 } else { 154 log("No files specified to query status on!", Project.MSG_WARN); 155 } 156 } 157 if (show == SHOW_ALL || show == SHOW_EXISTING) { 158 printRes(handler.getExisting(), EXISTING_HEADER); 159 } 160 if (show == SHOW_ALL || show == SHOW_NON_EXISTING) { 161 printRes(handler.getNonExisting(), NONEXISTING_HEADER); 162 } 163 } 164 165 169 public int getLengthOfTask() { 170 return fileNum; 171 } 172 173 178 int getPasses() { 179 return filesets.size(); 180 } 181 182 private void printRes(ArrayList ar, String header) { 183 log(header, Project.MSG_INFO); 184 for (int i = 0; i < ar.size(); i++) { 185 log((String ) ar.get(i), Project.MSG_INFO); 186 } 187 } 188 189 private void execP4Fstat(StringBuffer list) { 190 String l = list.substring(0); 191 if (debug) { 192 log("Executing fstat " + P4CmdOpts + " " + addCmd + l + "\n", 193 Project.MSG_INFO); 194 } 195 execP4Command("fstat " + P4CmdOpts + " " + addCmd + l, handler); 196 } 197 198 } 199 | Popular Tags |