1 18 package org.apache.tools.ant.taskdefs.cvslib; 19 20 import org.apache.tools.ant.taskdefs.AbstractCvsTask; 21 22 import java.io.ByteArrayOutputStream ; 23 import java.util.StringTokenizer ; 24 25 42 public class CvsVersion extends AbstractCvsTask { 43 static final long VERSION_1_11_2 = 11102; 44 static final long MULTIPLY = 100; 45 private String clientVersion; 46 private String serverVersion; 47 private String clientVersionProperty; 48 private String serverVersionProperty; 49 50 54 public String getClientVersion() { 55 return clientVersion; 56 } 57 61 public String getServerVersion() { 62 return serverVersion; 63 } 64 68 public void setClientVersionProperty(String clientVersionProperty) { 69 this.clientVersionProperty = clientVersionProperty; 70 } 71 72 76 public void setServerVersionProperty(String serverVersionProperty) { 77 this.serverVersionProperty = serverVersionProperty; 78 } 79 83 public boolean supportsCvsLogWithSOption() { 84 if (serverVersion == null) { 85 return false; 86 } 87 StringTokenizer tokenizer = new StringTokenizer (serverVersion, "."); 88 long counter = MULTIPLY * MULTIPLY; 89 long version = 0; 90 while (tokenizer.hasMoreTokens()) { 91 String s = tokenizer.nextToken(); 92 int i = 0; 93 for (i = 0; i < s.length(); i++) { 94 if (!Character.isDigit(s.charAt(i))) { 95 break; 96 } 97 } 98 String s2 = s.substring(0, i); 99 version = version + counter * Long.parseLong(s2); 100 if (counter == 1) { 101 break; 102 } 103 counter = counter / MULTIPLY; 104 } 105 return (version >= VERSION_1_11_2); 106 } 107 110 public void execute() { 111 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 112 this.setOutputStream(bos); 113 ByteArrayOutputStream berr = new ByteArrayOutputStream (); 114 this.setErrorStream(berr); 115 setCommand("version"); 116 super.execute(); 117 String output = bos.toString(); 118 StringTokenizer st = new StringTokenizer (output); 119 boolean client = false; 120 boolean server = false; 121 boolean cvs = false; 122 while (st.hasMoreTokens()) { 123 String currentToken = st.nextToken(); 124 if (currentToken.equals("Client:")) { 125 client = true; 126 } else if (currentToken.equals("Server:")) { 127 server = true; 128 } else if (currentToken.equals("(CVS)")) { 129 cvs = true; 130 } 131 if (client && cvs) { 132 if (st.hasMoreTokens()) { 133 clientVersion = st.nextToken(); 134 } 135 client = false; 136 cvs = false; 137 } else if (server && cvs) { 138 if (st.hasMoreTokens()) { 139 serverVersion = st.nextToken(); 140 } 141 server = false; 142 cvs = false; 143 } 144 145 } 146 if (clientVersionProperty != null) { 147 getProject().setNewProperty(clientVersionProperty, clientVersion); 148 } 149 if (serverVersionProperty != null) { 150 getProject().setNewProperty(serverVersionProperty, serverVersion); 151 } 152 } 153 } 154 | Popular Tags |