KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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  * Matt McCutchen <hashproduct+eclipse@gmail.com> - Bug 179174 CVS client sets timestamps back when replacing
11  *******************************************************************************/

12 package org.eclipse.team.internal.ccvs.core.client;
13
14 import java.util.Date JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.team.internal.ccvs.core.CVSException;
20 import org.eclipse.team.internal.ccvs.core.ICVSFile;
21 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
22
23 /**
24  * A specialized update that will ignore unmanaged local content like
25  * CheckoutWithOverwrite and avoid setting back the timestamps of files
26  * recreated after being deleted by PrepareForReplaceVisitor.
27  */

28 public class Replace extends Update {
29
30     private Set JavaDoc/*<ICVSFile>*/ prepDeletedFiles = null;
31
32     public Replace() {}
33     public Replace(Set JavaDoc/*<ICVSFile>*/ prepDeletedFiles) {
34         this.prepDeletedFiles = prepDeletedFiles;
35     }
36     
37     /**
38      * This class overrides the "Created" handler but uses the "Updated"
39      * behavior which will overwrite existing files.
40      */

41     public class CreatedResponseHandler extends UpdatedHandler {
42         public CreatedResponseHandler() {
43             super(UpdatedHandler.HANDLE_UPDATED);
44         }
45         public String JavaDoc getResponseID() {
46             return "Created"; //$NON-NLS-1$
47
}
48         protected void receiveTargetFile(Session session, ICVSFile file, String JavaDoc entryLine, Date JavaDoc modTime,
49             boolean binary, boolean readOnly, boolean executable, IProgressMonitor monitor) throws CVSException {
50             // Discard any timestamp for files being recreated after being
51
// deleted by PrepareForReplaceVisitor.
52
if (prepDeletedFiles != null && prepDeletedFiles.contains(file))
53                 modTime = null;
54             super.receiveTargetFile(session, file, entryLine, modTime, binary, readOnly, executable, monitor);
55         }
56     }
57
58     /* (non-Javadoc)
59      * @see org.eclipse.team.internal.ccvs.core.client.Command#doExecute(org.eclipse.team.internal.ccvs.core.client.Session, org.eclipse.team.internal.ccvs.core.client.Command.GlobalOption[], org.eclipse.team.internal.ccvs.core.client.Command.LocalOption[], java.lang.String[], org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener, org.eclipse.core.runtime.IProgressMonitor)
60      */

61     protected IStatus doExecute(
62             Session session,
63             GlobalOption[] globalOptions,
64             LocalOption[] localOptions,
65             String JavaDoc[] arguments,
66             ICommandOutputListener listener,
67             IProgressMonitor monitor)
68     throws CVSException {
69         
70         ResponseHandler newCreated = new CreatedResponseHandler();
71         ResponseHandler oldCreated = session.getResponseHandler(newCreated.getResponseID());
72         session.registerResponseHandler(newCreated);
73         try {
74             return super.doExecute(
75                     session,
76                     globalOptions,
77                     localOptions,
78                     arguments,
79                     listener,
80                     monitor);
81         } finally {
82             session.registerResponseHandler(oldCreated);
83         }
84     }
85 }
86
Popular Tags