oyvinmar / grails-closure-compiler

Grails Resources Plugin for Google Closure Compiler
Other
7 stars 6 forks source link

Added configuration for closure compiler options (both global and per file) #2

Closed madchicken closed 12 years ago

madchicken commented 12 years ago

This allows to add compiler options in the configuration. I also used default resource mapper config object to adhere other plugin standard.

Now it's possible to add custom compiler configuration by adding them to the configuration:

grails.resources.mappers.googleclosurecompiler.compilation_level = 'SIMPLE_OPTIMIZATIONS'
grails.resources.mappers.googleclosurecompiler.compilerOptions = [
    languageIn: CompilerOptions.LanguageMode.ECMASCRIPT5
]

If you want specify compiler options for a single file, it can be done using the attrs map in the ApplicationResource file:

resource url: 'js/ember.js', attrs: [googlecompiler: [languageIn: CompilerOptions.LanguageMode.ECMASCRIPT5]]
oyvinmar commented 12 years ago

Looks good, but I have trouble getting the changes to work with the provided compilerOptions. I get this error in my test project:

012-10-31 20:07:43,579 [localhost-startStop-1] ERROR plugins.DefaultGrailsPluginManager  - Error configuring dynamic methods for plugin [resources:1.2-RC1]: Cannot cast object '{}' with class 'groovy.util.ConfigObject' to class 'com.google.javascript.jscomp.CompilerOptions$LanguageMode' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.google.javascript.jscomp.CompilerOptions$LanguageMode(groovy.util.ConfigObject)
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '{}' with class 'groovy.util.ConfigObject' to class 'com.google.javascript.jscomp.CompilerOptions$LanguageMode' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.google.javascript.jscomp.CompilerOptions$LanguageMode(groovy.util.ConfigObject)
    at org.grails.plugin.gccresources.GoogleClosureCompilerResourceMapper$_map_closure1.doCall(GoogleClosureCompilerResourceMapper.groovy:35)
    at org.grails.plugin.gccresources.GoogleClosureCompilerResourceMapper.map(GoogleClosureCompilerResourceMapper.groovy:33)
    at org.grails.plugin.resource.mapper.ResourceMapper.invoke(ResourceMapper.groovy:139)
.....

When i use the following CompilerOption it works fine:

prettyPrint: true

Any ideas why it is causing an error?

madchicken commented 12 years ago

Uhm, I can't reproduce the issue: just tried both with:

grails.resources.mappers.googleclosurecompiler.compilerOptions = [ prettyPrint: true ]

and

grails.resources.mappers.googleclosurecompiler.compilerOptions.prettyPrint =  true

and it works as expected. Did you use another syntax?

oyvinmar commented 12 years ago

Maybe it wasn't entirely clear. It's when I use the example you provided it fails for me (the prettyPrint option works):

grails.resources.mappers.googleclosurecompiler.compilerOptions = [
    languageIn: CompilerOptions.LanguageMode.ECMASCRIPT5
]
madchicken commented 12 years ago

Really don't know: the config pasted is the same I'm using for a project I'm currently developing. Maybe a missing import in Config.groovy? You should have

import com.google.javascript.jscomp.CompilerOptions

in the beginning of the file.

oyvinmar commented 12 years ago

Yeah, that solved the issue :P

Thanks for the contribution!

I'll try to release the updated plugin to the grails repo within the week.