KickJava   Java API By Example, From Geeks To Geeks.

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


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.listeners;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.team.internal.ccvs.core.*;
16 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener;
17 import org.eclipse.team.internal.ccvs.core.util.Util;
18
19 public class StatusListener extends CommandOutputListener {
20     private static boolean isFolder = false;
21     private IStatusListener statusListener;
22
23     public StatusListener(IStatusListener statusListener) {
24         this.statusListener = statusListener;
25     }
26
27     public IStatus messageLine(String JavaDoc line, ICVSRepositoryLocation location, ICVSFolder commandRoot,
28         IProgressMonitor monitor) {
29         
30         // We're only concerned about file revisions.
31
if (line.startsWith(" Repository revision:")) { //$NON-NLS-1$
32
if (!line.startsWith(" Repository revision: No revision control file")) { //$NON-NLS-1$
33
int separatingTabIndex = line.indexOf('\t', 24);
34                 String JavaDoc remoteRevision = line.substring(24, separatingTabIndex);
35
36                 // This is the full location on the server (e.g. /home/cvs/repo/project/file.txt)
37
String JavaDoc fileLocation = line.substring(separatingTabIndex + 1, line.length() - 2);
38
39                 // Inform the listener about the file revision
40
statusListener.fileStatus(commandRoot, removeAtticSegment(fileLocation), remoteRevision);
41             }
42         }
43         return OK;
44     }
45
46     public IStatus errorLine(String JavaDoc line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) {
47         String JavaDoc serverMessage = getServerMessage(line, location);
48         if (serverMessage != null) {
49             if (serverMessage.startsWith("conflict:")) {//$NON-NLS-1$
50
// We get this because we made up an entry line to send to the server
51
// Therefore, we make this a warning!!!
52
return new CVSStatus(IStatus.WARNING, CVSStatus.CONFLICT, line, commandRoot);
53             }
54             if (serverMessage.startsWith("Examining")) {//$NON-NLS-1$
55
isFolder = true;
56                 return OK;
57             }
58         }
59         if (isFolder) {
60             // This used to do something but it was obviously wrong and there was no indication
61
// why it was needed. Therefore, I have removed the code to see if anything is effected
62
isFolder = false;
63         }
64         return super.errorLine(line, location, commandRoot, monitor);
65     }
66     
67     /**
68      * If the status returns that the file is in the Attic, then remove the
69      * Attic segment. This is because files added to a branch that are not in
70      * the main trunk (HEAD) are added to the Attic but cvs does magic on
71      * updateto put them in the correct location.
72      * (e.g. /project/Attic/file.txt -> /project/file.txt)
73      */

74     private String JavaDoc removeAtticSegment(String JavaDoc path) {
75         return Util.removeAtticSegment(path);
76     }
77 }
78
Popular Tags