Search in sources :

Example 1 with ProjectSubset

use of com.android.tools.idea.gradle.project.subset.ProjectSubset in project android by JetBrains.

the class DependencySetupErrors method reportModulesNotFoundIssues.

private void reportModulesNotFoundIssues(@NotNull List<MissingModule> missingModules) {
    if (!missingModules.isEmpty()) {
        MessageType type = ERROR;
        for (MissingModule missingModule : missingModules) {
            List<String> messageLines = new ArrayList<>();
            StringBuilder text = new StringBuilder();
            text.append(String.format("Unable to find module with Gradle path '%1$s' (needed by module", missingModule.dependencyPath));
            addDependentsToText(text, missingModule.dependentNames);
            text.append(".)");
            messageLines.add(text.toString());
            String backupLibraryName = missingModule.backupLibraryName;
            if (isNotEmpty(backupLibraryName)) {
                type = WARNING;
                String msg = String.format("Linking to library '%1$s' instead.", backupLibraryName);
                messageLines.add(msg);
            }
            mySyncMessages.report(new SyncMessage(MISSING_DEPENDENCIES, type, toStringArray(messageLines)));
        }
        // If the project is really a subset of the project, attempt to find and include missing modules.
        ProjectSubset projectSubset = ProjectSubset.getInstance(myProject);
        String[] selection = projectSubset.getSelection();
        boolean hasSelection = selection != null && selection.length > 0;
        if (type == ERROR && hasSelection && projectSubset.hasCachedModules()) {
            String text = "The missing modules may have been excluded from the project subset.";
            SyncMessage message = new SyncMessage(MISSING_DEPENDENCIES, MessageType.INFO, text);
            message.add(new IncludeMissingModulesHyperlink(missingModules));
            mySyncMessages.report(message);
        }
    }
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) MessageType(com.android.tools.idea.gradle.project.sync.messages.MessageType)

Example 2 with ProjectSubset

use of com.android.tools.idea.gradle.project.subset.ProjectSubset in project android by JetBrains.

the class UniquePathModuleValidatorStrategyTest method testFixAndReportFoundIssuesWithUniquePaths.

public void testFixAndReportFoundIssuesWithUniquePaths() throws Exception {
    Project project = getProject();
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
    ProjectSubset projectSubset = IdeComponents.replaceServiceWithMock(project, ProjectSubset.class);
    when(projectSubset.isFeatureEnabled()).thenReturn(false);
    Multimap<String, Module> modulesByPath = myStrategy.getModulesByPath();
    modulesByPath.putAll("path1", Lists.newArrayList(myModule1));
    modulesByPath.putAll("path2", Lists.newArrayList(myModule2));
    myStrategy.fixAndReportFoundIssues();
    SyncMessage message = syncMessages.getFirstReportedMessage();
    assertNull(message);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) Module(com.intellij.openapi.module.Module)

Example 3 with ProjectSubset

use of com.android.tools.idea.gradle.project.subset.ProjectSubset in project android by JetBrains.

the class Projects method getModulesToImport.

@NotNull
private static Collection<DataNode<ModuleData>> getModulesToImport(@NotNull Project project, @NotNull DataNode<ProjectData> projectInfo, boolean selectModulesToImport) {
    Collection<DataNode<ModuleData>> modules = findAll(projectInfo, ProjectKeys.MODULE);
    ProjectSubset subview = ProjectSubset.getInstance(project);
    if (!ApplicationManager.getApplication().isUnitTestMode() && ProjectSubset.getInstance(project).isFeatureEnabled() && modules.size() > 1) {
        if (selectModulesToImport) {
            // Importing a project. Allow user to select which modules to include in the project.
            Collection<DataNode<ModuleData>> selection = subview.showModuleSelectionDialog(modules);
            if (selection != null) {
                return selection;
            }
        } else {
            // We got here because a project was synced with Gradle. Make sure that we don't add any modules that were not selected during
            // project import (if applicable.)
            String[] persistedModuleNames = subview.getSelection();
            if (persistedModuleNames != null) {
                int moduleCount = persistedModuleNames.length;
                if (moduleCount > 0) {
                    List<String> moduleNames = Lists.newArrayList(persistedModuleNames);
                    List<DataNode<ModuleData>> selectedModules = Lists.newArrayListWithExpectedSize(moduleCount);
                    for (DataNode<ModuleData> module : modules) {
                        String name = module.getData().getExternalName();
                        if (moduleNames.contains(name)) {
                            selectedModules.add(module);
                        }
                    }
                    return selectedModules;
                }
            }
        }
    }
    // Delete any stored module selection.
    subview.clearSelection();
    // Import all modules, not just subset.
    return modules;
}
Also used : ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ProjectSubset

use of com.android.tools.idea.gradle.project.subset.ProjectSubset in project android by JetBrains.

the class UniquePathModuleValidatorStrategyTest method testFixAndReportFoundIssues.

public void testFixAndReportFoundIssues() throws Exception {
    Project project = getProject();
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
    ProjectSubset projectSubset = IdeComponents.replaceServiceWithMock(project, ProjectSubset.class);
    when(projectSubset.isFeatureEnabled()).thenReturn(false);
    Multimap<String, Module> modulesByPath = myStrategy.getModulesByPath();
    modulesByPath.putAll("path", Lists.newArrayList(myModule1, myModule2));
    when(myModule1.getName()).thenReturn("module1");
    when(myModule2.getName()).thenReturn("module2");
    myStrategy.fixAndReportFoundIssues();
    SyncMessage message = syncMessages.getFirstReportedMessage();
    assertNotNull(message);
    assertAbout(syncMessage()).that(message).hasMessageLine("The modules ['module1', 'module2'] point to same directory in the file system.", 0);
}
Also used : SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) ProjectSubset(com.android.tools.idea.gradle.project.subset.ProjectSubset) Module(com.intellij.openapi.module.Module)

Aggregations

ProjectSubset (com.android.tools.idea.gradle.project.subset.ProjectSubset)4 SyncMessage (com.android.tools.idea.gradle.project.sync.messages.SyncMessage)3 SyncMessagesStub (com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 MessageType (com.android.tools.idea.gradle.project.sync.messages.MessageType)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 NotNull (org.jetbrains.annotations.NotNull)1