Skip to content

Commit

Permalink
initial version of plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fterrier committed Mar 24, 2012
0 parents commit 44685b0
Show file tree
Hide file tree
Showing 78 changed files with 6,438 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .classpath
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="src" path="test/projects"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="web-app/WEB-INF/classes"/>
</classpath>
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.settings/
*.class
target
*.log
19 changes: 19 additions & 0 deletions .project
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>build-info-tag</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.springsource.sts.grails.core.nature</nature>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
42 changes: 42 additions & 0 deletions BuildInfoTagGrailsPlugin.groovy
@@ -0,0 +1,42 @@
class BuildInfoTagGrailsPlugin {
// the plugin version
def version = "0.1"
// the version or versions of Grails the plugin is designed for
def grailsVersion = "2.0 > *"
// the other plugins this plugin depends on
def dependsOn = [:]
// resources that are excluded from plugin packaging
def pluginExcludes = [
"grails-app/views/error.gsp"
]

def title = "Build Info Tag Plugin" // Headline display name of the plugin
def author = "François Terrier"
def authorEmail = "fterrier@gmail.com"
def description = '''\
Puts a build.info file in the generated WAR file and provides a GSP tag to display
the information in it. For now, the build number is the date and the plugin also
collects the GIT commit number and displays it (won't work on Windows).
'''

// URL to the plugin's documentation
def documentation = "http://grails.org/plugin/build-info-tag"

// Extra (optional) plugin metadata

// License: one of 'APACHE', 'GPL2', 'GPL3'
def license = "APACHE"

// Details of company behind the plugin (if there is one)
def organization = [ name: "CHAI", url: "http://www.clintonhealthaccess.org/" ]

// Any additional developers beyond the author specified above.
// def developers = [ [ name: "Joe Bloggs", email: "joe@bloggs.net" ]]

// Location of the plugin's issue tracker.
// def issueManagement = [ system: "JIRA", url: "http://jira.grails.org/browse/GPMYPLUGIN" ]

// Online location of the plugin's browseable source code.
def scm = [ url: "http://github.com/fterrier/grails-build-info-tag" ]

}
Empty file added README
Empty file.
5 changes: 5 additions & 0 deletions application.properties
@@ -0,0 +1,5 @@
#Grails Metadata file
#Sat Mar 24 13:44:31 CAT 2012
app.grails.version=2.0.0
app.name=build-info-tag
plugins.svn=1.0.1
37 changes: 37 additions & 0 deletions grails-app/conf/BuildConfig.groovy
@@ -0,0 +1,37 @@
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
repositories {
grailsCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//mavenCentral()
//mavenLocal()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.5'
}

plugins {
build(":tomcat:$grailsVersion",
":release:1.0.0") {
export = false
}
}
}
24 changes: 24 additions & 0 deletions grails-app/conf/Config.groovy
@@ -0,0 +1,24 @@
// configuration for plugin testing - will not be included in the plugin zip

log4j = {
// Example of changing the log pattern for the default console
// appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}

error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'

warn 'org.mortbay.log'
}
44 changes: 44 additions & 0 deletions grails-app/taglib/org/chai/buildinfo/BuildInfoTagLib.groovy
@@ -0,0 +1,44 @@
package org.chai.buildinfo

import grails.util.GrailsUtil;
import grails.util.Metadata;

class BuildInfoTagLib {

static namespace = "build"

def grailsApplication

def buildInstance
def buildInitialized = false

def getBuild() {
if (!buildInitialized) {
def resource = grailsApplication.parentContext.getResource("classpath:build.info")
if (resource.exists()) buildInstance = Metadata.getInstance(resource.inputStream)
else buildInstance = null
buildInitialized = true
}
return buildInstance
}

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"
}
}

}
11 changes: 11 additions & 0 deletions grails-app/views/error.gsp
@@ -0,0 +1,11 @@
<!doctype html>
<html>
<head>
<title>Grails Runtime Exception</title>
<meta name="layout" content="main">
<link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css">
</head>
<body>
<g:renderException exception="${exception}" />
</body>
</html>
9 changes: 9 additions & 0 deletions grails-app/views/templates/_buildInfo.gsp
@@ -0,0 +1,9 @@
${grailsApplication.metadata['app.name']}
${grailsApplication.metadata['app.version']}

