Search in sources :

Example 6 with Language

use of io.micronaut.starter.options.Language 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

Language (io.micronaut.starter.options.Language)6 Project (io.micronaut.starter.application.Project)4 RockerTemplate (io.micronaut.starter.template.RockerTemplate)4 ApplicationType (io.micronaut.starter.application.ApplicationType)2 Feature (io.micronaut.starter.feature.Feature)2 RockerModel (com.fizzed.rocker.RockerModel)1 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 GeneratorContext (io.micronaut.starter.application.generator.GeneratorContext)1 AvailableFeatures (io.micronaut.starter.feature.AvailableFeatures)1 DefaultFeature (io.micronaut.starter.feature.DefaultFeature)1 FeatureContext (io.micronaut.starter.feature.FeatureContext)1 LanguageSpecificFeature (io.micronaut.starter.feature.LanguageSpecificFeature)1 FeatureValidator (io.micronaut.starter.feature.validation.FeatureValidator)1 ConsoleOutput (io.micronaut.starter.io.ConsoleOutput)1 AbstractTestRockerModelProvider (io.micronaut.starter.options.AbstractTestRockerModelProvider)1 BuildTool (io.micronaut.starter.options.BuildTool)1 Options (io.micronaut.starter.options.Options)1 TestRockerModelProvider (io.micronaut.starter.options.TestRockerModelProvider)1 RenderResult (io.micronaut.starter.template.RenderResult)1 RockerWritable (io.micronaut.starter.template.RockerWritable)1