1 19 20 package org.netbeans.lib.cvsclient.command.annotate; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.netbeans.lib.cvsclient.*; 26 import org.netbeans.lib.cvsclient.command.*; 27 import org.netbeans.lib.cvsclient.connection.*; 28 import org.netbeans.lib.cvsclient.event.*; 29 import org.netbeans.lib.cvsclient.request.*; 30 31 35 public class AnnotateCommand extends BasicCommand { 36 39 protected EventManager eventManager; 40 41 45 private boolean useHeadIfNotFound; 46 47 50 private String annotateByDate; 51 52 55 private String annotateByRevision; 56 57 60 public AnnotateCommand() { 61 } 62 63 67 public Builder createBuilder(EventManager eventMan) { 68 return new AnnotateBuilder(eventMan, this); 69 } 70 71 77 public void execute(ClientServices client, EventManager em) 78 throws CommandException, AuthenticationException { 79 eventManager = em; 80 81 client.ensureConnection(); 82 83 super.execute(client, em); 84 85 excludeBinaryFiles(requests); 86 87 try { 88 if (useHeadIfNotFound) { 89 requests.add(1, new ArgumentRequest("-f")); } 91 if (annotateByDate != null && annotateByDate.length() > 0) { 92 requests.add(1, new ArgumentRequest("-D")); requests.add(2, new ArgumentRequest(getAnnotateByDate())); 94 } 95 if (annotateByRevision != null && annotateByRevision.length() > 0) { 96 requests.add(1, new ArgumentRequest("-r")); requests.add(2, new ArgumentRequest(getAnnotateByRevision())); 98 } 99 addRequestForWorkingDirectory(client); 100 addArgumentRequests(); 101 addRequest(CommandRequest.ANNOTATE); 102 client.processRequests(requests); 103 } 104 catch (CommandException ex) { 105 throw ex; 106 } 107 catch (Exception ex) { 108 throw new CommandException(ex, ex.getLocalizedMessage()); 109 } 110 finally { 111 requests.clear(); 112 } 113 } 114 115 private void excludeBinaryFiles(java.util.List requests) { 116 Iterator it = requests.iterator(); 117 while (it.hasNext()) { 118 Object obj = it.next(); 119 if (obj instanceof EntryRequest) { 120 EntryRequest req = (EntryRequest)obj; 121 if (req.getEntry().isBinary()) { 122 it.remove(); 123 if (it.hasNext()) { 124 it.next(); 126 it.remove(); 127 } 128 } 129 } 130 } 131 } 132 133 135 public void commandTerminated(TerminationEvent e) { 136 if (builder != null) { 137 builder.outputDone(); 138 } 139 } 140 141 145 public boolean isUseHeadIfNotFound() { 146 return useHeadIfNotFound; 147 } 148 149 153 public void setUseHeadIfNotFound(boolean useHeadIfNotFound) { 154 this.useHeadIfNotFound = useHeadIfNotFound; 155 } 156 157 161 public String getAnnotateByDate() { 162 return annotateByDate; 163 } 164 165 169 public void setAnnotateByDate(String annotateByDate) { 170 this.annotateByDate = annotateByDate; 171 } 172 173 177 public String getAnnotateByRevision() { 178 return annotateByRevision; 179 } 180 181 185 public void setAnnotateByRevision(String annotateByRevision) { 186 this.annotateByRevision = annotateByRevision; 187 } 188 189 194 public String getCVSCommand() { 195 StringBuffer toReturn = new StringBuffer ("annotate "); toReturn.append(getCVSArguments()); 197 File[] files = getFiles(); 198 if (files != null) { 199 for (int index = 0; index < files.length; index++) { 200 toReturn.append(files[index].getName() + " "); } 202 } 203 return toReturn.toString(); 204 } 205 206 210 public boolean setCVSCommand(char opt, String optArg) { 211 if (opt == 'R') { 212 setRecursive(true); 213 } 214 else if (opt == 'l') { 215 setRecursive(false); 216 } 217 else if (opt == 'r') { 218 setAnnotateByRevision(optArg); 219 } 220 else if (opt == 'D') { 221 setAnnotateByDate(optArg); 222 } 223 else if (opt == 'f') { 224 setUseHeadIfNotFound(true); 225 } 226 else { 227 return false; 228 } 229 return true; 230 } 231 232 235 public String getOptString() { 236 return "Rlr:D:f"; } 238 239 243 public void resetCVSCommand() { 244 setRecursive(true); 245 setAnnotateByDate(null); 246 setAnnotateByRevision(null); 247 setUseHeadIfNotFound(false); 248 } 249 250 254 public String getCVSArguments() { 255 StringBuffer toReturn = new StringBuffer (""); if (!isRecursive()) { 257 toReturn.append("-l "); } 259 if (getAnnotateByRevision() != null) { 260 toReturn.append("-r "); toReturn.append(getAnnotateByRevision()); 262 toReturn.append(" "); } 264 if (getAnnotateByDate() != null) { 265 toReturn.append("-D "); toReturn.append(getAnnotateByDate()); 267 toReturn.append(" "); } 269 if (isUseHeadIfNotFound()) { 270 toReturn.append("-f "); } 272 return toReturn.toString(); 273 } 274 275 } 276 | Popular Tags |