KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > CopyHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13
14 import org.eclipse.core.runtime.Assert;
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.team.internal.ccvs.core.*;
17
18 /**
19  * Handles a "Copy-file" response from the CVS server.
20  * <p>
21  * Suppose as a result of performing a command the CVS server responds
22  * as follows:<br>
23  * <pre>
24  * [...]
25  * Copy-file myproject/ \n
26  * /u/cvsroot/myproject/oldfile.txt \n
27  * newfile.txt
28  * [...]
29  * </pre>
30  * Then we copy (or optionally rename) the local file "oldfile.txt" in
31  * folder "myproject" to "newfile.txt". This response is used to create
32  * a backup copy of an existing file before merging in new changes.
33  * </p>
34  */

35 class CopyHandler extends ResponseHandler {
36     public String JavaDoc getResponseID() {
37         return "Copy-file"; //$NON-NLS-1$
38
}
39
40     public void handle(Session session, String JavaDoc localDir,
41         IProgressMonitor monitor) throws CVSException {
42         // read additional data for the response
43
String JavaDoc repositoryFile = session.readLine();
44         String JavaDoc newFile = session.readLine();
45         if (session.isNoLocalChanges() || ! session.isCreateBackups()) return;
46
47         // Get the local file
48
String JavaDoc fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$
49
ICVSFolder mParent = session.getLocalRoot().getFolder(localDir);
50         ICVSFile mFile = mParent.getFile(fileName);
51
52         Assert.isTrue(mParent.exists());
53         Assert.isTrue(mFile.exists() && mFile.isManaged());
54         
55         // rename the file
56
mFile.copyTo(newFile);
57     }
58 }
59
60
Popular Tags