Search in sources :

Example 16 with RockerTemplate

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

the class GoogleCloudRawFunction method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    ApplicationType type = generatorContext.getApplicationType();
    applyFunction(generatorContext, type);
    if (type == ApplicationType.FUNCTION) {
        Language language = generatorContext.getLanguage();
        Project project = generatorContext.getProject();
        String sourceFile = generatorContext.getSourcePath("/{packagePath}/Function");
        switch(language) {
            case GROOVY:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionGroovy.template(project)));
                break;
            case KOTLIN:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionKotlin.template(project)));
                break;
            case JAVA:
            default:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionJava.template(project)));
        }
        applyTestTemplate(generatorContext, project, "Function");
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) ApplicationType(io.micronaut.starter.application.ApplicationType) Project(io.micronaut.starter.application.Project) Language(io.micronaut.starter.options.Language)

Example 17 with RockerTemplate

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

the class GroovyApplication method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    GroovyApplicationFeature.super.apply(generatorContext);
    if (shouldGenerateApplicationFile(generatorContext)) {
        generatorContext.addTemplate("application", new RockerTemplate(getPath(), application.template(generatorContext.getProject(), generatorContext.getFeatures())));
        TestFramework testFramework = generatorContext.getTestFramework();
        String testSourcePath = generatorContext.getTestSourcePath("/{packagePath}/{className}");
        Project project = generatorContext.getProject();
        TestRockerModelProvider provider = new DefaultTestRockerModelProvider(spock.template(project), groovyJunit.template(project), groovyJunit.template(project), groovyJunit.template(project), koTest.template(project));
        generatorContext.addTemplate("applicationTest", new RockerTemplate(testSourcePath, provider.findModel(generatorContext.getLanguage(), testFramework)));
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TestFramework(io.micronaut.starter.options.TestFramework) TestRockerModelProvider(io.micronaut.starter.options.TestRockerModelProvider) DefaultTestRockerModelProvider(io.micronaut.starter.options.DefaultTestRockerModelProvider) DefaultTestRockerModelProvider(io.micronaut.starter.options.DefaultTestRockerModelProvider)

Example 18 with RockerTemplate

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

the class CreateTestCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(testName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    final String path = "/{packagePath}/{className}";
    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());
    String testPath = config.getTestFramework().getSourcePath(path, config.getSourceLanguage());
    RockerTemplate rockerTemplate = new RockerTemplate(testPath, rockerModel);
    RenderResult renderResult = templateRenderer.render(rockerTemplate);
    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) DefaultTestRockerModelProvider(io.micronaut.starter.options.DefaultTestRockerModelProvider) RenderResult(io.micronaut.starter.template.RenderResult) RockerModel(com.fizzed.rocker.RockerModel)

Example 19 with RockerTemplate

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

the class CreateProtoServiceCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(serviceName);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = templateRenderer.render(new RockerTemplate("src/main/proto/{propertyName}.proto", proto.template(project)));
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered Proto 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)

Example 20 with RockerTemplate

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

the class CreateCommandCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(name);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(javaApplication.getTemplate(project), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(groovyApplication.getTemplate(project), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(kotlinApplication.getTemplate(project), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("Rendered command 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();
        }
    }
    Language rockerTemplateLanguage = (config.getTestFramework().getSupportedLanguages().contains(config.getSourceLanguage())) ? config.getSourceLanguage() : config.getTestFramework().getDefaultLanguage();
    TestRockerModelProvider testRockerModelProvider = new CustomTestRockerModelProvider(project, junit.getJunitRockerModelProvider(project)) {

        @Override
        public RockerModel spock() {
            return spock.getModel(getProject());
        }

        @Override
        public RockerModel koTest() {
            return koTest.getModel(project);
        }
    };
    RockerModel rockerModel = testRockerModelProvider.findModel(rockerTemplateLanguage, config.getTestFramework());
    String path = config.getTestFramework().getSourcePath(PATH, rockerTemplateLanguage);
    RockerTemplate rockerTemplate = new RockerTemplate(path, rockerModel);
    renderResult = templateRenderer.render(rockerTemplate, overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("Rendered command 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) Language(io.micronaut.starter.options.Language) TestRockerModelProvider(io.micronaut.starter.options.TestRockerModelProvider) AbstractTestRockerModelProvider(io.micronaut.starter.options.AbstractTestRockerModelProvider) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) RenderResult(io.micronaut.starter.template.RenderResult) RockerModel(com.fizzed.rocker.RockerModel)

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