Search in sources :

Example 26 with Project

use of io.micronaut.starter.application.Project 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 27 with Project

use of io.micronaut.starter.application.Project 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 28 with Project

use of io.micronaut.starter.application.Project in project micronaut-starter by micronaut-projects.

the class CreateRepositoryCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(repositoryName);
    boolean jdbcRepository = config.getFeatures().contains("data-jdbc");
    String idTypeImport = null;
    if (idType.contains(".")) {
        idTypeImport = idType;
    } else if (!VALID_NO_PKG_ID_TYPES.contains(idType)) {
        throw new IllegalArgumentException("Code generation not supported for the specified id type: " + idType + ". Please specify the fully qualified class name.");
    }
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    String dialect = jdbcRepository ? config.getFeatures().stream().map(name -> {
        for (DatabaseDriverFeature feature : driverFeatures) {
            if (feature.getName().equals(name)) {
                return feature;
            }
        }
        return null;
    }).filter(Objects::nonNull).findFirst().map(DatabaseDriverFeature::getDataDialect).orElse(null) : null;
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/java/{packagePath}/{className}Repository.java", javaRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/groovy/{packagePath}/{className}Repository.groovy", groovyRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(new RockerTemplate("src/main/kotlin/{packagePath}/{className}Repository.kt", kotlinRepository.template(project, idTypeImport, idType, jdbcRepository, dialect)), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("@|blue ||@ Rendered repository 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 : ThrowingSupplier(io.micronaut.core.util.functional.ThrowingSupplier) Arrays(java.util.Arrays) Parameter(io.micronaut.context.annotation.Parameter) OutputHandler(io.micronaut.starter.io.OutputHandler) RockerTemplate(io.micronaut.starter.template.RockerTemplate) IOException(java.io.IOException) DatabaseDriverFeature(io.micronaut.starter.feature.database.DatabaseDriverFeature) Inject(javax.inject.Inject) Objects(java.util.Objects) Project(io.micronaut.starter.application.Project) List(java.util.List) CodeGenConfig(io.micronaut.starter.cli.CodeGenConfig) ConsoleOutput(io.micronaut.starter.io.ConsoleOutput) ReflectiveAccess(io.micronaut.core.annotation.ReflectiveAccess) RenderResult(io.micronaut.starter.template.RenderResult) Prototype(io.micronaut.context.annotation.Prototype) Language(io.micronaut.starter.options.Language) CodeGenCommand(io.micronaut.starter.cli.command.CodeGenCommand) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) CommandLine(picocli.CommandLine) RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) Objects(java.util.Objects) RenderResult(io.micronaut.starter.template.RenderResult) DatabaseDriverFeature(io.micronaut.starter.feature.database.DatabaseDriverFeature)

Example 29 with Project

use of io.micronaut.starter.application.Project in project micronaut-starter by micronaut-projects.

the class AwsAlexa method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    Project project = generatorContext.getProject();
    cancelIntentHandler(generatorContext, project);
    cancelIntentHandlerTest(generatorContext, project);
    fallbackIntentHandler(generatorContext, project);
    fallbackIntentHandlerTest(generatorContext, project);
    helpIntentHandler(generatorContext, project);
    helpIntentHandlerTest(generatorContext, project);
    launchRequestIntentHandler(generatorContext, project);
    launchRequestIntentHandlerTest(generatorContext, project);
    sessionEndedRequestIntentHandler(generatorContext, project);
    sessionEndedIntentHandlerTest(generatorContext, project);
    stopIntentHandler(generatorContext, project);
    stopIntentHandlerTest(generatorContext, project);
}
Also used : Project(io.micronaut.starter.application.Project)

Example 30 with Project

use of io.micronaut.starter.application.Project in project micronaut-starter by micronaut-projects.

the class FeatureDiffer method produceDiff.

/**
 * Produces a Diff for the given arguments.
 * @param projectGenerator The project generator
 * @param generatorContext The generator context
 * @param consoleOutput The console output
 * @throws Exception If something does wrong
 */
public void produceDiff(ProjectGenerator projectGenerator, GeneratorContext generatorContext, ConsoleOutput consoleOutput) throws Exception {
    MapOutputHandler outputHandler = new MapOutputHandler();
    Project project = generatorContext.getProject();
    ApplicationType applicationType = generatorContext.getApplicationType();
    projectGenerator.generate(applicationType, project, new Options(generatorContext.getLanguage(), generatorContext.getTestFramework(), generatorContext.getBuildTool(), generatorContext.getJdkVersion()), generatorContext.getOperatingSystem(), Collections.emptyList(), outputHandler, ConsoleOutput.NOOP);
    Map<String, String> oldProject = outputHandler.getProject();
    outputHandler = new MapOutputHandler();
    projectGenerator.generate(applicationType, project, outputHandler, generatorContext);
    Map<String, String> newProject = outputHandler.getProject();
    for (Map.Entry<String, String> entry : newProject.entrySet()) {
        String oldFile = oldProject.remove(entry.getKey());
        if (entry.getValue() == null) {
            continue;
        }
        List<String> oldFileLines = oldFile == null ? Collections.emptyList() : toLines(oldFile);
        String newFile = entry.getValue();
        List<String> newFileLines = toLines(newFile);
        Patch<String> diff = DiffUtils.diff(oldFileLines, newFileLines);
        List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(entry.getKey(), entry.getKey(), oldFileLines, diff, 3);
        if (!unifiedDiff.isEmpty()) {
            for (String delta : unifiedDiff) {
                if (delta.startsWith("+")) {
                    consoleOutput.green(delta);
                } else if (delta.startsWith("-")) {
                    consoleOutput.red(delta);
                } else {
                    consoleOutput.out(delta);
                }
            }
            consoleOutput.out("\n");
        }
    }
    for (Map.Entry<String, String> entry : oldProject.entrySet()) {
        if (entry.getValue() == null) {
            continue;
        }
        List<String> oldFileLines = toLines(entry.getValue());
        Patch<String> diff = DiffUtils.diff(oldFileLines, Collections.emptyList());
        List<String> unifiedDiff = UnifiedDiffUtils.generateUnifiedDiff(entry.getKey(), entry.getKey(), oldFileLines, diff, 3);
        if (!unifiedDiff.isEmpty()) {
            for (String delta : unifiedDiff) {
                if (delta.startsWith("+")) {
                    consoleOutput.green(delta);
                } else if (delta.startsWith("-")) {
                    consoleOutput.red(delta);
                } else {
                    consoleOutput.out(delta);
                }
            }
            consoleOutput.out("\n");
        }
    }
}
Also used : Project(io.micronaut.starter.application.Project) ApplicationType(io.micronaut.starter.application.ApplicationType) Options(io.micronaut.starter.options.Options) MapOutputHandler(io.micronaut.starter.io.MapOutputHandler) Map(java.util.Map)

Aggregations

Project (io.micronaut.starter.application.Project)36 RockerTemplate (io.micronaut.starter.template.RockerTemplate)23 RenderResult (io.micronaut.starter.template.RenderResult)17 TemplateRenderer (io.micronaut.starter.template.TemplateRenderer)17 RockerModel (com.fizzed.rocker.RockerModel)12 ApplicationType (io.micronaut.starter.application.ApplicationType)7 TestRockerModelProvider (io.micronaut.starter.options.TestRockerModelProvider)7 DefaultTestRockerModelProvider (io.micronaut.starter.options.DefaultTestRockerModelProvider)6 Language (io.micronaut.starter.options.Language)5 HttpStatusException (io.micronaut.http.exceptions.HttpStatusException)4 Options (io.micronaut.starter.options.Options)4 Get (io.micronaut.http.annotation.Get)3 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)3 ProjectGenerator (io.micronaut.starter.application.generator.ProjectGenerator)3 TestFramework (io.micronaut.starter.options.TestFramework)3 MapOutputHandler (io.micronaut.starter.io.MapOutputHandler)2 OutputHandler (io.micronaut.starter.io.OutputHandler)2 BuildTool (io.micronaut.starter.options.BuildTool)2 RockerWritable (io.micronaut.starter.template.RockerWritable)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2