Changes for page Custom Project Templates
Last modified by Bastian Triller on 2009/04/11 21:03
From version 37.1
edited by Mike Schrag
on 2007/10/03 16:15
on 2007/10/03 16:15
Change comment:
There is no comment for this version
To version 38.1
edited by David Holt
on 2009/03/31 19:03
on 2009/03/31 19:03
Change comment:
There is no comment for this version
Summary
-
Page properties (2 modified, 0 added, 0 removed)
Details
- Page properties
-
- Author
-
... ... @@ -1,1 +1,1 @@ 1 -XWiki. mschrag1 +XWiki.dholt - Content
-
... ... @@ -1,11 +1,19 @@ 1 - WOLips 3.3+ supports the definition ofcustom project templates. These templates support the declaration of custom configuration parameters and the files within the template are processed using the [[Velocity Template Engine>>http://velocity.apache.org/engine/devel/vtl-reference-guide.html]].1 +{{toc}}{{/toc}} 2 2 3 += Introduction = 4 + 5 +WOLips 3.3 supports the definition of custom project templates. These templates support the declaration of custom configuration parameters and the files within the template are processed using the [[Velocity Template Engine>>http://velocity.apache.org/engine/devel/vtl-reference-guide.html]]. 6 + 3 3 To use a custom project template, select the "WO Project from Template" option under the WOLips category of the New Project Wizard. 4 4 5 - [[image:WOProjectFromTemplate.png]]9 +{{info}} 6 6 7 - ==== Creating aTemplate====11 +!NewProjectFromTemplate.png! 8 8 13 +{{/info}} 14 + 15 += Creating a Template = 16 + 9 9 The declaration of templates is very simple. The template system looks for folders in the following locations (in the following order): 10 10 11 11 * The ProjectTemplates folder inside of the WOLips templateengine plugin jar ... ... @@ -12,23 +12,29 @@ 12 12 * /Library/Application Support/WOLips/Project Templates 13 13 * YourHomeDirocuments and Settingspplication DataOLipsroject Templates 14 14 * YourHomeDirocuments and SettingsppDataocalOLipsroject Templates 15 -* ,,/Library/Application Support/WOLips/Project Templates,,23 +* /Library/Application Support/WOLips/Project Templates 16 16 17 - Withoutanyadditionalmetadata,the templateystemderives thenameofthetemplatefromthenameofthefolderinone of the abovelocations. Forstance,if youcreate a folder named ",,/Library/ApplicationSupport/WOLips/ProjectTemplates/WonderApplication," the templatesystemwill offera templatenamed "WonderApplication" inthe templateelectiondialog. Projecttemplates foundlaterinthe listof locations abovewilloverride thoseof the same name fromearlier inthe list. Forinstance, a "Wonder Application" templatefoundin,,/Library willoverrode a "Wonder Application" templatefrom/Library.25 +If you want to look at the current templates that ships with WOLips, the best way to analyse them is by [[importing the source>>Building WOLips]] of WOLips from Subversion. The templates are located in //woproject/wolips/core/plugins/org.objectstyle.wolips.templateengine/ProjectTemplates//. 18 18 19 - Aftercreatinga templatefolder,you can createa hierarchyoffiles and folders within thatfolder.When you create a project using thistemplate, a copy of all ofthefiles andfoldersin your template will be usedtocreatethe newproject. It is upto you to declare //all// ofthefileswithinaproject,including Eclipse projectmetadata fileslike .classpath. Youcanrefertothebuilt-in project templatesas atarting pointforcreatingyour owncustomtemplates.27 +If you copy a stock template to test it out, renaming the folder is not sufficient for WOLips to show the new Template in the "WO Project From Template" list. You must make sure that the template name is also changed in the template.xml file. 20 20 21 - That's it!For creatingstaticboilerplate templates,you're done.29 +Without any additional metadata, the template system derives the name of the template from the name of the folder in one of the above locations. For instance, if you create a folder named ",,/Library/Application Support/WOLips/Project Templates/Wonder Application," the template system will offer a template named "Wonder Application" in the template selection dialog. Project templates found later in the list of locations above will override those of the same name from earlier in the list. For instance, a "Wonder Application" template found in /Library will overrode a "Wonder Application" template from /Library.,, 22 22 23 - ====TemplateMetadata andTemplate Inputs====31 +After creating a template folder, you can create a hierarchy of files and folders within that folder. When you create a project using this template, a copy of all of the files and folders in your template will be used to create the new project. It is up to you to declare //all// of the files within a project, including Eclipse project metadata files like .classpath. You can refer to the built-in project templates as a starting point for creating your own custom templates. 24 24 33 +That's it For creating static boilerplate templates, you're done. 34 + 35 += Template Metadata and Template Inputs = 36 + 25 25 For a static template, the simple process above is enough. However, it's a common requirement to have configuration options for project templates. The WOLips project template engine provides an easy way to declare these options. 26 26 27 -After creating a template using the directions in the above section, you can additionally create a file named "template.xml" inside your project template folder. For instance, in the example above, you would create the file ",,/Library/Application Support/WOLips/Project Templates/Wonder Application/template.xml". 39 +After creating a template using the directions in the above section, you can additionally create a file named "template.xml" inside your project template folder. For instance, in the example above, you would create the file ",,/Library/Application Support/WOLips/Project Templates/Wonder Application/template.xml".,, 28 28 29 29 An example template.xml is below: 30 30 31 - <?xml version="1.0" encoding="UTF-8"?> 43 +{{code value="xml"}} 44 + 45 +<?xml version="1.0" encoding="UTF-8"?> 32 32 <template name = "Wonder Application"> 33 33 <inputs> 34 34 <input name = "linkToWonderProjects" type = "Boolean"> ... ... @@ -51,19 +51,25 @@ 51 51 </inputs> 52 52 </template> 53 53 68 +{{/code}} 69 + 54 54 The "name" attribute of the template node overrides the name of the folder the templates are in. For instance, you could have the above template.xml inside a folder named "Template 1" and the template system would consider the name of the template to be "Wonder Application." 55 55 56 -Within a template, you can declare a single "inputs" node that can contain multiple "input" nodes. Each input node corresponds to a variable that will be presented to the user on the second page of the wizard. Each input specifies a "name" attribute, which will become the variable name of the input for later reference in the Velocity templates; and a "type" attribute which can be one of Boolean, String, or Integer. The type value determines the control that will be used to display the input to the user (String = text field, Boolean = checkbox, Integer = spinner, etc). Each input also contains a "question" node, whose value corresponds to the label of the control when displayed to the user. In the above example, the "linkToWonderFrameworks" will display a checkbox to the user with the label "Link to Wonder Frameworks?". Additionally, you can provide a "default" node that defines the default value of the variable. If a default is not specified, the default value will be null for all input types. 72 +Within a template, you can declare a single "inputs" node that can contain multiple "input" nodes. Each input node corresponds to a variable that will be presented to the user on the second page of the wizard. Each input specifies a "name" attribute, which will become the variable name of the input for later reference in the Velocity templates; and a "type" attribute which can be one of Boolean, String, Package, or Integer. The type value determines the control that will be used to display the input to the user (String = text field, Boolean = checkbox, Integer = spinner, Package = text field, etc). Each input also contains a "question" node, whose value corresponds to the label of the control when displayed to the user. In the above example, the "linkToWonderFrameworks" will display a checkbox to the user with the label "Link to Wonder Frameworks?". Additionally, you can provide a "default" node that defines the default value of the variable. If a default is not specified, the default value will be null for all input types. 57 57 74 +The package type is slight extension to the String type. For a variable declared as type Package, in addition to having your variable bound, you will also have a variable named "yourvariablename//folder" with replaces dots for slashes. For instance, if your variable is named "basePackage," you will also get a variable named "basePackage//folder." This is useful because you can use template variables in folder names on the filesystem. 75 + 58 58 Finally, the input system supports the declaration of enumerated types. By declaring an "options" node that contains an ordered set of "option" nodes, you can define the possible values that the user can provide. In the above example, the "YourFavoriteColor" input defines three options: Red, Green, and Blue. Each option node has a "name" attribute, which will be the value displayed to the user, and a "value" attribute, which will be the actual backing value of the selection. The value of the option should be of the type specified in the "type" attribute of the input. For instance, if you declare the input type to be "Integer," your option values should be integer values (in quotes). 59 59 60 -= ===Using Template Inputs ====78 += Using Template Inputs = 61 61 62 62 So now that you have template input defined, you will want to be able to use them. The name use used in the "name" attribute of your input declaration will be the name of the variable in your Velocity context. For instance, in the example above, the Velocity variable "linkToWonderProjects" will be bound to the boolean value corresponding to the user's selection, and can be used just like any other velocity variable. The Apache project provides a [[Velocity reference guide>>http://velocity.apache.org/engine/devel/vtl-reference-guide.html]]. 63 63 64 64 As an example, the Wonder Application template's .classpath file is defined as: 65 65 66 - <?xml version="1.0" encoding="UTF-8"?> 84 +{{code value="xml"}} 85 + 86 +<?xml version="1.0" encoding="UTF-8"?> 67 67 <classpath> 68 68 <classpathentry kind="src" path="Sources"/> 69 69 #if ($linkToWonderProjects) ... ... @@ -73,12 +73,16 @@ 73 73 <classpathentry combineaccessrules="false" kind="src" path="/JavaWOExtensions"/> 74 74 #end 75 75 #if ($linkToWonderFrameworks) 76 - <classpathentry kind="con" path="org.objectstyle.wolips.WO //CLASSPATH/ERExtensions/ERJars/ERPrototypes/JavaWOExtensions/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/>96 + <classpathentry kind="con" path="org.objectstyle.wolips.WO_CLASSPATH/ERExtensions/ERJars/ERPrototypes/JavaWOExtensions/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/> 77 77 #else 78 - <classpathentry kind="con" path="org.objectstyle.wolips.WO //CLASSPATH/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/>98 + <classpathentry kind="con" path="org.objectstyle.wolips.WO_CLASSPATH/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/> 79 79 #end 80 - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE //CONTAINER"/>100 + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> 81 81 <classpathentry kind="output" path="bin"/> 82 - </classpath> //102 + </classpath> 83 83 84 -Happy templating! 104 +{{/code}} 105 + 106 +In addition to variables inside of Velocity templates, you can also use template inputs in folder names. However, because $ is not allowed on some filesystems, we instead surround the variable names with "//" (for instance $someVariable would be //someVariable in the filename or path). As an example, the Wonder Application template has an input named "basePackage" (of type Package), which creates a magic variable named "basePackage//folder" (where the dots are turned into slashes), and the Source folder on the filesystem is named "Wonder Application/Sources///basePackage//folder//". 107 + 108 +Happy templating