Search in sources :

Example 6 with Feature

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

Example 7 with Feature

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

the class RequiredLanguageFeatureValidator method validatePreProcessing.

@Override
public void validatePreProcessing(Options options, ApplicationType applicationType, Set<Feature> features) {
    Map<Language, Set<String>> requiredLanguages = new HashMap<>();
    for (Feature feature : features) {
        if (feature instanceof LanguageSpecificFeature) {
            Language lang = ((LanguageSpecificFeature) feature).getRequiredLanguage();
            requiredLanguages.compute(lang, (key, value) -> {
                if (value == null) {
                    value = new HashSet<>();
                }
                value.add(feature.getName());
                return value;
            });
        }
    }
    Set<Language> languages = requiredLanguages.keySet();
    Iterator<Language> languageIterator = languages.iterator();
    if (languages.size() > 1) {
        Language first = languageIterator.next();
        Language second = languageIterator.next();
        throw new IllegalArgumentException(String.format("The selected features are incompatible. %s requires %s and %s requires %s", requiredLanguages.get(first), first, requiredLanguages.get(second), second));
    }
    Language requiredLanguage = languageIterator.hasNext() ? languageIterator.next() : null;
    if (options != null && requiredLanguage != null && requiredLanguage != options.getLanguage()) {
        throw new IllegalArgumentException(String.format("The selected features are incompatible. %s requires %s but %s was the selected language.", requiredLanguages.get(requiredLanguage), requiredLanguage, options.getLanguage()));
    }
}
Also used : Language(io.micronaut.starter.options.Language) LanguageSpecificFeature(io.micronaut.starter.feature.LanguageSpecificFeature) LanguageSpecificFeature(io.micronaut.starter.feature.LanguageSpecificFeature) Feature(io.micronaut.starter.feature.Feature)

Aggregations

Feature (io.micronaut.starter.feature.Feature)7 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)3 DefaultFeature (io.micronaut.starter.feature.DefaultFeature)2 FeatureContext (io.micronaut.starter.feature.FeatureContext)2 Language (io.micronaut.starter.options.Language)2 Options (io.micronaut.starter.options.Options)2 Singleton (javax.inject.Singleton)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 ApplicationType (io.micronaut.starter.application.ApplicationType)1 AvailableFeatures (io.micronaut.starter.feature.AvailableFeatures)1 FeaturePhase (io.micronaut.starter.feature.FeaturePhase)1 FeaturePredicate (io.micronaut.starter.feature.FeaturePredicate)1 LanguageSpecificFeature (io.micronaut.starter.feature.LanguageSpecificFeature)1 io.micronaut.starter.feature.other.template.readme (io.micronaut.starter.feature.other.template.readme)1 FeatureValidator (io.micronaut.starter.feature.validation.FeatureValidator)1 ConsoleOutput (io.micronaut.starter.io.ConsoleOutput)1 RockerWritable (io.micronaut.starter.template.RockerWritable)1 Template (io.micronaut.starter.template.Template)1 Writable (io.micronaut.starter.template.Writable)1