1 11 package org.eclipse.team.internal.ccvs.core.client.listeners; 12 13 14 import org.eclipse.core.runtime.*; 15 import org.eclipse.osgi.util.NLS; 16 import org.eclipse.team.internal.ccvs.core.*; 17 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener; 18 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; 19 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; 20 import org.eclipse.team.internal.ccvs.core.syncinfo.ResourceSyncInfo; 21 import org.eclipse.team.internal.ccvs.core.util.Util; 22 23 35 public class AdminKSubstListener extends CommandOutputListener { 36 private KSubstOption ksubstMode; 37 38 public AdminKSubstListener(KSubstOption ksubstMode) { 39 this.ksubstMode = ksubstMode; 40 } 41 42 public IStatus messageLine(String line, ICVSRepositoryLocation location, ICVSFolder commandRoot, 43 IProgressMonitor monitor) { 44 if (line.startsWith("RCS file:")) { String rcsFile = line.substring(10).trim(); 46 if (! rcsFile.endsWith(",v")) { return new CVSStatus(IStatus.ERROR, 48 NLS.bind(CVSMessages.AdminKSubstListener_expectedRCSFile, new String [] { rcsFile })); 49 } 50 IPath rcsFilePath = new Path(null, Util.removeAtticSegment(rcsFile.substring(0, rcsFile.length() - 2))); 51 try { 52 ICVSFile file = findLocalFileFor(commandRoot, rcsFilePath); 53 byte[] syncBytes = file.getSyncBytes(); 55 if (syncBytes != null) { 56 file.setSyncBytes(ResourceSyncInfo.setKeywordMode(syncBytes, ksubstMode), ICVSFile.UNKNOWN); 58 } 59 } catch (CVSException e) { 60 return e.getStatus(); 61 } 62 } 63 return OK; 64 } 65 66 private ICVSFile findLocalFileFor(ICVSFolder commandRoot, IPath rcsFilePath) throws CVSException { 67 68 FolderSyncInfo info = commandRoot.getFolderSyncInfo(); 70 String remoteRootLocation = info.getRemoteLocation(); 71 if (remoteRootLocation == null) { 72 throw new CVSException(new CVSStatus(IStatus.ERROR, 73 CVSMessages.AdminKSubstListener_commandRootNotManaged)); 74 } 75 IPath remoteRootPath = new Path(null, remoteRootLocation); 76 if (remoteRootPath.isPrefixOf(rcsFilePath)) { 77 IPath relativeFilePath = rcsFilePath.removeFirstSegments(remoteRootPath.segmentCount()); 78 ICVSFile file = commandRoot.getFile(relativeFilePath.toString()); 79 if (file.isManaged() && isMatchingPath(file, rcsFilePath)) { 80 return file; 81 } 82 } 83 84 ICVSFolder parent = findFolder(commandRoot, rcsFilePath.removeLastSegments(1)); 87 if (parent != null) { 88 ICVSFile file = parent.getFile(rcsFilePath.lastSegment()); 89 if (file.isManaged()) { 90 return file; 91 } 92 } 93 94 throw new CVSException(new CVSStatus(IStatus.ERROR, 96 NLS.bind(CVSMessages.AdminKSubstListener_expectedChildOfCommandRoot, new String [] { rcsFilePath.toString(), remoteRootPath.toString() }))); 97 } 98 99 private ICVSFolder findFolder(ICVSFolder commandRoot, IPath path) throws CVSException { 100 final String remotePath = path.toString(); 101 final ICVSFolder[] result = new ICVSFolder[] { null }; 102 commandRoot.accept(new ICVSResourceVisitor() { 103 public void visitFile(ICVSFile file) throws CVSException { 104 } 106 public void visitFolder(ICVSFolder folder) throws CVSException { 107 FolderSyncInfo info = folder.getFolderSyncInfo(); 108 if (info != null && info.getRemoteLocation().equals(remotePath)) { 109 result[0] = folder; 111 } 112 if (result[0] == null) { 113 folder.acceptChildren(this); 114 } 115 } 116 }); 117 return result[0]; 118 } 119 120 private boolean isMatchingPath(ICVSFile file, IPath rcsFilePath) throws CVSException { 121 FolderSyncInfo info = file.getParent().getFolderSyncInfo(); 122 return info != null 123 && info.getRemoteLocation().equals(rcsFilePath.removeLastSegments(1).toString()); 124 } 125 } 126 | Popular Tags |