|
12 | 12 | import java.io.Reader; |
13 | 13 | import java.io.StringReader; |
14 | 14 | import java.io.Writer; |
| 15 | +import java.net.MalformedURLException; |
| 16 | +import java.net.URL; |
| 17 | +import java.net.URLClassLoader; |
15 | 18 | import java.util.ArrayList; |
16 | 19 | import java.util.Date; |
17 | 20 | import java.util.List; |
|
22 | 25 | import freemarker.cache.ClassTemplateLoader; |
23 | 26 | import freemarker.cache.FileTemplateLoader; |
24 | 27 | import freemarker.cache.MultiTemplateLoader; |
| 28 | +import freemarker.cache.URLTemplateLoader; |
25 | 29 | import freemarker.cache.TemplateLoader; |
26 | 30 | import freemarker.ext.beans.BeansWrapperBuilder; |
27 | 31 | import freemarker.template.Configuration; |
@@ -67,15 +71,27 @@ public void init(File outputDirectory, String[] templatePaths) { |
67 | 71 |
|
68 | 72 | for (int i = 0; i < templatePaths.length; i++) { |
69 | 73 | File file = new File(templatePaths[i]); |
70 | | - if(file.exists() && file.isDirectory()) { |
71 | | - try { |
72 | | - loaders.add(new FileTemplateLoader(file)); |
73 | | - } |
74 | | - catch (IOException e) { |
75 | | - throw new RuntimeException("Problems with templatepath " + file, e); |
76 | | - } |
| 74 | + if(file.exists()) { |
| 75 | + if (file.isDirectory()) { |
| 76 | + try { |
| 77 | + loaders.add(new FileTemplateLoader(file)); |
| 78 | + } catch (IOException e) { |
| 79 | + throw new RuntimeException("Problems with templatepath " + file, e); |
| 80 | + } |
| 81 | + } else if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) { |
| 82 | + final URLClassLoader classLoaderForZip; |
| 83 | + try { |
| 84 | + classLoaderForZip = new URLClassLoader(new URL[]{ file.toURI().toURL() }, null); |
| 85 | + } catch (MalformedURLException e) { |
| 86 | + throw new RuntimeException("template path " + file + " is not a valid zip file", e); |
| 87 | + } |
| 88 | + |
| 89 | + loaders.add(new ClassTemplateLoader(classLoaderForZip, "/")); |
| 90 | + } else { |
| 91 | + log.warn("template path " + file + " is not a directory"); |
| 92 | + } |
77 | 93 | } else { |
78 | | - log.warn("template path" + file + " either does not exist or is not a directory"); |
| 94 | + log.warn("template path " + file + " does not exist"); |
79 | 95 | } |
80 | 96 | } |
81 | 97 | loaders.add(new ClassTemplateLoader(this.getClass(),"/")); // the template names are like pojo/Somewhere so have to be a rooted classpathloader |
|
0 commit comments