Search in sources :

Example 1 with ApplicationGeneratingEvent

use of io.micronaut.starter.api.event.ApplicationGeneratingEvent in project micronaut-starter by micronaut-projects.

the class AbstractCreateController method createProjectGeneratorContext.

public GeneratorContext createProjectGeneratorContext(ApplicationType type, @Pattern(regexp = "[\\w\\d-_\\.]+") String name, @Nullable List<String> features, @Nullable BuildTool buildTool, @Nullable TestFramework testFramework, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Nullable @Header(HttpHeaders.USER_AGENT) String userAgent) {
    Project project;
    try {
        project = NameUtils.parse(name);
    } catch (IllegalArgumentException e) {
        throw new HttpStatusException(HttpStatus.BAD_REQUEST, "Invalid project name: " + e.getMessage());
    }
    GeneratorContext generatorContext;
    try {
        generatorContext = projectGenerator.createGeneratorContext(type, project, new Options(lang, testFramework != null ? testFramework.toTestFramework() : null, buildTool == null ? BuildTool.GRADLE : buildTool, javaVersion != null ? javaVersion : JdkVersion.JDK_8), getOperatingSystem(userAgent), features != null ? features : Collections.emptyList(), ConsoleOutput.NOOP);
        try {
            eventPublisher.publishEvent(new ApplicationGeneratingEvent(generatorContext));
        } catch (Exception e) {
            LOG.warn("Error firing application generated event: " + e.getMessage(), e);
        }
    } catch (IllegalArgumentException e) {
        throw new HttpStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
    }
    return generatorContext;
}
Also used : Project(io.micronaut.starter.application.Project) Options(io.micronaut.starter.options.Options) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) ApplicationGeneratingEvent(io.micronaut.starter.api.event.ApplicationGeneratingEvent)

Aggregations

HttpStatusException (io.micronaut.http.exceptions.HttpStatusException)1 ApplicationGeneratingEvent (io.micronaut.starter.api.event.ApplicationGeneratingEvent)1 Project (io.micronaut.starter.application.Project)1 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)1 Options (io.micronaut.starter.options.Options)1