1 11 14 package org.eclipse.team.internal.ccvs.core.filesystem; 15 16 import java.util.HashMap ; 17 18 import org.eclipse.core.runtime.IPath; 19 import org.eclipse.core.runtime.Path; 20 import org.eclipse.team.internal.ccvs.core.CVSException; 21 import org.eclipse.team.internal.ccvs.core.CVSTag; 22 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFile; 23 import org.eclipse.team.internal.ccvs.core.ICVSRemoteFolder; 24 import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; 25 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 26 import org.eclipse.team.internal.ccvs.core.ICVSResource; 27 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; 28 29 class RLogTreeBuilder { 30 31 private ICVSRepositoryLocation location; 32 private RemoteFolderTree tree; 33 private CVSTag tag; 34 private HashMap folderMap; 35 private HashMap logMap; 36 private LogEntryCache cache; 37 38 public RLogTreeBuilder(ICVSRepositoryLocation location, CVSTag tag, LogEntryCache cache) { 39 this.tag = tag; 40 this.location = location; 41 this.cache = cache; 42 reset(); 43 } 44 45 public RemoteFolderTree getTree() { 46 return tree; 47 } 48 49 52 public void reset() { 53 folderMap = new HashMap (16); 54 logMap = new HashMap (16); 55 tree = new RemoteFolderTree(null, location, ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME, tag); 56 tree.setChildren(new ICVSRemoteResource[0]); 57 } 58 59 62 public void newFile(IPath remoteFilePath, ICVSRemoteFile remoteFile) { 63 try { 64 addFile(tree, tag, remoteFile, remoteFilePath); 65 } catch (CVSException e) { 66 } 67 } 68 69 private void addFile(RemoteFolderTree tree, CVSTag tag, ICVSRemoteFile file, IPath filePath) throws CVSException { 70 RemoteFolderTree parent = (RemoteFolderTree) getFolder(tree, tag, filePath.removeLastSegments(1), Path.EMPTY); 71 addChild(parent, file); 72 } 73 74 private void addChild(RemoteFolderTree tree, ICVSRemoteResource resource) { 75 logMap.put(resource, cache.getLogEntry(resource)); 77 78 ICVSRemoteResource[] children = tree.getChildren(); 79 ICVSRemoteResource[] newChildren; 80 if (children == null) { 81 newChildren = new ICVSRemoteResource[] {resource}; 82 } else { 83 newChildren = new ICVSRemoteResource[children.length + 1]; 84 System.arraycopy(children, 0, newChildren, 0, children.length); 85 newChildren[children.length] = resource; 86 } 87 tree.setChildren(newChildren); 88 } 89 90 93 private ICVSRemoteFolder getFolder(RemoteFolderTree tree, CVSTag tag, IPath remoteFolderPath, IPath parentPath) throws CVSException { 94 if (remoteFolderPath.segmentCount() == 0) 95 return tree; 96 String name = remoteFolderPath.segment(0); 97 ICVSResource child; 98 IPath childPath = parentPath.append(name); 99 if (tree.childExists(name)) { 100 child = tree.getChild(name); 101 } else { 102 child = new RemoteFolderTree(tree, tree.getRepository(), childPath.toString(), tag); 103 folderMap.put(childPath.toString(), child); 105 ((RemoteFolderTree) child).setChildren(new ICVSRemoteResource[0]); 106 addChild(tree, (ICVSRemoteResource) child); 107 } 108 return getFolder((RemoteFolderTree) child, tag, remoteFolderPath.removeFirstSegments(1), childPath); 109 } 110 111 public HashMap getFolderMap() { 112 return folderMap; 113 } 114 115 public HashMap getLogMap() { 116 return logMap; 117 } 118 } 119 | Popular Tags |