The following task extracts the current cvs sticky tag information from
a file and puts the value into a user-specified property. We use it
internally as information displayed in an About... box. Is this useful
enough for inclusion in the standard distribution?
- Todd
package com.vecna.ant.cvslib;
import org.apache.tools.ant.taskdefs.AbstractCvsTask;
import java.io.ByteArrayOutputStream;
import java.util.StringTokenizer;
/**
* this task allows to find out the sticky tag of a given file
*
* example usage :
* <cvsstickytag
* property="thetag"
* taggedFile="build.xml" />
*
* the task can be used also in the API by calling its execute method,
* then calling getStickyTag
*
* @ant.task category="scm"
*/
public class CvsStickyTagTask extends AbstractCvsTask {
private static final String DEFAULT_FILE = "build.xml";
private String stickyTag;
private String property;
private String taggedFile = DEFAULT_FILE;
/**
* get the CVS stick tag
* @return CVS client version
*/
public String getStickyTag() {
return stickyTag;
}
public void setProperty(String property) {
this.property = property;
}
public void setTaggedFile(String taggedFile) {
this.taggedFile = taggedFile;
}
/**
* the execute method running CvsStickyTagTask
*/
public void execute() {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
this.setOutputStream(bos);
ByteArrayOutputStream berr = new ByteArrayOutputStream();
this.setErrorStream(berr);
setCommand("status " + taggedFile);
super.execute();
String output = bos.toString();
StringTokenizer st = new StringTokenizer(output);
while (st.hasMoreTokens()) {
String currentToken = st.nextToken();
if (currentToken.equals("Tag:")) {
if (st.hasMoreTokens()) {
String tmp = st.nextToken();
stickyTag = tmp;
}
break;
}
}
if (property != null) {
getProject().setNewProperty(property, stickyTag);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]