1 19 package org.netbeans.lib.cvsclient.command.annotate; 20 21 import java.io.*; 22 import java.util.*; 23 24 import org.netbeans.lib.cvsclient.*; 25 import org.netbeans.lib.cvsclient.command.*; 26 import org.netbeans.lib.cvsclient.connection.*; 27 import org.netbeans.lib.cvsclient.event.*; 28 import org.netbeans.lib.cvsclient.request.*; 29 30 37 public class RannotateCommand extends BasicCommand { 38 39 40 44 private final List modules = new LinkedList(); 45 46 49 private final List expandedModules = new LinkedList(); 50 51 55 private boolean useHeadIfNotFound; 56 57 60 private String annotateByDate; 61 62 65 private String annotateByRevision; 66 67 70 private boolean headerAndDescOnly; 71 72 public RannotateCommand() { 73 resetCVSCommand(); 74 } 75 76 80 public void setModule(String module) { 81 modules.add(module); 82 } 83 84 87 88 public void clearModules() { 89 this.modules.clear(); 90 } 91 92 96 public void setModules(String [] modules) { 97 clearModules(); 98 if (modules == null) { 99 return; 100 } 101 for (int i = 0; i < modules.length; i++) { 102 String module = modules[i]; 103 this.modules.add(module); 104 } 105 } 106 107 public String [] getModules() { 108 String [] mods = new String [modules.size()]; 109 mods = (String [])modules.toArray(mods); 110 return mods; 111 } 112 113 private void processExistingModules(String localPath) { 114 if (expandedModules.size() == 0) { 115 return; 116 } 117 118 String [] directories = new String [expandedModules.size()]; 119 directories = (String [])expandedModules.toArray(directories); 120 setModules(directories); 121 } 122 123 124 130 public void execute(ClientServices client, EventManager em) 131 throws CommandException, AuthenticationException { 132 133 client.ensureConnection(); 134 135 requests = new LinkedList(); 136 if (client.isFirstCommand()) { 137 requests.add(new RootRequest(client.getRepository())); 138 } 139 for (Iterator it = modules.iterator(); it.hasNext();) { 140 String module = (String )it.next(); 141 requests.add(new ArgumentRequest(module)); 142 } 143 expandedModules.clear(); 144 requests.add(new DirectoryRequest(".", client.getRepository())); requests.add(new ExpandModulesRequest()); 146 try { 147 client.processRequests(requests); 148 } 149 catch (CommandException ex) { 150 throw ex; 151 } 152 catch (Exception ex) { 153 throw new CommandException(ex, ex.getLocalizedMessage()); 154 } 155 requests.clear(); 156 postExpansionExecute(client, em); 157 } 158 159 163 public void moduleExpanded(ModuleExpansionEvent e) { 164 expandedModules.add(e.getModule()); 165 } 166 167 173 private void postExpansionExecute(ClientServices client, EventManager em) 174 throws CommandException, AuthenticationException { 175 176 super.execute(client, em); 178 179 if (!isRecursive()) 183 { 184 requests.add(1, new ArgumentRequest("-l")); } 186 if (useHeadIfNotFound) { 187 requests.add(1, new ArgumentRequest("-f")); } 189 if (annotateByDate != null && annotateByDate.length() > 0) { 190 requests.add(1, new ArgumentRequest("-D")); requests.add(2, new ArgumentRequest(getAnnotateByDate())); 192 } 193 if (annotateByRevision != null && annotateByRevision.length() > 0) { 194 requests.add(1, new ArgumentRequest("-r")); requests.add(2, new ArgumentRequest(getAnnotateByRevision())); 196 } 197 198 199 for (Iterator it = modules.iterator(); it.hasNext();) { 200 String module = (String )it.next(); 201 requests.add(new ArgumentRequest(module)); 202 } 203 204 requests.add(new DirectoryRequest(".", client.getRepository())); requests.add(CommandRequest.RANNOTATE); 206 try { 207 client.processRequests(requests); 208 requests.clear(); 209 210 } 211 catch (CommandException ex) { 212 throw ex; 213 } 214 catch (Exception ex) { 215 throw new CommandException(ex, ex.getLocalizedMessage()); 216 } 217 } 218 219 220 public String getCVSCommand() { 221 StringBuffer toReturn = new StringBuffer ("rannotate "); toReturn.append(getCVSArguments()); 223 if (modules != null && modules.size() > 0) { 224 for (Iterator it = modules.iterator(); it.hasNext();) { 225 String module = (String )it.next(); 226 toReturn.append(module); 227 toReturn.append(' '); 228 } 229 } 230 else { 231 String localizedMsg = CommandException.getLocalMessage("ExportCommand.moduleEmpty.text"); toReturn.append(" "); toReturn.append(localizedMsg); 234 } 235 return toReturn.toString(); 236 } 237 238 public String getCVSArguments() { 239 StringBuffer toReturn = new StringBuffer (""); if (!isRecursive()) { 241 toReturn.append("-l "); } 243 if (getAnnotateByRevision() != null) { 244 toReturn.append("-r "); toReturn.append(getAnnotateByRevision()); 246 toReturn.append(" "); } 248 if (getAnnotateByDate() != null) { 249 toReturn.append("-D "); toReturn.append(getAnnotateByDate()); 251 toReturn.append(" "); } 253 if (isUseHeadIfNotFound()) { 254 toReturn.append("-f "); } 256 return toReturn.toString(); 257 } 258 259 public boolean setCVSCommand(char opt, String optArg) { 260 if (opt == 'R') { 261 setRecursive(true); 262 } 263 else if (opt == 'l') { 264 setRecursive(false); 265 } 266 else if (opt == 'r') { 267 setAnnotateByRevision(optArg); 268 } 269 else if (opt == 'D') { 270 setAnnotateByDate(optArg); 271 } 272 else if (opt == 'f') { 273 setUseHeadIfNotFound(true); 274 } 275 else { 276 return false; 277 } 278 return true; 279 } 280 281 public void resetCVSCommand() { 282 setRecursive(true); 283 setAnnotateByDate(null); 284 setAnnotateByRevision(null); 285 setUseHeadIfNotFound(false); 286 } 287 288 291 public String getOptString() { 292 return "Rlr:D:f"; } 294 295 296 300 public Builder createBuilder(EventManager eventMan) { 301 return new AnnotateBuilder(eventMan, this); 302 303 } 304 305 307 public void commandTerminated(TerminationEvent e) { 308 if (builder != null) { 309 builder.outputDone(); 310 } 311 } 312 313 317 public boolean isUseHeadIfNotFound() { 318 return useHeadIfNotFound; 319 } 320 321 325 public void setUseHeadIfNotFound(boolean useHeadIfNotFound) { 326 this.useHeadIfNotFound = useHeadIfNotFound; 327 } 328 329 333 public String getAnnotateByDate() { 334 return annotateByDate; 335 } 336 337 341 public void setAnnotateByDate(String annotateByDate) { 342 this.annotateByDate = annotateByDate; 343 } 344 345 349 public String getAnnotateByRevision() { 350 return annotateByRevision; 351 } 352 353 357 public void setAnnotateByRevision(String annotateByRevision) { 358 this.annotateByRevision = annotateByRevision; 359 } 360 361 } 362 | Popular Tags |