Search in sources :

Example 1 with Language

use of io.micronaut.starter.options.Language in project micronaut-starter by micronaut-projects.

the class OracleRawFunction method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    ApplicationType type = generatorContext.getApplicationType();
    if (type == ApplicationType.FUNCTION) {
        applyFunction(generatorContext, type);
        Language language = generatorContext.getLanguage();
        Project project = generatorContext.getProject();
        String sourceFile = generatorContext.getSourcePath("/{packagePath}/Function");
        switch(language) {
            case GROOVY:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, oracleRawFunctionGroovy.template(project)));
                break;
            case KOTLIN:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, oracleRawFunctionKotlin.template(project)));
                break;
            case JAVA:
            default:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, oracleRawFunctionJava.template(project)));
        }
        applyTestTemplate(generatorContext, project, "Function");
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) ApplicationType(io.micronaut.starter.application.ApplicationType) Project(io.micronaut.starter.application.Project) Language(io.micronaut.starter.options.Language)

Example 2 with Language

use of io.micronaut.starter.options.Language in project micronaut-starter by micronaut-projects.

the class GoogleCloudRawFunction method apply.

@Override
public void apply(GeneratorContext generatorContext) {
    ApplicationType type = generatorContext.getApplicationType();
    applyFunction(generatorContext, type);
    if (type == ApplicationType.FUNCTION) {
        Language language = generatorContext.getLanguage();
        Project project = generatorContext.getProject();
        String sourceFile = generatorContext.getSourcePath("/{packagePath}/Function");
        switch(language) {
            case GROOVY:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionGroovy.template(project)));
                break;
            case KOTLIN:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionKotlin.template(project)));
                break;
            case JAVA:
            default:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, gcpRawBackgroundFunctionJava.template(project)));
        }
        applyTestTemplate(generatorContext, project, "Function");
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) ApplicationType(io.micronaut.starter.application.ApplicationType) Project(io.micronaut.starter.application.Project) Language(io.micronaut.starter.options.Language)

Example 3 with Language

use of io.micronaut.starter.options.Language in project micronaut-starter by micronaut-projects.

the class CreateCommandCommand method call.

@Override
public Integer call() throws Exception {
    Project project = getProject(name);
    TemplateRenderer templateRenderer = getTemplateRenderer(project);
    RenderResult renderResult = null;
    if (config.getSourceLanguage() == Language.JAVA) {
        renderResult = templateRenderer.render(javaApplication.getTemplate(project), overwrite);
    } else if (config.getSourceLanguage() == Language.GROOVY) {
        renderResult = templateRenderer.render(groovyApplication.getTemplate(project), overwrite);
    } else if (config.getSourceLanguage() == Language.KOTLIN) {
        renderResult = templateRenderer.render(kotlinApplication.getTemplate(project), overwrite);
    }
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("Rendered command to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    Language rockerTemplateLanguage = (config.getTestFramework().getSupportedLanguages().contains(config.getSourceLanguage())) ? config.getSourceLanguage() : config.getTestFramework().getDefaultLanguage();
    TestRockerModelProvider testRockerModelProvider = new CustomTestRockerModelProvider(project, junit.getJunitRockerModelProvider(project)) {

        @Override
        public RockerModel spock() {
            return spock.getModel(getProject());
        }

        @Override
        public RockerModel koTest() {
            return koTest.getModel(project);
        }
    };
    RockerModel rockerModel = testRockerModelProvider.findModel(rockerTemplateLanguage, config.getTestFramework());
    String path = config.getTestFramework().getSourcePath(PATH, rockerTemplateLanguage);
    RockerTemplate rockerTemplate = new RockerTemplate(path, rockerModel);
    renderResult = templateRenderer.render(rockerTemplate, overwrite);
    if (renderResult != null) {
        if (renderResult.isSuccess()) {
            out("Rendered command test to " + renderResult.getPath());
        } else if (renderResult.isSkipped()) {
            warning("Rendering skipped for " + renderResult.getPath() + " because it already exists. Run again with -f to overwrite.");
        } else if (renderResult.getError() != null) {
            throw renderResult.getError();
        }
    }
    return 0;
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) Language(io.micronaut.starter.options.Language) TestRockerModelProvider(io.micronaut.starter.options.TestRockerModelProvider) AbstractTestRockerModelProvider(io.micronaut.starter.options.AbstractTestRockerModelProvider) TemplateRenderer(io.micronaut.starter.template.TemplateRenderer) RenderResult(io.micronaut.starter.template.RenderResult) RockerModel(com.fizzed.rocker.RockerModel)

Example 4 with Language

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

use of io.micronaut.starter.options.Language in project micronaut-starter by micronaut-projects.

the class AbstractFunctionFeature method applyFunction.

protected void applyFunction(GeneratorContext generatorContext, ApplicationType type) {
    BuildTool buildTool = generatorContext.getBuildTool();
    generatorContext.addHelpTemplate(new RockerWritable(readmeTemplate(generatorContext, generatorContext.getProject(), buildTool)));
    if (type == ApplicationType.DEFAULT) {
        final String className = StringUtils.capitalize(generatorContext.getProject().getPropertyName());
        Project project = generatorContext.getProject().withClassName(className);
        Language language = generatorContext.getLanguage();
        String sourceFile = generatorContext.getSourcePath("/{packagePath}/" + className + "Controller");
        switch(language) {
            case GROOVY:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, groovyControllerTemplate(project)));
                break;
            case KOTLIN:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, kotlinControllerTemplate(project)));
                break;
            case JAVA:
            default:
                generatorContext.addTemplate("function", new RockerTemplate(sourceFile, javaControllerTemplate(project)));
                break;
        }
        applyTestTemplate(generatorContext, project, className + getTestSuffix(type));
    }
}
Also used : RockerTemplate(io.micronaut.starter.template.RockerTemplate) Project(io.micronaut.starter.application.Project) RockerWritable(io.micronaut.starter.template.RockerWritable) Language(io.micronaut.starter.options.Language) BuildTool(io.micronaut.starter.options.BuildTool)

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