FileDocCategorySizeDatePackage
CvsVersion.javaAPI DocApache Ant 1.705326Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.cvslib

CvsVersion

public class CvsVersion extends org.apache.tools.ant.taskdefs.AbstractCvsTask
this task allows to find out the client and the server version of a CVS installation example usage : <cvsversion cvsRoot=":pserver:anoncvs@cvs.apache.org:/home/cvspublic" passfile="c:/programme/cygwin/home/antoine/.cvspass" clientversionproperty="apacheclient" serverversionproperty="apacheserver" /> the task can be used also in the API by calling its execute method, then calling getServerVersion and/or getClientVersion
ant.task
category="scm"
since
ant 1.6.1

Fields Summary
static final long
VERSION_1_11_2
static final long
MULTIPLY
private String
clientVersion
private String
serverVersion
private String
clientVersionProperty
private String
serverVersionProperty
Constructors Summary
Methods Summary
public voidexecute()
the execute method running CvsVersion

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        this.setOutputStream(bos);
        ByteArrayOutputStream berr = new ByteArrayOutputStream();
        this.setErrorStream(berr);
        setCommand("version");
        super.execute();
        String output = bos.toString();
        StringTokenizer st = new StringTokenizer(output);
        boolean client = false;
        boolean server = false;
        boolean cvs = false;
        while (st.hasMoreTokens()) {
            String currentToken = st.nextToken();
            if (currentToken.equals("Client:")) {
                client = true;
            } else if (currentToken.equals("Server:")) {
                server = true;
            } else if (currentToken.equals("(CVS)")) {
                cvs = true;
            }
            if (client && cvs) {
                if (st.hasMoreTokens()) {
                    clientVersion = st.nextToken();
                }
                client = false;
                cvs = false;
            } else if (server && cvs) {
                if (st.hasMoreTokens()) {
                    serverVersion = st.nextToken();
                }
                server = false;
                cvs = false;
            }

        }
        if (clientVersionProperty != null) {
            getProject().setNewProperty(clientVersionProperty, clientVersion);
        }
        if (serverVersionProperty != null) {
            getProject().setNewProperty(serverVersionProperty, serverVersion);
        }
    
public java.lang.StringgetClientVersion()
Get the CVS client version

return
CVS client version


                  
       
        return clientVersion;
    
public java.lang.StringgetServerVersion()
Get the CVS server version

return
CVS server version

        return serverVersion;
    
public voidsetClientVersionProperty(java.lang.String clientVersionProperty)
Set a property where to store the CVS client version

param
clientVersionProperty property for CVS client version

        this.clientVersionProperty = clientVersionProperty;
    
public voidsetServerVersionProperty(java.lang.String serverVersionProperty)
Set a property where to store the CVS server version

param
serverVersionProperty property for CVS server version

        this.serverVersionProperty = serverVersionProperty;
    
public booleansupportsCvsLogWithSOption()
Find out if the server version supports log with S option

return
boolean indicating if the server version supports log with S option

        if (serverVersion == null) {
            return false;
        }
        StringTokenizer tokenizer = new StringTokenizer(serverVersion, ".");
        long counter = MULTIPLY * MULTIPLY;
        long version = 0;
        while (tokenizer.hasMoreTokens()) {
            String s = tokenizer.nextToken();
            int i = 0;
            for (i = 0; i < s.length(); i++) {
                if (!Character.isDigit(s.charAt(i))) {
                    break;
                }
            }
            String s2 = s.substring(0, i);
            version = version + counter * Long.parseLong(s2);
            if (counter == 1) {
                break;
            }
            counter = counter / MULTIPLY;
        }
        return (version >= VERSION_1_11_2);