Search in sources :

Example 1 with ModuleToImport

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

the class ModuleListModel method computeRequiredModules.

private Multimap<ModuleToImport, ModuleToImport> computeRequiredModules(Set<ModuleToImport> modules) {
    Map<String, ModuleToImport> namesToModules = Maps.newHashMapWithExpectedSize(modules.size());
    // We only care about modules we are actually going to import.
    for (ModuleToImport module : modules) {
        namesToModules.put(module.name, module);
    }
    Multimap<ModuleToImport, ModuleToImport> requiredModules = LinkedListMultimap.create();
    Queue<ModuleToImport> queue = Lists.newLinkedList();
    for (ModuleToImport module : modules) {
        if (Objects.equal(module, myPrimaryModule) || !isUnselected(module, false)) {
            queue.add(module);
        }
    }
    while (!queue.isEmpty()) {
        ModuleToImport moduleToImport = queue.remove();
        for (ModuleToImport dep : Iterables.transform(moduleToImport.getDependencies(), Functions.forMap(namesToModules, null))) {
            if (dep != null) {
                if (!requiredModules.containsKey(dep)) {
                    queue.add(dep);
                }
                requiredModules.put(dep, moduleToImport);
            }
        }
    }
    return requiredModules;
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 2 with ModuleToImport

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

the class ModuleListModel method checkForDuplicateNames.

private void checkForDuplicateNames() {
    Collection<ModuleToImport> modules = getSelectedModules();
    ImmutableMultiset<String> names = ImmutableMultiset.copyOf(Iterables.transform(modules, new Function<ModuleToImport, String>() {

        @Override
        public String apply(@Nullable ModuleToImport input) {
            return input == null ? null : getModuleName(input);
        }
    }));
    for (ModuleToImport module : modules) {
        ModuleValidationState state = myModules.get(module);
        if (state == ModuleValidationState.OK) {
            if (names.count(getModuleName(module)) > 1) {
                myModules.put(module, ModuleValidationState.DUPLICATE_MODULE_NAME);
            }
        }
    }
}
Also used : Function(com.google.common.base.Function) ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ModuleToImport

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

the class ModuleListModel method revalidate.

private void revalidate(Iterable<ModuleToImport> modules) {
    myModules = validateModules(modules);
    myRequiredModules = computeRequiredModules(myModules.keySet());
    for (ModuleToImport module : myRequiredModules.keySet()) {
        myNameOverrides.remove(module);
    }
    checkForDuplicateNames();
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 4 with ModuleToImport

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

the class ModulesTable method updateModuleEditors.

private Collection<ModuleImportSettingsPane> updateModuleEditors() {
    isRefreshing = true;
    try {
        ModuleToImport primary = myListModel.getPrimary();
        setModuleNameVisibility(primary != null, myListModel.getAllModules().size() > 1);
        if (primary != null) {
            apply(myPrimaryModuleSettings, primary);
        }
        boolean isFirst = true;
        Collection<ModuleImportSettingsPane> editors = Lists.newLinkedList();
        Set<ModuleToImport> allModules = Sets.newTreeSet(new ModuleComparator(myListModel.getCurrentPath()));
        Iterables.addAll(allModules, Iterables.filter(myListModel.getAllModules(), Predicates.not(Predicates.equalTo(myListModel.getPrimary()))));
        for (final ModuleToImport module : allModules) {
            final ModuleImportSettingsPane pane = createModuleSetupPanel(module, isFirst);
            if (pane != null) {
                isFirst = false;
                editors.add(pane);
            }
        }
        return editors;
    } finally {
        isRefreshing = false;
    }
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 5 with ModuleToImport

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

the class ImportSourceLocationStep method applyBackgroundOperationResult.

private void applyBackgroundOperationResult(@NotNull PathValidationResult result) {
    assert EventQueue.isDispatchThread();
    Collection<ModuleToImport> modules = null;
    Project project = myContext.getProject();
    try {
        if (result.myStatus == PageStatus.OK) {
            assert result.myVfile != null && result.myImporter != null;
            modules = result.myImporter.findModules(result.myVfile);
            Set<String> missingSourceModuleNames = Sets.newTreeSet();
            for (ModuleToImport module : modules) {
                if (module.location == null || !module.location.exists()) {
                    missingSourceModuleNames.add(module.name);
                }
            }
            if (!missingSourceModuleNames.isEmpty()) {
                result = new PathValidationResult(PageStatus.MISSING_SUBPROJECTS, result.myVfile, result.myImporter, missingSourceModuleNames);
            }
        }
    } catch (IOException e) {
        LOG.error(e);
        result = PageStatus.INTERNAL_ERROR.result();
    }
    myValidating = false;
    myModulesPanel.setModules(project, result.myVfile, modules);
    myModulesScroller.setVisible(myModulesPanel.getComponentCount() > 0);
    ModuleImporter.setImporter(myContext, result.myImporter);
    updateStepStatus(result);
}
Also used : Project(com.intellij.openapi.project.Project) ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport) IOException(java.io.IOException)

Aggregations

ModuleToImport (com.android.tools.idea.gradle.project.ModuleToImport)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 IOException (java.io.IOException)3 VisibleForTesting (com.android.annotations.VisibleForTesting)1 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)1 ModuleListModel (com.android.tools.idea.npw.importing.ModuleListModel)1 Function (com.google.common.base.Function)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 Collection (java.util.Collection)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1