Search in sources :

Example 1 with DfGenerator

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);
    }
}
Also used : Context(org.apache.velocity.context.Context) ParseErrorException(org.apache.velocity.exception.ParseErrorException) BuildException(org.apache.tools.ant.BuildException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) DfGenerator(org.dbflute.friends.velocity.DfGenerator) SQLException(java.sql.SQLException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException)

Example 2 with DfGenerator

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());
}
Also used : DfFlutistLog4JLogSystem(org.dbflute.friends.velocity.DfFlutistLog4JLogSystem) DfGenerator(org.dbflute.friends.velocity.DfGenerator)

Example 3 with DfGenerator

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);
}
Also used : DfGenerator(org.dbflute.friends.velocity.DfGenerator)

Example 4 with DfGenerator

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;
}
Also used : DfGenerator(org.dbflute.friends.velocity.DfGenerator)

Example 5 with DfGenerator

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);
    }
}
Also used : DfGenerator(org.dbflute.friends.velocity.DfGenerator)

Aggregations

DfGenerator (org.dbflute.friends.velocity.DfGenerator)6 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 BuildException (org.apache.tools.ant.BuildException)1 Context (org.apache.velocity.context.Context)1 MethodInvocationException (org.apache.velocity.exception.MethodInvocationException)1 ParseErrorException (org.apache.velocity.exception.ParseErrorException)1 ResourceNotFoundException (org.apache.velocity.exception.ResourceNotFoundException)1 DfFlutistLog4JLogSystem (org.dbflute.friends.velocity.DfFlutistLog4JLogSystem)1 DfOldClassHandler (org.dbflute.logic.generate.deletefile.DfOldClassHandler)1 DfLanguageDependency (org.dbflute.logic.generate.language.DfLanguageDependency)1 DfLanguageClassPackage (org.dbflute.logic.generate.language.pkgstyle.DfLanguageClassPackage)1