1 19 package org.netbeans.lib.cvsclient.command.log; 20 21 import java.io.*; 22 23 import org.netbeans.lib.cvsclient.*; 24 import org.netbeans.lib.cvsclient.command.*; 25 import org.netbeans.lib.cvsclient.connection.*; 26 import org.netbeans.lib.cvsclient.event.*; 27 import org.netbeans.lib.cvsclient.request.*; 28 29 33 public class LogCommand extends BasicCommand { 34 37 protected EventManager eventManager; 38 39 42 private boolean defaultBranch; 43 44 47 private String dateFilter; 48 49 52 private boolean headerOnly; 53 54 57 private boolean noTags; 58 59 62 private String revisionFilter; 63 64 67 private String stateFilter; 68 69 72 private String userFilter; 73 74 77 private boolean headerAndDescOnly; 78 79 82 public LogCommand() { 83 resetCVSCommand(); 84 } 85 86 90 public Builder createBuilder(EventManager eventMan) { 91 return new LogBuilder(eventMan, this); 92 } 93 94 100 public void execute(ClientServices client, EventManager em) 101 throws CommandException, AuthenticationException { 102 client.ensureConnection(); 103 104 eventManager = em; 105 106 super.execute(client, em); 107 108 try { 109 if (defaultBranch) { 111 requests.add(1, new ArgumentRequest("-b")); } 113 if (headerAndDescOnly) { 114 requests.add(1, new ArgumentRequest("-t")); } 116 if (headerOnly) { 117 requests.add(1, new ArgumentRequest("-h")); } 119 if (noTags) { 120 requests.add(1, new ArgumentRequest("-N")); } 122 if (userFilter != null) { 123 requests.add(1, new ArgumentRequest("-w" + userFilter)); } 125 if (revisionFilter != null) { 126 requests.add(1, new ArgumentRequest("-r" + revisionFilter)); } 128 if (stateFilter != null) { 129 requests.add(1, new ArgumentRequest("-s" + stateFilter)); } 131 if (dateFilter != null) { 132 requests.add(1, new ArgumentRequest("-d" + dateFilter)); } 134 addRequestForWorkingDirectory(client); 135 addArgumentRequests(); 136 addRequest(CommandRequest.LOG); 137 138 client.processRequests(requests); 139 } 140 catch (CommandException ex) { 141 throw ex; 142 } 143 catch (Exception ex) { 144 throw new CommandException(ex, ex.getLocalizedMessage()); 145 } 146 finally { 147 requests.clear(); 148 if (!isBuilderSet()) { 149 builder = null; 150 } 151 } 152 } 153 154 158 public void commandTerminated(TerminationEvent e) { 159 if (builder != null) { 160 builder.outputDone(); 161 } 162 } 163 164 169 public boolean isDefaultBranch() { 170 return defaultBranch; 171 } 172 173 178 public void setDefaultBranch(boolean defaultBranch) { 179 this.defaultBranch = defaultBranch; 180 } 181 182 186 public String getDateFilter() { 187 return dateFilter; 188 } 189 190 193 public void setDateFilter(String dateFilter) { 194 this.dateFilter = dateFilter; 195 } 196 197 200 public boolean isHeaderOnly() { 201 return headerOnly; 202 } 203 204 207 public void setHeaderOnly(boolean headerOnly) { 208 this.headerOnly = headerOnly; 209 } 210 211 214 public boolean isNoTags() { 215 return noTags; 216 } 217 218 221 public void setNoTags(boolean noTags) { 222 this.noTags = noTags; 223 } 224 225 228 public String getRevisionFilter() { 229 return revisionFilter; 230 } 231 232 236 public void setRevisionFilter(String revisionFilter) { 237 this.revisionFilter = revisionFilter; 238 } 239 240 243 public String getStateFilter() { 244 return stateFilter; 245 } 246 247 250 public void setStateFilter(String stateFilter) { 251 this.stateFilter = stateFilter; 252 } 253 254 257 public String getUserFilter() { 258 return userFilter; 259 } 260 261 264 public void setUserFilter(String userFilter) { 265 this.userFilter = userFilter; 266 } 267 268 271 public boolean isHeaderAndDescOnly() { 272 return headerAndDescOnly; 273 } 274 275 278 public void setHeaderAndDescOnly(boolean headerAndDescOnly) { 279 this.headerAndDescOnly = headerAndDescOnly; 280 } 281 282 287 public String getCVSCommand() { 288 StringBuffer toReturn = new StringBuffer ("log "); toReturn.append(getCVSArguments()); 290 File[] files = getFiles(); 291 if (files != null) { 292 for (int index = 0; index < files.length; index++) { 293 toReturn.append(files[index].getName()); 294 toReturn.append(' '); 295 } 296 } 297 return toReturn.toString(); 298 } 299 300 304 public boolean setCVSCommand(char opt, String optArg) { 305 if (opt == 'R') { 306 setRecursive(true); 307 } 308 else if (opt == 'l') { 309 setRecursive(false); 310 } 311 else if (opt == 'b') { 312 setDefaultBranch(true); 313 } 314 else if (opt == 'h') { 315 setHeaderOnly(true); 316 } 317 else if (opt == 't') { 318 setHeaderAndDescOnly(true); 319 } 320 else if (opt == 'N') { 321 setNoTags(true); 322 } 323 else if (opt == 'd') { 324 setDateFilter(optArg); 325 } 326 else if (opt == 'r') { 327 setRevisionFilter(optArg == null ? "" : optArg); } 330 else if (opt == 's') { 331 setStateFilter(optArg); 332 } 333 else if (opt == 'w') { 334 setUserFilter(optArg == null ? "" : optArg); } 336 else { 337 return false; 338 } 339 return true; 340 } 341 342 public void resetCVSCommand() { 343 setRecursive(true); 344 setDefaultBranch(false); 345 setHeaderOnly(false); 346 setHeaderAndDescOnly(false); 347 setNoTags(false); 348 setDateFilter(null); 349 setRevisionFilter(null); 350 setStateFilter(null); 351 setUserFilter(null); 352 } 353 354 357 public String getOptString() { 358 return "RlbhtNd:r:s:w:"; } 360 361 365 public String getCVSArguments() { 366 StringBuffer toReturn = new StringBuffer (""); if (isDefaultBranch()) { 368 toReturn.append("-b "); } 370 if (isHeaderAndDescOnly()) { 371 toReturn.append("-t "); } 373 if (isHeaderOnly()) { 374 toReturn.append("-h "); } 376 if (isNoTags()) { 377 toReturn.append("-N "); } 379 if (!isRecursive()) { 380 toReturn.append("-l "); } 382 if (userFilter != null) { 383 toReturn.append("-w"); toReturn.append(userFilter); 385 toReturn.append(' '); 386 } 387 if (revisionFilter != null) { 388 toReturn.append("-r"); toReturn.append(revisionFilter); 390 toReturn.append(' '); 391 } 392 if (stateFilter != null) { 393 toReturn.append("-s"); toReturn.append(stateFilter); 395 toReturn.append(' '); 396 } 397 if (dateFilter != null) { 398 toReturn.append("-d"); toReturn.append(dateFilter); 400 toReturn.append(' '); 401 } 402 return toReturn.toString(); 403 } 404 405 } 406 | Popular Tags |