1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.internal.ccvs.core.CVSException; 20 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin; 21 import org.eclipse.team.internal.ccvs.core.CVSTag; 22 import org.eclipse.team.internal.ccvs.core.ICVSFile; 23 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 24 import org.eclipse.team.internal.ccvs.core.ICVSResource; 25 import org.eclipse.team.internal.ccvs.core.Policy; 26 import org.eclipse.team.internal.ccvs.core.client.Command; 27 import org.eclipse.team.internal.ccvs.core.client.Session; 28 import org.eclipse.team.internal.ccvs.core.client.Update; 29 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 30 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation; 31 32 35 public class FileContentCachingService { 36 37 String [] fileDiffs; 38 private CVSRepositoryLocation repository; 39 private ICVSFolder remoteRoot; 40 41 public static RemoteFolderTree buildRemoteTree(CVSRepositoryLocation repository, ICVSFolder root, CVSTag tag, IProgressMonitor monitor) throws CVSException { 42 monitor.beginTask(null, 100); 43 try { 44 RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, root, tag); 45 RemoteFolderTree tree = builder.buildTree(new ICVSResource[] { root }, Policy.subMonitorFor(monitor, 50)); 46 FileContentCachingService service = new FileContentCachingService(repository, tree, builder.getFileDiffs()); 47 service.cacheFileContents(Policy.subMonitorFor(monitor, 50)); 48 return tree; 49 } finally { 50 monitor.done(); 51 } 52 } 53 54 61 public static void fetchFileContents(RemoteFolderTree root, String [] filePaths, IProgressMonitor monitor) throws CVSException { 62 FileContentCachingService service = new FileContentCachingService((CVSRepositoryLocation)root.getRepository(), root, filePaths); 63 service.cacheFileContents(monitor); 64 } 65 66 public static RemoteFile buildRemoteTree(CVSRepositoryLocation repository, ICVSFile file, CVSTag tag, IProgressMonitor monitor) throws CVSException { 67 monitor.beginTask(null, 100); 68 try { 69 RemoteFolderTreeBuilder builder = new RemoteFolderTreeBuilder(repository, file.getParent(), tag); 70 RemoteFile remote = builder.buildTree(file, monitor); 71 if (builder.getFileDiffs().length > 0) { 72 remote.getStorage(Policy.subMonitorFor(monitor, 50)); 74 } 75 return remote; 76 } catch (TeamException e) { 77 throw CVSException.wrapException(e); 78 } finally { 79 monitor.done(); 80 } 81 } 82 83 public FileContentCachingService(CVSRepositoryLocation repository, RemoteFolderTree tree, String [] fileDiffs) { 84 this.repository = repository; 85 this.remoteRoot = tree; 86 this.fileDiffs = fileDiffs; 87 } 88 89 private void cacheFileContents(IProgressMonitor monitor) throws CVSException { 90 String [] files = getUncachedFiles(); 91 if (files.length == 0) return; 92 monitor.beginTask(null, 10 + files.length * 100); 95 Policy.checkCanceled(monitor); 96 Session session = new Session(repository, remoteRoot, false); 97 session.open(Policy.subMonitorFor(monitor, 10), false ); 98 try { 99 Policy.checkCanceled(monitor); 100 IStatus status = Command.UPDATE.execute(session, 101 Command.NO_GLOBAL_OPTIONS, 102 new LocalOption[] { Update.IGNORE_LOCAL_CHANGES }, 103 files, 104 null, 105 Policy.subMonitorFor(monitor, files.length * 100)); 106 if (!status.isOK()) { 107 CVSProviderPlugin.log (new CVSException(status)); 109 } 110 } finally { 111 session.close(); 112 monitor.done(); 113 } 114 } 115 116 119 private String [] getUncachedFiles() { 120 if (fileDiffs.length == 0) return fileDiffs; 121 List existing = new ArrayList (); 122 for (int i = 0; i < fileDiffs.length; i++) { 123 String filePath = fileDiffs[i]; 124 try { 125 ICVSFile file = remoteRoot.getFile(filePath); 126 if (file instanceof RemoteFile) { 127 if (!((RemoteFile)file).isContentsCached()) { 128 existing.add(filePath); 129 } 130 } 131 } catch (CVSException e) { 132 } 134 } 135 return (String []) existing.toArray(new String [existing.size()]); 136 } 137 } 138 | Popular Tags |