Permalink
Browse files

upgrade to grails 2.0

add test project
change auto-test script to only run "affected" tests by default, will add option to run entire suite
  • Loading branch information...
1 parent 575bdca commit 55d2bf97f8365464c474ac0ff978e769ff69c1ca Mike Hugo committed Jan 31, 2012
Showing with 2,901 additions and 11,552 deletions.
  1. +8 −0 .gitignore
  2. +5 −36 AutoTestGrailsPlugin.groovy
  3. +2 −6 application.properties
  4. +26 −0 grails-app/conf/BuildConfig.groovy
  5. 0 grails-app/i18n/messages.properties
  6. BIN grails-auto-test-0.1.zip
  7. +0 −19 plugin.xml
  8. +56 −151 scripts/AutoTest.groovy
  9. +0 −10 scripts/_Install.groovy
  10. +0 −5 scripts/_Uninstall.groovy
  11. +0 −10 scripts/_Upgrade.groovy
  12. +14 −0 test/project/bookstore/.classpath
  13. +19 −0 test/project/bookstore/.project
  14. +3 −0 test/project/bookstore/.settings/org.codehaus.groovy.eclipse.preferences.prefs
  15. +6 −0 test/project/bookstore/application.properties
  16. +5 −0 test/project/bookstore/grails-app/conf/ApplicationResources.groovy
  17. +7 −0 test/project/bookstore/grails-app/conf/BootStrap.groovy
  18. +49 −0 test/project/bookstore/grails-app/conf/BuildConfig.groovy
  19. +93 −0 test/project/bookstore/grails-app/conf/Config.groovy
  20. +43 −0 test/project/bookstore/grails-app/conf/DataSource.groovy
  21. +13 −0 test/project/bookstore/grails-app/conf/UrlMappings.groovy
  22. +3 −0 test/project/bookstore/grails-app/conf/spring/resources.groovy
  23. +10 −0 test/project/bookstore/grails-app/domain/bookstore/Book.groovy
  24. +55 −0 test/project/bookstore/grails-app/i18n/messages.properties
  25. +55 −0 test/project/bookstore/grails-app/i18n/messages_cs_CZ.properties
  26. +56 −0 test/project/bookstore/grails-app/i18n/messages_da.properties
  27. +55 −0 test/project/bookstore/grails-app/i18n/messages_de.properties
  28. +55 −0 test/project/bookstore/grails-app/i18n/messages_es.properties
  29. +19 −0 test/project/bookstore/grails-app/i18n/messages_fr.properties
  30. +19 −0 test/project/bookstore/grails-app/i18n/messages_it.properties
  31. +55 −0 test/project/bookstore/grails-app/i18n/messages_ja.properties
  32. +55 −0 test/project/bookstore/grails-app/i18n/messages_nl.properties
  33. +59 −0 test/project/bookstore/grails-app/i18n/messages_pt_BR.properties
  34. +34 −0 test/project/bookstore/grails-app/i18n/messages_pt_PT.properties
  35. +31 −0 test/project/bookstore/grails-app/i18n/messages_ru.properties
  36. +55 −0 test/project/bookstore/grails-app/i18n/messages_sv.properties
  37. +55 −0 test/project/bookstore/grails-app/i18n/messages_th.properties
  38. +18 −0 test/project/bookstore/grails-app/i18n/messages_zh_CN.properties
  39. +11 −0 test/project/bookstore/grails-app/views/error.gsp
  40. +116 −0 test/project/bookstore/grails-app/views/index.gsp
  41. +28 −0 test/project/bookstore/grails-app/views/layouts/main.gsp
  42. +15 −0 test/project/bookstore/test/unit/bookstore/BookTests.groovy
  43. +33 −0 test/project/bookstore/web-app/WEB-INF/applicationContext.xml
  44. +14 −0 test/project/bookstore/web-app/WEB-INF/sitemesh.xml
  45. +550 −0 test/project/bookstore/web-app/WEB-INF/tld/grails.tld
  46. +311 −0 test/project/bookstore/web-app/WEB-INF/tld/spring.tld
  47. +109 −0 test/project/bookstore/web-app/css/errors.css
  48. +585 −0 test/project/bookstore/web-app/css/main.css
  49. +82 −0 test/project/bookstore/web-app/css/mobile.css
  50. BIN test/project/bookstore/web-app/images/apple-touch-icon-retina.png
  51. BIN test/project/bookstore/web-app/images/apple-touch-icon.png
  52. BIN test/project/bookstore/web-app/images/favicon.ico
  53. BIN { → test/project/bookstore}/web-app/images/grails_logo.jpg
  54. BIN { → test/project/bookstore}/web-app/images/grails_logo.png
  55. BIN { → test/project/bookstore}/web-app/images/leftnav_btm.png
  56. BIN { → test/project/bookstore}/web-app/images/leftnav_midstretch.png
  57. BIN { → test/project/bookstore}/web-app/images/leftnav_top.png
  58. BIN { → test/project/bookstore}/web-app/images/skin/database_add.png
  59. BIN { → test/project/bookstore}/web-app/images/skin/database_delete.png
  60. BIN { → test/project/bookstore}/web-app/images/skin/database_edit.png
  61. BIN { → test/project/bookstore}/web-app/images/skin/database_save.png
  62. BIN { → test/project/bookstore}/web-app/images/skin/database_table.png
  63. BIN { → test/project/bookstore}/web-app/images/skin/exclamation.png
  64. BIN { → test/project/bookstore}/web-app/images/skin/house.png
  65. BIN { → test/project/bookstore}/web-app/images/skin/information.png
  66. BIN { → test/project/bookstore}/web-app/images/skin/shadow.jpg
  67. BIN { → test/project/bookstore}/web-app/images/skin/sorted_asc.gif
  68. BIN { → test/project/bookstore}/web-app/images/skin/sorted_desc.gif
  69. BIN { → test/project/bookstore}/web-app/images/spinner.gif
  70. BIN { → test/project/bookstore}/web-app/images/springsource.png
  71. +9 −0 test/project/bookstore/web-app/js/application.js
  72. +0 −267 web-app/css/main.css
  73. BIN web-app/images/favicon.ico
  74. +0 −13 web-app/js/application.js
  75. +0 −7 web-app/js/prototype/animation.js
  76. +0 −136 web-app/js/prototype/builder.js
  77. +0 −965 web-app/js/prototype/controls.js
  78. +0 −974 web-app/js/prototype/dragdrop.js
  79. +0 −1,122 web-app/js/prototype/effects.js
  80. +0 −4,184 web-app/js/prototype/prototype.js
  81. +0 −2,691 web-app/js/prototype/rico.js
  82. +0 −58 web-app/js/prototype/scriptaculous.js
  83. +0 −275 web-app/js/prototype/slider.js
  84. +0 −55 web-app/js/prototype/sound.js
  85. +0 −568 web-app/js/prototype/unittest.js
