KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.core.runtime.IProgressMonitor;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.osgi.util.NLS;
16 import org.eclipse.team.internal.ccvs.core.*;
17 import org.eclipse.team.internal.ccvs.core.CVSException;
18 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
19 import org.eclipse.team.internal.ccvs.core.CVSStatus;
20 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
21 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
22 import org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener;
23 import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
24
25 /**
26  * Here are some of the output formats we know about:
27  *
28  * Concurrent Versions System (CVS) 1.11.1p1 (client/server)
29  * Concurrent Versions System (CVS) NT 1.11.1.1 (Build 27)
30  * Concurrent Versions System (CVSNT) 1.11.1.3 (Build 57a) (client/server)
31  */

32 public class Version extends RemoteCommand {
33
34     private static final String JavaDoc CVS_NT_PREFIX_1 = "Concurrent Versions System (CVS) NT "; //$NON-NLS-1$
35
private static final String JavaDoc CVS_NT_PREFIX_2 = "Concurrent Versions System (CVSNT) "; //$NON-NLS-1$
36
private static final String JavaDoc CVS_PREFIX = "Concurrent Versions System (CVS) "; //$NON-NLS-1$
37
/**
38      * @see Request#getRequestId()
39      */

40     protected String JavaDoc getRequestId() {
41         return "version"; //$NON-NLS-1$
42
}
43
44     public IStatus execute(Session session, final ICVSRepositoryLocation location, IProgressMonitor monitor) throws CVSException {
45         
46         // The server may not support the version request
47
if ( ! session.isValidRequest(getRequestId())) {
48             IStatus status = new CVSStatus(IStatus.WARNING, CVSStatus.SERVER_IS_UNKNOWN, NLS.bind(CVSMessages.Version_versionNotValidRequest, new String JavaDoc[] { location.getHost() }), session.getLocalRoot());
49             ((CVSRepositoryLocation)location).setServerPlaform(CVSRepositoryLocation.UNKNOWN_SERVER);
50             CVSProviderPlugin.log(status);
51             return status;
52         }
53         
54         ICommandOutputListener listener = new ICommandOutputListener() {
55             public IStatus messageLine(String JavaDoc line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) {
56                 String JavaDoc knownPrefix = null;
57                 boolean isCVSNT = false;
58                 if (line.startsWith(CVS_NT_PREFIX_1)) {
59                     isCVSNT = true;
60                     knownPrefix = CVS_NT_PREFIX_1;
61                 } else if (line.startsWith(CVS_NT_PREFIX_2)) {
62                     isCVSNT = true;
63                     knownPrefix = CVS_NT_PREFIX_2;
64                 } else if (line.startsWith(CVS_PREFIX)) {
65                     knownPrefix = CVS_PREFIX;
66                 }
67                 IStatus status = OK;
68                 int serverType = CVSRepositoryLocation.CVS_SERVER;
69                 if (knownPrefix != null) {
70                     String JavaDoc versionNumber = line.substring(knownPrefix.length(), line.indexOf(' ', knownPrefix.length() + 1));
71                     if (versionNumber.startsWith("1.10") || versionNumber.equals("1.11") || versionNumber.equals("1.11.1")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
72
serverType = CVSRepositoryLocation.UNSUPPORTED_SERVER;
73                         status = new CVSStatus(IStatus.WARNING, CVSStatus.UNSUPPORTED_SERVER_VERSION, NLS.bind(CVSMessages.Version_unsupportedVersion, new String JavaDoc[] { location.getHost(), versionNumber }),location);
74                     } else if (isCVSNT) {
75                         serverType = CVSRepositoryLocation.CVSNT_SERVER;
76                     }
77                 } else {
78                     serverType = CVSRepositoryLocation.UNKNOWN_SERVER;
79                     status = new CVSStatus(IStatus.INFO, CVSStatus.SERVER_IS_UNKNOWN, NLS.bind(CVSMessages.Version_unknownVersionFormat, new String JavaDoc[] { location.getHost(), line }), location);
80                 }
81                 ((CVSRepositoryLocation)location).setServerPlaform(serverType);
82                 return status;
83             }
84             public IStatus errorLine(String JavaDoc line, ICVSRepositoryLocation location, ICVSFolder commandRoot, IProgressMonitor monitor) {
85                 return new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, line, commandRoot);
86             }
87         };
88         
89         return execute(session, NO_GLOBAL_OPTIONS, NO_LOCAL_OPTIONS, new String JavaDoc[] {}, listener, monitor);
90     }
91     
92     /* (non-Javadoc)
93      * @see org.eclipse.team.internal.ccvs.core.client.Command#isWorkspaceModification()
94      */

95     protected boolean isWorkspaceModification() {
96         return false;
97     }
98     
99 }
100
Popular Tags