Search in sources :

Example 1 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class ExternalProjectsStructure method updateProjects.

public void updateProjects(Collection<DataNode<ProjectData>> toImport) {
    List<String> orphanProjects = ContainerUtil.mapNotNull(myNodeMapping.entrySet(), entry -> entry.getValue() instanceof ProjectNode ? entry.getKey() : null);
    for (DataNode<ProjectData> each : toImport) {
        final ProjectData projectData = each.getData();
        final String projectPath = projectData.getLinkedExternalProjectPath();
        orphanProjects.remove(projectPath);
        ExternalSystemNode projectNode = findNodeFor(projectPath);
        if (projectNode instanceof ProjectNode) {
            doMergeChildrenChanges(projectNode, each, new ProjectNode(myExternalProjectsView, each));
        } else {
            ExternalSystemNode node = myNodeMapping.remove(projectPath);
            if (node != null) {
                SimpleNode parent = node.getParent();
                if (parent instanceof ExternalSystemNode) {
                    ((ExternalSystemNode) parent).remove(projectNode);
                }
            }
            projectNode = new ProjectNode(myExternalProjectsView, each);
            myNodeMapping.put(projectPath, projectNode);
        }
        if (toImport.size() == 1) {
            myTreeBuilder.expand(projectNode, null);
        }
        doUpdateProject((ProjectNode) projectNode);
    }
    //remove orphan projects from view
    for (String orphanProjectPath : orphanProjects) {
        ExternalSystemNode projectNode = myNodeMapping.remove(orphanProjectPath);
        if (projectNode instanceof ProjectNode) {
            SimpleNode parent = projectNode.getParent();
            if (parent instanceof ExternalSystemNode) {
                ((ExternalSystemNode) parent).remove(projectNode);
                updateUpTo(projectNode);
            }
        }
    }
}
Also used : ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 2 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData 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 3 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class ExternalProjectsViewImpl method init.

public void init() {
    Disposer.register(myProject, this);
    initTree();
    final ToolWindowManagerEx manager = ToolWindowManagerEx.getInstanceEx(myProject);
    final ToolWindowManagerAdapter listener = new ToolWindowManagerAdapter() {

        boolean wasVisible = false;

        @Override
        public void stateChanged() {
            if (myToolWindow.isDisposed())
                return;
            boolean visible = myToolWindow.isVisible();
            if (!visible || wasVisible) {
                wasVisible = visible;
                return;
            }
            scheduleStructureUpdate();
            wasVisible = true;
        }
    };
    manager.addToolWindowManagerListener(listener, myProject);
    getShortcutsManager().addListener(new ExternalSystemShortcutsManager.Listener() {

        @Override
        public void shortcutsUpdated() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    getTaskActivator().addListener(new ExternalSystemTaskActivator.Listener() {

        @Override
        public void tasksActivationChanged() {
            scheduleTasksUpdate();
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.updateNodes(RunConfigurationNode.class);
            });
        }
    });
    ((RunManagerEx) RunManager.getInstance(myProject)).addRunManagerListener(new RunManagerListener() {

        private void changed() {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                myStructure.visitNodes(ModuleNode.class, node -> node.updateRunConfigurations());
            });
        }

        @Override
        public void runConfigurationAdded(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationRemoved(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }

        @Override
        public void runConfigurationChanged(@NotNull RunnerAndConfigurationSettings settings) {
            changed();
        }
    });
    ExternalSystemApiUtil.subscribe(myProject, myExternalSystemId, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onUseAutoImportChange(boolean currentValue, @NotNull final String linkedProjectPath) {
            scheduleStructureRequest(() -> {
                assert myStructure != null;
                final List<ProjectNode> projectNodes = myStructure.getNodes(ProjectNode.class);
                for (ProjectNode projectNode : projectNodes) {
                    final ProjectData projectData = projectNode.getData();
                    if (projectData != null && projectData.getLinkedExternalProjectPath().equals(linkedProjectPath)) {
                        projectNode.updateProject();
                        break;
                    }
                }
            });
        }
    });
    myToolWindow.setAdditionalGearActions(createAdditionalGearActionsGroup());
    scheduleStructureUpdate();
}
Also used : ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) TreeState(com.intellij.ide.util.treeView.TreeState) PopupHandler(com.intellij.ui.PopupHandler) ExternalSystemApiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil) SmartList(com.intellij.util.SmartList) Disposer(com.intellij.openapi.util.Disposer) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) SimpleTree(com.intellij.ui.treeStructure.SimpleTree) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WriteExternalException(com.intellij.openapi.util.WriteExternalException) NotNull(org.jetbrains.annotations.NotNull) ExternalTaskExecutionInfo(com.intellij.openapi.externalSystem.model.execution.ExternalTaskExecutionInfo) InputEvent(java.awt.event.InputEvent) java.util(java.util) ExternalSystemActionUtil(com.intellij.openapi.externalSystem.action.ExternalSystemActionUtil) ExternalSystemTaskActivator(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemTaskActivator) ExternalSystemViewGearAction(com.intellij.openapi.externalSystem.action.ExternalSystemViewGearAction) NonNls(org.jetbrains.annotations.NonNls) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) InvalidDataException(com.intellij.openapi.util.InvalidDataException) ContainerUtil(com.intellij.util.containers.ContainerUtil) ExternalProjectsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManager) NotificationGroup(com.intellij.notification.NotificationGroup) Project(com.intellij.openapi.project.Project) ExternalSystemUiUtil(com.intellij.openapi.externalSystem.util.ExternalSystemUiUtil) com.intellij.openapi.externalSystem.model(com.intellij.openapi.externalSystem.model) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) DisposeAwareRunnable(com.intellij.util.DisposeAwareRunnable) TreeSelectionModel(javax.swing.tree.TreeSelectionModel) ExternalSystemUiAware(com.intellij.openapi.externalSystem.ExternalSystemUiAware) ExternalSystemTaskLocation(com.intellij.openapi.externalSystem.service.execution.ExternalSystemTaskLocation) Disposable(com.intellij.openapi.Disposable) com.intellij.execution(com.intellij.execution) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) ToolWindowEx(com.intellij.openapi.wm.ex.ToolWindowEx) TaskData(com.intellij.openapi.externalSystem.model.task.TaskData) ToolWindowImpl(com.intellij.openapi.wm.impl.ToolWindowImpl) Navigatable(com.intellij.pom.Navigatable) Element(org.jdom.Element) ScrollPaneFactory(com.intellij.ui.ScrollPaneFactory) ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ExternalSystemShortcutsManager(com.intellij.openapi.externalSystem.service.project.manage.ExternalSystemShortcutsManager) SmartList(com.intellij.util.SmartList) List(java.util.List) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 4 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class ProjectDataManager method importData.

