Search in sources :

Example 1 with DevTemplateModule

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

the class TemplateCompilerTask method compileImpl.

public void compileImpl(TemplateCompileOptions options) throws IOException {
    File buildDir = getProject().getBuildDir();
    //need to make customizable...
    File groovySrcGen = new File(buildDir, "groovysrc");
    System.out.println("groovy src directory=" + groovySrcGen);
    Charset encoding = Charset.forName(options.getEncoding());
    TemplateCompileConfig config = new TemplateCompileConfig(false);
    config.setFileEncoding(encoding);
    config.setPluginClient(true);
    config.setGroovySrcWriteDirectory(groovySrcGen);
    System.out.println("custom tags=" + options.getCustomTags());
    config.setCustomTagsFromPlugin(options.getCustomTags());
    LogLevel logLevel = getProject().getGradle().getStartParameter().getLogLevel();
    File destinationDir = getDestinationDir();
    System.out.println("destDir=" + destinationDir);
    File routeIdFile = new File(destinationDir, ProdTemplateModule.ROUTE_META_FILE);
    if (routeIdFile.exists())
        routeIdFile.delete();
    routeIdFile.createNewFile();
    System.out.println("routeId.txt file=" + routeIdFile.getAbsolutePath());
    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) {
            System.out.println("file=" + f);
            String fullName = findFullName(baseDir, f);
            System.out.println("name=" + fullName);
            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)

Example 2 with DevTemplateModule

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

the class TestSimpleTemplate method setup.

@Before
public void setup() {
    Injector injector = Guice.createInjector(new DevTemplateModule(new TemplateCompileConfig(false)), new StubModule());
    svc = injector.getInstance(DevTemplateService.class);
}
Also used : DevTemplateService(org.webpieces.templatingdev.impl.DevTemplateService) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) StubModule(org.webpieces.templatingdev.api.StubModule) Injector(com.google.inject.Injector) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) Before(org.junit.Before)

Example 3 with DevTemplateModule

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

the class PlatformOverridesForTest method configure.

@Override
public void configure(Binder binder) {
    binder.bind(ChannelManager.class).toInstance(mgr);
    binder.bind(Time.class).toInstance(time);
    binder.bind(ScheduledExecutorService.class).toInstance(mockTimer);
    //By using the DevTemplateService, we do not need to re-run the gradle build and generate html
    //files every time we change the html code AND instead can just run the test in our IDE.
    //That said, there is a setting when this test runs in gradle that skips this step and runs the
    //production groovy *.class file that will be run in production (ie. the test run in the IDE
    //and run in gradle differ just a little :( )
    //BUTTTTTT, the upside is when run in gradle we are running the full prod version
    binder.install(new DevTemplateModule(templateConfig));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ChannelManager(org.webpieces.nio.api.ChannelManager) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Time(com.webpieces.util.time.Time) MockTime(org.webpieces.mock.time.MockTime)

Example 4 with DevTemplateModule

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

the class OverridesForEmbeddedSvrNoParsing method configure.

@Override
public void configure(Binder binder) {
    binder.bind(HttpFrontendManager.class).toInstance(frontEnd);
    binder.bind(MeterRegistry.class).toInstance(metrics);
    binder.bind(Time.class).toInstance(time);
    binder.bind(ScheduledExecutorService.class).toInstance(mockTimer);
    // By using the DevTemplateService, we do not need to re-run the gradle build and generate html
    // files every time we change the html code AND instead can just run the test in our IDE.
    // That said, there is a setting when this test runs in gradle that skips this step and runs the
    // production groovy *.class file that will be run in production (ie. the test run in the IDE
    // and run in gradle differ just a little :( )
    // BUTTTTTT, the upside is when run in gradle we are running the full prod version
    binder.install(new DevTemplateModule(templateConfig));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) HttpFrontendManager(org.webpieces.frontend2.api.HttpFrontendManager) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Time(org.webpieces.util.time.Time) MockTime(org.webpieces.mock.time.MockTime) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

Example 5 with DevTemplateModule

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

the class OverridesForEmbeddedSvrWithParsing method configure.

@Override
public void configure(Binder binder) {
    binder.bind(MeterRegistry.class).toInstance(metrics);
    binder.bind(ChannelManager.class).toInstance(mgr);
    binder.bind(Time.class).toInstance(time);
    binder.bind(ScheduledExecutorService.class).toInstance(mockTimer);
    // By using the DevTemplateService, we do not need to re-run the gradle build and generate html
    // files every time we change the html code AND instead can just run the test in our IDE.
    // That said, there is a setting when this test runs in gradle that skips this step and runs the
    // production groovy *.class file that will be run in production (ie. the test run in the IDE
    // and run in gradle differ just a little :( )
    // BUTTTTTT, the upside is when run in gradle we are running the full prod version
    binder.install(new DevTemplateModule(templateConfig));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ChannelManager(org.webpieces.nio.api.ChannelManager) DevTemplateModule(org.webpieces.templatingdev.api.DevTemplateModule) Time(org.webpieces.util.time.Time) MockTime(org.webpieces.mock.time.MockTime) MeterRegistry(io.micrometer.core.instrument.MeterRegistry)

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