KickJava   Java API By Example, From Geeks To Geeks.

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


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  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13
14 import java.util.Collection JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Status;
20 import org.eclipse.osgi.util.NLS;
21 import org.eclipse.team.internal.ccvs.core.*;
22 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
23
24 public class Commit extends Command {
25     /*** Local options: specific to commit ***/
26     // Forces a file to be committed even if it has not been modified; implies -l.
27
// NOTE: This option is not fully supported -- a file will not be sent
28
// unless it is dirty. The primary use is to resend a file that may
29
// or may not be changed (e.g. could depend on CR/LF translations, etc...)
30
// and force the server to create a new revision and reply Checked-in.
31
public static final LocalOption FORCE = new LocalOption("-f"); //$NON-NLS-1$
32

33     protected Commit() { }
34     protected String JavaDoc getRequestId() {
35         return "ci"; //$NON-NLS-1$
36
}
37
38     /**
39      * Send all files under the workingFolder as changed files to
40      * the server.
41      */

42     protected ICVSResource[] sendLocalResourceState(Session session, GlobalOption[] globalOptions,
43         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor)
44         throws CVSException {
45
46         // Get the folders we want to work on
47
checkResourcesManaged(session, resources);
48         
49         // Send all changed files to the server
50
ModifiedFileSender visitor = new ModifiedFileSender(session, localOptions);
51         visitor.visit(session, resources, monitor);
52         
53         // Send the changed files as arguments (because this is what other cvs clients do)
54
ICVSFile[] changedFiles = visitor.getModifiedFiles();
55         for (int i = 0; i < changedFiles.length; i++) {
56             session.sendArgument(changedFiles[i].getRelativePath(session.getLocalRoot()));
57         }
58         return changedFiles;
59     }
60     
61     /**
62      * On successful finish, prune empty directories if the -P or -D option was specified.
63      */

64     protected IStatus commandFinished(Session session, GlobalOption[] globalOptions,
65         LocalOption[] localOptions, ICVSResource[] resources, IProgressMonitor monitor,
66         IStatus status) throws CVSException {
67         // If we didn't succeed, don't do any post processing
68
if (status.getCode() == CVSStatus.SERVER_ERROR) {
69             return status;
70         }
71
72         // If pruning is enable, prune empty directories after a commit
73
if (CVSProviderPlugin.getPlugin().getPruneEmptyDirectories()) {
74             new PruneFolderVisitor().visit(session, resources);
75         }
76         
77         // Reset the timestamps of any committed files that are still dirty.
78
// Only do so if there were no E messages from the server
79
if (status.isOK()) {
80             for (int i = 0; i < resources.length; i++) {
81                 ICVSResource resource = resources[i];
82                 if (!resource.isFolder()) {
83                     ICVSFile cvsFile = (ICVSFile)resources[i];
84                     if (cvsFile.exists() && cvsFile.isModified(null)) {
85                         status = mergeStatus(status, clearModifiedState(cvsFile));
86                     }
87                 }
88             }
89         }
90         return status;
91     }
92     
93     protected IStatus clearModifiedState(ICVSFile cvsFile) throws CVSException {
94         byte[] info = cvsFile.getSyncBytes();
95         IResource resource = cvsFile.getIResource();
96         String JavaDoc filePath;
97         if (resource == null) {
98             filePath = cvsFile.getRepositoryRelativePath();
99         } else {
100             filePath = resource.getFullPath().toString();
101         }
102         if (info == null) {
103             // There should be sync info. Log the problem
104
return new Status(IStatus.WARNING, CVSProviderPlugin.ID, 0, NLS.bind(CVSMessages.Commit_syncInfoMissing, new String JavaDoc[] { filePath }), null);
105         }
106         cvsFile.checkedIn(null, true /* commit in progress */);
107         return new Status(IStatus.INFO, CVSProviderPlugin.ID, 0, NLS.bind(CVSMessages.Commit_timestampReset, new String JavaDoc[] { filePath }), null); //;
108
}
109     
110     /**
111      * We do not want to send the arguments here, because we send
112      * them in sendRequestsToServer (special handling).
113      */

114     protected void sendArguments(Session session, String JavaDoc[] arguments) throws CVSException {
115     }
116     
117     public final IStatus execute(Session session, GlobalOption[] globalOptions, LocalOption[] localOptions,
118         ICVSResource[] arguments, Collection JavaDoc filesToCommitAsText,
119         ICommandOutputListener listener, IProgressMonitor pm) throws CVSException {
120         
121         session.setTextTransferOverride(filesToCommitAsText);
122         try {
123             return super.execute(session, globalOptions, localOptions, arguments, listener, pm);
124         } finally {
125             session.setTextTransferOverride(null);
126         }
127     }
128     
129     protected String JavaDoc getDisplayText() {
130         return "commit"; //$NON-NLS-1$
131
}
132 }
133
Popular Tags