1
/*****************************************************************************
2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is the CVS Client Library.
27
* The Initial Developer of the Original Software is Robert Greig.
28
* Portions created by Robert Greig are Copyright (C) 2000.
29
* All Rights Reserved.
31
* If you wish your version of this file to be governed by only the CDDL
32
* or only the GPL Version 2, indicate your decision by adding
33
* "[Contributor] elects to include this software in this distribution
34
* under the [CDDL or GPL Version 2] license." If you do not indicate a
35
* single choice of license, a recipient has the option to distribute
36
* your version of this file under either the CDDL, the GPL Version 2 or
37
* to extend the choice of license to its licensees as provided above.
38
* However, if you add GPL Version 2 code and therefore, elected the GPL
39
* Version 2 license, then the option applies only if the new code is
40
* made subject to such option by the copyright holder.
42
* Contributor(s): Robert Greig.
43
*****************************************************************************/
44
package org.netbeans.lib.cvsclient.response;
50
import org.netbeans.lib.cvsclient.admin.*;
51
import org.netbeans.lib.cvsclient.event.*;
52
import org.netbeans.lib.cvsclient.file.*;
53
import org.netbeans.lib.cvsclient.util.*;
56
* Sends a diff of a particular file, indicating that the file currently
57
* checked-out needs to be updated by the patch sent with this response.
58
* @author Milos Kleint
60
class RcsDiffResponse implements Response {
62
private static final boolean DEBUG = false;
65
* The local path of the new file.
67
private String localPath;
70
* The full repository path of the file.
72
private String repositoryPath;
77
private String entryLine;
85
* fullpath to the file being processed.
87
protected String localFile;
90
* The date Formatter used to parse and format dates.
91
* Format is: "EEE MMM dd HH:mm:ss yyyy"
93
private DateFormat dateFormatter;
96
* Process the data for the response.
97
* @param r the buffered reader allowing the client to read the server's
98
* response. Note that the actual response name has already been read
99
* and the reader is positioned just before the first argument, if any.
100
* @param services various services that are useful to response handlers
101
* @throws ResponseException if something goes wrong handling this response
103
public void process(LoggedDataInputStream dis, ResponseServices services)
104
throws ResponseException {
106
localPath = dis.readLine();
107
repositoryPath = dis.readLine();
108
entryLine = dis.readLine();
109
mode = dis.readLine();
111
String nextLine = dis.readLine();
113
boolean useGzip = (nextLine.charAt(0) == 'z');
115
int length = Integer.parseInt(useGzip ? nextLine.substring(1)
119
System.err.println("Got update response."); //NOI18N
120
System.err.println("LocalPath is : " + localPath); //NOI18N
121
System.err.println("Repository path is : " + repositoryPath); //NOI18N
122
System.err.println("Entries line is : " + entryLine); //NOI18N
123
System.err.println("Mode is : " + mode); //NOI18N
124
System.err.println("Next line (length) is : " + nextLine); //NOI18N
125
System.err.println("File length is : " + length); //NOI18N
128
// now read in the file
129
final String filePath = services.convertPathname(localPath,
132
final File newFile = new File(filePath);
134
if (services.getGlobalOptions().isExcluded(newFile)) {
136
length -= dis.skip(length);
141
localFile = newFile.getAbsolutePath();
142
final Entry entry = new Entry(entryLine);
144
FileHandler fileHandler = useGzip ? services.getGzipFileHandler()
145
: services.getUncompressedFileHandler();
146
// FileHandler fileHandler = useGzip ? getGzippedFileHandler()
147
// : getUncompressedFileHandler();
148
fileHandler.setNextFileDate(services.getNextFileDate());
150
// check if the file is binary
151
if (entry.isBinary()) {
152
// should actually not happen. it's possible to send pathces for text files only..
153
//TODO add BugLog print here
156
fileHandler.writeRcsDiffFile(filePath, mode, dis, length);
159
// we set the date the file was last modified in the Entry line
160
// so that we can easily determine whether the file has been
162
// for files with conflicts skip the setting of the conflict field.
163
//NOT SURE THIS IS NESSESARY HERE..
164
String conflictString = null;
165
if ((entry.getConflict() != null) &&
166
(entry.getConflict().charAt(0) == Entry.HAD_CONFLICTS)) {
167
if (entry.getConflict().charAt(1) ==
168
Entry.TIMESTAMP_MATCHES_FILE) {
169
final Date d = new Date(newFile.lastModified());
170
conflictString = getEntryConflict(d, true);
173
conflictString = entry.getConflict().substring(1);
177
final Date d = new Date(newFile.lastModified());
178
conflictString = getEntryConflict(d, false);
180
entry.setConflict(conflictString);
182
// update the admin files (i.e. within the CVS directory)
183
services.updateAdminData(localPath, repositoryPath, entry);
185
FileUpdatedEvent e = new FileUpdatedEvent(this, filePath);
186
services.getEventManager().fireCVSEvent(e);
187
//System.err.println("Finished writing file");
189
catch (IOException e) {
190
throw new ResponseException(e);
195
* Returns the Conflict field for the file's entry.
196
* Can be overriden by subclasses.
197
* (For example the MergedResponse that sets the "result of merge" there.)
198
* @param date the date to put in
199
* @param hadConflicts if there were conflicts (e.g after merge)
200
* @return the conflict field
202
protected String getEntryConflict(Date date, boolean hadConflicts) {
203
return getDateFormatter().format(date);
207
* Is this a terminal response, i.e. should reading of responses stop
208
* after this response. This is true for responses such as OK or
211
public boolean isTerminalResponse() {
216
* Returns the DateFormatter instance that parses and formats date Strings.
217
* The exact format matches the one in Entry.getLastModifiedDateFormatter() method.
220
protected DateFormat getDateFormatter() {
221
if (dateFormatter == null) {
222
dateFormatter = new SimpleDateFormat(Entry.getLastModifiedDateFormatter().toPattern(), Locale.US);
223
dateFormatter.setTimeZone(Entry.getTimeZone());
225
return dateFormatter;