Search in sources :

Example 16 with ProjectData

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

the class ProjectSubset method findAndIncludeModules.

public void findAndIncludeModules(@NotNull Collection<String> moduleGradlePaths) {
    DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
    if (projectInfo == null) {
        return;
    }
    Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
    if (!moduleInfos.isEmpty()) {
        Project project = myProject;
        new Task.Modal(project, "Finding Missing Modules", false) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                String[] originalSelection = getSelection();
                Set<String> selection = originalSelection != null ? Sets.newHashSet(originalSelection) : Sets.newHashSet();
                List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
                boolean found = false;
                int doneCount = 0;
                for (DataNode<ModuleData> moduleInfo : moduleInfos) {
                    indicator.setFraction(++doneCount / moduleInfos.size());
                    String name = getNameOf(moduleInfo);
                    if (selection.contains(name)) {
                        selectedModules.add(moduleInfo);
                        continue;
                    }
                    DataNode<GradleModuleModel> gradleProjectNode = find(moduleInfo, GRADLE_MODULE_MODEL);
                    if (gradleProjectNode != null) {
                        GradleModuleModel gradleModuleModel = gradleProjectNode.getData();
                        if (moduleGradlePaths.contains(gradleModuleModel.getGradlePath())) {
                            selection.add(name);
                            selectedModules.add(moduleInfo);
                            found = true;
                        }
                    }
                }
                if (!selectedModules.isEmpty() && found) {
                    setSelection(selectedModules);
                    populate(project, projectInfo, selectedModules, DEFAULT_REQUEST);
                }
            }
        }.queue();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 17 with ProjectData

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

the class UniquePathModuleValidatorStrategy method fixAndReportFoundIssues.

