1 11 package org.eclipse.team.internal.ccvs.core.filesystem; 12 13 import java.io.InputStream ; 14 import java.net.URI ; 15 16 import org.eclipse.core.filesystem.IFileInfo; 17 import org.eclipse.core.filesystem.IFileStore; 18 import org.eclipse.core.filesystem.provider.FileInfo; 19 import org.eclipse.core.filesystem.provider.FileStore; 20 import org.eclipse.core.resources.IStorage; 21 import org.eclipse.core.runtime.*; 22 import org.eclipse.team.core.TeamException; 23 import org.eclipse.team.core.variants.IResourceVariant; 24 import org.eclipse.team.internal.ccvs.core.*; 25 26 public class CVSFileStore extends FileStore { 27 28 29 private final CVSURI uri; 30 private IFileInfo info; 31 32 public CVSFileStore(CVSURI uri, IFileInfo info) { 33 this.uri = uri; 34 this.info = info; 35 } 36 37 public boolean canReturnFullTree() { 38 return true; 39 } 40 41 public String [] childNames(int options, IProgressMonitor monitor) throws CoreException { 42 monitor = Policy.monitorFor(monitor); 43 IFileInfo[] infos = childInfos(options, monitor); 44 String [] names = new String [infos.length]; 45 for (int i = 0; i < infos.length; i++) { 46 names[i] = infos[i].getName(); 47 } 48 return names; 49 } 50 51 public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException { 52 monitor = Policy.monitorFor(monitor); 53 if (info != null && !info.isDirectory()) { 54 return new IFileInfo[0]; 55 } 56 ICVSRemoteFolder folder = uri.toFolder(); 57 ICVSResource[] children = folder.fetchChildren(monitor); 58 59 IFileInfo[] childInfos = new IFileInfo[children.length]; 60 for (int i = 0; i < children.length; i++) { 61 ICVSResource child = children[i]; 62 IFileInfo info = getFileInfo(child, monitor); 63 childInfos[i] = info; 64 } 65 return childInfos; 66 } 67 68 public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException { 69 monitor = Policy.monitorFor(monitor); 70 IFileInfo[] infos = childInfos(options, monitor); 71 IFileStore[] children = new IFileStore[infos.length]; 72 for (int i = 0; i < infos.length; i++) { 73 children[i] = getChild(infos[i]); 74 } 75 return children; 76 } 77 78 private IFileStore getChild(IFileInfo info) { 79 return new CVSFileStore(uri.append(info.getName()), info); 80 } 81 82 public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException { 83 monitor = Policy.monitorFor(monitor); 84 ICVSRemoteFolder folder = uri.getParentFolder(); 85 86 if (folder == null) { 87 FileInfo info = new FileInfo(); 89 info.setExists(true); 90 info.setName(uri.getRepositoryName()); 91 info.setDirectory(true); 92 } 93 ICVSResource[] children = folder.fetchChildren(monitor); 94 ICVSResource resource = null; 95 for (int i = 0; i < children.length; i++) { 96 ICVSResource child = children[i]; 97 if (child.getName().equals(getName())) { 98 resource = child; 99 break; 100 } 101 } 102 return getFileInfo(resource, monitor); 103 } 104 105 private IFileInfo getFileInfo(ICVSResource resource, IProgressMonitor monitor) throws TeamException { 106 monitor = Policy.monitorFor(monitor); 107 if (resource == null) 108 return null; 109 FileInfo info = new FileInfo(); 110 info.setExists(true); 111 info.setName(resource.getName()); 112 if (!resource.isFolder()) { 113 ICVSRemoteFile file = (ICVSRemoteFile) resource; 114 ILogEntry entry = file.getLogEntry(monitor); 115 info.setLastModified(entry.getDate().getTime()); 116 } else { 117 info.setLastModified(0); 118 info.setDirectory(true); 119 } 120 return info; 121 } 122 123 public IFileStore getChild(String name) { 124 if (info != null && !info.isDirectory()) { 125 return null; 126 } 127 return new CVSFileStore(uri.append(name), null); 128 } 129 130 public IFileStore getChild(IPath path) { 131 return new CVSFileStore(uri.append(path), null); 132 } 133 134 135 public String getName() { 136 return uri.getLastSegment(); 137 } 138 139 public IFileStore getParent() { 140 if (uri.isRepositoryRoot()) { 141 return null; 142 } 143 return new CVSFileStore(uri.removeLastSegment(), null); 144 } 145 146 public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException { 147 monitor = Policy.monitorFor(monitor); 148 ICVSRemoteFile file = uri.toFile(); 149 IStorage storage = ((IResourceVariant) file).getStorage(monitor); 150 return storage.getContents(); 151 } 152 153 public URI toURI() { 154 return uri.toURI(); 155 } 156 157 public CVSURI getCVSURI() { 158 return uri; 159 } 160 161 } 162 | Popular Tags |