Skip to content

Commit

Permalink
fix for GRAILS-1503
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.codehaus.org/grails/trunk@5234 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
  • Loading branch information
graeme committed Aug 20, 2007
1 parent 46fcf6c commit 7807699
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 46 deletions.
Binary file modified lib/groovy-all-1.1-beta-3-SNAPSHOT.jar
Binary file not shown.
30 changes: 30 additions & 0 deletions scripts/Bootstrap.groovy
Expand Up @@ -3,6 +3,8 @@ import org.codehaus.groovy.grails.commons.ApplicationAttributes;
import org.codehaus.groovy.grails.commons.GrailsApplication;
import org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator;
import org.springframework.context.ApplicationContext;
import org.codehaus.groovy.grails.plugins.*
import org.springframework.core.io.*
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mock.web.MockServletContext;
Expand All @@ -16,6 +18,34 @@ includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )
task ('default': "This task will load the Grails application context into the command window with a variable named 'ctx'") {
bootstrap()
}

task(loadApp:"Loads the Grails application object") {
def beans = new grails.spring.BeanBuilder().beans {
resourceHolder(org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder) {
resources = "file:${basedir}/**/grails-app/**/*.groovy"
}
grailsResourceLoader(org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean) {
grailsResourceHolder = resourceHolder
}
grailsApplication(org.codehaus.groovy.grails.commons.DefaultGrailsApplication.class, ref("grailsResourceLoader"))
}

appCtx = beans.createApplicationContext()
def ctx = appCtx
ctx.servletContext = new MockServletContext()
grailsApp = ctx.grailsApplication

pluginManager = new DefaultGrailsPluginManager(pluginResources as Resource[], grailsApp)

PluginManagerHolder.setPluginManager(pluginManager)
pluginManager.loadPlugins()
pluginManager.doArtefactConfiguration()
grailsApp.initialise()
}
task(configureApp:"Configures the Grails application and builds an ApplicationContext") {
def config = new org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator(grailsApp,appCtx)
appCtx = config.configure(new MockServletContext())
}

task(bootstrap: "The implementation task") {
depends(classpath)
Expand Down
26 changes: 23 additions & 3 deletions scripts/Console.groovy
Expand Up @@ -23,19 +23,39 @@
*/

import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
import groovy.text.SimpleTemplateEngine
import groovy.text.SimpleTemplateEngine
import org.codehaus.groovy.grails.support.*

Ant.property(environment:"env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"

includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )
includeTargets << new File ( "${grailsHome}/scripts/Package.groovy" )
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )

task ('default': "Load the Grails interactive Swing console") {
depends( checkVersion, configureProxy, packageApp, classpath, packagePlugins )
console()
}