@SuppressWarnings("unchecked")
public void importData(@NotNull Collection<DataNode<?>> nodes, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider, boolean synchronous) {
    if (project.isDisposed())
        return;
    MultiMap<Key<?>, DataNode<?>> grouped = ExternalSystemApiUtil.recursiveGroup(nodes);
    for (Key<?> key : myServices.getValue().keySet()) {
        if (!grouped.containsKey(key)) {
            grouped.put(key, Collections.<DataNode<?>>emptyList());
        }
    }
    final Collection<DataNode<?>> projects = grouped.get(ProjectKeys.PROJECT);
    // only one project(can be multi-module project) expected for per single import
    assert projects.size() == 1 || projects.isEmpty();
    final DataNode<ProjectData> projectNode = (DataNode<ProjectData>) ContainerUtil.getFirstItem(projects);
    final ProjectData projectData;
    ProjectSystemId projectSystemId;
    if (projectNode != null) {
        projectData = projectNode.getData();
        projectSystemId = projectNode.getData().getOwner();
        ExternalProjectsDataStorage.getInstance(project).saveInclusionSettings(projectNode);
    } else {
        projectData = null;
        DataNode<ModuleData> aModuleNode = (DataNode<ModuleData>) ContainerUtil.getFirstItem(grouped.get(ProjectKeys.MODULE));
        projectSystemId = aModuleNode != null ? aModuleNode.getData().getOwner() : null;
    }
    if (projectSystemId != null) {
        ExternalSystemUtil.scheduleExternalViewStructureUpdate(project, projectSystemId);
    }
    List<Runnable> onSuccessImportTasks = ContainerUtil.newSmartList();
    try {
        final Set<Map.Entry<Key<?>, Collection<DataNode<?>>>> entries = grouped.entrySet();
        final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
        if (indicator != null) {
            indicator.setIndeterminate(false);
        }
        final int size = entries.size();
        int count = 0;
        List<Runnable> postImportTasks = ContainerUtil.newSmartList();
        for (Map.Entry<Key<?>, Collection<DataNode<?>>> entry : entries) {
            if (indicator != null) {
                String message = ExternalSystemBundle.message("progress.update.text", projectSystemId != null ? projectSystemId.getReadableName() : "", "Refresh " + getReadableText(entry.getKey()));
                indicator.setText(message);
                indicator.setFraction((double) count++ / size);
            }
            doImportData(entry.getKey(), entry.getValue(), projectData, project, modelsProvider, postImportTasks, onSuccessImportTasks);
        }
        for (Runnable postImportTask : postImportTasks) {
            postImportTask.run();
        }
        commit(modelsProvider, project, synchronous, "Imported data");
        if (indicator != null) {
            indicator.setIndeterminate(true);
        }
    } catch (Throwable t) {
        dispose(modelsProvider, project, synchronous);
        ExceptionUtil.rethrowAllAsUnchecked(t);
    }
    for (Runnable onSuccessImportTask : ContainerUtil.reverse(onSuccessImportTasks)) {
        onSuccessImportTask.run();
    }
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) MultiMap(com.intellij.util.containers.MultiMap) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 5 with ProjectData

