use of io.micronaut.starter.application.generator.GeneratorContext 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);
}
use of io.micronaut.starter.application.generator.GeneratorContext 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);
}
use of io.micronaut.starter.application.generator.GeneratorContext in project micronaut-starter by micronaut-projects.
the class ListFeatures method output.
void output(ConsoleOutput consoleOutput) {
FeatureContext featureContext = contextFactory.createFeatureContext(availableFeatures, Collections.emptyList(), applicationType, options, operatingSystem);
GeneratorContext generatorContext = contextFactory.createGeneratorContext(null, featureContext, ConsoleOutput.NOOP);
Set<Feature> defaultFeatures = generatorContext.getFeatures().getFeatures();
List<Feature> allFeatures = availableFeatures.getFeatures().collect(Collectors.toList());
int width = allFeatures.stream().map(Feature::getName).max(Comparator.comparingInt(String::length)).map(String::length).get() + 8;
Map<String, List<Feature>> featuresByCategory = allFeatures.stream().sorted(Comparator.comparing(Feature::getName)).collect(Collectors.groupingBy(Feature::getCategory));
featuresByCategory = new TreeMap<>(featuresByCategory);
consoleOutput.out("Available Features");
consoleOutput.out("@|blue (+)|@ denotes the feature is included by default");
consoleOutput.out(" " + String.format("%1$-" + width + "s", "Name") + "Description");
consoleOutput.out(" " + new String(new char[width - 2]).replace("\0", "-") + " ---------------");
featuresByCategory.forEach((category, features) -> {
consoleOutput.out(" @|bold,underline,magenta " + category + "|@");
listFeatures(consoleOutput, defaultFeatures, features, width);
consoleOutput.out("");
});
}
use of io.micronaut.starter.application.generator.GeneratorContext in project micronaut-starter by micronaut-projects.
the class Readme method apply.
@Override
public void apply(GeneratorContext generatorContext) {
List<Feature> featuresWithDocumentationLinks = generatorContext.getFeatures().getFeatures().stream().filter(feature -> feature.getMicronautDocumentation() != null || feature.getThirdPartyDocumentation() != null).collect(Collectors.toList());
List<Writable> helpTemplates = generatorContext.getHelpTemplates();
if (!helpTemplates.isEmpty() || !featuresWithDocumentationLinks.isEmpty()) {
generatorContext.addTemplate("readme", new Template() {
@Override
public String getPath() {
return "README.md";
}
@Override
public void write(OutputStream outputStream) throws IOException {
for (Writable writable : generatorContext.getHelpTemplates()) {
writable.write(outputStream);
}
for (Feature feature : featuresWithDocumentationLinks) {
Writable writable = new RockerWritable(readme.template(feature));
writable.write(outputStream);
}
}
});
}
}
Aggregations