Search in sources :

Example 1 with RockerTemplate

use of io.micronaut.starter.template.RockerTemplate in project micronaut-starter by micronaut-projects.

the class CreateKafkaProducer method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(producerName);
    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 = javaProducer.template(project);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        rockerModel = groovyProducer.template(project);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        rockerModel = kotlinProducer.template(project);
    }
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered Kafka producer 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 2 with RockerTemplate

use of io.micronaut.starter.template.RockerTemplate in project micronaut-starter by micronaut-projects.

the class CreateNatsProducer method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(producerName);
    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 = javaProducer.template(project);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        rockerModel = groovyProducer.template(project);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        rockerModel = kotlinProducer.template(project);
    }
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered Nats producer 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 3 with RockerTemplate

use of io.micronaut.starter.template.RockerTemplate in project micronaut-starter by micronaut-projects.

the class CreateRabbitMQProducer method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(producerName);
    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 = javaProducer.template(project);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        rockerModel = groovyProducer.template(project);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        rockerModel = kotlinProducer.template(project);
    }
    renderResult = templateRenderer.render(new RockerTemplate(path, rockerModel), overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered RabbitMQ producer 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 4 with RockerTemplate

use of io.micronaut.starter.template.RockerTemplate in project micronaut-starter by micronaut-projects.

the class DefaultProjectGenerator method generate.

@Override
public void generate(ApplicationType applicationType, Project project, OutputHandler outputHandler, GeneratorContext generatorContext) throws Exception {
    List<String> features = new ArrayList<>(generatorContext.getFeatures().size());
    features.addAll(generatorContext.getFeatures());
    features.sort(Comparator.comparing(Function.identity()));
    generatorContext.addTemplate("micronautCli", new RockerTemplate("micronaut-cli.yml", cli.template(generatorContext.getLanguage(), generatorContext.getTestFramework(), generatorContext.getBuildTool(), generatorContext.getProject(), features, applicationType)));
    generatorContext.applyFeatures();
    try (TemplateRenderer templateRenderer = TemplateRenderer.create(project, outputHandler)) {
        for (Template template : generatorContext.getTemplates().values()) {
            RenderResult renderResult = templateRenderer.render(template);
            if (renderResult.getError() != null) {
                throw renderResult.getError();
            }
        }
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) ArrayList(java.util.ArrayList) RenderResult(io.micronaut.starter.template.RenderResult) RockerTemplate(io.micronaut.starter.template.RockerTemplate) Template(io.micronaut.starter.template.Template)

Example 5 with RockerTemplate

use of io.micronaut.starter.template.RockerTemplate in project micronaut-starter by micronaut-projects.

the class CreateWebsocketServerCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(serverName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/java/{packagePath}/{className}Server.java", javaWebsocketServer.template(project)), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/groovy/{packagePath}/{className}Server.groovy", groovyWebsocketServer.template(project)), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/kotlin/{packagePath}/{className}Server.kt", kotlinWebsocketServer.template(project)), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered websocket server 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)

Aggregations

RockerTemplate (io.micronaut.starter.template.RockerTemplate)32 Project (io.micronaut.starter.application.Project)23 TemplateRenderer (io.micronaut.starter.template.TemplateRenderer)19 RenderResult (io.micronaut.starter.template.RenderResult)18 RockerModel (com.fizzed.rocker.RockerModel)14 TestRockerModelProvider (io.micronaut.starter.options.TestRockerModelProvider)6 DefaultTestRockerModelProvider (io.micronaut.starter.options.DefaultTestRockerModelProvider)5 Language (io.micronaut.starter.options.Language)5 TestFramework (io.micronaut.starter.options.TestFramework)3 ApplicationType (io.micronaut.starter.application.ApplicationType)2 BuildTool (io.micronaut.starter.options.BuildTool)2 BinaryTemplate (io.micronaut.starter.template.BinaryTemplate)2 URLTemplate (io.micronaut.starter.template.URLTemplate)2 Parameter (io.micronaut.context.annotation.Parameter)1 Prototype (io.micronaut.context.annotation.Prototype)1 ReflectiveAccess (io.micronaut.core.annotation.ReflectiveAccess)1 ThrowingSupplier (io.micronaut.core.util.functional.ThrowingSupplier)1 OperatingSystem (io.micronaut.starter.application.OperatingSystem)1 CodeGenConfig (io.micronaut.starter.cli.CodeGenConfig)1 CodeGenCommand (io.micronaut.starter.cli.command.CodeGenCommand)1