Search in sources :

Example 46 with DataNode

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

the class ExternalProjectDataSelectorDialog method getModifiableDataNode.

@NotNull
private static DataNode getModifiableDataNode(@NotNull DataNode node) {
    DataNode modifiedDataNode = (DataNode) node.getUserData(MODIFIED_NODE_KEY);
    if (modifiedDataNode == null) {
        modifiedDataNode = node.nodeCopy();
        node.putUserData(MODIFIED_NODE_KEY, modifiedDataNode);
    }
    return modifiedDataNode;
}
Also used : DataNode(com.intellij.openapi.externalSystem.model.DataNode) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with DataNode

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

the class AbstractExternalProjectImportBuilder method ensureProjectIsDefined.

/**
   * Asks current builder to ensure that target external project is defined.
   *
   * @param wizardContext             current wizard context
   * @throws ConfigurationException   if external project is not defined and can't be constructed
   */
@SuppressWarnings("unchecked")
public void ensureProjectIsDefined(@NotNull WizardContext wizardContext) throws ConfigurationException {
    final String externalSystemName = myExternalSystemId.getReadableName();
    File projectFile = getProjectFile();
    if (projectFile == null) {
        throw new ConfigurationException(ExternalSystemBundle.message("error.project.undefined"));
    }
    projectFile = getExternalProjectConfigToUse(projectFile);
    final Ref<ConfigurationException> error = new Ref<>();
    final ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {

        @Override
        public void onSuccess(@Nullable DataNode<ProjectData> externalProject) {
            myExternalProjectNode = externalProject;
        }

        @Override
        public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
            if (!StringUtil.isEmpty(errorDetails)) {
                LOG.warn(errorDetails);
            }
            error.set(new ConfigurationException(ExternalSystemBundle.message("error.resolve.with.log_link", errorMessage, PathManager.getLogPath()), ExternalSystemBundle.message("error.resolve.generic")));
        }
    };
    final Project project = getProject(wizardContext);
    final File finalProjectFile = projectFile;
    final String externalProjectPath = FileUtil.toCanonicalPath(finalProjectFile.getAbsolutePath());
    final Ref<ConfigurationException> exRef = new Ref<>();
    executeAndRestoreDefaultProjectSettings(project, () -> {
        try {
            ExternalSystemUtil.refreshProject(project, myExternalSystemId, externalProjectPath, callback, true, ProgressExecutionMode.MODAL_SYNC);
        } catch (IllegalArgumentException e) {
            exRef.set(new ConfigurationException(e.getMessage(), ExternalSystemBundle.message("error.cannot.parse.project", externalSystemName)));
        }
    });
    ConfigurationException ex = exRef.get();
    if (ex != null) {
        throw ex;
    }
    if (myExternalProjectNode == null) {
        ConfigurationException exception = error.get();
        if (exception != null) {
            throw exception;
        }
    } else {
        applyProjectSettings(wizardContext);
    }
}
Also used : Project(com.intellij.openapi.project.Project) Ref(com.intellij.openapi.util.Ref) ConfigurationException(com.intellij.openapi.options.ConfigurationException) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectRefreshCallback(com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 48 with DataNode

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

the class ToolWindowModuleService method processData.

@Override
protected void processData(@NotNull final Collection<DataNode<ModuleData>> nodes, @NotNull Project project) {
    if (nodes.isEmpty()) {
        return;
    }
    ProjectSystemId externalSystemId = nodes.iterator().next().getData().getOwner();
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
    assert manager != null;
    final MultiMap<DataNode<ProjectData>, DataNode<ModuleData>> grouped = ExternalSystemApiUtil.groupBy(nodes, ProjectKeys.PROJECT);
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> data = ContainerUtilRt.newHashMap();
    for (Map.Entry<DataNode<ProjectData>, Collection<DataNode<ModuleData>>> entry : grouped.entrySet()) {
        data.put(ExternalProjectPojo.from(entry.getKey().getData()), ContainerUtilRt.map2List(entry.getValue(), MAPPER));
    }
    AbstractExternalSystemLocalSettings settings = manager.getLocalSettingsProvider().fun(project);
    Set<String> pathsToForget = detectRenamedProjects(data, settings.getAvailableProjects());
    if (!pathsToForget.isEmpty()) {
        settings.forgetExternalProjects(pathsToForget);
    }
    Map<ExternalProjectPojo, Collection<ExternalProjectPojo>> projects = ContainerUtilRt.newHashMap(settings.getAvailableProjects());
    projects.putAll(data);
    settings.setAvailableProjects(projects);
}
Also used : AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) MultiMap(com.intellij.util.containers.MultiMap)

