KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > ant > taskdefs > CVSVersionTask


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant.ant.taskdefs;
8
9
10 import java.io.File JavaDoc;
11 import java.io.FileNotFoundException JavaDoc;
12 import java.io.FileReader JavaDoc;
13 import java.io.IOException JavaDoc;
14
15 import org.apache.tools.ant.BuildException;
16 import org.apache.tools.ant.Task;
17
18
19 /**
20  * <p>
21  * This task is used to find the DC version using CVS. I have
22  * to assume that this task is run from somewhere where a CVS
23  * directory exists. This should always be true.
24  * </p>
25  *
26  * @author Brian Pontarelli
27  */

28 public class CVSVersionTask extends Task {
29
30     private String JavaDoc property;
31
32
33     /**
34      * Sets the name of the property which will contain the version.
35      *
36      * @param property The property's name
37      */

38     public void setProperty(String JavaDoc property) {
39         this.property = property;
40     }
41
42
43     /**
44      * Executes the lookup of the version.
45      *
46      * @throws org.apache.tools.ant.BuildException
47      */

48     public void execute() throws BuildException {
49         File JavaDoc file = new File JavaDoc("CVS/Tag");
50         if (file.exists() && file.isFile()) {
51
52             // Read the contents of the file into a String
53
StringBuffer JavaDoc buf = new StringBuffer JavaDoc(16);
54             try {
55                 FileReader JavaDoc reader = new FileReader JavaDoc(file);
56                 int ch = reader.read();
57                 while (ch != -1) {
58                     buf.append((char) ch);
59                     ch = reader.read();
60                 }
61             } catch (FileNotFoundException JavaDoc e) {
62                 throw new BuildException(e);
63             } catch (IOException JavaDoc ioe) {
64                 throw new BuildException(ioe);
65             }
66
67             String JavaDoc tag = buf.toString().trim();
68             getProject().setProperty(property, tag.substring(1));
69         } else {
70             getProject().setProperty(property, "0.0.0");
71         }
72     }
73 }
74
Popular Tags