1 11 package org.eclipse.team.internal.ccvs.core.filesystem; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.filesystem.IFileInfo; 16 import org.eclipse.core.filesystem.IFileStore; 17 import org.eclipse.core.filesystem.provider.FileInfo; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.TeamException; 20 import org.eclipse.team.internal.ccvs.core.*; 21 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; 22 23 public class CVSFileTree { 24 25 private RemoteFolderTree remoteTree; 26 private HashMap remoteFolders; 28 private HashMap logMap; 29 private CVSURI baseURI; 30 31 public CVSFileTree(IFileStore treeRoot, CVSURI uri, RemoteFolderTree remoteTree, HashMap remoteFolders, HashMap logMap) { 32 this.remoteTree = remoteTree; 33 this.baseURI = uri; 34 this.remoteFolders = remoteFolders; 35 this.logMap = logMap; 36 } 37 38 public IFileStore[] getChildrenFileStores(IFileStore store) { 39 CVSURI cvsUri = CVSURI.fromUri(store.toURI()); 40 RemoteFolderTree folderTree = (RemoteFolderTree) remoteFolders.get(cvsUri.getProjectStrippedPath().toString()); 41 42 if (folderTree == null) 43 return null; 44 45 ICVSRemoteResource[] remoteResources = folderTree.getChildren(); 46 IFileStore[] fileStore = new IFileStore[remoteResources.length]; 47 for (int i = 0; i < remoteResources.length; i++) { 48 IFileInfo fileInfo; 49 try { 50 fileInfo = getFileInfo((ICVSResource) remoteResources[i], new NullProgressMonitor()); 51 fileStore[i] = new CVSFileStore(baseURI.append(fileInfo.getName()), fileInfo); 52 } catch (TeamException e) {} 53 } 54 return fileStore; 55 } 56 57 private IFileInfo getFileInfo(ICVSResource resource, IProgressMonitor monitor) throws TeamException { 58 monitor = Policy.monitorFor(monitor); 59 if (resource == null) 60 return null; 61 FileInfo info = new FileInfo(); 62 info.setExists(true); 63 info.setName(resource.getName()); 64 if (!resource.isFolder()) { 65 ICVSRemoteFile file = (ICVSRemoteFile) resource; 66 ILogEntry entry = (ILogEntry) logMap.get(file); 68 info.setLastModified(entry.getDate().getTime()); 70 } else { 71 info.setLastModified(0); 72 info.setDirectory(true); 73 } 74 return info; 75 } 76 77 public IFileInfo[] getChildrenFileInfos(IFileStore store) { 78 79 CVSURI cvsUri = CVSURI.fromUri(store.toURI()); 80 RemoteFolderTree folderTree = (RemoteFolderTree) remoteFolders.get(cvsUri.getProjectStrippedPath().toString()); 81 82 if (folderTree == null) 83 return null; 84 85 ICVSRemoteResource[] remoteResources = folderTree.getChildren(); 86 IFileInfo[] fileInfos = new IFileInfo[remoteResources.length]; 87 for (int i = 0; i < remoteResources.length; i++) { 88 IFileInfo fileInfo; 89 try { 90 fileInfo = getFileInfo((ICVSResource) remoteResources[i], new NullProgressMonitor()); 91 fileInfos[i] = fileInfo; 92 } catch (TeamException e) {} 93 } 94 return fileInfos; 95 } 96 97 public IFileInfo getFileInfo(IFileStore store) { 98 ICVSRemoteFolder folder=null; 99 String resourceName = null; 100 CVSURI cvsUri = CVSURI.fromUri(store.toURI()); 101 102 folder = cvsUri.getParentFolder(); 103 resourceName = cvsUri.getLastSegment(); 104 105 if (folder.getName().equals(ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME)) { 106 FileInfo info = new FileInfo(); 108 info.setExists(true); 109 info.setName(resourceName); 110 info.setDirectory(true); 111 return info; 112 } 113 try { 114 RemoteFolderTree remoteFolder = (RemoteFolderTree) remoteFolders.get(folder.getName()); 115 116 if (remoteFolder == null){ 117 String repoPath = folder.getRepositoryRelativePath(); 118 IPath repoPath2 = new Path(repoPath); 119 repoPath2 = repoPath2.removeFirstSegments(1); 120 remoteFolder = (RemoteFolderTree) remoteFolders.get(repoPath2.toString()); 121 } 122 123 if (remoteFolder == null) 125 remoteFolder = remoteTree; 126 127 128 ICVSRemoteResource[] children =remoteFolder.getChildren(); 129 ICVSResource resource = null; 130 for (int i = 0; i < children.length; i++) { 131 ICVSResource child = children[i]; 132 if (child.getName().equals(resourceName)) { 133 resource = child; 134 break; 135 } 136 } 137 return getFileInfo(resource, new NullProgressMonitor()); 138 } catch (CoreException e) { 139 CVSProviderPlugin.log(e); 140 return null; 141 } 142 } 143 144 145 146 } 147 | Popular Tags |