Build ${buildDate}
Git ${gitCommit}

<!-- System ${systemName} -->
<!-- Timezone ${timezone} -->

28 changes: 28 additions & 0 deletions plugin.xml
@@ -0,0 +1,28 @@
<plugin name='build-info-tag' version='0.1' grailsVersion='2.0.0 &gt; *'>
<author>François Terrier</author>
<authorEmail>fterrier@gmail.com</authorEmail>
<title>Build Info Tag Plugin</title>
<description>Puts a build.info file in the generated WAR file and provides a GSP tag to display
the information in it. For now, the build number is the date and the plugin also
collects the GIT commit number and displays it (won't work on Windows).
</description>
<documentation>http://grails.org/plugin/build-info-tag</documentation>
<type>BuildInfoTagGrailsPlugin</type>
<resources>
<resource>org.chai.buildinfo.BuildInfoTagLib</resource>
</resources>
<repositories />
<dependencies />
<plugins>
<runtime>
<plugin group='org.grails.plugins' name='resources' version='1.1.5' />
<plugin group='org.grails.plugins' name='hibernate' version='2.0.0' />
<plugin group='org.grails.plugins' name='jquery' version='1.7.1' />
</runtime>
<build>
<plugin group='org.grails.plugins' name='tomcat' version='2.0.0' />
</build>
</plugins>
<runtimePluginRequirements />
<behavior />
</plugin>
27 changes: 27 additions & 0 deletions scripts/_Events.groovy
@@ -0,0 +1,27 @@
import grails.util.Metadata;

import java.text.SimpleDateFormat;

eventCreateWarStart = { warName, stagingDir ->

def formatter = new SimpleDateFormat("ddMMyyyy-HHmmss")
def buildDate = formatter.format(new Date(System.currentTimeMillis()))
buildDate += '-'+Calendar.getInstance().getTimeZone().getDisplayName(false, TimeZone.SHORT)

def gitCommit = ''
try {
// TODO make it platform independant
def proc = "git rev-parse HEAD".execute()
gitCommit = proc.text
} catch (Exception e) {}

Metadata build = Metadata.getInstance(new File("${stagingDir}/WEB-INF/classes/build.info"));
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}"

}
14 changes: 14 additions & 0 deletions test/projects/test-build-info/.classpath
@@ -0,0 +1,14 @@
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="com.springsource.sts.grails.core.CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="web-app/WEB-INF/classes"/>
</classpath>
19 changes: 19 additions & 0 deletions test/projects/test-build-info/.project
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>test-build-info</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.springsource.sts.grails.core.nature</nature>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
6 changes: 6 additions & 0 deletions test/projects/test-build-info/application.properties
@@ -0,0 +1,6 @@
#Grails Metadata file
#Sat Mar 24 15:37:03 CAT 2012
app.grails.version=2.0.0
app.name=test-build-info
app.servlet.version=2.5
app.version=0.1
@@ -0,0 +1,5 @@
modules = {
application {
resource url:'js/application.js'
}
}
@@ -0,0 +1,7 @@
class BootStrap {

def init = { servletContext ->
}
def destroy = {
}
}
48 changes: 48 additions & 0 deletions test/projects/test-build-info/grails-app/conf/BuildConfig.groovy
@@ -0,0 +1,48 @@
grails.servlet.version = "2.5" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
//grails.project.war.file = "target/${appName}-${appVersion}.war"

grails.plugin.location.'build-info-tag' = "../../.."

grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve

repositories {
inherits true // Whether to inherit repository definitions from plugins
grailsPlugins()
grailsHome()
grailsCentral()
mavenCentral()

// uncomment these to enable remote dependency resolution from public Maven repositories
//mavenCentral()
//mavenLocal()
//mavenRepo "http://snapshots.repository.codehaus.org"
//mavenRepo "http://repository.codehaus.org"
//mavenRepo "http://download.java.net/maven/2/"
//mavenRepo "http://repository.jboss.com/maven2/"
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

// runtime 'mysql:mysql-connector-java:5.1.16'
}

plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.5"

build ":tomcat:$grailsVersion"
}
}

0 comments on commit 44685b0

Please sign in to comment.