TASSVersion.java
package edu.udel.cis.vsl.tass;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Figures out what version of TASS this is.
*
* There are three elements to the notion of "version of TASS", all strings: the
* version, revision, and date. The version is something like "1.0.2". The
* revision is the revision number from Subversion repository used for this
* build of TASS. It is something like "1832" but may contain additional symbols
* to indicate, for example, that the code has been modified after checking out
* that revision. The date is some representation of the time and date the
* release was made.
*
* Two approaches are taken, depending on whether this is an official release,
* or a development snapshot. For an official release, all 3 elements are
* hard-coded into this class when the release is made. For a snapshot, the
* first element (version) is still hard-coded, but the other two pieces of
* information are extracted from the svn archive using the svnversion and svn
* info commands. These will only work if the code is invoked from the root TASS
* directory.
*
*/
public class TASSVersion {
public static String VERSION = "1.2";
public static String REVISION = null;
public static String DATE = null;
public static String getVersion() {
return VERSION;
}
public static String getRevision() {
if (REVISION != null)
return REVISION;
try {
Process p = Runtime.getRuntime().exec("svnversion -n");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line = reader.readLine();
return line;
} catch (IOException e1) {
return null;
} catch (InterruptedException e2) {
return null;
}
}
public static String getDate() {
if (DATE != null)
return DATE;
try {
Process p = Runtime.getRuntime().exec("svn info");
BufferedReader reader = new BufferedReader(new InputStreamReader(p
.getInputStream()));
String line = reader.readLine();
String result = null;
while (line != null) {
int pos1 = line.indexOf("Date: ");
if (pos1 >= 0) {
pos1 += 6;
int pos2 = line.indexOf(' ', pos1);
if (pos2 >= 0) {
result = line.substring(pos1, pos2);
break;
}
}
line = reader.readLine();
}
p.waitFor();
return result;
} catch (IOException e1) {
return null;
} catch (InterruptedException e2) {
return null;
}
}
public static String getVersionLong() {
return "v" + VERSION + " (r" + getRevision() + ", " + getDate() + ")";
}
/**
* Prints the version string to stdout. To execute: java
* edu.udel.cis.vsl.tass.TASSVersion
*/
public static void main(String[] args) {
System.out.println(getVersionLong());
System.out.flush();
}
}