Griffon 0.9 sneak peek: application archetypes
Since the beginning a developer was able to create new artifacts using a predefined template, usually located somewhere in the Griffon distribution install directory. Developers also had the choice to provide their own templates local to an application, or even bundle them in plugins. While all this works fine and dandy the missing piece was being able to tweak the initial MVC group that is generated when an application is created, simply because no local templates are available as the application has not been created yet; same thing with plugins.
Application archetypes fill that void.
Application archetypes are simple zip files with an application descriptor and templates. Despite this, Griffon provides a few scripts that let you manage archetypes: create-archetype, package-archetype, install-archetype, uninstall-archetype. Here's how the default archetype descriptor (application.groovy) looks
import griffon.util.Metadata
includeTargets << griffonScript("_GriffonPlugins") includeTargets << griffonScript("_GriffonInit") includeTargets << griffonScript("CreateMvc" ) target(createApplicationProject: 'Creates a new application project') { createProjectWithDefaults() createMVC() // to install plugins do the following // Metadata md = Metadata.getInstance("${basedir}/application.properties") // installPluginExternal md, pluginName, pluginVersion // // pluginVersion is optional } setDefaultTarget(createApplicationProject)Templates are stored relative to the archetype descriptor under templates/artifacts. You're free to modify and add as many templates as needed. You can also add other files that can be copied to the application, like a LICENSE.TXT or README for example, just remember you must write the copying code yourself in the archetype descriptor.
Archetypes are registered with the application metadata so that when a new artifact is created the appropriate template is used. However if you wish to override this setting while creating an artifact then specify an -archetype=<name> argument to the create-* script. The following is the template search order
- local to the application -> $basedir/src/templates/artifacts
- provided by a plugin -> $pluginHome/*/src/templates/artifacts
- local archetype -> ~/.griffon/<version>/archetypes/<name>/templates/artifacts
- global archetype -> $griffonHome/archetypes/<name>/templates/artifacts
The archetype install options are very similar to plugins, you can install them from a zip file location or from an URL. There is no central management for archetypes at the moment as there is for plugins.
That's all for now. Keep on Groovying!
About Andres Almiray
Andres is a Java/Groovy developer and Java Champion, with more than 11 years of experience in software design and development. He has been involved in web and desktop application developments since the early days of Java. He has also been teacher of computer science courses in the most prestigious education institute in Mexico. His current interests include Groovy and Swing. He is a true believer of open source and has participated in popular projects like Groovy, Griffon, JMatter and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member and current project lead of the Griffon framework. He blogs periodically at http://jroller.com/aalmiray. You can find him on twitter too as @aalmiray. He likes to spend time with his beloved wife, Ixchel, when not hacking around.
More About Andres »NFJS, the Magazine
December Issue Now AvailableBDD and REST
by Brian SlettenMocks and Stubs in Groovy Tests
by Kenneth KousenAlgorithms for Better Text Search Results
by John GriffinKnowns and Unknowns of Scrum and Agile
by Brian Tarbox