1 19 20 package org.netbeans.lib.cvsclient.command.add; 21 22 import java.io.*; 23 24 import org.netbeans.lib.cvsclient.command.*; 25 import org.netbeans.lib.cvsclient.event.*; 26 27 33 public class AddBuilder implements Builder { 34 private static final String UNKNOWN = ": nothing known about"; private static final String ADDED = " added to the repository"; private static final String WARNING = ": warning: "; private static final String ALREADY_ENTERED = " has already been entered"; private static final String SCHEDULING = ": scheduling file `"; private static final String USE_COMMIT = ": use 'cvs commit' "; private static final String DIRECTORY = "Directory "; private static final String READDING = ": re-adding file "; private static final String RESURRECTED = ", resurrected"; private static final String RESUR_VERSION = ", version "; 45 private static final boolean DEBUG = false; 46 47 50 private AddInformation addInformation; 51 52 55 private EventManager eventManager; 56 57 61 private String fileDirectory; 62 63 private AddCommand addCommand; 64 65 private boolean readingTags; 66 67 public AddBuilder(EventManager eventManager, AddCommand addCommand) { 68 this.eventManager = eventManager; 69 this.addCommand = addCommand; 70 } 71 72 public void outputDone() { 73 if (addInformation != null) { 74 FileInfoEvent event = new FileInfoEvent(this, addInformation); 75 eventManager.fireCVSEvent(event); 76 addInformation = null; 77 } 78 } 79 80 public void parseLine(String line, boolean isErrorMessage) { 81 if (line.endsWith(ADDED)) { 82 String directory = 83 line.substring(DIRECTORY.length(), line.indexOf(ADDED)); 84 addDirectory(directory); 85 } 86 else if (line.indexOf(SCHEDULING) >= 0) { 87 String filename = 88 line.substring(line.indexOf(SCHEDULING) + SCHEDULING.length(), line.indexOf('\'')).trim(); 89 addFile(filename); 90 } 91 else if (line.indexOf(READDING) >= 0) { 92 String filename = 93 line.substring(line.indexOf(READDING) + READDING.length(), line.indexOf('(')).trim(); 94 addFile(filename); 95 } 96 else if (line.endsWith(RESURRECTED)) { 97 String filename = 98 line.substring(0, line.length() - RESURRECTED.length()); 99 resurrectFile(filename); 100 } 101 } 103 104 private File createFile(String fileName) { 105 File locFile = addCommand.getFileEndingWith(fileName); 106 if (locFile == null) { 107 String name = fileName.replace('\\', '/'); 115 File[] files = addCommand.getFiles(); 116 int maxLevel = name.length(); 117 File bestMatch = null; 118 String [] paths = new String [files.length]; 119 for (int index = 0; index < files.length; index++) { 120 paths[index] = files[index].getAbsolutePath().replace('\\', '/'); 121 } 122 int start = name.lastIndexOf('/'); 123 String part = null; 124 if (start < 0) { 125 part = name; 126 } else { 127 part = name.substring(start + 1); 128 } 129 while (start >= 0 || part != null) { 130 boolean wasMatch = false; 131 for (int index = 0; index < paths.length; index++) { 132 if (paths[index].endsWith(part)) { 133 bestMatch = files[index]; 134 wasMatch = true; 135 } 136 } 137 start = name.lastIndexOf('/', start - 1); 138 if (start < 0 || !wasMatch) { 139 break; 140 } 141 part = name.substring(start + 1); 142 } 143 return bestMatch; 144 } 145 return locFile; 146 } 147 148 private void addDirectory(String name) { 149 addInformation = new AddInformation(); 150 addInformation.setType(AddInformation.FILE_ADDED); 151 String dirName = name.replace('\\', '/'); 152 157 addInformation.setFile(createFile(dirName)); 158 outputDone(); 159 } 160 161 private void addFile(String name) { 162 addInformation = new AddInformation(); 163 addInformation.setFile(createFile(name)); 164 addInformation.setType(AddInformation.FILE_ADDED); 165 outputDone(); 166 } 167 168 private void resurrectFile(String line) { 169 int versionIndex = line.lastIndexOf(RESUR_VERSION); 170 String version = line.substring(versionIndex + RESUR_VERSION.length()).trim(); 171 String cutLine = line.substring(0, versionIndex).trim(); 172 int fileIndex = cutLine.lastIndexOf(' '); 173 String name = cutLine.substring(fileIndex).trim(); 174 175 if (DEBUG) { 176 System.out.println("line1=" + line); System.out.println("versionIndex=" + versionIndex); System.out.println("version=" + version); System.out.println("fileindex=" + fileIndex); System.out.println("filename=" + name); } 182 183 addInformation = new AddInformation(); 184 addInformation.setType(AddInformation.FILE_RESURRECTED); 185 addInformation.setFile(createFile(name)); 186 outputDone(); 187 } 188 189 public void parseEnhancedMessage(String key, Object value) { 190 } 191 } 192 | Popular Tags |