1 19 package org.netbeans.lib.cvsclient.command.update; 20 21 import java.io.*; 22 23 import org.netbeans.lib.cvsclient.command.*; 24 import org.netbeans.lib.cvsclient.event.*; 25 26 32 public class UpdateBuilder 33 implements Builder { 34 35 38 public static final String UNKNOWN = ": nothing known about"; public static final String EXAM_DIR = ": Updating"; public static final String TO_ADD = ": use `cvs add' to create an entry for"; public static final String STATES = "U P A R M C ? "; public static final String WARNING = ": warning: "; public static final String SERVER = "server: "; public static final String PERTINENT = "is not (any longer) pertinent"; public static final String REMOVAL = "for removal"; public static final String SERVER_SCHEDULING = "server: scheduling"; public static final String CONFLICTS = "rcsmerge: warning: conflicts during merge"; public static final String NOT_IN_REPOSITORY = "is no longer in the repository"; private static final String MERGE_SAME = " already contains the differences between"; 51 private static final String MERGED = "Merging differences between"; 53 56 private DefaultFileInfoContainer fileInfoContainer; 57 58 61 private EventManager eventManager; 62 63 66 private final String localPath; 67 68 private String diagnostics; 69 70 73 private String fileMergedOrConflict; 74 75 76 public UpdateBuilder(EventManager eventManager, String localPath) { 77 this.eventManager = eventManager; 78 this.localPath = localPath; 79 } 80 81 public void outputDone() { 82 fileMergedOrConflict = null; 83 if (fileInfoContainer != null) { 84 if (fileInfoContainer.getFile() == null) { 85 System.err.println("#65387 CVS: firing invalid event while processing: " + diagnostics); 86 } 87 eventManager.fireCVSEvent(new FileInfoEvent(this, fileInfoContainer)); 88 fileInfoContainer = null; 89 } 90 } 91 92 public void parseLine(String line, boolean isErrorMessage) { 93 diagnostics = line; 94 if (line.indexOf(UNKNOWN) >= 0) { 95 processUnknownFile(line, line.indexOf(UNKNOWN) + UNKNOWN.length()); 96 } 97 else if (line.indexOf(TO_ADD) >= 0) { 98 processUnknownFile(line, line.indexOf(TO_ADD) + TO_ADD.length()); 99 } 100 else if (line.indexOf(EXAM_DIR) >= 0) { return; 102 } 103 else if (line.startsWith(CONFLICTS)) { 104 if (fileInfoContainer != null) { 105 fileInfoContainer.setType("C"); } 108 fileMergedOrConflict = "C"; 109 } 110 else if (line.indexOf(WARNING) >= 0) { 111 if (line.indexOf(PERTINENT) > 0) { 112 String filename = line.substring(line.indexOf(WARNING) + WARNING.length(), 113 line.indexOf(PERTINENT)).trim(); 114 processNotPertinent(filename); 115 } 116 } 117 else if (line.indexOf(SERVER_SCHEDULING) >= 0) { 118 if (line.indexOf(REMOVAL) > 0) { 119 String filename = line.substring(line.indexOf(SERVER_SCHEDULING) + SERVER_SCHEDULING.length(), 120 line.indexOf(REMOVAL)).trim(); 121 processNotPertinent(filename); 122 } 123 } 124 else if (line.indexOf(MERGE_SAME) >= 0) { ensureExistingFileInfoContainer(); 126 fileInfoContainer.setType(DefaultFileInfoContainer.MERGED_FILE); 127 String path = line.substring(0, line.indexOf(MERGE_SAME)); 128 fileInfoContainer.setFile(createFile(path)); 129 outputDone(); 130 } 131 else if (line.startsWith(MERGED)) { outputDone(); 133 fileMergedOrConflict = "G"; 134 } 135 else if (line.indexOf(NOT_IN_REPOSITORY) > 0) { 136 String filename = line.substring(line.indexOf(SERVER) + SERVER.length(), 137 line.indexOf(NOT_IN_REPOSITORY)).trim(); 138 processNotPertinent(filename); 139 return; 140 } 141 else { 142 if (line.length() > 2) { 144 String firstChar = line.substring(0, 2); 145 if (STATES.indexOf(firstChar) >= 0) { 146 processFile(line); 147 return; 148 } 149 } 150 } 151 } 152 153 private File createFile(String fileName) { 154 return new File(localPath, fileName); 155 } 156 157 private void ensureExistingFileInfoContainer() { 158 if (fileInfoContainer != null) { 159 return; 160 } 161 fileInfoContainer = new DefaultFileInfoContainer(); 162 } 163 164 private void processUnknownFile(String line, int index) { 165 outputDone(); 166 fileInfoContainer = new DefaultFileInfoContainer(); 167 fileInfoContainer.setType("?"); String fileName = (line.substring(index)).trim(); 169 fileInfoContainer.setFile(createFile(fileName)); 170 } 171 172 private void processFile(String line) { 173 String fileName = line.substring(2).trim(); 174 175 if (fileName.startsWith("no file")) { fileName = fileName.substring(8); 177 } 178 179 if (fileName.startsWith("./")) { fileName = fileName.substring(2); 181 } 182 183 File file = createFile(fileName); 184 if (fileInfoContainer != null) { 185 if (fileInfoContainer.getFile() == null) { 188 fileInfoContainer.setFile(file); 191 } 192 if (file.equals(fileInfoContainer.getFile())) { 193 if (fileInfoContainer.getType().equals("?")) { 195 fileInfoContainer = null; 196 } else { 197 outputDone(); 198 return; 199 } 200 } 201 } 202 203 if (fileMergedOrConflict != null && line.charAt(0) == 'M') { 204 line = fileMergedOrConflict; } 206 207 outputDone(); 208 ensureExistingFileInfoContainer(); 209 210 fileInfoContainer.setType(line.substring(0, 1)); 211 fileInfoContainer.setFile(file); 212 } 213 214 private void processLog(String line) { 215 ensureExistingFileInfoContainer(); 216 } 217 218 private void processNotPertinent(String fileName) { 219 outputDone(); 220 File fileToDelete = createFile(fileName); 221 222 ensureExistingFileInfoContainer(); 223 224 fileInfoContainer.setType(DefaultFileInfoContainer.PERTINENT_STATE); 226 fileInfoContainer.setFile(fileToDelete); 227 } 228 229 230 public void parseEnhancedMessage(String key, Object value) { 231 if (key.equals(EnhancedMessageEvent.MERGED_PATH)) { 232 ensureExistingFileInfoContainer(); 233 String path = value.toString(); 234 File newFile = new File(path); 235 if (newFile.equals(fileInfoContainer.getFile()) == false) { 237 fileInfoContainer.setFile(newFile); 238 fileInfoContainer.setType(DefaultFileInfoContainer.MERGED_FILE); 239 if (fileMergedOrConflict != null) { 240 fileInfoContainer.setType(fileMergedOrConflict); 241 } 242 } 243 outputDone(); 244 } 245 } 246 } 247 248 | Popular Tags |