Search in sources :

Example 1 with ImportSpecBuilder

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

the class ExternalSystemUtil method refreshProjects.

/**
   * Asks to refresh all external projects of the target external system linked to the given ide project based on provided spec
   *
   * @param spec import specification
   */
public static void refreshProjects(@NotNull final ImportSpec spec) {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(spec.getExternalSystemId());
    if (manager == null) {
        return;
    }
    AbstractExternalSystemSettings<?, ?, ?> settings = manager.getSettingsProvider().fun(spec.getProject());
    final Collection<? extends ExternalProjectSettings> projectsSettings = settings.getLinkedProjectsSettings();
    if (projectsSettings.isEmpty()) {
        return;
    }
    final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
    final ExternalProjectRefreshCallback callback;
    if (spec.getCallback() == null) {
        callback = new MyMultiExternalProjectRefreshCallback(spec.getProject(), projectDataManager, spec.getExternalSystemId());
    } else {
        callback = spec.getCallback();
    }
    Set<String> toRefresh = ContainerUtilRt.newHashSet();
    for (ExternalProjectSettings setting : projectsSettings) {
        // don't refresh project when auto-import is disabled if such behavior needed (e.g. on project opening when auto-import is disabled)
        if (!setting.isUseAutoImport() && spec.whenAutoImportEnabled())
            continue;
        toRefresh.add(setting.getExternalProjectPath());
    }
    if (!toRefresh.isEmpty()) {
        ExternalSystemNotificationManager.getInstance(spec.getProject()).clearNotifications(null, NotificationSource.PROJECT_SYNC, spec.getExternalSystemId());
        for (String path : toRefresh) {
            refreshProject(path, new ImportSpecBuilder(spec).callback(callback).build());
        }
    }
}
Also used : ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 2 with ImportSpecBuilder

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

the class ExternalSystemUtil method refreshProject.

/**
   * <p>
   * Refresh target gradle project.
   *
   * @param project             target intellij project to use
   * @param externalProjectPath path of the target external project
   * @param callback            callback to be notified on refresh result
   * @param isPreviewMode       flag that identifies whether libraries should be resolved during the refresh
   * @param reportRefreshError  prevent to show annoying error notification, e.g. if auto-import mode used
   */
public static void refreshProject(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId, @NotNull final String externalProjectPath, @NotNull final ExternalProjectRefreshCallback callback, final boolean isPreviewMode, @NotNull final ProgressExecutionMode progressExecutionMode, final boolean reportRefreshError) {
    ImportSpecBuilder builder = new ImportSpecBuilder(project, externalSystemId).callback(callback).use(progressExecutionMode);
    if (isPreviewMode)
        builder.usePreviewMode();
    if (!reportRefreshError)
        builder.dontReportRefreshErrors();
    refreshProject(externalProjectPath, builder.build());
}
Also used : ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 3 with ImportSpecBuilder

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

the class ExternalSystemImportingTestCase method doImportProject.

private void doImportProject() {
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(myProject, getExternalSystemId());
    final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    projectSettings.setExternalProjectPath(getProjectPath());
    Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
    projects.remove(projectSettings);
    projects.add(projectSettings);
    systemSettings.setLinkedProjectsSettings(projects);
    final Ref<Couple<String>> error = Ref.create();
    ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(myProject, getExternalSystemId()).use(ProgressExecutionMode.MODAL_SYNC).callback(new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
            if (externalProject == null) {
                System.err.println("Got null External project after import");
                return;
            }
            ServiceManager.getService(ProjectDataManager.class).importData(externalProject, myProject, true);
            System.out.println("External project was successfully imported");
        }

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
            error.set(Couple.of(errorMessage, errorDetails));
        }
    }).forceWhenUptodate());
    if (!error.isNull()) {
        String failureMsg = "Import failed: " + error.get().first;
        if (StringUtil.isNotEmpty(error.get().second)) {
            failureMsg += "\nError details: \n" + error.get().second;
        }
        fail(failureMsg);
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) Couple(com.intellij.openapi.util.Couple) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 4 with ImportSpecBuilder

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

