|
24 | 24 | import java.io.Reader; |
25 | 25 | import java.io.StringReader; |
26 | 26 | import java.io.Writer; |
| 27 | +import java.net.MalformedURLException; |
| 28 | +import java.net.URL; |
| 29 | +import java.net.URLClassLoader; |
27 | 30 | import java.util.ArrayList; |
28 | 31 | import java.util.Date; |
29 | 32 | import java.util.List; |
|
34 | 37 | import freemarker.cache.ClassTemplateLoader; |
35 | 38 | import freemarker.cache.FileTemplateLoader; |
36 | 39 | import freemarker.cache.MultiTemplateLoader; |
| 40 | +import freemarker.cache.URLTemplateLoader; |
37 | 41 | import freemarker.cache.TemplateLoader; |
38 | 42 | import freemarker.ext.beans.BeansWrapperBuilder; |
39 | 43 | import freemarker.template.Configuration; |
@@ -79,15 +83,27 @@ public void init(File outputDirectory, String[] templatePaths) { |
79 | 83 |
|
80 | 84 | for (int i = 0; i < templatePaths.length; i++) { |
81 | 85 | File file = new File(templatePaths[i]); |
82 | | - if(file.exists() && file.isDirectory()) { |
83 | | - try { |
84 | | - loaders.add(new FileTemplateLoader(file)); |
85 | | - } |
86 | | - catch (IOException e) { |
87 | | - throw new RuntimeException("Problems with templatepath " + file, e); |
88 | | - } |
| 86 | + if(file.exists()) { |
| 87 | + if (file.isDirectory()) { |
| 88 | + try { |
| 89 | + loaders.add(new FileTemplateLoader(file)); |
| 90 | + } catch (IOException e) { |
| 91 | + throw new RuntimeException("Problems with templatepath " + file, e); |
| 92 | + } |
| 93 | + } else if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) { |
| 94 | + final URLClassLoader classLoaderForZip; |
| 95 | + try { |
| 96 | + classLoaderForZip = new URLClassLoader(new URL[]{ file.toURI().toURL() }, null); |
| 97 | + } catch (MalformedURLException e) { |
| 98 | + throw new RuntimeException("template path " + file + " is not a valid zip file", e); |
| 99 | + } |
| 100 | + |
| 101 | + loaders.add(new ClassTemplateLoader(classLoaderForZip, "/")); |
| 102 | + } else { |
| 103 | + log.warn("template path " + file + " is not a directory"); |
| 104 | + } |
89 | 105 | } else { |
90 | | - log.warn("template path" + file + " either does not exist or is not a directory"); |
| 106 | + log.warn("template path " + file + " does not exist"); |
91 | 107 | } |
92 | 108 | } |
93 | 109 | loaders.add(new ClassTemplateLoader(this.getClass(),"/")); // the template names are like pojo/Somewhere so have to be a rooted classpathloader |
|
0 commit comments