edvinasbartkus / grails-coffeescript-resources

Another CoffeeScript compiler for Grails
Other
20 stars 10 forks source link

Crash when deployed as a war #6

Closed jfaissolle closed 12 years ago

jfaissolle commented 12 years ago

Hello,

when I deploy my application as a war in Tomcat, the plugin tries to compile the coffee sources during the spring configuration phase (because of the code in doWithApplicationContext). This breaks because the source path is not found in this environment. I think that script compilation should not be part of Spring initialization.

I currently use the following workaround / hack in order to be able to use the plugin in dev as well as in prod mode.

scripts/_Events.groovy

import grails.util.GrailsUtil
import grails.util.Environment

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH

eventCompileEnd = { source ->
    if (Environment.current == Environment.PRODUCTION) {
        def moduleManageClass = classLoader.loadClass("org.grails.plugins.coffeescript.ModuleManager")

        def config = new ConfigObject()
        config.merge(new ConfigSlurper(GrailsUtil.environment).parse(classLoader.loadClass('Config')))
        CH.setConfig(config)

        moduleManageClass.newInstance().compileModules()
    }
}

grails-app/conf/spring/resources.groovy

import grails.util.Environment
// Place your Spring DSL code here

// Place your Spring DSL code here
beans = {

    // HACK
    if (Environment.current == Environment.PRODUCTION) {
        org.grails.plugins.coffeescript.ModuleManager.metaClass.compileModules = { ->
            println 'Coffee compilation deactivated'
        }
    }
    // -HACK
}
splix commented 12 years ago

Same issue. Even for grails run-war

It works well without new ModuleManager().compileModules() in doWithApplicationContext. And as I see, all other resources plugins don't do anything in doWithApplicationContext (most of them have empty method). It's really not a spring configuration.

So, maybe it's better to remove this lines?

edvinasbartkus commented 12 years ago

With the latest version you can add coffee script resources to resource plugin modules. No problems running the war there :-)