Search in sources :

Example 1 with FeatureContext

use of io.micronaut.starter.feature.FeatureContext in project micronaut-starter by micronaut-projects.

the class DefaultProjectGenerator method createGeneratorContext.

@Override
public GeneratorContext createGeneratorContext(ApplicationType applicationType, Project project, Options options, @Nullable OperatingSystem operatingSystem, List<String> selectedFeatures, ConsoleOutput consoleOutput) {
    AvailableFeatures availableFeatures = beanContext.getBean(AvailableFeatures.class, Qualifiers.byName(applicationType.getName()));
    FeatureContext featureContext = contextFactory.createFeatureContext(availableFeatures, selectedFeatures, applicationType, options, operatingSystem);
    return contextFactory.createGeneratorContext(project, featureContext, consoleOutput);
}
Also used : AvailableFeatures(io.micronaut.starter.feature.AvailableFeatures) FeatureContext(io.micronaut.starter.feature.FeatureContext)

Example 2 with FeatureContext

use of io.micronaut.starter.feature.FeatureContext in project micronaut-starter by micronaut-projects.

the class ContextFactory method createFeatureContext.

public FeatureContext createFeatureContext(AvailableFeatures availableFeatures, List<String> selectedFeatures, ApplicationType applicationType, Options options, @Nullable OperatingSystem operatingSystem) {
    final Set<Feature> features = Collections.newSetFromMap(new IdentityHashMap<>(8));
    for (String name : selectedFeatures) {
        Feature feature = availableFeatures.findFeature(name).orElse(null);
        if (feature != null) {
            features.add(feature);
        } else {
            throw new IllegalArgumentException("The requested feature does not exist: " + name);
        }
    }
    Language language = determineLanguage(options.getLanguage(), features);
    Options newOptions = options.withLanguage(language);
    availableFeatures.getAllFeatures().filter(f -> f instanceof DefaultFeature).filter(f -> ((DefaultFeature) f).shouldApply(applicationType, newOptions, features)).forEach(features::add);
    featureValidator.validatePreProcessing(newOptions, applicationType, features);
    return new FeatureContext(newOptions, applicationType, operatingSystem, features);
}
Also used : FeatureValidator(io.micronaut.starter.feature.validation.FeatureValidator) Options(io.micronaut.starter.options.Options) FeatureContext(io.micronaut.starter.feature.FeatureContext) java.util(java.util) ConsoleOutput(io.micronaut.starter.io.ConsoleOutput) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) Feature(io.micronaut.starter.feature.Feature) Nullable(edu.umd.cs.findbugs.annotations.Nullable) AvailableFeatures(io.micronaut.starter.feature.AvailableFeatures) GeneratorContext(io.micronaut.starter.application.generator.GeneratorContext) Language(io.micronaut.starter.options.Language) Singleton(javax.inject.Singleton) Options(io.micronaut.starter.options.Options) Language(io.micronaut.starter.options.Language) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) DefaultFeature(io.micronaut.starter.feature.DefaultFeature) Feature(io.micronaut.starter.feature.Feature) FeatureContext(io.micronaut.starter.feature.FeatureContext)

Example 3 with FeatureContext

use of io.micronaut.starter.feature.FeatureContext 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)

Aggregations

FeatureContext (io.micronaut.starter.feature.FeatureContext)3 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)2 AvailableFeatures (io.micronaut.starter.feature.AvailableFeatures)2 Feature (io.micronaut.starter.feature.Feature)2 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 DefaultFeature (io.micronaut.starter.feature.DefaultFeature)1 FeatureValidator (io.micronaut.starter.feature.validation.FeatureValidator)1 ConsoleOutput (io.micronaut.starter.io.ConsoleOutput)1 Language (io.micronaut.starter.options.Language)1 Options (io.micronaut.starter.options.Options)1 java.util (java.util)1 Singleton (javax.inject.Singleton)1