Search in sources :

Example 16 with Project

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

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

Example 18 with Project

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

the class DiffController method diffFeature.

/**
 * Returns a diff for the given application type and feature.
 *
 * @param type The application type
 * @param feature The feature
 * @param build The build tool
 * @param test The test framework
 * @param lang The lang
 * @param javaVersion The java version
 * @param requestInfo The request info
 * @return A string representing the difference
 */
@Get(uri = "/{type}/feature/{feature}{?lang,build,test,javaVersion,name}", produces = MediaType.TEXT_PLAIN)
@Override
@ApiResponse(responseCode = "404", description = "If no difference is found")
@ApiResponse(responseCode = "400", description = "If the supplied parameters are invalid")
@ApiResponse(responseCode = "200", description = "A textual diff", content = @Content(mediaType = "text/plain"))
public Flowable<String> diffFeature(@NotNull ApplicationType type, @Nullable String name, @NonNull @NotBlank String feature, @Nullable BuildTool build, @Nullable TestFramework test, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Parameter(hidden = true) RequestInfo requestInfo) {
    ProjectGenerator projectGenerator;
    GeneratorContext generatorContext;
    try {
        Project project = name != null ? NameUtils.parse(name) : this.project;
        Options options = new Options(lang != null ? lang : Language.JAVA, test != null ? test : TestFramework.JUNIT, build != null ? build : BuildTool.GRADLE);
        projectGenerator = this.projectGenerator;
        generatorContext = projectGenerator.createGeneratorContext(type, project, options, UserAgentParser.getOperatingSystem(requestInfo.getUserAgent()), Collections.singletonList(feature), ConsoleOutput.NOOP);
    } catch (IllegalArgumentException e) {
        throw new HttpStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
    }
    return diffFlowable(projectGenerator, generatorContext);
}
Also used : Project(io.micronaut.starter.application.Project) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) ProjectGenerator(io.micronaut.starter.application.generator.ProjectGenerator) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) Get(io.micronaut.http.annotation.Get) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 19 with Project

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

the class DiffController method diffApp.

/**
 * Diffs the whole application for all selected features.
 * @param type The application type
 * @param name The name of the application
 * @param features The features
 * @param build The build tool
 * @param test The test framework
 * @param lang The lang
 * @param requestInfo The request info
 * @return An HTTP response that emits a writable
 */
@Get(uri = "/{type}/{name}{?features,lang,build,test,javaVersion}", produces = MediaType.TEXT_PLAIN)
@Override
@ApiResponse(responseCode = "404", description = "If no difference is found")
@ApiResponse(responseCode = "400", description = "If the supplied parameters are invalid")
@ApiResponse(responseCode = "200", description = "A textual diff", content = @Content(mediaType = "text/plain"))
public Flowable<String> diffApp(ApplicationType type, @Pattern(regexp = "[\\w\\d-_\\.]+") String name, @Nullable List<String> features, @Nullable BuildTool build, @Nullable TestFramework test, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Parameter(hidden = true) RequestInfo requestInfo) throws IOException {
    ProjectGenerator projectGenerator;
    GeneratorContext generatorContext;
    try {
        Project project = name != null ? NameUtils.parse(name) : this.project;
        Options options = new Options(lang != null ? lang : Language.JAVA, test != null ? test : TestFramework.JUNIT, build != null ? build : BuildTool.GRADLE);
        projectGenerator = this.projectGenerator;
        generatorContext = projectGenerator.createGeneratorContext(type, project, options, UserAgentParser.getOperatingSystem(requestInfo.getUserAgent()), features != null ? features : Collections.emptyList(), ConsoleOutput.NOOP);
    } catch (IllegalArgumentException e) {
        throw new HttpStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
    }
    return diffFlowable(projectGenerator, generatorContext);
}
Also used : Project(io.micronaut.starter.application.Project) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) ProjectGenerator(io.micronaut.starter.application.generator.ProjectGenerator) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) Get(io.micronaut.http.annotation.Get) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse)

Example 20 with Project

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

the class PreviewController method previewApp.

/**
 * Previews the contents of a generated application..
 * @param type The application type The application type
 * @param name The name of the application The name of the application
 * @param features The features The chosen features
 * @param build The build type (optional, defaults to Gradle)
 * @param test The test framework (optional, defaults to JUnit)
 * @param lang The language (optional, defaults to Java)
 * @return A preview of the application contents.
 */
@Get(uri = "/{type}/{name}{?features,lang,build,test,javaVersion}", produces = MediaType.APPLICATION_JSON)
@Override
public PreviewDTO previewApp(ApplicationType type, String name, @Nullable List<String> features, @Nullable BuildTool build, @Nullable TestFramework test, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Parameter(hidden = true) RequestInfo requestInfo) throws IOException {
    try {
        Project project = NameUtils.parse(name);
        MapOutputHandler outputHandler = new MapOutputHandler();
        projectGenerator.generate(type, project, new Options(lang, test != null ? test.toTestFramework() : null, build == null ? BuildTool.GRADLE : build, javaVersion == null ? JdkVersion.JDK_8 : javaVersion), getOperatingSystem(requestInfo.getUserAgent()), features == null ? Collections.emptyList() : features, outputHandler, ConsoleOutput.NOOP);
        Map<String, String> contents = outputHandler.getProject();
        PreviewDTO previewDTO = new PreviewDTO(contents);
        previewDTO.addLink(Relationship.CREATE, requestInfo.link(Relationship.CREATE, type));
        previewDTO.addLink(Relationship.SELF, requestInfo.self());
        return previewDTO;
    } catch (IllegalArgumentException e) {
        throw new HttpStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
    } catch (Exception e) {
        LOG.error("Error generating application: " + e.getMessage(), e);
        throw new IOException(e.getMessage(), e);
    }
}
Also used : Project(io.micronaut.starter.application.Project) Options(io.micronaut.starter.options.Options) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) IOException(java.io.IOException) MapOutputHandler(io.micronaut.starter.io.MapOutputHandler) HttpStatusException(io.micronaut.http.exceptions.HttpStatusException) IOException(java.io.IOException) Get(io.micronaut.http.annotation.Get)

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