task(console:"The console implementation task") {
Ant.java(classname:"grails.ui.Console", failonerror:true)

rootLoader.addURL(classesDir.toURL())
loadApp()
configureApp()
def b = new Binding()
b.ctx = appCtx
b.grailsApplication = grailsApp
def c = new groovy.ui.Console(grailsApp.classLoader, b)
c.beforeExecution = {
appCtx.getBeansOfType(PersistenceContextInterceptor).each { k,v ->
v.init()
}
}
c.afterExecution = {
appCtx.getBeansOfType(PersistenceContextInterceptor).each { k,v ->
v.flush()
v.destroy()
}
}
c.run()
}
4 changes: 3 additions & 1 deletion scripts/Init.groovy
Expand Up @@ -436,7 +436,9 @@ void setClasspath() {
compConfig = new CompilerConfiguration()
compConfig.setClasspath(cpath.toString());
rootLoader = getClass().classLoader.rootLoader
populateRootLoader(rootLoader, jarFiles)
populateRootLoader(rootLoader, jarFiles)

rootLoader?.addURL(new File("${basedir}/grails-app/conf/hibernate").toURL())
parentLoader = getClass().getClassLoader()
classpathSet = true

Expand Down
28 changes: 23 additions & 5 deletions scripts/Shell.groovy
Expand Up @@ -23,21 +23,39 @@
*/

import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU
import groovy.text.SimpleTemplateEngine
import groovy.text.SimpleTemplateEngine
import org.codehaus.groovy.grails.support.*

Ant.property(environment:"env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"

includeTargets << new File ( "${grailsHome}/scripts/Init.groovy" )
includeTargets << new File ( "${grailsHome}/scripts/Package.groovy" )
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )

task ('default': "Load the Grails interactive shell") {
depends( configureProxy, packageApp, classpath )
shell()
}

task(shell:"The shell implementation task") {
// Ant.java(classname:"grails.ui.InteractiveShell", failonerror:true,
// classpathref:"grails.classpath",fork:true)
Ant.java(classname:"grails.ui.InteractiveShell", failonerror:true)
rootLoader.addURL(classesDir.toURL())
loadApp()
configureApp()
def b = new Binding()
b.ctx = appCtx
b.grailsApplication = grailsApp
def c = new groovy.ui.InteractiveShell(grailsApp.classLoader, b,System.in,System.out,System.err)
c.beforeExecution = {
appCtx.getBeansOfType(PersistenceContextInterceptor).each { k,v ->
v.init()
}
}
c.afterExecution = {
appCtx.getBeansOfType(PersistenceContextInterceptor).each { k,v ->
v.flush()
v.destroy()
}
}
c.run()

}
48 changes: 11 additions & 37 deletions scripts/TestApp.groovy
Expand Up @@ -48,6 +48,7 @@ result = new TestResult()
compilationFailures = []

includeTargets << new File ( "${grailsHome}/scripts/Package.groovy" )
includeTargets << new File ( "${grailsHome}/scripts/Bootstrap.groovy" )

task ('default': "Run a Grails applications unit tests") {
depends( classpath, checkVersion, configureProxy, packagePlugins )
Expand Down Expand Up @@ -184,36 +185,11 @@ def runTests = { suite, TestResult result, Closure callback ->
}
task(runUnitTests:"Run Grails' unit tests under the test/unit directory") {
try {
def classLoader = getClass().classLoader

classLoader.rootLoader.addURL(new File("${basedir}/grails-app/conf/hibernate").toURL())
def beans = new grails.spring.BeanBuilder().beans {
resourceHolder(org.codehaus.groovy.grails.commons.spring.GrailsResourceHolder) {
resources = "file:${basedir}/**/grails-app/**/*.groovy"
}
grailsResourceLoader(org.codehaus.groovy.grails.commons.GrailsResourceLoaderFactoryBean) {
grailsResourceHolder = resourceHolder
}
grailsApplication(org.codehaus.groovy.grails.commons.DefaultGrailsApplication.class, ref("grailsResourceLoader"))
}

appCtx = beans.createApplicationContext()
def ctx = appCtx
ctx.servletContext = new MockServletContext()
grailsApp = ctx.grailsApplication

loadApp()

pluginManager = new DefaultGrailsPluginManager(pluginResources as Resource[], grailsApp)

PluginManagerHolder.setPluginManager(pluginManager)
pluginManager.loadPlugins()
pluginManager.doArtefactConfiguration()
grailsApp.initialise()

pluginManager.getGrailsPlugin("core")?.doWithDynamicMethods(appCtx)
pluginManager.getGrailsPlugin("logging")?.doWithDynamicMethods(appCtx)
pluginManager.getGrailsPlugin("core")?.doWithDynamicMethods(appCtx)
pluginManager.getGrailsPlugin("logging")?.doWithDynamicMethods(appCtx)


def testFiles = resolveTestResources { "test/unit/${it}.groovy" }
testFiles = testFiles.findAll { it.exists() }
if(testFiles.size() == 0) {
Expand Down Expand Up @@ -258,26 +234,24 @@ task(runIntegrationTests:"Runs Grails' tests under the test/integration director
}



def config = new org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator(grailsApp,appCtx)
def ctx = config.configure(new MockServletContext())
def app = ctx.getBean(GrailsApplication.APPLICATION_ID)
configureApp()
def app = appCtx.getBean(GrailsApplication.APPLICATION_ID)
if(app.parentContext == null) {
app.applicationContext = ctx
app.applicationContext = appCtx
}
def classLoader = app.classLoader
def suite = new TestSuite()

populateTestSuite(suite, testFiles, classLoader, ctx)
populateTestSuite(suite, testFiles, classLoader, appCtx)
if(suite.testCount() > 0) {
int testCases = suite.countTestCases()
println "-------------------------------------------------------"
println "Running ${testCases} Integration Test${testCases > 1 ? 's' : ''}..."


def beanNames = ctx.getBeanNamesForType(PersistenceContextInterceptor)
def beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor)
def interceptor = null
if(beanNames.size() > 0)interceptor = ctx.getBean(beanNames[0])
if(beanNames.size() > 0)interceptor = appCtx.getBean(beanNames[0])


try {
Expand All @@ -286,7 +260,7 @@ task(runIntegrationTests:"Runs Grails' tests under the test/integration director
def start = new Date()
runTests(suite, result) { test, invocation ->
name = test.name[0..-6]
def webRequest = GWU.bindMockWebRequest(ctx)
def webRequest = GWU.bindMockWebRequest(appCtx)

// @todo this is horrible and dirty, should find a better way
if(name.endsWith("Controller")) {
Expand Down

0 comments on commit 7807699

Please sign in to comment.