Search in sources :

Example 1 with Template

use of com.android.tools.idea.templates.Template in project android by JetBrains.

the class RenderTemplateModel method renderTemplate.

private boolean renderTemplate(boolean dryRun, @NotNull Project project, @NotNull AndroidProjectPaths paths, @Nullable List<File> filesToOpen, @Nullable List<File> filesToReformat) {
    final Template template = myTemplateHandle.getTemplate();
    File moduleRoot = paths.getModuleRoot();
    if (moduleRoot == null) {
        return false;
    }
    // @formatter:off
    final RenderingContext context = RenderingContext.Builder.newContext(template, project).withCommandName(myCommandName).withDryRun(dryRun).withShowErrors(true).withModuleRoot(paths.getModuleRoot()).withParams(myTemplateValues).intoOpenFiles(filesToOpen).intoTargetFiles(filesToReformat).build();
    // @formatter:on
    return template.render(context);
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) File(java.io.File) Template(com.android.tools.idea.templates.Template)

Example 2 with Template

use of com.android.tools.idea.templates.Template 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);
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) File(java.io.File) Template(com.android.tools.idea.templates.Template)

Example 3 with Template

use of com.android.tools.idea.templates.Template 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);
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) Parameter(com.android.tools.idea.templates.Parameter) Template(com.android.tools.idea.templates.Template)

Example 4 with Template

use of com.android.tools.idea.templates.Template 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);
}
Also used : RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) Template(com.android.tools.idea.templates.Template)

Example 5 with Template

use of com.android.tools.idea.templates.Template 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);
}
Also used : Project(com.intellij.openapi.project.Project) RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) Template(com.android.tools.idea.templates.Template)

Aggregations

Template (com.android.tools.idea.templates.Template)5 RenderingContext (com.android.tools.idea.templates.recipe.RenderingContext)5 File (java.io.File)2 Parameter (com.android.tools.idea.templates.Parameter)1 Project (com.intellij.openapi.project.Project)1