View
@@ -0,0 +1,8 @@
+AutoTest.iml
+AutoTest.ipr
+AutoTest.iws
+test/project/bookstore/stacktrace.log
+test/project/bookstore/target/
+test/project/bookstore/web-app/WEB-INF/tld/c.tld
+test/project/bookstore/web-app/WEB-INF/tld/fmt.tld
+.DS_Store
@@ -1,50 +1,19 @@
class AutoTestGrailsPlugin {
- // the plugin version
- def version = "0.1"
- // the version or versions of Grails the plugin is designed for
- def grailsVersion = "1.2.1 > *"
- // the other plugins this plugin depends on
+ def version = "1.0"
+ def grailsVersion = "2.0.0 > *"
def dependsOn = [:]
- // resources that are excluded from plugin packaging
+
def pluginExcludes = [
"grails-app/views/error.gsp"
]
- // TODO Fill in these fields
- def author = "Bjoern Wilmsmann"
- def authorEmail = "bjoern@metasieve.com"
+ def author = "Bjoern Wilmsmann, Mike Hugo"
+ def authorEmail = "bjoern@metasieve.com, mike@piragua.com"
def title = "Auto test plugin"
def description = '''\\
Auto test plugin.
'''
- // URL to the plugin's documentation
def documentation = "http://grails.org/plugin/auto-test"
- def doWithSpring = {
- // TODO Implement runtime spring config (optional)
- }
-
- def doWithApplicationContext = { applicationContext ->
- // TODO Implement post initialization spring config (optional)
- }
-
- def doWithWebDescriptor = { xml ->
- // TODO Implement additions to web.xml (optional)
- }
-
- def doWithDynamicMethods = { ctx ->
- // TODO Implement registering dynamic methods to classes (optional)
- }
-
- def onChange = { event ->
- // TODO Implement code that is executed when any artefact that this plugin is
- // watching is modified and reloaded. The event contains: event.source,
- // event.application, event.manager, event.ctx, and event.plugin.
- }
-
- def onConfigChange = { event ->
- // TODO Implement code that is executed when the project configuration changes.
- // The event is the same as for 'onChange'.
- }
}
View
@@ -1,6 +1,2 @@
-#Grails Metadata file
-#Sun Mar 14 18:30:35 CET 2010
-app.grails.version=1.2.1
-app.name=AutoTest
-plugins.hibernate=1.2.1
-plugins.tomcat=1.2.1
+app.grails.version=2.0.0
+app.name=AutoTest
@@ -0,0 +1,26 @@
+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()
+ mavenCentral()
+ }
+ dependencies {
+ test ('commons-io:commons-io:1.2'){
+ export = false
+ }
+ }
+
+ plugins {
+ }
+}
No changes.
View
Binary file not shown.
View
@@ -1,19 +0,0 @@
-<plugin name='auto-test' version='0.1' grailsVersion='1.2.1 &gt; *'>
- <author>Bjoern Wilmsmann</author>
- <authorEmail>bjoern@metasieve.com</authorEmail>
- <title>Auto test plugin</title>
- <description>\
-Auto test plugin.
-</description>
- <documentation>http://grails.org/plugin/auto-test</documentation>
- <resources>
- <resource>DataSource</resource>
- <resource>UrlMappings</resource>
- </resources>
- <dependencies>
- <resolvers>
- <resolver type='grailsPlugins' name='grailsPlugins' />
- </resolvers>
- </dependencies>
- <behavior />
-</plugin>
View
@@ -1,166 +1,71 @@
-import org.codehaus.groovy.grails.plugins.PluginManagerHolder
+import grails.build.logging.GrailsConsole
+import groovy.transform.Synchronized
+import org.apache.commons.io.monitor.FileAlterationListenerAdaptor
+import org.apache.commons.io.monitor.FileAlterationMonitor
+import org.apache.commons.io.monitor.FileAlterationObserver
+import org.codehaus.groovy.grails.cli.GrailsScriptRunner
+import org.codehaus.groovy.grails.cli.interactive.InteractiveMode
+
+includeTargets << grailsScript("_GrailsSettings")
+includeTargets << grailsScript("_GrailsTest")
+includeTargets << grailsScript("_GrailsCompile")
-scriptEnv = 'test'
+target(default: "autotest") {
-includeTargets << grailsScript("_GrailsArgParsing")
-includeTargets << grailsScript("_GrailsClean")
-includeTargets << grailsScript("_GrailsCompile")
-includeTargets << grailsScript("_GrailsInit")
-includeTargets << grailsScript("_GrailsPackage")
-includeTargets << grailsScript("_GrailsTest")
+ File baseProjectDirectory = new File(basedir)
+ long interval = 2000
+ FileListener listener = new FileListener()
-TEST_PHASE_AND_TYPE_SEPARATOR = ':'
-
-recompileFrequency = System.getProperty("recompile.frequency")
-recompileFrequency = recompileFrequency ? recompileFrequency.toInteger() : 3
-
-target(main: "Auto test") {
- depends(checkVersion,
- configureProxy,
- parseArguments,
- cleanTestReports,
- packageApp)
-
- // The test targeting patterns
- def testTargeters = []
-
- // The params that target a phase and/or type
- def phaseAndTypeTargeters = []
-
- // Separate the type/phase targeters from the test targeters
- argsMap["params"].each {
- def destination = it.contains(TEST_PHASE_AND_TYPE_SEPARATOR) ? phaseAndTypeTargeters : testTargeters
- destination << it
- }
+ FileAlterationObserver observer = new FileAlterationObserver(baseProjectDirectory);
+ observer.addListener(listener)
+ observer.initialize()
- // If we are targeting tests, set testNames (from _GrailsTest)
- if (testTargeters) testNames = testTargeters
-
- // treat pre 1.2 phase targeting args as '«phase»:' for backwards compatibility
- ["unit", "integration", "functional", "other"].each {
- if (argsMap[it]) {
- phaseAndTypeTargeters << "${it}${TEST_PHASE_AND_TYPE_SEPARATOR}"
- argsMap.remove(it) // these are not test "options"
- }
+ GrailsConsole.getInstance().updateStatus "listening for changes to directory ${baseProjectDirectory}"
+
+ FileAlterationMonitor monitor = new FileAlterationMonitor(interval);
+ monitor.addObserver(observer);
+ monitor.start();
+
+}
+class FileListener extends FileAlterationListenerAdaptor {
+ Set testsToRun = []
+
+ @Synchronized
+ void onFileChange(File file) {
+ addTestName(file)
}
-
- // process the phaseAndTypeTargeters, populating the targetPhasesAndTypes map from _GrailsTest
- phaseAndTypeTargeters.each {
- def parts = it.split(TEST_PHASE_AND_TYPE_SEPARATOR, 2)
- def targetPhase = parts[0] ?: TEST_PHASE_WILDCARD
- def targetType = parts[1] ?: TEST_TYPE_WILDCARD
-
- if (!targetPhasesAndTypes.containsKey(targetPhase)) targetPhasesAndTypes[targetPhase] = []
- targetPhasesAndTypes[targetPhase] << targetType
+
+ @Override
+ void onFileCreate(File file) {
+ addTestName(file)
}
-
- // Any switch style args are "test options" (from _GrailsTest)
- argsMap.each {
- if (it.key != 'params') {
- testOptions[it.key] = it.value
+
+ private addTestName(File file) {
+ if (file.name.endsWith('.groovy') || file.name.endsWith('.java')) {
+ String test = file.name.replaceAll(/.groovy|.java/, '').replaceAll(/Tests\z|Test\z|Spec\z/, '')
+ testsToRun << test
}
}
- if (argsMap["xml"]) {
- reportFormats = [ "xml" ]
- createTestReports = false
- }
- else {
- createTestReports = !argsMap["no-reports"]
- }
+ @Override
+ @Synchronized
+ void onStop(FileAlterationObserver observer) {
+ if (testsToRun) {
+ String command = "test-app ${testsToRun.join(' ')}"
+ GrailsConsole.getInstance().updateStatus("${testsToRun.size()} files modified, running test-app command with: ${command}")
- reRunTests = argsMap["rerun"]
-
- // run tests
- allTests()
-
- println '---------------------'
- println 'Auto Test is running.'
- println '---------------------'
-
- Long lastModified = new Date().time
- Boolean autoRecompile = true
- Boolean keepRunning = true
-
- while (keepRunning) {
- if (autoRecompile) {
- lastModified = checkModificationTime(lastModified) {
- try {
- cleanTestReports()
- compile()
-
- Thread currentThread = Thread.currentThread()
- classLoader = new URLClassLoader([classesDir.toURI().toURL()] as URL[], rootLoader)
- currentThread.setContextClassLoader classLoader
- PluginManagerHolder.pluginManager = null
-
- // reload plugins
- loadPlugins()
-
- // run tests
- allTests()
-
- println '--------------------------------'
- println 'Tests run. Auto Test is running.'
- println '--------------------------------'
- } catch (Throwable e) {
- logError("Error running tests", e)
- exit(1)
- }
- }
- }
- sleep(recompileFrequency * 1000)
- }
-}
+ def parser = GrailsScriptRunner.getCommandLineParser()
+ def commandLine = parser.parseString(command)
+ InteractiveMode.current.scriptRunner.executeScriptWithCaching(commandLine)
-setDefaultTarget(main)
-
-private checkModificationTime(def lastModified, def callback) {
- def foldersToCheck = [ "${basedir}/grails-app",
- "${basedir}/test",
- "${basedir}/src"]
-
- def tmp = lastModified
- foldersToCheck.each { folderName ->
- def folder = new File(folderName)
- folder.eachDir { file ->
- def fileModificationTime = checkFileModificationTime(file, tmp)
-
- if (fileModificationTime > tmp) {
- tmp = fileModificationTime
- }
- }
- }
-
- if(lastModified < tmp) {
- try {
- callback()
- }
- catch(Exception e) {
- logError("Error automatically running tests", e)
+ testsToRun = []
}
}
- lastModified = tmp
- return lastModified
-}
+ @Override
+ void onStart(FileAlterationObserver observer) {
+ testsToRun = []
+ }
-private checkFileModificationTime(def file, def tmp) {
- def fileModificationTime
-
- if (file.isDirectory()) {
- for (nestedFile in file.listFiles()) {
- fileModificationTime = checkFileModificationTime(nestedFile, tmp)
- if (fileModificationTime > tmp) {
- return fileModificationTime
- }
- }
- }
-
- fileModificationTime = file.lastModified()
- if (fileModificationTime > tmp) {
- tmp = fileModificationTime
- }
-
- return tmp
-}
+
+}
View
@@ -1,10 +0,0 @@
-//
-// This script is executed by Grails after plugin was installed to project.
-// This script is a Gant script so you can use all special variables provided
-// by Gant (such as 'baseDir' which points on project base dir). You can
-// use 'ant' to access a global instance of AntBuilder
-//
-// For example you can create directory under project tree:
-//
-// ant.mkdir(dir:"${basedir}/grails-app/jobs")
-//
@@ -1,5 +0,0 @@
-//
-// This script is executed by Grails when the plugin is uninstalled from project.
-// Use this script if you intend to do any additional clean-up on uninstall, but
-// beware of messing up SVN directories!
-//
View
@@ -1,10 +0,0 @@
-//
-// This script is executed by Grails during application upgrade ('grails upgrade'
-// command). This script is a Gant script so you can use all special variables
-// provided by Gant (such as 'baseDir' which points on project base dir). You can
-// use 'ant' to access a global instance of AntBuilder
-//
-// For example you can create directory under project tree:
-//
-// ant.mkdir(dir:"${basedir}/grails-app/jobs")
-//
@@ -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>
Oops, something went wrong.

0 comments on commit 55d2bf9

Please sign in to comment.