I'm currently a little bit unhappy with the code generation support for example
grails create-domain-class.
For a simple project the current code generation is sufficent, but for more real world projects which will be organized in plugins, the current code generation is not nice.
I need copyright, User name a.s.o. on level grails project/plugin. Some of the projects will be open source, others closed source or different customers. So currently there is a lot of
DRY-violation.
br>
My
suggestions:
-
Exchange the simple ant replacement in _GrailsCreateArtifact.groovy (ant.replace(... "@artifact.name@", ...)) with a template engine, i.e. Velocity.
- Additional values like license, copyright, creational date, creator could be set by something like GRAILS_OPT or set within special grails file (i.e. .options) within the project root included as -D list.
I would be fancy about three levels:
-
in the project itself (most specific): extends or overwrite parent directory .options if exists OR $HOME/.grails/.options if exists
-
in the parent directory above the grails projects (less specific) : extends $HOME/.grails/.options if exists
- within the $HOME/.grails directory
- If the old templates has been installed ($PRJOJECT_HOME/src/templates/artifacts) , the old one should be taken. But if new templates (extension .vm) has been installed these should be taken.
- There is variable point to the template directory, for example:
-Dgrails.template.dir=$PROJECT_PATH/templates. This give total flexibility which project(s) should use which templates. If this environment variable has been provided grails install-templates uses this environment variable for creating project specific templates or copy the templates from GRAILS_HOME.
- It would be nice to add values for replacement like:
- year of creation. Using for (c) 2009
- Date format for creational date timestamp.
- Filename in lower, upper case and the camel case name with and without extension
- Artifact name in lower, upper case and the camel name
Examples:
1. Content of .options
GRAILS_OPT="-grails.template.dir=D$HOME/.grails/templates/artifacts -Duser.name='Marko (markol@mymail.com)' -Dcopyright='Mumek Software' $GRAILS_OPT"
2. Directory structure
/home/mumek/.grails/.options (-Dgrails.template.dir=$HOME/.grails/templates/artifacts)
/home/mumek2008/projects/custom1/.options (-Dgrails.template.dir='${baseDir}/../templates/artifacts')
/home/mumek2008/projects/custom1/prj1/.options : uses this options
/home/mumek2008/projects/custom1/prj2 : uses /home/mumek2008/projects/custom1/.options
/home/mumek2008/projects/custom2/proj : uses /home/mumek/.grails/.options settings
/home/mumek2008/projects/custom3/oldgrails/src/templates/artifacts/*.groovy exists: The old templates will be used (even /home/mumek2008/.grails/.options exists)
This kind of template managment are convenient using a version control system (VCS), 'cause the .options files and the templates could be stored within the VCS.
What do you think about it? It's worth the development or are there a different solution already available. Did I miss something important (an unexpected dependency).
I started changing _GrailsCreateArtifact.groovy and grailsStart script.
Regards
Marko