1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.ant;
20
21 import java.io.File;
22 import java.util.ArrayList;
23 import java.util.HashMap;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.apache.tools.ant.BuildException;
29 import org.apache.tools.ant.Task;
30 import org.apache.tools.ant.types.Parameter;
31
32 import net.sf.jameleon.util.GenSyntaxReference;
33
34 /***
35 * An Ant task that takes the registered FunctionalPoints and generates a syntax reference for each one.
36 */
37 public class GenSyntaxReferenceTask extends Task{
38
39 protected File outputFile;
40 protected String plugin = "TestCaseTagDefs";
41 protected String templateName = "syntaxReference.txt";
42 protected List parameters;
43
44 public GenSyntaxReferenceTask(){
45 parameters = new ArrayList();
46 }
47
48 /***
49 * Adds a template parameter to be passed to the Velocity template
50 *
51 * @param parameter a name/value parameter.
52 */
53 public void addTemplateParam(Parameter parameter){
54 parameters.add(parameter);
55 }
56
57 /***
58 * Sets the name of the file, not including path of the template to use. Defaults to 'syntaxReference.txt'.
59 * @param templateName - the name of the file, not including path of the template to use.
60 * NOTE: This fileName is loaded from the CLASSPATH.
61 */
62 public void setTemplateName(String templateName){
63 this.templateName = templateName;
64 }
65
66 /***
67 * Sets the plugin to generate the syntax reference from. Defaults to TestCaseTagDefs
68 * @param plugin - the plugin to generate the syntax reference from. For the htmlunit-plugin, pass in 'htmlunit-plugin'.
69 */
70 public void setPlugin(String plugin){
71 this.plugin = plugin;
72 }
73
74 /***
75 * Set the file where the syntax reference will be generated.
76 * @param fileName - The name of the file.
77 */
78 public void setOutputFile(File fileName){
79 outputFile = fileName;
80 }
81
82 /***
83 * Jameleon's implementation of Task.execute().
84 *
85 * @exception BuildException Ant's way of reporting exception
86 */
87 public final void execute() throws BuildException {
88 if (outputFile == null) {
89 outputFile = new File(getProject().getBaseDir(), "xdocs/syntax-reference.xml");
90 }
91 if (plugin == null) {
92 throw new BuildException("plugin must be set!");
93 }
94 Map params = new HashMap();
95 GenSyntaxReference generator = new GenSyntaxReference();
96 if (parameters != null) {
97 Iterator it = parameters.iterator();
98 Parameter param;
99 while (it.hasNext()) {
100 param = (Parameter)it.next();
101 params.put(param.getName(), param.getValue());
102 }
103 }
104 try{
105 System.out.println("Generating "+outputFile.getAbsolutePath());
106 generator.genReferenceForPlugin(plugin, templateName, outputFile, params);
107 }catch(Exception e){
108 e.printStackTrace();
109 throw new BuildException("An error occured while generating the syntax reference file: "+e.getMessage(), e);
110 }
111 }
112
113 }