use of com.intellij.openapi.externalSystem.model.project.ProjectData in project intellij-community by JetBrains.

the class AbstractExternalProjectImportBuilder method commit.

@Override
public List<Module> commit(final Project project, final ModifiableModuleModel model, final ModulesProvider modulesProvider, final ModifiableArtifactModel artifactModel) {
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, Boolean.TRUE);
    final DataNode<ProjectData> externalProjectNode = getExternalProjectNode();
    if (externalProjectNode != null) {
        beforeCommit(externalProjectNode, project);
    }
    final boolean isFromUI = model != null;
    final List<Module> modules = ContainerUtil.newSmartList();
    final IdeModifiableModelsProvider modelsProvider = isFromUI ? new IdeUIModifiableModelsProvider(project, model, (ModulesConfigurator) modulesProvider, artifactModel) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    } : new IdeModifiableModelsProviderImpl(project) {

        @NotNull
        @Override
        public Module newModule(@NotNull @NonNls String filePath, String moduleTypeId) {
            final Module module = super.newModule(filePath, moduleTypeId);
            modules.add(module);
            return module;
        }
    };
    AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(project, myExternalSystemId);
    final ExternalProjectSettings projectSettings = getCurrentExternalProjectSettings();
    //noinspection unchecked
    Set<ExternalProjectSettings> projects = ContainerUtilRt.newHashSet(systemSettings.getLinkedProjectsSettings());
    // add current importing project settings to linked projects settings or replace if similar already exist
    projects.remove(projectSettings);
    projects.add(projectSettings);
    //noinspection unchecked
    systemSettings.copyFrom(myControl.getSystemSettings());
    //noinspection unchecked
    systemSettings.setLinkedProjectsSettings(projects);
    if (externalProjectNode != null) {
        if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
            ExternalProjectDataSelectorDialog dialog = new ExternalProjectDataSelectorDialog(project, new InternalExternalProjectInfo(myExternalSystemId, projectSettings.getExternalProjectPath(), externalProjectNode));
            if (dialog.hasMultipleDataToSelect()) {
                dialog.showAndGet();
            } else {
                Disposer.dispose(dialog.getDisposable());
            }
        }
        if (!project.isInitialized()) {
            StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings));
        } else
            finishImport(project, externalProjectNode, isFromUI, modules, modelsProvider, projectSettings);
    }
    return modules;
}
Also used : IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) InternalExternalProjectInfo(com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo) NotNull(org.jetbrains.annotations.NotNull) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings) IdeUIModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeUIModifiableModelsProvider) AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) ExternalProjectDataSelectorDialog(com.intellij.openapi.externalSystem.service.ui.ExternalProjectDataSelectorDialog) ModulesConfigurator(com.intellij.openapi.roots.ui.configuration.ModulesConfigurator) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Aggregations

ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)40 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)13 DataNode (com.intellij.openapi.externalSystem.model.DataNode)12 Project (com.intellij.openapi.project.Project)8 ExternalProjectSettings (com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)7 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)5 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)4 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 MultiMap (com.intellij.util.containers.MultiMap)4 NotNull (org.jetbrains.annotations.NotNull)4 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)3 InternalExternalProjectInfo (com.intellij.openapi.externalSystem.model.internal.InternalExternalProjectInfo)3 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 Module (com.intellij.openapi.module.Module)3 Task (com.intellij.openapi.progress.Task)3 DataNodeCaches (com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches)2 ImportSpecBuilder (com.intellij.openapi.externalSystem.importing.ImportSpecBuilder)2 ExternalProjectPojo (com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo)2