Search in sources :

Example 6 with RenderingContext

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

Example 7 with RenderingContext

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);
}
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 8 with RenderingContext

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

Example 9 with RenderingContext

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

Example 10 with RenderingContext

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);
}
Also used : Project(com.intellij.openapi.project.Project) RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) File(java.io.File)

Aggregations

RenderingContext (com.android.tools.idea.templates.recipe.RenderingContext)13 File (java.io.File)10 Template (com.android.tools.idea.templates.Template)5 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 IOException (java.io.IOException)4 RecipeExecutor (com.android.tools.idea.templates.recipe.RecipeExecutor)3 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)3 Module (com.intellij.openapi.module.Module)2 GradleInvocationResult (com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult)1 NewProjectWizardState (com.android.tools.idea.npw.NewProjectWizardState)1 FreemarkerUtils (com.android.tools.idea.templates.FreemarkerUtils)1 TemplateProcessingException (com.android.tools.idea.templates.FreemarkerUtils.TemplateProcessingException)1 Parameter (com.android.tools.idea.templates.Parameter)1 Recipe (com.android.tools.idea.templates.recipe.Recipe)1 TemplateWizardState (com.android.tools.idea.wizard.template.TemplateWizardState)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)1 Pair (com.intellij.openapi.util.Pair)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1