1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import java.util.ArrayList ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.*; 18 import org.eclipse.osgi.util.NLS; 19 import org.eclipse.team.internal.ccvs.core.*; 20 import org.eclipse.team.internal.ccvs.core.client.*; 21 import org.eclipse.team.internal.ccvs.core.client.Command.*; 22 import org.eclipse.team.internal.ccvs.core.client.listeners.*; 23 import org.eclipse.team.internal.ccvs.core.connection.CVSServerException; 24 import org.eclipse.team.internal.ccvs.core.util.Util; 25 26 31 public class RemoteFolderMemberFetcher implements IUpdateMessageListener, IStatusListener { 32 33 private final RemoteFolder parentFolder; 34 private CVSTag tag; 35 36 List folders = new ArrayList (); List files = new ArrayList (); boolean exists = true; 39 List exceptions = new ArrayList (); 41 protected RemoteFolderMemberFetcher(RemoteFolder parentFolder, CVSTag tag) { 42 this.tag = tag; 43 this.parentFolder = parentFolder; 44 } 45 46 54 public void fetchMembers(IProgressMonitor monitor) throws CVSException { 55 fetchMembers(monitor, tag); 56 } 57 public void fetchMembers(IProgressMonitor monitor, CVSTag tag) throws CVSException { 58 final IProgressMonitor progress = Policy.monitorFor(monitor); 59 progress.beginTask(CVSMessages.RemoteFolder_getMembers, 100); 60 try { 61 updateParentFolderChildren(); 63 IStatus status = performUpdate(Policy.subMonitorFor(progress, 50), tag); 65 updateParentFolderChildren(); 67 Policy.checkCanceled(monitor); 68 69 performErrorCheck(status, CVSMessages.RemoteFolder_errorFetchingMembers); 71 72 ICVSFile[] remoteFiles = getFiles(); 74 if (remoteFiles.length > 0) { 75 updateFileRevisions(remoteFiles, Policy.subMonitorFor(progress, 50)); 76 } else { 77 progress.worked(50); 78 } 79 } catch (CVSServerException e) { 80 if ( ! e.isNoTagException() && e.containsErrors()) 81 throw e; 82 if (tag == null) 83 throw e; 84 Policy.checkCanceled(progress); 88 fetchMembers(Policy.subMonitorFor(progress, 50), null); 89 } finally { 90 progress.done(); 91 } 92 } 93 94 protected IStatus performUpdate(IProgressMonitor progress, CVSTag tag) throws CVSException { 95 progress.beginTask(null, 100); 96 Session session = new Session(parentFolder.getRepository(), parentFolder, false ); 97 session.open(Policy.subMonitorFor(progress, 10), false ); 98 try { 99 final List localOptions = new ArrayList (); 101 localOptions.add(Update.RETRIEVE_ABSENT_DIRECTORIES); 102 if (tag != null) localOptions.add(Update.makeTagOption(tag)); 103 104 return Command.UPDATE.execute( 105 session, 106 new GlobalOption[] { Command.DO_NOT_CHANGE }, 107 (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), 108 new ICVSResource[] { parentFolder }, 109 new UpdateListener(this), 110 Policy.subMonitorFor(progress, 90)); 111 } finally { 112 session.close(); 113 } 114 } 115 116 protected void updateFileRevisions(final ICVSFile[] files, IProgressMonitor monitor) throws CVSException { 117 118 monitor = Policy.monitorFor(monitor); 120 monitor.beginTask(null, 100); 121 QuietOption quietness = CVSProviderPlugin.getPlugin().getQuietness(); 122 try { 123 CVSProviderPlugin.getPlugin().setQuietness(Command.VERBOSE); 124 Session session = new Session(parentFolder.getRepository(), parentFolder, false ); 125 session.open(Policy.subMonitorFor(monitor, 10), false ); 126 try { 127 IStatus status = Command.STATUS.execute( 128 session, 129 Command.NO_GLOBAL_OPTIONS, 130 Command.NO_LOCAL_OPTIONS, 131 files, 132 new StatusListener(this), 133 Policy.subMonitorFor(monitor, 90)); 134 performErrorCheck(status, CVSMessages.RemoteFolder_errorFetchingRevisions); 135 } finally { 137 session.close(); 138 } 139 } finally { 140 CVSProviderPlugin.getPlugin().setQuietness(quietness); 141 } 142 } 143 144 private void performErrorCheck(IStatus status, String errorTitle) throws CVSException { 145 if (status.getCode() == CVSStatus.SERVER_ERROR) { 146 if (folders.size() + files.size() == 0) { 148 throw new CVSServerException(status); 149 } else { 150 CVSProviderPlugin.log(new CVSServerException(status)); 151 } 152 } 153 if (!exists) { 154 IStatus notExistStatus = new CVSStatus(IStatus.ERROR, CVSStatus.DOES_NOT_EXIST, NLS.bind(CVSMessages.RemoteFolder_doesNotExist, new String [] { this.parentFolder.getRepositoryRelativePath() }), parentFolder); 155 throw new CVSException(notExistStatus); 156 } 157 158 if ( ! exceptions.isEmpty()) { 160 if (exceptions.size() == 1) { 161 throw (CVSException)exceptions.get(0); 162 } else { 163 MultiStatus multi = new MultiStatus(CVSProviderPlugin.ID, 0, errorTitle, null); 164 for (int i = 0; i < exceptions.size(); i++) { 165 multi.merge(((CVSException)exceptions.get(i)).getStatus()); 166 } 167 throw new CVSException(multi); 168 } 169 } 170 } 171 172 175 public void directoryInformation(ICVSFolder commandRoot, String stringPath, boolean newDirectory) { 176 try { 177 IPath path = this.parentFolder.getRelativePathFromRootRelativePath(commandRoot, new Path(null, stringPath)); 178 if (path.segmentCount() == 1) { 179 String pathName = path.lastSegment(); 180 if (!pathName.equals(".")) { recordFolder(path.lastSegment()); 182 } 183 } 184 } catch (CVSException e) { 185 exceptions.add(e); 186 } 187 } 188 189 192 public void directoryDoesNotExist(ICVSFolder parent, String stringPath) { 193 try { 194 IPath path = this.parentFolder.getRelativePathFromRootRelativePath(parent, new Path(null, stringPath)); 195 if (path.isEmpty()) { 196 parentDoesNotExist(); 197 } 198 } catch (CVSException e) { 199 exceptions.add(e); 200 } 201 } 202 203 206 public void fileInformation(int type, ICVSFolder parent, String filename) { 207 try { 208 IPath filePath = new Path(null, filename); 209 filePath = this.parentFolder.getRelativePathFromRootRelativePath(parent, filePath); 210 if( filePath.segmentCount() == 1 ) { 211 String properFilename = filePath.lastSegment(); 212 recordFile(properFilename); 213 } 214 } catch (CVSException e) { 215 exceptions.add(e); 216 } 217 } 218 219 222 public void fileDoesNotExist(ICVSFolder parent, String filename) { 223 } 224 225 228 public void fileStatus(ICVSFolder commandRoot, String path, String remoteRevision) { 229 if (remoteRevision == IStatusListener.FOLDER_REVISION) 230 return; 232 try { 233 ((RemoteFile)parentFolder.getChild(Util.getLastSegment(path))).setRevision(remoteRevision); 234 } catch (CVSException e) { 235 exceptions.add(e); 236 } 237 } 238 239 245 protected RemoteFolder recordFolder(String name) { 246 RemoteFolder folder = new RemoteFolder( 247 parentFolder, 248 parentFolder.getRepository(), 249 Util.appendPath(parentFolder.getRepositoryRelativePath(), name), 250 tag); 251 folders.add(folder); 252 return folder; 253 } 254 255 263 protected RemoteFile recordFile(String name) { 264 RemoteFile file = new RemoteFile( 265 parentFolder, 266 Update.STATE_NONE, 267 name, 268 null, 269 null, 270 tag); 271 files.add(file); 272 return file; 273 } 274 275 280 protected void parentDoesNotExist() { 281 exists = false; 282 } 283 284 288 protected void updateParentFolderChildren() { 289 parentFolder.setChildren(getFetchedChildren()); 290 } 291 292 296 protected ICVSFile[] getFiles() { 297 return (ICVSFile[]) files.toArray(new ICVSFile[files.size()]); 298 } 299 300 304 public ICVSRemoteResource[] getFetchedChildren() { 305 ICVSRemoteResource[] resources = new ICVSRemoteResource[folders.size() + files.size()]; 306 int count = 0; 307 for (Iterator iter = folders.iterator(); iter.hasNext();) { 308 ICVSRemoteResource resource = (ICVSRemoteResource) iter.next(); 309 resources[count++] = resource; 310 } 311 for (Iterator iter = files.iterator(); iter.hasNext();) { 312 ICVSRemoteResource resource = (ICVSRemoteResource) iter.next(); 313 resources[count++] = resource; 314 } 315 return resources; 316 } 317 318 } 319 | Popular Tags |