@Override
void fixAndReportFoundIssues() {
    Set<String> modulePaths = myModulesByPath.keySet();
    for (String modulePath : modulePaths) {
        Collection<Module> modules = myModulesByPath.get(modulePath);
        int moduleCount = modules.size();
        if (moduleCount <= 1) {
            continue;
        }
        StringBuilder msg = new StringBuilder();
        msg.append("The modules [");
        int i = 0;
        Set<String> moduleNames = Sets.newHashSet();
        for (Module module : modules) {
            if (i++ != 0) {
                msg.append(", ");
            }
            String name = module.getName();
            moduleNames.add(name);
            msg.append("'").append(name).append("'");
        }
        msg.append("] point to same directory in the file system.");
        String[] lines = { msg.toString(), "Each module has to have a unique path." };
        SyncMessage message = new SyncMessage(PROJECT_STRUCTURE_ISSUES, ERROR, lines);
        List<DataNode<ModuleData>> modulesToDisplayInDialog = Lists.newArrayList();
        Project project = getProject();
        if (ProjectSubset.getInstance(project).isFeatureEnabled()) {
            DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(project).getCachedProjectData();
            if (projectInfo != null) {
                Collection<DataNode<ModuleData>> cachedModules = findAll(projectInfo, MODULE);
                for (DataNode<ModuleData> moduleNode : cachedModules) {
                    if (moduleNames.contains(moduleNode.getData().getExternalName())) {
                        modulesToDisplayInDialog.add(moduleNode);
                    }
                }
            }
        }
        if (!modulesToDisplayInDialog.isEmpty()) {
            message.add(new AddOrRemoveModulesHyperlink());
        }
        SyncMessages.getInstance(project).report(message);
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 18 with ProjectData

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

the class IdeaGradleSync method sync.

@Override
public void sync(@NotNull Project project, @NotNull GradleSyncInvoker.Request request, @Nullable GradleSyncListener listener) {
    // Prevent IDEA from syncing with Gradle. We want to have full control of syncing.
    project.putUserData(ExternalSystemDataKeys.NEWLY_IMPORTED_PROJECT, true);
    if (SYNC_WITH_CACHED_MODEL_ONLY || request.isUseCachedGradleModels()) {
        GradleProjectSyncData syncData = GradleProjectSyncData.getInstance((project));
        if (syncData != null && syncData.canUseCachedProjectData()) {
            DataNodeCaches dataNodeCaches = DataNodeCaches.getInstance(project);
            DataNode<ProjectData> cache = dataNodeCaches.getCachedProjectData();
            if (cache != null && !dataNodeCaches.isCacheMissingModels(cache)) {
                PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
                // @formatter:off
                setupRequest.setUsingCachedGradleModels(true).setGenerateSourcesAfterSync(false).setLastSyncTimestamp(syncData.getLastGradleSyncTimestamp());
                // @formatter:on
                boolean newProject = request.isNewProject();
                ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, newProject, !newProject, true);
                setUpTask.onSuccess(cache);
                return;
            }
        }
    }
    PostSyncProjectSetup.Request setupRequest = new PostSyncProjectSetup.Request();
    // @formatter:off
    setupRequest.setGenerateSourcesAfterSync(request.isGenerateSourcesOnSuccess()).setCleanProjectAfterSync(request.isCleanProject());
    // @formatter:on
    String externalProjectPath = getBaseDirPath(project).getPath();
    ProjectSetUpTask setUpTask = new ProjectSetUpTask(project, setupRequest, listener, request.isNewProject(), false, false);
    ProgressExecutionMode executionMode = request.getProgressExecutionMode();
    refreshProject(project, GRADLE_SYSTEM_ID, externalProjectPath, setUpTask, false, /* resolve dependencies */
    executionMode, true);
}
Also used : GradleProjectSyncData(com.android.tools.idea.gradle.project.GradleProjectSyncData) PostSyncProjectSetup(com.android.tools.idea.gradle.project.sync.setup.post.PostSyncProjectSetup) DataNodeCaches(com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches) ProgressExecutionMode(com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 19 with ProjectData

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

the class GradleSyncIntegrationTest method testWithCacheMissingModules.

// Verifies that if syncing using cached model, and if the cached model is missing data, we fall back to a full Gradle sync.
// See: https://code.google.com/p/android/issues/detail?id=160899
public void testWithCacheMissingModules() throws Exception {
    Project project = getProject();
    myOriginalDataNodeCaches = DataNodeCaches.getInstance(project);
    loadSimpleApplication();
    // Simulate data node cache is missing modules.
    //noinspection unchecked
    DataNode<ProjectData> cache = mock(DataNode.class);
    DataNodeCaches dataNodeCaches = IdeComponents.replaceServiceWithMock(project, DataNodeCaches.class);
    when(dataNodeCaches.getCachedProjectData()).thenReturn(cache);
    when(dataNodeCaches.isCacheMissingModels(cache)).thenReturn(true);
    GradleSyncInvoker.Request request = new GradleSyncInvoker.Request();
    // @formatter:off
    request.setGenerateSourcesOnSuccess(false).setUseCachedGradleModels(true);
    // @formatter:on
    // Sync again, and a full sync should occur, since the cache is missing modules.
    // 'waitForGradleProjectSyncToFinish' will never finish and test will time out and fail if the IDE never gets notified that the sync
    // finished.
    requestSyncAndWait(request);
}
Also used : Project(com.intellij.openapi.project.Project) DataNodeCaches(com.android.tools.idea.gradle.project.sync.idea.data.DataNodeCaches) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 20 with ProjectData

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

the class ExternalProjectDataSelectorDialog method doOKAction.

@Override
protected void doOKAction() {
    loadingPanel.setLoadingText("Please wait...");
    loadingPanel.startLoading();
    final DataNode<ProjectData> projectStructure = myProjectInfo.getExternalProjectStructure();
    if (projectStructure != null) {
        final boolean[] isModified = { false };
        ExternalSystemApiUtil.visit(projectStructure, node -> {
            final DataNode modifiedDataNode = node.getUserData(MODIFIED_NODE_KEY);
            if (modifiedDataNode != null) {
                if (node.isIgnored() != modifiedDataNode.isIgnored()) {
                    node.setIgnored(modifiedDataNode.isIgnored());
                    isModified[0] = true;
                }
                node.removeUserData(MODIFIED_NODE_KEY);
                node.removeUserData(CONNECTED_UI_NODE_KEY);
            }
        });
        if (isModified[0]) {
            DataNode<?> notIgnoredNode = ContainerUtil.find(projectStructure.getChildren(), node -> !node.isIgnored());
            projectStructure.setIgnored(notIgnoredNode == null);
            // execute when current dialog is closed
            ExternalSystemUtil.invokeLater(myProject, ModalityState.NON_MODAL, () -> {
                final ProjectData projectData = projectStructure.getData();
                String title = ExternalSystemBundle.message("progress.refresh.text", projectData.getExternalName(), projectData.getOwner().getReadableName());
                new Task.Backgroundable(myProject, title, true, PerformInBackgroundOption.DEAF) {

                    @Override
                    public void run(@NotNull ProgressIndicator indicator) {
                        ServiceManager.getService(ProjectDataManager.class).importData(projectStructure, myProject, false);
                    }
                }.queue();
            });
        }
    }
    super.doOKAction();
}
Also used : Task(com.intellij.openapi.progress.Task) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) 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