1 11 package org.eclipse.team.internal.ccvs.core.filesystem; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.team.core.TeamException; 17 import org.eclipse.team.internal.ccvs.core.*; 18 import org.eclipse.team.internal.ccvs.core.client.*; 19 import org.eclipse.team.internal.ccvs.core.client.listeners.LogEntry; 20 import org.eclipse.team.internal.ccvs.core.client.listeners.LogListener; 21 import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; 22 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderTree; 23 24 public class RemoteLogger { 25 26 static final String DEAD_STATE = "dead"; 28 private ICVSRemoteFolder remoteFolder; 29 private LogEntryCache cache; 30 31 private RLogTreeBuilder treeBuilder; 32 33 public RemoteLogger(ICVSRemoteFolder folder) { 34 this.remoteFolder = folder; 35 } 36 37 private void getRemoteChildren(CVSTag tag, IProgressMonitor monitor) { 38 Session session = new Session(this.remoteFolder.getRepository(), this.remoteFolder, false ); 39 try { 40 this.cache = new LogEntryCache(); 42 LogListener listener = new LogListener(cache); 43 44 Command.LocalOption[] localOptions = getLocalOptions(tag, null); 45 try { 46 session.open(Policy.subMonitorFor(monitor, 10)); 47 RLog rlog = new RLog(); 48 rlog.execute(session, Command.NO_GLOBAL_OPTIONS, localOptions, new ICVSRemoteResource[] {this.remoteFolder}, listener, Policy.subMonitorFor(monitor, 90)); 49 } catch (CVSException e) { 50 } 51 } finally { 52 session.close(); 53 } 54 } 55 56 public ICVSResource[] fetchChildren(IProgressMonitor monitor) throws CVSException, TeamException { 57 return fetchTree(monitor).getChildren(); 58 } 59 60 public HashMap getFolderMap() { 61 return treeBuilder.getFolderMap(); 62 } 63 64 public RemoteFolderTree fetchTree(IProgressMonitor monitor) throws CVSException, TeamException { 65 try{ 66 monitor.beginTask(null, 100); 67 CVSTag tag = this.remoteFolder.getTag(); 68 if (tag == null) 69 tag = CVSTag.DEFAULT; 70 71 getRemoteChildren(tag, new SubProgressMonitor(monitor,70)); 72 73 final ICVSRemoteFolder project = this.remoteFolder; 74 String [] entry = this.cache.getCachedFilePaths(); 76 77 treeBuilder = new RLogTreeBuilder(project.getRepository(), tag, cache); 78 for (int i = 0; i < entry.length; i++) { 79 ILogEntry[] logEntry = this.cache.getLogEntries(entry[i]); 80 81 if (logEntry[0].getState() != null && logEntry[0].getState().equals(DEAD_STATE)) 83 continue; 84 85 ICVSRemoteFile remoteFile = logEntry[0].getRemoteFile(); 86 if (tag.getType() == CVSTag.BRANCH && remoteFile.getRevision().equals(LogListener.BRANCH_REVISION)) 89 verifyRevision(tag, logEntry[0], remoteFile); 90 91 IPath logPath = new Path(null, remoteFile.getRepositoryRelativePath()); 92 if (logPath.segmentCount() > 0) { 93 String [] pathSegments = logPath.segments(); 95 int index; 96 String projectName = project.getName(); 97 for (index = 0; index < pathSegments.length; index++) { 98 if (pathSegments[index].equals(projectName)) 99 break; 100 } 101 logPath = logPath.removeFirstSegments(index + 1); 102 } 103 treeBuilder.newFile(logPath, remoteFile); 104 } 105 106 return treeBuilder.getTree(); 107 } 108 finally{ 109 monitor.done(); 110 } 111 } 112 113 protected Command.LocalOption[] getLocalOptions(CVSTag tag1, CVSTag tag2) { 114 if (tag1 != null && tag2 != null) { 115 return new Command.LocalOption[] {RLog.NO_TAGS, RLog.ONLY_INCLUDE_CHANGES, RLog.makeTagOption(tag1, tag2)}; 116 } else if (tag1 != null) { 117 if (tag1.getType() == CVSTag.HEAD || tag1.getType() == CVSTag.VERSION) 118 return new Command.LocalOption[] {RLog.NO_TAGS, RLog.ONLY_INCLUDE_CHANGES, RLog.getCurrentTag(tag1)}; 119 120 if (tag1.getType() == CVSTag.DATE) 121 return new Command.LocalOption[] {RLog.NO_TAGS, RLog.ONLY_INCLUDE_CHANGES, RLog.REVISIONS_ON_DEFAULT_BRANCH, RLog.getCurrentTag(tag1)}; 122 return new Command.LocalOption[] {RLog.getCurrentTag(tag1)}; 124 } else { 125 return new Command.LocalOption[] {RLog.NO_TAGS, RLog.ONLY_INCLUDE_CHANGES}; 126 } 127 } 128 129 private void verifyRevision(CVSTag tag, ILogEntry entry, ICVSRemoteFile remoteFile) throws CVSException { 130 if (entry instanceof LogEntry) { 131 LogEntry logEntry = (LogEntry) entry; 132 String [] allBranchRevisions = logEntry.getBranchRevisions(); 133 CVSTag[] allCVSTags = entry.getTags(); 134 for (int i = 0; i < allCVSTags.length; i++) { 135 if (allCVSTags[i].equals(tag)) { 136 ((RemoteFile) remoteFile).setRevision(allBranchRevisions[i]); 138 break; 139 } 140 } 141 } 142 } 143 144 public HashMap getLogMap() { 145 return treeBuilder.getLogMap(); 146 } 147 148 } 149 | Popular Tags |