Example 49 with DataNode

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

the class ExternalSystemImportingTestCase method ignoreData.

protected void ignoreData(BooleanFunction<DataNode<?>> booleanFunction, final boolean ignored) {
    final ExternalProjectInfo externalProjectInfo = ProjectDataManager.getInstance().getExternalProjectData(myProject, getExternalSystemId(), getCurrentExternalProjectSettings().getExternalProjectPath());
    assertNotNull(externalProjectInfo);
    final DataNode<ProjectData> projectDataNode = externalProjectInfo.getExternalProjectStructure();
    assertNotNull(projectDataNode);
    final Collection<DataNode<?>> nodes = ExternalSystemApiUtil.findAllRecursively(projectDataNode, booleanFunction);
    for (DataNode<?> node : nodes) {
        ExternalSystemApiUtil.visit(node, dataNode -> dataNode.setIgnored(ignored));
    }
    ServiceManager.getService(ProjectDataManager.class).importData(projectDataNode, myProject, true);
}
Also used : ExternalProjectInfo(com.intellij.openapi.externalSystem.model.ExternalProjectInfo) ProjectDataManager(com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 50 with DataNode

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

the class ExternalSystemViewDefaultContributor method addModuleNodes.

private static void addModuleNodes(@NotNull ExternalProjectsView externalProjectsView, @NotNull MultiMap<Key<?>, DataNode<?>> dataNodes, @NotNull List<ExternalSystemNode<?>> result) {
    final Collection<DataNode<?>> moduleDataNodes = dataNodes.get(ProjectKeys.MODULE);
    if (!moduleDataNodes.isEmpty()) {
        final AbstractExternalSystemSettings systemSettings = ExternalSystemApiUtil.getSettings(externalProjectsView.getProject(), externalProjectsView.getSystemId());
        for (DataNode<?> dataNode : moduleDataNodes) {
            final ModuleData data = (ModuleData) dataNode.getData();
            final ExternalProjectSettings projectSettings = systemSettings.getLinkedProjectSettings(data.getLinkedExternalProjectPath());
            DataNode<ProjectData> projectDataNode = ExternalSystemApiUtil.findParent(dataNode, PROJECT);
            final boolean isRoot = projectSettings != null && data.getLinkedExternalProjectPath().equals(projectSettings.getExternalProjectPath()) && projectDataNode != null && projectDataNode.getData().getInternalName().equals(data.getInternalName());
            //noinspection unchecked
            final ModuleNode moduleNode = new ModuleNode(externalProjectsView, (DataNode<ModuleData>) dataNode, isRoot);
            result.add(moduleNode);
        }
    }
}
Also used : AbstractExternalSystemSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ExternalProjectSettings(com.intellij.openapi.externalSystem.settings.ExternalProjectSettings)

Aggregations

DataNode (com.intellij.openapi.externalSystem.model.DataNode)52 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)22 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)14 NotNull (org.jetbrains.annotations.NotNull)13 Module (com.intellij.openapi.module.Module)11 File (java.io.File)9 Project (com.intellij.openapi.project.Project)7 Nullable (org.jetbrains.annotations.Nullable)7 GradleModuleModel (com.android.tools.idea.gradle.project.model.GradleModuleModel)6 GradleSourceSetData (org.jetbrains.plugins.gradle.model.data.GradleSourceSetData)5 ExternalProjectInfo (com.intellij.openapi.externalSystem.model.ExternalProjectInfo)4 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)4 IdeaModule (org.gradle.tooling.model.idea.IdeaModule)4 ExternalProjectRefreshCallback (com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 Pair (com.intellij.openapi.util.Pair)3 MultiMap (com.intellij.util.containers.MultiMap)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)2