Version Differences for Stamping

(AHPSCRIPTS-6)
Line 33:
       
  stampContext.put("timestamp", ""+stamp);</pre>    stampContext.put("timestamp", ""+stamp);</pre> 
       
    + = Perforce: Read File From Depot Without Syncing and Parse Using Regex =  
    + This script will read a file from the Perforce depot without syncing, and will parse it on a line-by-line basis, using regex matching to get values.  
    + ==== AHPSCRIPTS-31 ====  
    + <pre>import java.io.*;  
    + import java.util.*;  
    + import java.util.regex.*;  
       
    + org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger("script");  
    + /*  
    + Two possible paths:  
    + Release Branch:  
    + //depot/R99/mtt/version.inc  
    + FeatureSet (Development) Branch:  
    + //depot/projects/FS/FS00999/mtt/version.inc  
    + And the name of the AntHill project will be the branch name  
    + */  
    + String sProjectName = (String)ProjectLookup.getCurrent().getName();  
    + String depotPath = "//depot/";  
    + if (sProjectName.matches("\\s*R\\d+.*")) {  
    + depotPath += sProjectName;  
    + }  
    + else if (sProjectName.matches("\\s*FS\\d+.*")) {  
    + depotPath += "projects/FS/" + sProjectName;  
    + }  
    + depotPath += "/mtt/version.inc";  
       
    + //Use exec of "p4 print" to read file directly from depot server to stdout  
    + String[] cmdarray = {  
    + "p4.exe",  
    + "-Q", "winansi",  
    + "-C", "utf16le-bom",  
    + "-p", "server:9999",  
    + "-u", "account",  
    + "-P", "password",  
    + "print",  
    + depotPath};  
       
    + log.warn("Calling command: " + Arrays.toString(cmdarray));  
       
    + Runtime runtime = Runtime.getRuntime();  
    + Process process = runtime.exec(cmdarray);  
    + InputStream is = process.getInputStream();  
    + InputStreamReader isr = new InputStreamReader(is);  
    + BufferedReader br = new BufferedReader(isr);  
       
    + //Parse lines from file looking for WebRelease and Hotfix values  
    + Pattern webrelPattern  
    + = Pattern.compile("^\\s*CURRENT_WEBREL\\s*=\\s*([0-9]+)");  
    + Pattern hotfixPattern  
    + = Pattern.compile("^\\s*BUILD_HOTFIX_VERSION\\s*=\\s*([0-9]+)");  
       
    + String line; String sWebRel; String sHotFix;  
    + while ((line = br.readLine()) != null) {  
    + Matcher webrelMatch = webrelPattern.matcher(line);  
    + Matcher hotfixMatch = hotfixPattern.matcher(line);  
    + if (webrelMatch.matches()) {  
    + sWebRel = (String)webrelMatch.group(1);  
    + log.warn("WebRel = " + sWebRel);  
    + }  
    + if (hotfixMatch.matches()) {  
    + sHotFix = (String)hotfixMatch.group(1);  
    + log.warn("HotFix = " + sHotFix);  
    + }  
    + }  
       
    + String value = "NF";  
    + if ((null != sWebRel) && (null != sHotFix)) {  
    + value = sWebRel + "_" + sHotFix;  
    + }  
       
    + stampContext.put("Revision", "" + value);</pre>