Search in sources :

Example 1 with ImportSpec

use of com.intellij.openapi.externalSystem.importing.ImportSpec in project intellij-community by JetBrains.

the class GradleModuleBuilder method setupModule.

@Override
protected void setupModule(Module module) throws ConfigurationException {
    super.setupModule(module);
    assert rootProjectPath != null;
    VirtualFile buildScriptFile = null;
    final BuildScriptDataBuilder buildScriptDataBuilder = getBuildScriptData(module);
    try {
        if (buildScriptDataBuilder != null) {
            buildScriptFile = buildScriptDataBuilder.getBuildScriptFile();
            final String text = buildScriptDataBuilder.build();
            appendToFile(buildScriptFile, "\n" + text);
        }
    } catch (IOException e) {
        LOG.warn("Unexpected exception on applying frameworks templates", e);
    }
    final Project project = module.getProject();
    if (myWizardContext.isCreatingNewProject()) {
        getExternalProjectSettings().setExternalProjectPath(rootProjectPath);
        AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
        project.putUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT, Boolean.TRUE);
        //noinspection unchecked
        settings.linkProject(getExternalProjectSettings());
    } else {
        FileDocumentManager.getInstance().saveAllDocuments();
        final GradleProjectSettings gradleProjectSettings = getExternalProjectSettings();
        final VirtualFile finalBuildScriptFile = buildScriptFile;
        Runnable runnable = () -> {
            if (myParentProject == null) {
                gradleProjectSettings.setExternalProjectPath(rootProjectPath);
                AbstractExternalSystemSettings settings = ExternalSystemApiUtil.getSettings(project, GradleConstants.SYSTEM_ID);
                //noinspection unchecked
                settings.linkProject(gradleProjectSettings);
            }
            ImportSpec importSpec = new ImportSpecBuilder(project, GradleConstants.SYSTEM_ID).use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).createDirectoriesForEmptyContentRoots().useDefaultCallback().build();
            ExternalSystemUtil.refreshProject(rootProjectPath, importSpec);
            final PsiFile psiFile;
            if (finalBuildScriptFile != null) {
                psiFile = PsiManager.getInstance(project).findFile(finalBuildScriptFile);
                if (psiFile != null) {
                    EditorHelper.openInEditor(psiFile);
                }
            }
        };
        // execute when current dialog is closed
        ExternalSystemUtil.invokeLater(project, ModalityState.NON_MODAL, runnable);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) BuildScriptDataBuilder(org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder) PsiFile(com.intellij.psi.PsiFile) IOException(java.io.IOException) ImportSpec(com.intellij.openapi.externalSystem.importing.ImportSpec) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Aggregations

ImportSpec (com.intellij.openapi.externalSystem.importing.ImportSpec)1 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 IOException (java.io.IOException)1 BuildScriptDataBuilder (org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder)1 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)1