Search in sources :

Example 6 with DevTemplateModule

use of org.webpieces.templatingdev.api.DevTemplateModule in project webpieces by deanhiller.

the class TemplateCompile method compileImpl.

public void compileImpl(TemplateCompileOptions options) throws IOException {
    File buildDir = getProject().getBuildDir();
    // need to make customizable...
    File groovySrcGen = new File(buildDir, "groovysrc");
    log.log(LogLevel.LIFECYCLE, "putting groovy scripts in: " + groovySrcGen);
    Charset encoding = Charset.forName(options.getEncoding());
    TemplateCompileConfig config = new TemplateCompileConfig(false);
    config.setFileEncoding(encoding);
    config.setPluginClient(true);
    config.setGroovySrcWriteDirectory(groovySrcGen);
    log.log(LogLevel.LIFECYCLE, "Custom tags: " + options.getCustomTags());
    config.setCustomTagsFromPlugin(options.getCustomTags());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    File destinationDir = getDestinationDirectory().getAsFile().get();
    log.log(LogLevel.LIFECYCLE, "Writing class files to destDir: " + destinationDir);
    File routeIdFile = new File(destinationDir, ProdConstants.ROUTE_META_FILE);
    if (routeIdFile.exists())
        routeIdFile.delete();
    routeIdFile.createNewFile();
    log.log(LogLevel.LIFECYCLE, "routeId file: " + routeIdFile);
    FileCollection srcCollection = getSource();
    Set<File> files = srcCollection.getFiles();
    File firstFile = files.iterator().next();
    File baseDir = findBase(firstFile);
    try (FileOutputStream routeOut = new FileOutputStream(routeIdFile);
        OutputStreamWriter write = new OutputStreamWriter(routeOut, encoding.name());
        BufferedWriter bufWrite = new BufferedWriter(write)) {
        Injector injector = Guice.createInjector(new StubModule(), new DevTemplateModule(config, new PluginCompileCallback(destinationDir, bufWrite)));
        HtmlToJavaClassCompiler compiler = injector.getInstance(HtmlToJavaClassCompiler.class);
        GroovyClassLoader cl = new GroovyClassLoader();
        for (File f : files) {
            String fullName = findFullName(baseDir, f);
            log.log(LogLevel.INFO, "file compile name={}, file={}", fullName, f);
            String source = readSource(f);
            compiler.compile(cl, fullName, source);
        }
    }
    setDidWork(true);
}
Also used : Charset(java.nio.charset.Charset) HtmlToJavaClassCompiler(org.webpieces.templatingdev.impl.HtmlToJavaClassCompiler) FileCollection(org.gradle.api.file.FileCollection) LogLevel(org.gradle.api.logging.LogLevel) BufferedWriter(java.io.BufferedWriter) GroovyClassLoader(groovy.lang.GroovyClassLoader) StubModule(org.webpieces.templatingdev.api.StubModule) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Injector(com.google.inject.Injector) FileOutputStream(java.io.FileOutputStream) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Aggregations

DevTemplateModule (org.webpieces.templatingdev.api.DevTemplateModule)6 Injector (com.google.inject.Injector)3 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)3 MockTime (org.webpieces.mock.time.MockTime)3 StubModule (org.webpieces.templatingdev.api.StubModule)3 TemplateCompileConfig (org.webpieces.templatingdev.api.TemplateCompileConfig)3 GroovyClassLoader (groovy.lang.GroovyClassLoader)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)2 BufferedWriter (java.io.BufferedWriter)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 Charset (java.nio.charset.Charset)2 FileCollection (org.gradle.api.file.FileCollection)2 LogLevel (org.gradle.api.logging.LogLevel)2 ChannelManager (org.webpieces.nio.api.ChannelManager)2 HtmlToJavaClassCompiler (org.webpieces.templatingdev.impl.HtmlToJavaClassCompiler)2 Time (org.webpieces.util.time.Time)2 Time (com.webpieces.util.time.Time)1 Before (org.junit.Before)1