1 19 package org.netbeans.lib.cvsclient.command.status; 20 21 import java.io.*; 22 23 import org.netbeans.lib.cvsclient.command.*; 24 import org.netbeans.lib.cvsclient.event.*; 25 import org.netbeans.lib.cvsclient.file.*; 26 27 34 public class StatusBuilder implements Builder { 35 private static final String UNKNOWN = ": nothing known about"; private static final String EXAM_DIR = ": Examining"; private static final String NOT_IN_REPOSITORY = "No revision control file"; 39 private static final String FILE = "File: "; private static final String STATUS = "Status:"; private static final String NO_FILE_FILENAME = "no file"; private static final String WORK_REV = " Working revision:"; private static final String REP_REV = " Repository revision:"; private static final String TAG = " Sticky Tag:"; private static final String DATE = " Sticky Date:"; private static final String OPTIONS = " Sticky Options:"; private static final String EXISTING_TAGS = " Existing Tags:"; private static final String EMPTY_BEFORE_TAGS = " "; private static final String NO_TAGS = " No Tags Exist"; private static final String UNKNOWN_FILE = "? "; 52 55 private StatusInformation statusInformation; 56 57 60 private EventManager eventManager; 61 62 private final StatusCommand statusCommand; 63 private String relativeDirectory; 64 private final String localPath; 65 66 private boolean beginning; 67 68 private boolean readingTags; 69 70 private final File[] fileArray; 71 72 75 public StatusBuilder(EventManager eventManager, 76 StatusCommand statusCommand) { 77 this.eventManager = eventManager; 78 this.statusCommand = statusCommand; 79 80 File[] fileArray = statusCommand.getFiles(); 81 if (fileArray != null) { 82 this.fileArray = new File[fileArray.length]; 83 System.arraycopy(fileArray, 0, this.fileArray, 0, fileArray.length); 84 } 85 else { 86 this.fileArray = null; 87 } 88 89 this.localPath = statusCommand.getLocalDirectory(); 90 91 this.beginning = true; 92 } 93 94 public void outputDone() { 95 if (statusInformation != null) { 96 eventManager.fireCVSEvent(new FileInfoEvent(this, statusInformation)); 97 statusInformation = null; 98 readingTags = false; 99 } 100 } 101 102 public void parseLine(String line, boolean isErrorMessage) { 103 if (readingTags) { 104 if (line.startsWith(NO_TAGS)) { 105 outputDone(); 106 return; 107 } 108 109 int bracket = line.indexOf("\t("); 110 if (bracket > 0) { 111 String tag = line.substring(0, bracket).trim(); 113 String rev = line.substring(bracket + 2, line.length() - 1); 114 115 if (statusInformation == null) { 116 statusInformation = new StatusInformation(); 117 } 118 statusInformation.addExistingTag(tag, rev); 119 } 120 else { 121 outputDone(); 122 return; 123 } 124 } 125 126 if (line.startsWith(UNKNOWN_FILE) && beginning) { 127 File file = new File(localPath, line.substring(UNKNOWN_FILE.length())); 128 statusInformation = new StatusInformation(); 129 statusInformation.setFile(file); 130 statusInformation.setStatusString(FileStatus.UNKNOWN.toString()); 131 outputDone(); 132 } 133 134 if (line.startsWith(UNKNOWN)) { 135 outputDone(); 136 beginning = false; 137 } 138 else if (line.indexOf(EXAM_DIR) >= 0) { 139 relativeDirectory = line.substring(line.indexOf(EXAM_DIR) + EXAM_DIR.length()).trim(); 140 beginning = false; 141 } 142 else if (line.startsWith(FILE)) { 143 outputDone(); 144 statusInformation = new StatusInformation(); 145 processFileAndStatusLine(line.substring(FILE.length())); 146 beginning = false; 147 } 148 else if (line.startsWith(WORK_REV)) { 149 processWorkRev(line.substring(WORK_REV.length())); 150 } 151 else if (line.startsWith(REP_REV)) { 152 processRepRev(line.substring(REP_REV.length())); 153 158 } 159 else if (line.startsWith(TAG)) { 160 processTag(line.substring(TAG.length())); 161 } 162 else if (line.startsWith(DATE)) { 163 processDate(line.substring(DATE.length())); 164 } 165 else if (line.startsWith(OPTIONS)) { 166 processOptions(line.substring(OPTIONS.length())); 167 if (!statusCommand.isIncludeTags()) { 168 outputDone(); 169 } 170 } 171 else if (line.startsWith(EXISTING_TAGS)) { 172 readingTags = true; 173 } 174 } 175 176 private File createFile(String fileName) { 177 File file = null; 178 179 if (relativeDirectory != null) { 180 if (relativeDirectory.trim().equals(".")) { file = new File(localPath, fileName); 182 } 183 else { 184 file = new File(localPath, relativeDirectory + '/' + fileName); 185 } 186 } 187 else if (fileArray != null) { 188 for (int i = 0; i < fileArray.length; i++) { 189 File currentFile = fileArray[i]; 190 if (currentFile == null || currentFile.isDirectory()) { 191 continue; 192 } 193 194 String currentFileName = currentFile.getName(); 195 if (fileName.equals(currentFileName)) { 196 fileArray[i] = null; 197 file = currentFile; 198 break; 199 } 200 } 201 } 202 203 if (file == null) { 204 System.err.println("JAVACVS ERROR!! wrong algorithm for assigning path to single files(1)!!"); 205 } 206 207 return file; 208 } 209 210 private void processFileAndStatusLine(String line) { 211 int statusIndex = line.lastIndexOf(STATUS); 212 String fileName = line.substring(0, statusIndex).trim(); 213 if (fileName.startsWith(NO_FILE_FILENAME)) { 214 fileName = fileName.substring(8); 215 } 216 217 statusInformation.setFile(createFile(fileName)); 218 219 String status = new String (line.substring(statusIndex + 8).trim()); 220 statusInformation.setStatusString(status); 221 } 222 223 private boolean assertNotNull() { 224 if (statusInformation == null) { 225 System.err.println("Bug: statusInformation must not be null!"); 226 return false; 227 } 228 229 return true; 230 } 231 232 private void processWorkRev(String line) { 233 if (!assertNotNull()) { 234 return; 235 } 236 statusInformation.setWorkingRevision(line.trim().intern()); 237 } 238 239 private void processRepRev(String line) { 240 if (!assertNotNull()) { 241 return; 242 } 243 line = line.trim(); 244 if (line.startsWith(NOT_IN_REPOSITORY)) { 245 statusInformation.setRepositoryRevision(line.trim().intern()); 246 return; 247 } 248 249 int firstSpace = line.indexOf('\t'); 250 if (firstSpace > 0) { 251 statusInformation.setRepositoryRevision( 252 line.substring(0, firstSpace).trim().intern()); 253 statusInformation.setRepositoryFileName( 254 new String (line.substring(firstSpace).trim())); 255 } 256 else { 257 statusInformation.setRepositoryRevision(""); statusInformation.setRepositoryFileName(""); } 260 } 261 262 private void processTag(String line) { 263 if (!assertNotNull()) { 264 return; 265 } 266 statusInformation.setStickyTag(line.trim().intern()); 267 } 268 269 private void processDate(String line) { 270 if (!assertNotNull()) { 271 return; 272 } 273 statusInformation.setStickyDate(line.trim().intern()); 274 } 275 276 private void processOptions(String line) { 277 if (!assertNotNull()) { 278 return; 279 } 280 statusInformation.setStickyOptions(line.trim().intern()); 281 } 282 283 public void parseEnhancedMessage(String key, Object value) { 284 } 285 286 } 287 | Popular Tags |