Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Extension {
public String revengFile = null;
public Boolean generateAnnotations = true;
public Boolean useGenerics = true;
public String templatePath = null;

public Extension(Project project) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void doWork() {
File outputFolder = getOutputFolder();
hbmExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, createJdbcDescriptor());
hbmExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputFolder);
String templatePath = getExtension().templatePath;
if (templatePath != null) {
getLogger().lifecycle("Setting template path to: " + templatePath);
hbmExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] { templatePath });
}
getLogger().lifecycle("Starting DAO export to directory: " + outputFolder + "...");
hbmExporter.start();
getLogger().lifecycle("DAO export finished");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ void doWork() {
File outputFolder = getOutputFolder();
hbmExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, createJdbcDescriptor());
hbmExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputFolder);
String templatePath = getExtension().templatePath;
if (templatePath != null) {
getLogger().lifecycle("Setting template path to: " + templatePath);
hbmExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] { templatePath });
}
getLogger().lifecycle("Starting HBM export to directory: " + outputFolder + "...");
hbmExporter.start();
getLogger().lifecycle("HBM export finished");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ void doWork() {
File outputFolder = getOutputFolder();
pojoExporter.getProperties().put(ExporterConstants.METADATA_DESCRIPTOR, createJdbcDescriptor());
pojoExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, outputFolder);
String templatePath = getExtension().templatePath;
if (templatePath != null) {
getLogger().lifecycle("Setting template path to: " + templatePath);
pojoExporter.getProperties().put(ExporterConstants.TEMPLATE_PATH, new String[] { templatePath });
}
getLogger().lifecycle("Starting Java export to directory: " + outputFolder + "...");
pojoExporter.start();
getLogger().lifecycle("Java export finished");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
Expand All @@ -34,6 +37,7 @@
import freemarker.cache.ClassTemplateLoader;
import freemarker.cache.FileTemplateLoader;
import freemarker.cache.MultiTemplateLoader;
import freemarker.cache.URLTemplateLoader;
import freemarker.cache.TemplateLoader;
import freemarker.ext.beans.BeansWrapperBuilder;
import freemarker.template.Configuration;
Expand Down Expand Up @@ -79,15 +83,27 @@ public void init(File outputDirectory, String[] templatePaths) {

for (int i = 0; i < templatePaths.length; i++) {
File file = new File(templatePaths[i]);
if(file.exists() && file.isDirectory()) {
try {
loaders.add(new FileTemplateLoader(file));
}
catch (IOException e) {
throw new RuntimeException("Problems with templatepath " + file, e);
}
if(file.exists()) {
if (file.isDirectory()) {
try {
loaders.add(new FileTemplateLoader(file));
} catch (IOException e) {
throw new RuntimeException("Problems with templatepath " + file, e);
}
} else if (file.getName().endsWith(".zip") || file.getName().endsWith(".jar")) {
final URLClassLoader classLoaderForZip;
try {
classLoaderForZip = new URLClassLoader(new URL[]{ file.toURI().toURL() }, null);
} catch (MalformedURLException e) {
throw new RuntimeException("template path " + file + " is not a valid zip file", e);
}

loaders.add(new ClassTemplateLoader(classLoaderForZip, "/"));
} else {
log.warn("template path " + file + " is not a directory");
}
} else {
log.warn("template path" + file + " either does not exist or is not a directory");
log.warn("template path " + file + " does not exist");
}
}
loaders.add(new ClassTemplateLoader(this.getClass(),"/")); // the template names are like pojo/Somewhere so have to be a rooted classpathloader
Expand Down Expand Up @@ -266,14 +282,12 @@ public void processTemplate(String templateName, Writer output, String rootConte
}*/

public boolean templateExists(String templateName) {
TemplateLoader templateLoader = freeMarkerEngine.getTemplateLoader();
TemplateLoader templateLoader = freeMarkerEngine.getTemplateLoader();

try {
return templateLoader.findTemplateSource(templateName)!=null;
}
catch (IOException e) {
throw new RuntimeException("templateExists for " + templateName + " failed", e);
}
return templateLoader.findTemplateSource(templateName) != null;
} catch (IOException e) {
throw new RuntimeException("templateExists for " + templateName + " failed", e);
}
}

}