use of org.dbflute.friends.velocity.DfGenerator in project dbflute-core by dbflute.
the class DfAbstractTexenTask method fireVelocityProcess.
protected void fireVelocityProcess() {
assertBasicAntParameter();
// set up the encoding of templates from DBFlute property
setInputEncoding(getBasicProperties().getTemplateFileEncoding());
setOutputEncoding(getBasicProperties().getSourceFileEncoding());
try {
initializeGeneratorInstance();
final DfGenerator generator = setupGenerator();
final Context ctx = setupControlContext();
_log.info("generator.parse(\"" + controlTemplate + "\", ctx);");
generator.parse(controlTemplate, ctx);
generator.shutdown();
cleanup();
} catch (BuildException e) {
throw e;
} catch (MethodInvocationException e) {
final String method = e.getReferenceName() + "." + e.getMethodName() + "()";
String msg = "Exception thrown by " + method + ": control=" + controlTemplate;
throw new IllegalStateException(msg, e.getWrappedThrowable());
} catch (ParseErrorException e) {
throw new IllegalStateException("Velocity syntax error: control=" + controlTemplate, e);
} catch (ResourceNotFoundException e) {
throw new IllegalStateException("Resource not found: control=" + controlTemplate, e);
} catch (Exception e) {
throw new IllegalStateException("Generation failed: control=" + controlTemplate, e);
}
}
use of org.dbflute.friends.velocity.DfGenerator in project dbflute-core by dbflute.
the class DfAbstractTexenTask method initializeGeneratorInstance.
protected void initializeGeneratorInstance() {
final DfGenerator generator = getGenerator();
// re-create if already exists
generator.initializeEngine();
if (templatePath != null) {
generator.setProperty("file.resource.loader.path", templatePath);
}
if (useClasspath) {
final String resourceLoaderName = "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader";
generator.addProperty("resource.loader", "classpath");
generator.setProperty("classpath.resource.loader.class", resourceLoaderName);
generator.setProperty("classpath.resource.loader.cache", "false");
generator.setProperty("classpath.resource.loader.modificationCheckInterval", "2");
}
generator.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS, DfFlutistLog4JLogSystem.class.getName());
}
use of org.dbflute.friends.velocity.DfGenerator in project dbflute-core by dbflute.
the class DfFreeGenManager method setOutputDirectory.
// ===================================================================================
// Directory
// =========
public void setOutputDirectory(String outputDirectory) {
final DfGenerator generator = getGenerator();
final String existingPath = generator.getOutputPath();
if (existingPath != null && existingPath.equals(outputDirectory)) {
return;
}
_log.info("...Setting up generateOutputDirectory: " + outputDirectory);
generator.setOutputPath(outputDirectory);
}
use of org.dbflute.friends.velocity.DfGenerator in project dbflute-core by dbflute.
the class DfAbstractTexenTask method setupGenerator.
protected DfGenerator setupGenerator() {
final DfGenerator generator = getGenerator();
// *set up later using DBFlute property (dfprop)
// generator.setOutputPath(outputDirectory);
// actually from DBFlute property (dfprop)
// because these variables could be set up before here
generator.setInputEncoding(inputEncoding);
generator.setOutputEncoding(outputEncoding);
if (templatePath != null) {
generator.setTemplatePath(templatePath);
}
return generator;
}
use of org.dbflute.friends.velocity.DfGenerator in project dbflute-core by dbflute.
the class DfOutsideSqlProperties method switchSql2EntityOutputDirectory.
public void switchSql2EntityOutputDirectory(String outputDirectory) {
final DfGenerator generator = getGeneratorInstance();
final String outputPath = generator.getOutputPath();
if (outputDirectory == null) {
// means back to Sql2Entity output directory
final String mainOutDir = getSql2EntityOutputDirectory();
if (!outputPath.equals(mainOutDir)) {
// if different
_log.info("...Switching sql2EntityOutputDirectory: " + mainOutDir);
// back to library project
generator.setOutputPath(mainOutDir);
}
} else if (!outputPath.equals(outputDirectory)) {
// if different
_log.info("...Switching sql2EntityOutputDirectory: " + outputDirectory);
generator.setOutputPath(outputDirectory);
}
}
Aggregations