KickJava   Java API By Example, From Geeks To Geeks.

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


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.listeners;
12
13
14 import java.io.PrintStream JavaDoc;
15
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
19 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
20 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener;
21 import org.eclipse.team.internal.ccvs.core.client.Session;
22
23 public class DiffListener extends CommandOutputListener {
24     PrintStream JavaDoc patchStream;
25     boolean wroteToStream;
26     
27     //Error Messages returned by CVS
28
static final String JavaDoc ERR_NOSUCHDIRECTORY = "cvs [diff aborted]: no such directory"; //$NON-NLS-1$
29

30     public DiffListener(PrintStream JavaDoc patchStream) {
31         this.patchStream = patchStream;
32         wroteToStream=false;
33     }
34     
35     public IStatus messageLine(
36             String JavaDoc line,
37             ICVSRepositoryLocation location,
38             ICVSFolder commandRoot,
39             IProgressMonitor monitor) {
40         
41         // Special handling to avoid getting duplicate CRs when generating a patch on windows.
42
// If the remote file has CR/LF in it, then the line will have a CR at the end.
43
// We need to remove it so we don't end up with two CRs (since the printStream will also add one).
44
// On *nix, we want to include the CR since it will not be added by the printStream (see bug 92162).
45
if (Session.IS_CRLF_PLATFORM && line.length() > 0 && line.charAt(line.length() - 1) == '\r') {
46             line = line.substring(0, line.length() - 1);
47         }
48         patchStream.println(line);
49         wroteToStream=true;
50         
51         return OK;
52     }
53
54     public IStatus errorLine(
55             String JavaDoc line,
56             ICVSRepositoryLocation location,
57             ICVSFolder commandRoot,
58             IProgressMonitor monitor) {
59         // ignore server messages for now - this is used only with the diff
60
// request and the errors can be safely ignored.
61
if (getServerMessage(line, location) != null) {
62             return OK;
63         }
64         
65         //Check to see if this is a no such directory message
66
if (line.indexOf(ERR_NOSUCHDIRECTORY) != -1){
67             return OK;
68         }
69         return super.errorLine(line, location, commandRoot, monitor);
70     }
71
72     public boolean wroteToStream() {
73         return wroteToStream;
74     }
75 }
76
Popular Tags