Search in sources :

Example 6 with GeneratorContext

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);
}
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 7 with 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);
}
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 8 with 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("");
    });
}
Also used : GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) Feature(io.micronaut.starter.feature.Feature) FeatureContext(io.micronaut.starter.feature.FeatureContext)

Example 9 with GeneratorContext

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);
                }
            }
        });
    }
}
Also used : OutputStream(java.io.OutputStream) Options(io.micronaut.starter.options.Options) Writable(io.micronaut.starter.template.Writable) ApplicationType(io.micronaut.starter.application.ApplicationType) Feature(io.micronaut.starter.feature.Feature) Set(java.util.Set) IOException(java.io.IOException) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Template(io.micronaut.starter.template.Template) List(java.util.List) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) NonNull(edu.umd.cs.findbugs.annotations.NonNull) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) RockerWritable(io.micronaut.starter.template.RockerWritable) io.micronaut.starter.feature.other.template.readme(io.micronaut.starter.feature.other.template.readme) FeaturePhase(io.micronaut.starter.feature.FeaturePhase) RockerWritable(io.micronaut.starter.template.RockerWritable) OutputStream(java.io.OutputStream) Writable(io.micronaut.starter.template.Writable) RockerWritable(io.micronaut.starter.template.RockerWritable) IOException(java.io.IOException) Feature(io.micronaut.starter.feature.Feature) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) Template(io.micronaut.starter.template.Template)

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