the class ExternalSystemStartupActivity method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        return;
    }
    Runnable task = () -> {
        for (ExternalSystemManager<?, ?, ?, ?, ?> manager : ExternalSystemApiUtil.getAllManagers()) {
            if (manager instanceof StartupActivity) {
                ((StartupActivity) manager).runActivity(project);
            }
        }
        if (project.getUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT) != Boolean.TRUE) {
            for (ExternalSystemManager manager : ExternalSystemManager.EP_NAME.getExtensions()) {
                final boolean isNewProject = project.getUserData(ExternalSystemDataKeys.NEWLY_CREATED_PROJECT) == Boolean.TRUE;
                if (isNewProject) {
                    ExternalSystemUtil.refreshProjects(new ImportSpecBuilder(project, manager.getSystemId()).createDirectoriesForEmptyContentRoots());
                }
            }
        }
        ExternalToolWindowManager.handle(project);
        ExternalSystemVcsRegistrar.handle(project);
        ProjectRenameAware.beAware(project);
    };
    ExternalProjectsManager.getInstance(project).init();
    DumbService.getInstance(project).runWhenSmart(DisposeAwareRunnable.create(task, project));
}
Also used : StartupActivity(com.intellij.openapi.startup.StartupActivity) ExternalSystemManager(com.intellij.openapi.externalSystem.ExternalSystemManager) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Example 5 with ImportSpecBuilder

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

the class GradleRefreshProjectDependenciesAction method perform.

@Override
public void perform(@NotNull final Project project, @NotNull ProjectSystemId projectSystemId, @NotNull AbstractExternalEntityData externalEntityData, @NotNull AnActionEvent e) {
    final List<ExternalSystemNode> selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext());
    final ExternalSystemNode<?> externalSystemNode = ContainerUtil.getFirstItem(selectedNodes);
    assert externalSystemNode != null;
    final ExternalConfigPathAware externalConfigPathAware = externalSystemNode.getData() instanceof ExternalConfigPathAware ? (ExternalConfigPathAware) externalSystemNode.getData() : null;
    assert externalConfigPathAware != null;
    // We save all documents because there is a possible case that there is an external system config file changed inside the ide.
    FileDocumentManager.getInstance().saveAllDocuments();
    final ExternalProjectSettings linkedProjectSettings = ExternalSystemApiUtil.getSettings(project, projectSystemId).getLinkedProjectSettings(externalConfigPathAware.getLinkedExternalProjectPath());
    final String externalProjectPath = linkedProjectSettings == null ? externalConfigPathAware.getLinkedExternalProjectPath() : linkedProjectSettings.getExternalProjectPath();
    ExternalSystemUtil.refreshProject(externalProjectPath, new ImportSpecBuilder(project, projectSystemId).useDefaultCallback().use(ProgressExecutionMode.IN_BACKGROUND_ASYNC).withArguments("--refresh-dependencies").build());
}
Also used : ExternalConfigPathAware(com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware) ExternalSystemNode(com.intellij.openapi.externalSystem.view.ExternalSystemNode) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) ImportSpecBuilder(com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)

Aggregations

ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)7 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)4 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)3 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)2 Couple (com.intellij.openapi.util.Couple)2 ExternalSystemManager (com.intellij.openapi.externalSystem.ExternalSystemManager)1 ImportSpec (com.intellij.openapi.externalSystem.importing.ImportSpec)1 ExternalConfigPathAware (com.intellij.openapi.externalSystem.model.project.ExternalConfigPathAware)1 ProjectDataManager (com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager)1 ExternalSystemNode (com.intellij.openapi.externalSystem.view.ExternalSystemNode)1 Project (com.intellij.openapi.project.Project)1 StartupActivity (com.intellij.openapi.startup.StartupActivity)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 DisposeAwareRunnable (com.intellij.util.DisposeAwareRunnable)1 IOException (java.io.IOException)1 BuildScriptDataBuilder (org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder)1 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)1