1 11 package org.eclipse.team.internal.ccvs.ui.operations; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.ArrayList ; 15 import java.util.Date ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.team.internal.ccvs.core.*; 21 import org.eclipse.team.internal.ccvs.core.client.*; 22 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 23 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener; 24 import org.eclipse.team.internal.ccvs.core.resources.RemoteFile; 25 import org.eclipse.team.internal.ccvs.core.resources.RemoteFolderSandbox; 26 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 27 import org.eclipse.team.internal.ccvs.ui.Policy; 28 import org.eclipse.ui.IWorkbenchPart; 29 30 34 public class CheckoutToRemoteFolderOperation extends CheckoutOperation { 35 36 RemoteFolderSandbox sandbox; 37 38 42 public class CreatedResponseHandler extends UpdatedHandler { 43 public CreatedResponseHandler() { 44 super(UpdatedHandler.HANDLE_CREATED); 45 } 46 49 protected void receiveTargetFile( 50 Session session, 51 ICVSFile mFile, 52 String entryLine, 53 Date modTime, 54 boolean binary, 55 boolean readOnly, 56 boolean executable, 57 IProgressMonitor monitor) 58 throws CVSException { 59 60 if (mFile instanceof RemoteFile) { 61 try { 62 ((RemoteFile)mFile).aboutToReceiveContents(entryLine.getBytes()); 63 super.receiveTargetFile( 64 session, 65 mFile, 66 entryLine, 67 modTime, 68 binary, 69 readOnly, 70 executable, 71 monitor); 72 } finally { 73 ((RemoteFile)mFile).doneReceivingContents(); 74 } 75 } else { 76 super.receiveTargetFile( 77 session, 78 mFile, 79 entryLine, 80 modTime, 81 binary, 82 readOnly, 83 executable, 84 monitor); 85 } 86 } 87 } 88 89 public class SandboxCheckout extends Checkout { 90 91 94 protected IStatus commandFinished( 95 Session session, 96 GlobalOption[] globalOptions, 97 LocalOption[] localOptions, 98 ICVSResource[] resources, 99 IProgressMonitor monitor, 100 IStatus status) 101 throws CVSException { 102 103 return status; 105 } 106 107 110 protected IStatus doExecute( 111 Session session, 112 GlobalOption[] globalOptions, 113 LocalOption[] localOptions, 114 String [] arguments, 115 ICommandOutputListener listener, 116 IProgressMonitor monitor) 117 throws CVSException { 118 119 ResponseHandler newCreated = new CreatedResponseHandler(); 120 ResponseHandler oldCreated = session.getResponseHandler(newCreated.getResponseID()); 121 session.registerResponseHandler(newCreated); 122 try { 123 return super.doExecute( 124 session, 125 globalOptions, 126 localOptions, 127 arguments, 128 listener, 129 monitor); 130 } finally { 131 session.registerResponseHandler(oldCreated); 132 } 133 } 134 135 } 136 public static ICVSRemoteFolder checkoutRemoteFolder(IWorkbenchPart part, ICVSRemoteFolder folder, IProgressMonitor monitor) throws CVSException, InvocationTargetException , InterruptedException { 137 CheckoutToRemoteFolderOperation op = new CheckoutToRemoteFolderOperation(part, folder); 138 op.run(monitor); 139 return op.getResultingFolder(); 140 } 141 public CheckoutToRemoteFolderOperation(IWorkbenchPart part, ICVSRemoteFolder remoteFolder) { 142 super(part, new ICVSRemoteFolder[] { remoteFolder }); 143 } 144 145 148 protected IStatus checkout( 149 ICVSRemoteFolder folder, 150 IProgressMonitor monitor) 151 throws CVSException { 152 153 IPath sandboxPath = new Path(null, folder.getRepositoryRelativePath()).removeLastSegments(1); 154 String pathString; 155 if (sandboxPath.isEmpty()) { 156 pathString = ICVSRemoteFolder.REPOSITORY_ROOT_FOLDER_NAME; 157 } else { 158 pathString = sandboxPath.toString(); 159 } 160 sandbox = new RemoteFolderSandbox(null, folder.getRepository(), pathString, folder.getTag()); 161 return checkout(folder, sandbox, monitor); 162 } 163 164 167 protected String getTaskName() { 168 return NLS.bind(CVSUIMessages.CheckoutToRemoteFolderOperation_0, new String [] { getRemoteFolders()[0].getName() }); 169 } 170 171 protected IStatus checkout(final ICVSRemoteFolder resource, final ICVSFolder sandbox, IProgressMonitor pm) throws CVSException { 172 ICVSRepositoryLocation repository = resource.getRepository(); 174 final Session session = new Session(repository, sandbox); 176 pm.beginTask(null, 100); 177 Policy.checkCanceled(pm); 178 session.open(Policy.subMonitorFor(pm, 5), false ); 179 try { 180 List localOptions = new ArrayList (); 182 CVSTag tag = resource.getTag(); 184 if (tag == null) { 185 tag = CVSTag.DEFAULT; 187 } 188 localOptions.add(Update.makeTagOption(tag)); 189 localOptions.add(Checkout.makeDirectoryNameOption(resource.getName())); 190 191 IStatus status = new SandboxCheckout().execute(session, 193 Command.NO_GLOBAL_OPTIONS, 194 (LocalOption[])localOptions.toArray(new LocalOption[localOptions.size()]), 195 new String []{resource.getRepositoryRelativePath()}, 196 null, 197 Policy.subMonitorFor(pm, 90)); 198 if (status.getCode() == CVSStatus.SERVER_ERROR) { 199 return status; 201 } 202 return OK; 203 } catch (CVSException e) { 204 return e.getStatus(); 208 } finally { 209 session.close(); 210 pm.done(); 211 } 212 } 213 214 public ICVSRemoteFolder getResultingFolder() throws CVSException { 215 return (ICVSRemoteFolder)sandbox.getFolder(getRemoteFolders()[0].getName()); 216 } 217 } 218 | Popular Tags |