source: release-kits/lirk3/resources/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsVersion.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 5.2 KB
Line 
1/*
2 * Copyright 2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.cvslib;
18
19import org.apache.tools.ant.taskdefs.AbstractCvsTask;
20
21import java.io.ByteArrayOutputStream;
22import java.util.StringTokenizer;
23
24/**
25 * this task allows to find out the client and the server version of a
26 * CVS installation
27 *
28 * example usage :
29 * <cvsversion
30 * cvsRoot=":pserver:[email protected]:/home/cvspublic"
31 * passfile="c:/programme/cygwin/home/antoine/.cvspass"
32 * clientversionproperty="apacheclient"
33 * serverversionproperty="apacheserver" />
34 *
35 * the task can be used also in the API by calling its execute method,
36 * then calling getServerVersion and/or getClientVersion
37 *
38 * @ant.task category="scm"
39 * @since ant 1.6.1
40 */
41public class CvsVersion extends AbstractCvsTask {
42 static final long VERSION_1_11_2 = 11102;
43 static final long MULTIPLY = 100;
44 private String clientVersion;
45 private String serverVersion;
46 private String clientVersionProperty;
47 private String serverVersionProperty;
48 /**
49 * get the CVS client version
50 * @return CVS client version
51 */
52 public String getClientVersion() {
53 return clientVersion;
54 }
55 /**
56 * get the CVS server version
57 * @return CVS server version
58 */
59 public String getServerVersion() {
60 return serverVersion;
61 }
62 /**
63 * set a property where to store the CVS client version
64 * @param clientVersionProperty property for CVS client version
65 */
66 public void setClientVersionProperty(String clientVersionProperty) {
67 this.clientVersionProperty = clientVersionProperty;
68 }
69
70 /**
71 * set a property where to store the CVS server version
72 * @param serverVersionProperty property for CVS server version
73 */
74 public void setServerVersionProperty(String serverVersionProperty) {
75 this.serverVersionProperty = serverVersionProperty;
76 }
77 /**
78 * find out if the server version supports log with S option
79 * @return boolean indicating if the server version supports log with S option
80 */
81 public boolean supportsCvsLogWithSOption() {
82 if (serverVersion == null) {
83 return false;
84 }
85 StringTokenizer mySt = new StringTokenizer(serverVersion, ".");
86 long versionNumber;
87 long counter = MULTIPLY * MULTIPLY;
88 long version = 0;
89 while (mySt.hasMoreTokens()) {
90 String s = mySt.nextToken();
91 int i = 0;
92 for (i = 0; i < s.length(); i++) {
93 if (!Character.isDigit(s.charAt(i))) {
94 break;
95 }
96 }
97 String s2 = s.substring(0, i);
98 version = version + counter * Long.parseLong(s2);
99 if (counter == 1) {
100 break;
101 }
102 counter = counter / MULTIPLY;
103 }
104 return (version >= VERSION_1_11_2);
105 }
106 /**
107 * the execute method running CvsVersion
108 */
109 public void execute() {
110 ByteArrayOutputStream bos = new ByteArrayOutputStream();
111 this.setOutputStream(bos);
112 ByteArrayOutputStream berr = new ByteArrayOutputStream();
113 this.setErrorStream(berr);
114 setCommand("version");
115 super.execute();
116 String output = bos.toString();
117 StringTokenizer st = new StringTokenizer(output);
118 boolean client = false;
119 boolean server = false;
120 boolean cvs = false;
121 while (st.hasMoreTokens()) {
122 String currentToken = st.nextToken();
123 if (currentToken.equals("Client:")) {
124 client = true;
125 } else if (currentToken.equals("Server:")) {
126 server = true;
127 } else if (currentToken.equals("(CVS)")) {
128 cvs = true;
129 }
130 if (client && cvs) {
131 if (st.hasMoreTokens()) {
132 clientVersion = st.nextToken();
133 }
134 client = false;
135 cvs = false;
136 } else if (server && cvs) {
137 if (st.hasMoreTokens()) {
138 serverVersion = st.nextToken();
139 }
140 server = false;
141 cvs = false;
142 }
143
144 }
145 if (clientVersionProperty != null) {
146 getProject().setNewProperty(clientVersionProperty, clientVersion);
147 }
148 if (serverVersionProperty != null) {
149 getProject().setNewProperty(serverVersionProperty, serverVersion);
150 }
151 }
152}
Note: See TracBrowser for help on using the repository browser.