Wiki source code of Custom Project Templates

Version 35.1 by Mike Schrag on 2007/10/03 16:16

Hide last authors
Mike Schrag 30.1 1 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]].
David Avendasora 20.1 2
Pascal Robert 22.1 3 To use a custom project template, select the "WO Project from Template" option under the WOLips category of the New Project Wizard.
David Avendasora 20.1 4
Mike Schrag 32.1 5 [[image:WOProjectFromTemplate.png]]
David Avendasora 20.1 6
Mike Schrag 30.1 7 ==== Creating a Template ====
Pascal Robert 22.1 8
David Avendasora 20.1 9 The declaration of templates is very simple. The template system looks for folders in the following locations (in the following order):
10
Pascal Robert 22.1 11 * The ProjectTemplates folder inside of the WOLips templateengine plugin jar
12 * /Library/Application Support/WOLips/Project Templates
Mike Schrag 34.1 13 * YourHomeDirocuments and Settingspplication DataOLipsroject Templates
14 * YourHomeDirocuments and SettingsppDataocalOLipsroject Templates
Mike Schrag 30.1 15 * ,,/Library/Application Support/WOLips/Project Templates,,
David Avendasora 20.1 16
Mike Schrag 30.1 17 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.
David Avendasora 20.1 18
Mike Schrag 30.1 19 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.
David Avendasora 20.1 20
Mike Schrag 30.1 21 That's it! For creating static boilerplate templates, you're done.
David Avendasora 20.1 22
Mike Schrag 30.1 23 ==== Template Metadata and Template Inputs ====
David Avendasora 20.1 24
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
Mike Schrag 30.1 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". ,,
David Avendasora 20.1 28
29 An example template.xml is below:
30
Mike Schrag 34.1 31 {{code value="xml"}}
32
Mike Schrag 30.1 33 <?xml version="1.0" encoding="UTF-8"?>
Pascal Robert 22.1 34 <template name = "Wonder Application">
David Avendasora 20.1 35 <inputs>
Pascal Robert 22.1 36 <input name = "linkToWonderProjects" type = "Boolean">
37 <question>Link to Wonder Projects?</question>
38 <default>false</default>
David Avendasora 20.1 39 </input>
Pascal Robert 22.1 40 <input name = "linkToWonderFrameworks" type = "Boolean">
41 <question>Link to Wonder Frameworks?</question>
42 <default>true</default>
David Avendasora 20.1 43 </input>
44 <input name = "YourFavoriteColor" type = "String">
45 <question>Your Favorite Color?</question>
46 <options>
47 <option name = "Red" value = "#FF0000"/>
48 <option name = "Green" value = "#00FF00"/>
49 <option name = "Blue" value = "#0000FF"/>
50 </options>
51 <default>#FF0000</default>
52 </input>
53 </inputs>
54 </template>
55
Mike Schrag 34.1 56 {{/code}}
57
Pascal Robert 22.1 58 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."
David Avendasora 20.1 59
Mike Schrag 30.1 60 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.
David Avendasora 20.1 61
62 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).
63
Mike Schrag 30.1 64 ==== Using Template Inputs ====
David Avendasora 20.1 65
Pascal Robert 22.1 66 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]].
David Avendasora 20.1 67
Pascal Robert 22.1 68 As an example, the Wonder Application template's .classpath file is defined as:
David Avendasora 20.1 69
Mike Schrag 34.1 70 {{code value="xml"}}
71
Mike Schrag 30.1 72 <?xml version="1.0" encoding="UTF-8"?>
Pascal Robert 22.1 73 <classpath>
74 <classpathentry kind="src" path="Sources"/>
75 #if ($linkToWonderProjects)
76 <classpathentry combineaccessrules="false" kind="src" path="/ERJars"/>
77 <classpathentry combineaccessrules="false" kind="src" path="/ERExtensions"/>
78 <classpathentry combineaccessrules="false" kind="src" path="/ERPrototypes"/>
79 <classpathentry combineaccessrules="false" kind="src" path="/JavaWOExtensions"/>
80 #end
81 #if ($linkToWonderFrameworks)
Mike Schrag 34.1 82 <classpathentry kind="con" path="org.objectstyle.wolips.WO_CLASSPATH/ERExtensions/ERJars/ERPrototypes/JavaWOExtensions/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/>
Pascal Robert 22.1 83 #else
Mike Schrag 34.1 84 <classpathentry kind="con" path="org.objectstyle.wolips.WO_CLASSPATH/JavaEOAccess/JavaEOControl/JavaFoundation/JavaJDBCAdaptor/JavaWebObjects/JavaXML"/>
Pascal Robert 22.1 85 #end
Mike Schrag 34.1 86 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
Pascal Robert 22.1 87 <classpathentry kind="output" path="bin"/>
Mike Schrag 34.1 88 </classpath>
David Avendasora 20.1 89
Mike Schrag 34.1 90 {{/code}}
91
Mike Schrag 30.1 92 Happy templating!