- Timestamp:
- May 14, 2010, 12:13:05 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/AppCoreController.groovy
r521 r531 48 48 if(applicationVcsRevision.size() > 7) { // Svn's $Rev: NUM $ 49 49 applicationVcsRevision = applicationVcsRevision[6..-3] 50 applicationString += " (r " + applicationVcsRevision + ")"50 applicationString += " (rev " + applicationVcsRevision + ")" 51 51 } 52 52 else -
trunk/scripts/_UpdateRev.groovy
r526 r531 4 4 5 5 /** 6 * Compare and update the app.vcsRevision property in application.properties and metadata. 7 * May be run directly by "grails update-rev" or from _Events.groovy by eventCompileStart. 6 * Check and update the app.vcsRevision property in application.properties file and metadata. 7 * May be run directly by `grails update-rev` and normally run by _Events.groovy and eventCompileStart. 8 * The revision in the properties file is checked against the version control system (VCS) revision 9 * and updated if required. 10 * The VCS revision is written to the properties file so that it is available in the compiled war. 11 * The compile is intentionally allowed to go ahead if a handled exception occurs. 12 * VCS currently supported: subversion. 8 13 */ 9 target(updateVcsRevision: " Update the app.vcsRevision property in application.propertiesand metadata.") {14 target(updateVcsRevision: "Check and update the app.vcsRevision property in application.properties file and metadata.") { 10 15 11 16 def result = [:] 12 17 18 // Properties file. 19 def url = basedir + "/application.properties" 20 def propertiesFile = new File(url) 21 13 22 def fail = { Map m -> 23 updateInMemoryMetadata('Unknown') 24 def writeResult = writePropertiesFileRevision(propertiesFile, 'Unknown') 25 if(writeResult.error) { 26 m.code= writeResult.error.code 27 m.args= writeResult.error.args 28 } 29 14 30 result.error = [ code: m.code, args: m.args ] 15 31 println "Error: UpdateRev script: " + result.error … … 17 33 } 18 34 19 def url = basedir + "/application.properties" 35 // Get propertiesFile revision. 36 def properitesFileResult = getPropertiesFileRevision(propertiesFile) 37 if(properitesFileResult.error) 38 return fail(code: properitesFileResult.error.code, args: properitesFileResult.error.args) 20 39 21 def propertiesFile = new File(url) 22 if(!propertiesFile.isFile()) 23 return fail(code:"application.properties.file.not.found", args:[url]) 24 25 def appRevision = getAppRevision(propertiesFile) 26 if(appRevision.error) 27 return fail(code: appRevision.error.code, args: appRevision.error.args) 28 29 def svnRevision = getSvnRevision() 30 if(svnRevision.error) 31 return fail(code: svnRevision.error.code, args: svnRevision.error.args) 40 // Get VCS revision. 41 def vcsResult = getVcsRevision() 42 if(vcsResult.error) 43 return fail(code: vcsResult.error.code, args: vcsResult.error.args) 32 44 33 45 // Compare and update. 34 if( appRevision.revision != svnRevision.revision) {46 if(properitesFileResult.revision != vcsResult.revision) { 35 47 36 println "app.vcsRevision = "+ appRevision.revision +', SVN Revision = '+svnRevision.revision48 println "app.vcsRevision = "+properitesFileResult.revision +', VCS Revision = '+vcsResult.revision 37 49 38 // Update metadata if already loaded. 39 if(binding.variables.containsKey('metadata')) { 40 //binding.variables.each { println it.key } // print available. 41 def metadata = binding.variables['metadata'] 42 metadata['app.vcsRevision'] = '$Rev: '+svnRevision.revision+' $' 43 } 50 updateInMemoryMetadata(vcsResult.revision) 44 51 45 52 // Update application.properties file. 46 def writeResult = write VcsRevision(propertiesFile, svnRevision.revision)53 def writeResult = writePropertiesFileRevision(propertiesFile, vcsResult.revision) 47 54 if(writeResult.error) 48 55 return fail(code: writeResult.error.code, args: writeResult.error.args) … … 50 57 } // if(rev != rev) 51 58 else { 52 println "VCS Revisions match: app.vcsRevision = "+appRevision.revision +', SVN Revision = '+svnRevision.revision +'.'59 println "VCS Revisions match: app.vcsRevision = ${properitesFileResult.revision}, VCS Revision = ${vcsResult.revision}." 53 60 } 54 61 … … 62 69 * @retuns A map containing revision and lineNumber otherwise an error map. 63 70 */ 64 def get AppRevision(propertiesFile) {71 def getPropertiesFileRevision(propertiesFile) { 65 72 def result = [:] 66 73 … … 69 76 return result 70 77 } 78 79 if(!propertiesFile.isFile()) 80 return fail(code:"application.properties.file.not.found", args:[propertiesFile.getAbsoluteFile()]) 71 81 72 82 propertiesFile.eachLine { line, lineNumber -> … … 92 102 * @retuns A map containing revision otherwise an error map. 93 103 */ 94 def get SvnRevision() {104 def getVcsRevision() { 95 105 def result = [:] 96 106 … … 116 126 // Success. 117 127 return result 118 } // getSvnRevision() 128 } // getVcsRevision() 129 130 /** 131 * Update the in memory metadata if already loaded. 132 * Available vars: binding.variables.each { println it.key } 133 */ 134 def updateInMemoryMetadata(revision) { 135 if(binding.variables.containsKey('metadata')) { 136 def metadata = binding.variables['metadata'] 137 metadata['app.vcsRevision'] = '$Rev: '+revision+' $' 138 } 139 } // updateInMemoryMetadata() 119 140 120 141 /** … … 122 143 * @retuns An error map if any errors. 123 144 */ 124 def write VcsRevision(propertiesFile, revision) {145 def writePropertiesFileRevision(propertiesFile, revision) { 125 146 def result = [:] 126 147 … … 130 151 } 131 152 153 if(!propertiesFile.isFile()) 154 return fail(code:"application.properties.file.not.found", args:[propertiesFile.getAbsoluteFile()]) 155 132 156 def revisionString = 'app.vcsRevision=\\$Rev: '+revision+' \\$' 133 println "Updating application.properties with: ${revisionString}"157 println "Updating application.properties file with: ${revisionString}" 134 158 135 159 def processFileInplace = { file, Closure processText -> … … 145 169 return result 146 170 147 } // write VcsRevision()171 } // writePropertiesFileRevision()
Note: See TracChangeset
for help on using the changeset viewer.