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");
}
}
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");
}
}
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;
}
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);
}
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));
}
}
Aggregations