1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package edu.samplu.common;
17
18 import java.io.File;
19 import java.io.InputStream;
20
21 import freemarker.cache.ClassTemplateLoader;
22 import freemarker.cache.TemplateLoader;
23 import freemarker.template.Configuration;
24
25
26
27
28 public class FreemarkerSTGenerator {
29 private static Configuration cfg = new Configuration();
30
31
32 private static String DIR_TMPL = "/Gen/";
33
34
35 private static TemplateLoader templateLoader = new ClassTemplateLoader(FreemarkerSTGenerator.class, DIR_TMPL);
36
37 private static String STJUNITBASE_TMPL = "STJUnitBase.ftl";
38 private static String STJUNITBKMRKGEN_TMPL = "STJUnitBkMrkGen.ftl";
39 private static String STJUNITNAVGEN_TMPL = "STJUnitNavGen.ftl";
40 private static String STNGBASE_TMPL = "STNGBase.ftl";
41 private static String STNGBKMRKGEN_TMPL = "STNGBkMrkGen.ftl";
42 private static String STNGNAVGEN_TMPL = "STNGNavGen.ftl";
43
44 public static void main(String[] args) throws Exception {
45 cfg.setTemplateLoader(templateLoader);
46
47 String propsLocation = "/GenFiles/Group.properties";
48 if (args.length > 0) {
49 propsLocation = "/GenFiles/" + args[0];
50 }
51
52
53 createFile(propsLocation, STJUNITBASE_TMPL);
54 createFile(propsLocation, STJUNITBKMRKGEN_TMPL);
55 createFile(propsLocation, STJUNITNAVGEN_TMPL);
56 createFile(propsLocation, STNGBASE_TMPL);
57 createFile(propsLocation, STNGBKMRKGEN_TMPL);
58 createFile(propsLocation, STNGNAVGEN_TMPL);
59 }
60
61 private static void createFile(String propLocation, String template) throws Exception {
62 try {
63 InputStream in = FreemarkerSTGenerator.class.getResourceAsStream(propLocation);
64 File f1 = new File("src" + File.separatorChar + "it" + File.separatorChar + "resources"
65 + File.separatorChar + "GenFiles" + File.separatorChar
66 + propLocation.substring(propLocation.lastIndexOf("/"), propLocation.lastIndexOf("."))
67 + template.substring(0, template.length() - 4) + ".java");
68 FreemarkerUtil.ftlWrite(f1, cfg.getTemplate(template), in);
69
70 } catch (Exception e) {
71 e.printStackTrace();
72 throw new Exception("Unable to generate files", e);
73 }
74 }
75 }