use of com.android.tools.idea.templates.recipe.RenderingContext in project android by JetBrains.
the class NewModuleModel method renderModule.
private boolean renderModule(boolean dryRun, @NotNull Map<String, Object> templateState, @NotNull Project project) {
File projectRoot = new File(project.getBasePath());
File moduleRoot = new File(projectRoot, myModuleName.get());
Template template = Template.createFromPath(myTemplateFile.getValue());
// @formatter:off
RenderingContext context = RenderingContext.Builder.newContext(template, project).withCommandName("New Module").withDryRun(dryRun).withShowErrors(true).withOutputRoot(projectRoot).withModuleRoot(moduleRoot).withParams(templateState).build();
// @formatter:on
return template.render(context);
}
use of com.android.tools.idea.templates.recipe.RenderingContext in project android by JetBrains.
the class NewFormFactorModulePath method renderActivity.
private boolean renderActivity(boolean dryRun, Map<String, Object> templateState, File projectRoot, File moduleRoot) {
TemplateEntry templateEntry = myState.get(KEY_SELECTED_TEMPLATE);
if (templateEntry == null) {
return true;
}
Template activityTemplate = templateEntry.getTemplate();
for (Parameter parameter : templateEntry.getMetadata().getParameters()) {
templateState.put(parameter.id, myState.get(myParameterStep.getParameterKey(parameter)));
}
RenderingContext activityContext = RenderingContext.Builder.newContext(activityTemplate, myWizard.getProject()).withCommandName("New Module").withDryRun(dryRun).withShowErrors(true).withOutputRoot(projectRoot).withModuleRoot(moduleRoot).withParams(templateState).withGradleSync(myGradleSyncIfNecessary).intoTargetFiles(myState.get(TARGET_FILES_KEY)).intoOpenFiles(myState.get(FILES_TO_OPEN_KEY)).intoDependencies(myState.get(DEPENDENCIES_KEY)).build();
return activityTemplate.render(activityContext);
}
use of com.android.tools.idea.templates.recipe.RenderingContext in project android by JetBrains.
the class NewFormFactorModulePath method renderModule.
private boolean renderModule(boolean dryRun, Map<String, Object> templateState, File projectRoot, File moduleRoot) {
Template template = Template.createFromPath(myTemplateFile);
// @formatter:off
RenderingContext context = RenderingContext.Builder.newContext(template, myWizard.getProject()).withCommandName("New Module").withDryRun(dryRun).withShowErrors(true).withOutputRoot(projectRoot).withModuleRoot(moduleRoot).withParams(templateState).withGradleSync(myGradleSyncIfNecessary).intoTargetFiles(myState.get(TARGET_FILES_KEY)).intoOpenFiles(myState.get(FILES_TO_OPEN_KEY)).intoDependencies(myState.get(DEPENDENCIES_KEY)).build();
// @formatter:on
return template.render(context);
}
use of com.android.tools.idea.templates.recipe.RenderingContext in project android by JetBrains.
the class ConfigureAndroidProjectPath method performFinishingOperation.
private boolean performFinishingOperation(boolean dryRun) {
Project project = getProject();
assert project != null;
Template projectTemplate = Template.createFromName(Template.CATEGORY_PROJECTS, WizardConstants.PROJECT_TEMPLATE_NAME);
// @formatter:off
final RenderingContext context = RenderingContext.Builder.newContext(projectTemplate, project).withCommandName("New Project").withDryRun(dryRun).withShowErrors(true).withParams(myState.flatten()).intoTargetFiles(myState.get(WizardConstants.TARGET_FILES_KEY)).build();
// @formatter:on
return projectTemplate.render(context);
}
use of com.android.tools.idea.templates.recipe.RenderingContext in project android by JetBrains.
the class JavaModuleDynamicPath method performFinishingOperation.
private boolean performFinishingOperation(boolean dryRun) {
Project project = getProject();
assert project != null;
Map<String, Object> parameterValueMap = Maps.newHashMap();
// Grab our parameters from the state
parameterValueMap.putAll(myState.flatten());
// Compute the module directory
String projectName = (String) parameterValueMap.get(FormFactorUtils.ATTR_MODULE_NAME);
String moduleName = WizardUtils.computeModuleName(projectName, getProject());
String modulePath = FileUtil.toSystemIndependentName(FileUtil.join(project.getBasePath(), moduleName));
parameterValueMap.put(TemplateMetadata.ATTR_PROJECT_OUT, modulePath);
parameterValueMap.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
// Compute the output directory
String packageName = myState.get(PACKAGE_NAME);
assert packageName != null;
String packagePath = FileUtil.join(myState.getNotNull(SRC_DIR, "src/main/java/"), packageName.replace('.', '/'));
String srcOut = FileUtil.toSystemIndependentName(FileUtil.join(modulePath, packagePath));
parameterValueMap.put(TemplateMetadata.ATTR_SRC_OUT, srcOut);
parameterValueMap.put(TemplateMetadata.ATTR_IS_NEW_PROJECT, true);
parameterValueMap.put(ATTR_IS_LIBRARY_MODULE, true);
// Set Java version, if not already done
if (!parameterValueMap.containsKey(ATTR_JAVA_VERSION)) {
// We can't JUST look at the overall project level language level, since
// Gradle sync appears not to sync the overall project level; instead we
// have to take the min of all the modules
LanguageLevel min = ApplicationManager.getApplication().runReadAction(new Computable<LanguageLevel>() {
@Override
public LanguageLevel compute() {
LanguageLevel min = null;
for (Module module : ModuleManager.getInstance(project).getModules()) {
LanguageLevelModuleExtension moduleLevelExt = LanguageLevelModuleExtensionImpl.getInstance(module);
if (moduleLevelExt != null) {
LanguageLevel moduleLevel = moduleLevelExt.getLanguageLevel();
if (moduleLevel != null) {
if (min == null) {
min = moduleLevel;
} else if (moduleLevel.compareTo(min) < 0) {
min = moduleLevel;
}
}
}
}
if (min == null) {
min = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
}
return min;
}
});
parameterValueMap.put(ATTR_JAVA_VERSION, min.getCompilerComplianceDefaultOption());
}
// @formatter:off
RenderingContext context = RenderingContext.Builder.newContext(myTemplate, project).withCommandName("New Java Library").withDryRun(dryRun).withShowErrors(true).withModuleRoot(new File(FileUtil.toSystemDependentName(modulePath))).withParams(parameterValueMap).withGradleSync(false).build();
// @formatter:on
return myTemplate.render(context);
}
Aggregations