From the IlrVelocityGenerator class
You can write a new code generator class that inherits from the IlrVelocityGenerator class by redefining the method that matches your project and then generating the necessary files.
About this task
Procedure
- To generate all the files that you need, redefine the generateProjectContent(IJavaProject) or generateProjectContent(IProject) method,
depending on the kind of project that you want to generate. The following methods are available:
- generateVelocityFile to generate a file in the project. Use the getTemplateDirectory method to locate the template file.
- generateVelocityFileInSrc to generate a file in the src directory of the project. Use the getTemplateDirectory method to locate the template file.
- generateVelocityFileto generate a file in the project. Use the templateDirectory parameter to specify the template directory.
- generateVelocityFileInSrc to generate a file in the src directory of the project. Use the templateDirectory parameter to specify the template directory.
Start the implementation by calling the parent method.
For example:public void generateProjectContent(IJavaProject javaProject) { super.generateProjectContent(javaProject); generateVelocityFile("myDestinationDirectory", "", myAbsolutePathToTheTemplateDirectory, "myTemplate.vm", null, ".properties", "myTemplate.vm"); } - Redefine the getTemplateDirectory method.
This method indicates the path for the velocity template files. If you use only the method generateVelocityFile or generateVelocityFileInSrc, these methods can return null. These methods use the templateDirectory parameter to get the path of the velocity template files.
- Redefine the initializeContext method.
This method is called each time you call a generateVelocityFile or generateVelocityFileInSrc method in the generateProjectContent method. The initializeContext method sets your parameters relative to the RuleApp project in the generated file. Some accessors are provided to help you retrieve and format the information in the generated file.
You must call a context.put method for each velocity parameter in your .vm file.
For example:protected VelocityContext initializeContext(Object userData , VelocityContext context) { if ( userData instanceof String ) { String templateFile = (String) userData; if ( templateFile.equals("myTemplate.vm") ) { context.put("package", getPackagePrefix()); context.put("header", getFileHeader()); context.put("ruleapp-name", getRuleAppProject().getDescriptor().getName()); context.put("ruleapp-version", getRuleAppProject().getDescriptor().getVersion()); } } return context; }