1 19 package org.netbeans.modules.subversion.client.parser; 20 21 import java.io.File ; 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Date ; 25 import java.util.List ; 26 import java.util.Map ; 27 import org.tigris.subversion.svnclientadapter.ISVNInfo; 28 import org.tigris.subversion.svnclientadapter.ISVNStatus; 29 import org.tigris.subversion.svnclientadapter.SVNNodeKind; 30 import org.tigris.subversion.svnclientadapter.SVNScheduleKind; 31 import org.tigris.subversion.svnclientadapter.SVNStatusKind; 32 import org.xml.sax.SAXException ; 33 34 38 public class SvnWcParser { 39 40 41 public SvnWcParser() { 42 } 43 44 private WorkingCopyDetails getWCDetails(File file) throws IOException , SAXException { 45 Map <String , String > attributes = EntriesCache.getInstance().getFileAttributes(file); 46 return WorkingCopyDetails.createWorkingCopy(file, attributes); 47 } 48 49 52 public ISVNStatus[] getStatus(File path, boolean descend, boolean getAll) throws LocalSubversionException { 53 List <ISVNStatus> l = getStatus(path, descend); 54 return l.toArray(new ISVNStatus[l.size()]); 65 } 66 67 private List <ISVNStatus> getStatus(File path, boolean descend) throws LocalSubversionException { 68 List <ISVNStatus> ret = new ArrayList <ISVNStatus>(20); 69 70 File [] children = path.listFiles(); 71 if(children != null && children.length > 0) { 72 for (int i = 0; i < children.length; i++) { 73 ret.add(getSingleStatus(children[i])); 74 if(descend && children[i].isDirectory()) { 75 ret.addAll(getStatus(children[i], descend)); 76 } 77 } 78 } 79 ret.add(getSingleStatus(path)); 80 return ret; 81 } 82 83 public ISVNStatus getSingleStatus(File file) throws LocalSubversionException { 84 String finalTextStatus = SVNStatusKind.NORMAL.toString(); 85 String finalPropStatus = SVNStatusKind.NONE.toString(); 86 87 try { 88 WorkingCopyDetails wcDetails = getWCDetails(file); 89 if (wcDetails.isHandled()) { 90 91 if (wcDetails.propertiesExist()) { 92 finalPropStatus = SVNStatusKind.NORMAL.toString(); 93 if (wcDetails.propertiesModified()) { 95 finalPropStatus = SVNStatusKind.MODIFIED.toString(); 96 } 97 } 98 if (wcDetails.isFile()) { 99 if (wcDetails.textModified()) { 102 finalTextStatus = SVNStatusKind.MODIFIED.toString(); 103 } 104 } 105 106 String value = wcDetails.getValue("schedule"); if (value != null) { 108 if (value.equals("add")) { finalTextStatus = SVNStatusKind.ADDED.toString(); 110 finalPropStatus = SVNStatusKind.NONE.toString(); 111 } else if (value.equals("delete")) { finalTextStatus = SVNStatusKind.DELETED.toString(); 113 finalPropStatus = SVNStatusKind.NONE.toString(); 114 } 115 } 118 value = wcDetails.getValue("deleted"); if (value != null) { 120 if (value.equals("true")) { finalTextStatus = SVNStatusKind.UNVERSIONED.toString(); 122 finalPropStatus = SVNStatusKind.NONE.toString(); 123 } 124 } 125 126 String fileUrl = wcDetails.getValue("url"); long revision = wcDetails.getLongValue("revision"); String nodeKind = wcDetails.getValue("kind", "normal"); String lastCommitAuthor = wcDetails.getValue("last-author"); long lastChangedRevision = wcDetails.getLongValue("committed-rev"); Date lastCommittedDate = wcDetails.getDateValue("committed-date"); 133 boolean isCopied = wcDetails.getBooleanValue("copied"); String urlCopiedFrom = null; 135 if (isCopied) { 136 urlCopiedFrom = wcDetails.getValue("copyfrom-url"); } 138 139 File conflictNew = null; 140 File conflictOld = null; 141 File conflictWorking = null; 142 value = wcDetails.getValue("conflict-wrk"); if (value != null && ((String )value).length() > 0) { 144 conflictWorking = new File (file.getParentFile(), value); 145 } 146 147 value = wcDetails.getValue("conflict-new"); if (value != null && ((String )value).length() > 0) { 149 conflictNew = new File (file.getParentFile(), value); 150 } 151 value = wcDetails.getValue("conflict-old"); if (value != null && ((String )value).length() > 0) { 153 conflictOld = new File (file.getParentFile(), value); 154 } 155 if ((conflictNew != null) || (conflictOld != null)) { 156 finalTextStatus = SVNStatusKind.CONFLICTED.toString(); 157 } 158 159 Date lockCreationDate = wcDetails.getDateValue("lock-creation-date"); String lockComment = null; 161 String lockOwner = null; 162 if (lockCreationDate != null) { 163 lockComment = wcDetails.getValue("lock-comment"); lockOwner = wcDetails.getValue("lock-owner"); } 166 167 return new ParserSvnStatus( 168 file, 169 fileUrl, 170 revision, 171 nodeKind, 172 finalTextStatus, 173 finalPropStatus, 174 lastCommitAuthor, 175 lastChangedRevision, 176 lastCommittedDate, 177 isCopied, 178 urlCopiedFrom, 179 conflictNew, 180 conflictOld, 181 conflictWorking, 182 lockCreationDate, 183 lockComment, 184 lockOwner); 185 } else { 186 return new ParserSvnStatus( 188 file, 189 wcDetails.getValue("url"), 0, 191 "unknown", SVNStatusKind.UNVERSIONED.toString(), 193 SVNStatusKind.UNVERSIONED.toString(), 194 null, 195 0, 196 null, 197 false, 198 null, 199 null, 200 null, 201 null, 202 null, 203 null, 204 null); 205 } 206 207 } catch (IOException ex) { 208 throw new LocalSubversionException(ex); 209 } catch (SAXException ex) { 210 throw new LocalSubversionException(ex); 211 } catch (IllegalArgumentException ex) { 212 throw new LocalSubversionException(ex); 213 } 214 } 215 216 public ISVNInfo getInfoFromWorkingCopy(File file) throws LocalSubversionException { 217 218 ISVNInfo returnValue = null; 219 try { 220 WorkingCopyDetails wcDetails = getWCDetails(file); if (wcDetails.isHandled()) { 222 String fileUrl = wcDetails.getValue("url"); String reposUrl = wcDetails.getValue("repos"); String reposUuid = wcDetails.getValue("uuid"); String schedule = wcDetails.getValue("schedule"); if (schedule == null) { 227 schedule = SVNScheduleKind.NORMAL.toString(); 228 } 229 230 long revision = wcDetails.getLongValue("revision"); boolean isCopied = wcDetails.getBooleanValue("copied"); String urlCopiedFrom = null; 233 long revisionCopiedFrom = 0; 234 if (isCopied) { 235 urlCopiedFrom = wcDetails.getValue("copyfrom-url"); revisionCopiedFrom = wcDetails.getLongValue("copyfrom-rev"); } 238 239 Date lastCommittedDate = wcDetails.getDateValue("committed-date"); long lastChangedRevision = wcDetails.getLongValue("committed-rev"); String lastCommitAuthor = wcDetails.getValue("last-author"); Date lastDatePropsUpdate = wcDetails.getDateValue("prop-time"); Date lastDateTextUpdate = wcDetails.getDateValue("text-time"); 245 Date lockCreationDate = wcDetails.getDateValue("lock-creation-date"); String lockComment = null; 247 String lockOwner = null; 248 if (lockCreationDate != null) { 249 lockComment = wcDetails.getValue("lock-comment"); lockOwner = wcDetails.getValue("lock-owner"); } 252 253 String nodeKind = wcDetails.getValue("kind", "normal"); returnValue = new ParserSvnInfo(file, fileUrl, reposUrl, reposUuid, 255 schedule, revision, isCopied, urlCopiedFrom, revisionCopiedFrom, 256 lastCommittedDate, lastChangedRevision, lastCommitAuthor, 257 lastDatePropsUpdate, lastDateTextUpdate, lockCreationDate, 258 lockOwner, lockComment, nodeKind, wcDetails.getPropertiesFile(), wcDetails.getBasePropertiesFile()); 259 } else { 260 String fileUrl = wcDetails.getValue("url"); String reposUrl = wcDetails.getValue("repos"); String reposUuid = wcDetails.getValue("uuid"); returnValue = new ParserSvnInfo(file, fileUrl, reposUrl, reposUuid, 264 SVNScheduleKind.NORMAL.toString(), 0, false, null, 0, null, 0, null, 265 null, null, null, null, null, SVNNodeKind.UNKNOWN.toString(), null, null); 266 } 267 } catch (IOException ex) { 268 throw new LocalSubversionException(ex); 269 } catch (SAXException ex) { 270 throw new LocalSubversionException(ex); 271 } 272 return returnValue; 273 } 274 275 } 276 277 | Popular Tags |