Index: trunk/scripts/_UpdateRev.groovy
===================================================================
--- trunk/scripts/_UpdateRev.groovy	(revision 526)
+++ trunk/scripts/_UpdateRev.groovy	(revision 531)
@@ -4,12 +4,28 @@
 
 /**
-* Compare and update the app.vcsRevision property in application.properties and metadata.
-* May be run directly by "grails update-rev" or from _Events.groovy by eventCompileStart.
+* Check and update the app.vcsRevision property in application.properties file and metadata.
+* May be run directly by `grails update-rev` and normally run by _Events.groovy and eventCompileStart.
+* The revision in the properties file is checked against the version control system (VCS) revision
+* and updated if required.
+* The VCS revision is written to the properties file so that it is available in the compiled war.
+* The compile is intentionally allowed to go ahead if a handled exception occurs.
+* VCS currently supported: subversion.
 */
-target(updateVcsRevision: "Update the app.vcsRevision property in application.properties and metadata.") {
+target(updateVcsRevision: "Check and update the app.vcsRevision property in application.properties file and metadata.") {
 
     def result = [:]
 
+    // Properties file.
+    def url = basedir + "/application.properties"
+    def propertiesFile = new File(url)
+
     def fail = { Map m ->
+        updateInMemoryMetadata('Unknown')
+        def writeResult = writePropertiesFileRevision(propertiesFile, 'Unknown')
+        if(writeResult.error) {
+            m.code= writeResult.error.code
+            m.args= writeResult.error.args
+        }
+
         result.error = [ code: m.code, args: m.args ]
         println "Error: UpdateRev script: " + result.error
@@ -17,32 +33,23 @@
     }
 
-    def url = basedir + "/application.properties"
+    // Get propertiesFile revision.
+    def properitesFileResult = getPropertiesFileRevision(propertiesFile)
+    if(properitesFileResult.error)
+        return fail(code: properitesFileResult.error.code, args: properitesFileResult.error.args)
 
-    def propertiesFile = new File(url)
-        if(!propertiesFile.isFile())
-            return fail(code:"application.properties.file.not.found", args:[url])
-
-    def appRevision = getAppRevision(propertiesFile)
-    if(appRevision.error)
-        return fail(code: appRevision.error.code, args: appRevision.error.args)
-
-    def svnRevision = getSvnRevision()
-    if(svnRevision.error)
-        return fail(code: svnRevision.error.code, args: svnRevision.error.args)
+    // Get VCS revision.
+    def vcsResult = getVcsRevision()
+    if(vcsResult.error)
+        return fail(code: vcsResult.error.code, args: vcsResult.error.args)
 
     // Compare and update.
-    if(appRevision.revision != svnRevision.revision) {
+    if(properitesFileResult.revision != vcsResult.revision) {
 
-        println "app.vcsRevision = "+appRevision.revision +', SVN Revision = '+svnRevision.revision
+        println "app.vcsRevision = "+properitesFileResult.revision +', VCS Revision = '+vcsResult.revision
 
-        // Update metadata if already loaded.
-        if(binding.variables.containsKey('metadata')) {
-            //binding.variables.each { println it.key } // print available.
-            def metadata = binding.variables['metadata']
-            metadata['app.vcsRevision'] = '$Rev: '+svnRevision.revision+' $'
-        }
+        updateInMemoryMetadata(vcsResult.revision)
 
         // Update application.properties file.
-        def writeResult = writeVcsRevision(propertiesFile, svnRevision.revision)
+        def writeResult = writePropertiesFileRevision(propertiesFile, vcsResult.revision)
         if(writeResult.error)
             return fail(code: writeResult.error.code, args: writeResult.error.args)
@@ -50,5 +57,5 @@
     } // if(rev != rev)
     else {
-        println "VCS Revisions match: app.vcsRevision = "+appRevision.revision +', SVN Revision = '+svnRevision.revision +'.'
+        println "VCS Revisions match: app.vcsRevision = ${properitesFileResult.revision}, VCS Revision = ${vcsResult.revision}."
     }
 
@@ -62,5 +69,5 @@
 * @retuns A map containing revision and lineNumber otherwise an error map.
 */
-def getAppRevision(propertiesFile) {
+def getPropertiesFileRevision(propertiesFile) {
     def result = [:]
 
@@ -69,4 +76,7 @@
         return result
     }
+
+    if(!propertiesFile.isFile())
+        return fail(code:"application.properties.file.not.found", args:[propertiesFile.getAbsoluteFile()])
 
     propertiesFile.eachLine { line, lineNumber ->
@@ -92,5 +102,5 @@
 * @retuns A map containing revision otherwise an error map.
 */
-def getSvnRevision() {
+def getVcsRevision() {
     def result = [:]
 
@@ -116,5 +126,16 @@
     // Success.
     return result
-} // getSvnRevision()
+} // getVcsRevision()
+
+/** 
+* Update the in memory metadata if already loaded.
+* Available vars: binding.variables.each { println it.key }
+*/
+def updateInMemoryMetadata(revision) {
+    if(binding.variables.containsKey('metadata')) {
+        def metadata = binding.variables['metadata']
+        metadata['app.vcsRevision'] = '$Rev: '+revision+' $'
+    }
+} // updateInMemoryMetadata()
 
 /**
@@ -122,5 +143,5 @@
 * @retuns An error map if any errors.
 */
-def writeVcsRevision(propertiesFile, revision) {
+def writePropertiesFileRevision(propertiesFile, revision) {
     def result = [:]
 
@@ -130,6 +151,9 @@
     }
 
+    if(!propertiesFile.isFile())
+        return fail(code:"application.properties.file.not.found", args:[propertiesFile.getAbsoluteFile()])
+
     def revisionString = 'app.vcsRevision=\\$Rev: '+revision+' \\$'
-    println "Updating application.properties with: ${revisionString}"
+    println "Updating application.properties file with: ${revisionString}"
 
     def processFileInplace = { file, Closure processText ->
@@ -145,3 +169,3 @@
     return result
 
-} // writeVcsRevision()
+} // writePropertiesFileRevision()
