Search in sources :

Example 11 with RockerModel

use of com.fizzed.rocker.RockerModel in project micronaut-starter by micronaut-projects.

the class CreateGrpcServiceCommand method call.

@Override
public Integer call() throws Exception {
    CreateProtoServiceCommand command = getCommand(CreateProtoServiceCommand.class);
    command.serviceName = serviceName;
    int exitCode = command.call();
    if (exitCode > 0) {
        return exitCode;
    }
    Project project = getProject(serviceName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    String path = "/{packagePath}/{className}";
    path = config.getSourceLanguage().getSourcePath(path);
    RockerModel rockerModel = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        rockerModel = javaService.template(project);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        rockerModel = groovyService.template(project);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        rockerModel = kotlinService.template(project);
    }
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered gRPC service to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    return 0;
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) RenderResult(io.micronaut.starter.template.RenderResult) RockerModel(com.fizzed.rocker.RockerModel)

Example 12 with RockerModel

use of com.fizzed.rocker.RockerModel in project micronaut-starter by micronaut-projects.

the class CreateKafkaListener method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(listenerName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    String path = "/{packagePath}/{className}";
    path = config.getSourceLanguage().getSourcePath(path);
    RockerModel rockerModel = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        rockerModel = javaListener.template(project);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        rockerModel = groovyListener.template(project);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        rockerModel = kotlinListener.template(project);
    }
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered Kafka listener to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    return 0;
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) RenderResult(io.micronaut.starter.template.RenderResult) RockerModel(com.fizzed.rocker.RockerModel)

Example 13 with RockerModel

use of com.fizzed.rocker.RockerModel in project micronaut-starter by micronaut-projects.

the class CreateControllerCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(controllerName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(new RockerTemplate(Language.JAVA.getSrcDir() + "/{packagePath}/{className}Controller." + Language.JAVA.getExtension(), javaController.template(project)), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(new RockerTemplate(Language.GROOVY.getSrcDir() + "/{packagePath}/{className}Controller." + Language.GROOVY.getExtension(), groovyController.template(project)), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(new RockerTemplate(Language.KOTLIN.getSrcDir() + "/{packagePath}/{className}Controller." + Language.KOTLIN.getExtension(), kotlinController.template(project)), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered controller to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    renderResult = null;
    String path = "/{packagePath}/{className}Controller";
    path = config.getTestFramework().getSourcePath(path, config.getSourceLanguage());
    TestRockerModelProvider provider = new DefaultTestRockerModelProvider(spock.template(project), javaJunit.template(project), groovyJunit.template(project), kotlinJunit.template(project), koTest.template(project));
    RockerModel rockerModel = provider.findModel(config.getSourceLanguage(), config.getTestFramework());
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered test to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    return 0;
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TestRockerModelProvider(io.micronaut.starter.options.TestRockerModelProvider) DefaultTestRockerModelProvider(io.micronaut.starter.options.DefaultTestRockerModelProvider) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) RenderResult(io.micronaut.starter.template.RenderResult) DefaultTestRockerModelProvider(io.micronaut.starter.options.DefaultTestRockerModelProvider) RockerModel(com.fizzed.rocker.RockerModel)

Example 14 with RockerModel

use of com.fizzed.rocker.RockerModel in project micronaut-starter by micronaut-projects.

the class GeneratorContext method addTemplate.

public void addTemplate(String templateName, String triggerFile, RockerModel javaTemplate, RockerModel kotlinTemplate, RockerModel groovyTemplate) {
    RockerModel rockerModel = parseModel(javaTemplate, kotlinTemplate, groovyTemplate);
    addTemplate(templateName, new RockerTemplate(triggerFile, rockerModel));
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) RockerModel(com.fizzed.rocker.RockerModel)

Aggregations

RockerModel (com.fizzed.rocker.RockerModel)14 RockerTemplate (io.micronaut.starter.template.RockerTemplate)14 Project (io.micronaut.starter.application.Project)12 RenderResult (io.micronaut.starter.template.RenderResult)12 TemplateRenderer (io.micronaut.starter.template.TemplateRenderer)12 TestRockerModelProvider (io.micronaut.starter.options.TestRockerModelProvider)3 DefaultTestRockerModelProvider (io.micronaut.starter.options.DefaultTestRockerModelProvider)2 AbstractTestRockerModelProvider (io.micronaut.starter.options.AbstractTestRockerModelProvider)1 Language (io.micronaut.starter.options.Language)1