Search in sources :

Example 1 with Template

use of io.micronaut.starter.template.Template 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 2 with Template

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

the class Readme method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    List<Feature> featuresWithDocumentationLinks = generatorContext.getFeatures().getFeatures().stream().filter(feature -> feature.getMicronautDocumentation() != null || feature.getThirdPartyDocumentation() != null).collect(Collectors.toList());
    List<Writable> helpTemplates = generatorContext.getHelpTemplates();
    if (!helpTemplates.isEmpty() || !featuresWithDocumentationLinks.isEmpty()) {
        generatorContext.addTemplate("readme", new Template() {

            @Override
            public String getPath() {
                return "README.md";
            }

            @Override
            public void write(OutputStream outputStream) throws IOException {
                for (Writable writable : generatorContext.getHelpTemplates()) {
                    writable.write(outputStream);
                }
                for (Feature feature : featuresWithDocumentationLinks) {
                    Writable writable = new RockerWritable(readme.template(feature));
                    writable.write(outputStream);
                }
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) Options(io.micronaut.starter.options.Options) Writable(io.micronaut.starter.template.Writable) ApplicationType(io.micronaut.starter.application.ApplicationType) Feature(io.micronaut.starter.feature.Feature) Set(java.util.Set) IOException(java.io.IOException) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Template(io.micronaut.starter.template.Template) List(java.util.List) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) NonNull(edu.umd.cs.findbugs.annotations.NonNull) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) RockerWritable(io.micronaut.starter.template.RockerWritable) io.micronaut.starter.feature.other.template.readme(io.micronaut.starter.feature.other.template.readme) FeaturePhase(io.micronaut.starter.feature.FeaturePhase) RockerWritable(io.micronaut.starter.template.RockerWritable) OutputStream(java.io.OutputStream) Writable(io.micronaut.starter.template.Writable) RockerWritable(io.micronaut.starter.template.RockerWritable) IOException(java.io.IOException) Feature(io.micronaut.starter.feature.Feature) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) Template(io.micronaut.starter.template.Template)

Aggregations

Template (io.micronaut.starter.template.Template)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 ApplicationType (io.micronaut.starter.application.ApplicationType)1 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)1 DefaultFeature (io.micronaut.starter.feature.DefaultFeature)1 Feature (io.micronaut.starter.feature.Feature)1 FeaturePhase (io.micronaut.starter.feature.FeaturePhase)1 io.micronaut.starter.feature.other.template.readme (io.micronaut.starter.feature.other.template.readme)1 Options (io.micronaut.starter.options.Options)1 RenderResult (io.micronaut.starter.template.RenderResult)1 RockerTemplate (io.micronaut.starter.template.RockerTemplate)1 RockerWritable (io.micronaut.starter.template.RockerWritable)1 TemplateRenderer (io.micronaut.starter.template.TemplateRenderer)1 Writable (io.micronaut.starter.template.Writable)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1