Changes for page Custom Project Templates

Last modified by Bastian Triller on 2009/04/11 21:03

From version 57.1
edited by David Avendasora
on 2009/04/11 20:08
Change comment: There is no comment for this version
To version 61.1
edited by David Avendasora
on 2009/04/11 21:03
Change comment: Migrated to Confluence 5.3

Summary

Details

Page properties
Parent
... ... @@ -1,0 +1,1 @@
1 +WOLips Tutorials
Tags
... ... @@ -1,0 +1,1 @@
1 +wikireview
Content
... ... @@ -1,26 +1,26 @@
1 -{{toc}}{{/toc}}
1 +{{toc/}}
2 2  
3 3  = Introduction =
4 4  
5 -WOLips 3.3 supports the definition of custom project templates. These templates support creating new types of WebObjects projects beyond the ones that ship with WOLips.
5 +WOLips 3.3+ supports the definition of custom project templates. These templates support creating new types of WebObjects projects beyond the ones that ship with WOLips.
6 6  
7 7  To use a custom project template, create a new project by going to the "File" menu and selecting "New -> Other..." then select the "WO Project from Template" option under the WOLips section.
8 -[[image:NewProjectFromTemplate.png]]
8 +[[image:attach:NewProjectFromTemplate.png]]
9 9  
10 10  = Creating a Template =
11 11  
12 -Templates are basically like a regular project folder, but some of the contents are modified to use the variables defined in the template.xml file to change their names or values in their contents. The modified files within the template are processed using the [[Velocity Template Engine>>http://velocity.apache.org/engine/devel/vtl-reference-guide.html]].
12 +Templates are basically like a regular project folder, but some of the contents are modified to use the variables defined in the template.xml file to change their names or values in their contents. The modified files within the template are processed using the [[Velocity Template Engine>>url:http://velocity.apache.org/engine/devel/vtl-reference-guide.html||shape="rect"]].
13 13  
14 14  The declaration of templates is very simple. The template system looks for folders in the following locations (in the following order):
15 15  
16 16  1. The ProjectTemplates folder inside of the WOLips templateengine plugin jar
17 17  1. /Library/Application Support/WOLips/Project Templates
18 -1. YourHomeDirocuments and Settingspplication DataOLipsroject Templates
19 -1. YourHomeDirocuments and SettingsppDataocalOLipsroject Templates
20 -1. /Library/Application Support/WOLips/Project Templates
18 +1. YourHomeDir\Documents and Settings\Application Data\WOLips\Project Templates
19 +1. YourHomeDir\Documents and Settings\AppData\Local\WOLips\Project Templates
20 +1. ~~/Library/Application Support/WOLips/Project Templates
21 21  
22 22  {{note}}
23 -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 override a "Wonder Application" template from /Library.
23 +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 override a "Wonder Application" template from /Library.
24 24  {{/note}}
25 25  
26 26  The name that the template shows up as in the New Project wizard is controlled by one of two things:
... ... @@ -28,41 +28,49 @@
28 28  1. The template's folder name
29 29  1. The name attribute of the template tag in the template.xml file inside the template folder (if present, this overrides the value set by the template folder name).
30 30  
31 -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. If you then set the name attribute to "My Wonder Application", that is what you will see in the dialog.,,
31 +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. If you then set the name attribute to "My Wonder Application", that is what you will see in the dialog.
32 32  
33 -If you want to look at the current templates that ship 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//.
33 +If you want to look at the current templates that ship with WOLips, the best way to analyse them is by [[importing the source>>doc:WOL.Building WOLips]] of WOLips from Subversion. The templates are located in //woproject/wolips/core/plugins/org.objectstyle.wolips.templateengine/ProjectTemplates//.
34 34  
35 -Here is an additional custom template for creating [[Wonder ERD2W Applications>>Custom Project Templates^Wonder ERD2W Application.zip||title="Click to download attachment"]] that you can view as an example.
35 +Here is an additional custom template for creating [[Wonder ERD2W Applications>>attach:WOL.Custom Project Templates@Wonder ERD2W Application.zip]] that you can view as an example.
36 36  
37 37  {{note}}
38 -Remember, if you copy an existing template to test it out you must rename both the folder *and* the name attribute of the template tag in the template.xml file otherwise whichever loads last will replace the first!
38 +Remember, if you copy an existing template to test it out you must rename both the folder **and** the name attribute of the template tag in the template.xml file otherwise whichever loads last will replace the first!
39 39  {{/note}}
40 40  
41 41  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.
42 42  
43 -That's it For creating static boilerplate templates, you're done.
43 +That's it! For creating static boilerplate templates, you're done.
44 44  
45 45  = Template Metadata and Template Inputs =
46 46  
47 47  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.
48 48  
49 -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".,,
49 +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/My Application Template/template.xml".
50 50  
51 51  An example template.xml is below:
52 52  
53 -{{code value="xml"}}
53 +{{code 0="xml"}}
54 54  
55 55  <?xml version="1.0" encoding="UTF-8"?>
56 - <template name = "Wonder Application">
56 + <template name = "My Application">
57 57   <inputs>
58 - <input name = "linkToWonderProjects" type = "Boolean">
59 - <question>Link to Wonder Projects?</question>
60 - <default>false</default>
58 + <input name = "basePackage" type = "Package">
59 + <question>Base Package?</question>
60 + <default>your.app</default>
61 61   </input>
62 - <input name = "linkToWonderFrameworks" type = "Boolean">
63 - <question>Link to Wonder Frameworks?</question>
64 - <default>true</default>
62 + <input name = "componentsPackage" type = "Package">
63 + <question>Components Package?</question>
64 + <default>your.app.components</default>
65 65   </input>
66 + <input name = "servletDeployment" type = "Boolean">
67 + <question>Deploy to Servlet Container?</question>
68 + <default>false</default>
69 + </input>
70 + <input name = "webXML" type = "Boolean">
71 + <question>Autogenerate web.xml file?</question>
72 + <default>false</default>
73 + </input>
66 66   <input name = "YourFavoriteColor" type = "String">
67 67   <question>Your Favorite Color?</question>
68 68   <options>
... ... @@ -77,21 +77,31 @@
77 77  
78 78  {{/code}}
79 79  
80 -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."
88 +If you don't set a "name" attribute in the "template" tag, the name of the Template Folder will be used. In this example the Template will show up as "My Application" in the list of available templates. If "name" handn't been defined, the it would show up as the folder name, which was "My Application Template".
81 81  
82 -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.
90 +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 will determine the type of control presented to the user. They are:
83 83  
84 -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.
92 +* Boolean -> Check Box
93 +* String -> Text Field
94 +* Package -> Text Field
95 +* Integer -> Spinner
85 85  
86 -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).
97 +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 "servletDeployment" will display a checkbox to the user with the label "Deploy to Servlet Container?". 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.
87 87  
99 +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". If the user left the default of "your.app" in the basePackage field, then the two variables would be:
100 +
101 +* basePackage = "your.app"
102 +* basePackage_folder = "your/app"
103 +
104 +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).
105 +
88 88  = Using Template Inputs =
89 89  
90 -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]].
108 +So now that you have template inputs defined, you need to be able to use them. The name used in the "name" attribute of your input node will be the name of the variable you can use in your template's files. For instance, in the example above, the Velocity variable "servletDeployment" 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>>url:http://velocity.apache.org/engine/devel/vtl-reference-guide.html||shape="rect"]].
91 91  
92 -As an example, the .classpath file can be modified to automatically add a link to the JavaWOJSPServlet.framework if the user is prompted and selects "Deploy to Servlet Container" in the the new project wizard.
110 +As an example, the .classpath file can be modified to automatically add a link to the JavaWOJSPServlet.framework if the user selects "Deploy to Servlet Container" in the the wizard.
93 93  
94 -{{code value="xml"}}
112 +{{code 0="xml"}}
95 95  
96 96  <?xml version="1.0" encoding="UTF-8"?>
97 97  <classpath>
... ... @@ -111,6 +111,19 @@
111 111  
112 112  {{/code}}
113 113  
114 -In addition to variables inside of Velocity templates, you can also use template variables in folder and file 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//".
132 +In addition to variables inside of Velocity templates, you can also use template variables in folder and file 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 template above has an input named "basePackage" (of type Package) which, as we learned above, creates two variables: "basePackage" and "basePackage_folder". Since we are going to be using this variable to name (and define the path) of a folder in the Sources directory, we need to use the alternate version of the variable. Create a new folder in the Sources directory of the project templaet and instead of using "${basePackage_folder}" as the file name, we must use "~_~_basePackage_folder~_~_".
115 115  
116 -Happy templating
134 += Special Circumstances =
135 +
136 +===== Flagging files to be skipped by Velocity =====
137 +
138 +If there are files in your template that should not be processed by Velocity as the project is being setup, you will need to end the file name with "~_~_binary" which will cause Velocity to strip the "~_~_binary" off the file name, but skip processing the contents of the file. Examples of files that you'd want to flag are:
139 +
140 +* EOGenerator Templates
141 +* Custom builder .launch files.
142 +
143 +===== Using keypaths =====
144 +
145 +If you need to call a method on a given variable, you need to include the "()" at the end of the method name. An eample is in the build.properties file. In order to get the lowercase version of the project name, you have to call "${projectName.toLowerCase()}"
146 +
147 +Happy templating!
NewProjectFromTemplate.png
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +60.7 KB
Content
Wonder ERD2W Application.zip
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.XWikiGuest
Size
... ... @@ -1,0 +1,1 @@
1 +32.3 KB
Content
XWiki.XWikiComments[0]
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.probert
Comment
... ... @@ -1,0 +1,1 @@
1 +Need to add intructions on how to find the templates in WOLips' source.
Date
... ... @@ -1,0 +1,1 @@
1 +2007-12-15 18:28:18.0
XWiki.XWikiComments[1]
Author
... ... @@ -1,0 +1,1 @@
1 +XWiki.dholt
Comment
... ... @@ -1,0 +1,3 @@
1 +Mike has revealed the location of the included templates in a recent email to the list:
2 +
3 +"We have a couple built in in the new format. You can unjar your org.objectstyle.wolips.templateengine plugin and see the ones we have included (in the ProjectTemplates folder ... the "templates" folder contains the old style ones, like D2W, which is broken)."
Date
... ... @@ -1,0 +1,1 @@
1 +2008-12-09 17:27:05.0