Search in sources :

Example 1 with GeneratorContext

use of io.micronaut.starter.application.generator.GeneratorContext 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 project The project
 * @param applicationType The application type
 * @param options The options
 * @param features The features to diff
 * @param consoleOutput The console output
 * @throws Exception If something does wrong
 */
public void produceDiff(ProjectGenerator projectGenerator, Project project, ApplicationType applicationType, Options options, @Nullable OperatingSystem operatingSystem, List<String> features, ConsoleOutput consoleOutput) throws Exception {
    GeneratorContext generatorContext = projectGenerator.createGeneratorContext(applicationType, project, options, operatingSystem, features, consoleOutput);
    produceDiff(projectGenerator, generatorContext, consoleOutput);
}
Also used : GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext)

Example 2 with GeneratorContext

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

the class GitHubCreateService method creatApp.

protected GitHubRepository creatApp(@NonNull ApplicationType type, @NonNull String name, @Nullable List<String> features, @Nullable BuildTool buildTool, @Nullable TestFramework testFramework, @Nullable Language lang, @Nullable JdkVersion javaVersion, @NonNull String code, @NonNull String state, @Nullable String userAgent) {
    AccessToken accessToken = getGitHubAccessToken(code, state);
    String authToken = TOKEN_PREFIX + accessToken.getAccessToken();
    GitHubUser gitHubUser = getGitHubUser(authToken);
    GeneratorContext generatorContext = createProjectGeneratorContext(type, name, features, buildTool, testFramework, lang, javaVersion, userAgent);
    String repoName = generatorContext.getProject().getName();
    String repoDescription = String.format("Micronaut %s Application", generatorContext.getProject().getNaturalName());
    GitHubRepository githubRepository = createGitHubRepository(authToken, repoName, repoDescription, gitHubUser);
    pushToGithubRepository(generatorContext, gitHubUser, githubRepository, accessToken);
    return githubRepository;
}
Also used : GitHubUser(io.micronaut.starter.api.create.github.client.v3.GitHubUser) AccessToken(io.micronaut.starter.api.create.github.client.oauth.AccessToken) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) GitHubRepository(io.micronaut.starter.api.create.github.client.v3.GitHubRepository)

Example 3 with GeneratorContext

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

the class ZipCreateController method generateAppIntoZipFile.

public HttpResponse<Writable> generateAppIntoZipFile(@NotNull ApplicationType type, @NotNull String name, @Nullable List<String> features, @Nullable BuildTool buildTool, @Nullable TestFramework testFramework, @Nullable Language lang, @Nullable JdkVersion javaVersion, @Nullable String userAgent) {
    GeneratorContext generatorContext = createProjectGeneratorContext(type, name, features, buildTool, testFramework, lang, javaVersion, userAgent);
    MutableHttpResponse<Writable> response = HttpResponse.created(new Writable() {

        @Override
        public void writeTo(OutputStream outputStream, @Nullable Charset charset) throws IOException {
            try {
                projectGenerator.generate(type, generatorContext.getProject(), new ZipOutputHandler(outputStream), generatorContext);
                outputStream.flush();
            } catch (Exception e) {
                LOG.error("Error generating application: " + e.getMessage(), e);
                throw new IOException(e.getMessage(), e);
            }
        }

        @Override
        public void writeTo(Writer out) {
        // no-op, output stream used
        }
    });
    return response.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + getFilename(generatorContext.getProject()));
}
Also used : OutputStream(java.io.OutputStream) Writable(io.micronaut.core.io.Writable) Charset(java.nio.charset.Charset) IOException(java.io.IOException) ZipOutputHandler(io.micronaut.starter.io.ZipOutputHandler) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) IOException(java.io.IOException) Writer(java.io.Writer)

Example 4 with GeneratorContext

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

the class GenerationListener method onApplicationGenerated.

@EventListener
void onApplicationGenerated(ApplicationGeneratingEvent event) {
    GeneratorContext context = event.getSource();
    List<SelectedFeature> features = context.getFeatures().stream().map(SelectedFeature::new).collect(Collectors.toList());
    Generated generated = new Generated(context.getApplicationType(), context.getLanguage(), context.getBuildTool(), context.getTestFramework(), context.getJdkVersion());
    generated.setSelectedFeatures(features);
    if (analyticsOperations != null) {
        analyticsOperations.applicationGenerated(generated).whenComplete((httpStatus, throwable) -> {
            if (throwable != null) {
                if (LOG.isErrorEnabled()) {
                    LOG.error("Error occurred reporting analytics: " + throwable.getMessage(), throwable);
                }
            }
        });
    }
}
Also used : SelectedFeature(io.micronaut.starter.analytics.SelectedFeature) Generated(io.micronaut.starter.analytics.Generated) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) EventListener(io.micronaut.runtime.event.annotation.EventListener)

Example 5 with GeneratorContext

use of io.micronaut.starter.application.generator.GeneratorContext 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

GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)9 HttpStatusException (io.micronaut.http.exceptions.HttpStatusException)3 Project (io.micronaut.starter.application.Project)3 Get (io.micronaut.http.annotation.Get)2 ProjectGenerator (io.micronaut.starter.application.generator.ProjectGenerator)2 Feature (io.micronaut.starter.feature.Feature)2 Options (io.micronaut.starter.options.Options)2 ApiResponse (io.swagger.v3.oas.annotations.responses.ApiResponse)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Writable (io.micronaut.core.io.Writable)1 EventListener (io.micronaut.runtime.event.annotation.EventListener)1 Generated (io.micronaut.starter.analytics.Generated)1 SelectedFeature (io.micronaut.starter.analytics.SelectedFeature)1 AccessToken (io.micronaut.starter.api.create.github.client.oauth.AccessToken)1 GitHubRepository (io.micronaut.starter.api.create.github.client.v3.GitHubRepository)1 GitHubUser (io.micronaut.starter.api.create.github.client.v3.GitHubUser)1 ApplicationGeneratingEvent (io.micronaut.starter.api.event.ApplicationGeneratingEvent)1 ApplicationType (io.micronaut.starter.application.ApplicationType)1