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);
}
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;
}
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()));
}
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);
}
}
});
}
}
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;
}
Aggregations