Skip to content

Commit

Permalink
show build info not only in prod mode
Browse files Browse the repository at this point in the history
  • Loading branch information
enr committed Oct 17, 2012
1 parent b64dc43 commit a5023a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
27 changes: 11 additions & 16 deletions grails-app/taglib/org/chai/buildinfo/BuildInfoTagLib.groovy
Expand Up @@ -23,22 +23,17 @@ class BuildInfoTagLib {
}

def buildInfo = {attrs, body ->
if (GrailsUtil.environment == 'production') {
if (build == null) {
out << "no build info found"
}
else {
out << render(plugin:'buildInfoTag', template:'/templates/buildInfo', model:[
buildDate: build.'app.buildDate',
gitCommit: build.'app.gitCommit',
systemName: build.'app.systemName',
timezone: build.'app.timezone'
])
}
}
else {
out << "no build info in ${GrailsUtil.environment} environment"
}
if (build == null) {
out << "no build info found"
}
else {
out << render(plugin:'buildInfoTag', template:'/templates/buildInfo', model:[
buildDate: build.'app.buildDate',
gitCommit: build.'app.gitCommit',
systemName: build.'app.systemName',
timezone: build.'app.timezone'
])
}
}

}
23 changes: 19 additions & 4 deletions scripts/_Events.groovy
Expand Up @@ -2,8 +2,13 @@ import grails.util.Metadata;

import java.text.SimpleDateFormat;

eventCreateWarStart = { warName, stagingDir ->

// the only way I found to know the trigger.
def triggeredFromRunApp(String message) {
return message?.startsWith("Server running.")
}

def writeBuildInfoFile(path) {
println "Write build info file ${path}"
def formatter = new SimpleDateFormat("ddMMyyyy-HHmmss")
def buildDate = formatter.format(new Date(System.currentTimeMillis()))
buildDate += '-'+Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT)
Expand All @@ -15,13 +20,23 @@ eventCreateWarStart = { warName, stagingDir ->
gitCommit = proc.text
} catch (Exception e) {}

Metadata build = Metadata.getInstance(new File("${stagingDir}/WEB-INF/classes/build.info"));
Metadata build = Metadata.getInstance(new File(path));
build.'app.buildDate' = buildDate
build.'app.gitCommit' = gitCommit
build.'app.systemName' = InetAddress.getLocalHost().getHostName()
build.'app.timezone' = Calendar.getInstance().getTimeZone().getID()
build.persist()

println "Compile Starting on build #${buildDate}, git commit: ${gitCommit}"

}

eventStatusFinal = { message ->
def isRunApp = triggeredFromRunApp(message)
if (isRunApp) {
writeBuildInfoFile("${classesDir}/build.info")
}
}

eventCreateWarStart = { warName, stagingDir ->
writeBuildInfoFile("${stagingDir}/WEB-INF/classes/build.info")
}

0 comments on commit a5023a9

Please sign in to comment.