Search in sources :

Example 36 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class GradleBuildInvoker method generateSources.

public void generateSources(boolean cleanProject) {
    BuildMode buildMode = SOURCE_GEN;
    setProjectBuildMode(buildMode);
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    List<String> tasks = findTasksToExecute(moduleManager.getModules(), buildMode, TestCompileType.NONE);
    if (cleanProject) {
        tasks.add(0, CLEAN_TASK_NAME);
    }
    executeTasks(tasks, Collections.singletonList(createGenerateSourcesOnlyProperty()));
}
Also used : BuildMode(com.android.tools.idea.gradle.util.BuildMode) ModuleManager(com.intellij.openapi.module.ModuleManager)

Example 37 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class MakeBeforeRunTaskProvider method createAvailableTasks.

private List<String> createAvailableTasks() {
    ModuleManager moduleManager = ModuleManager.getInstance(myProject);
    List<String> gradleTasks = Lists.newArrayList();
    for (Module module : moduleManager.getModules()) {
        GradleFacet facet = GradleFacet.getInstance(module);
        if (facet == null) {
            continue;
        }
        GradleModuleModel gradleModuleModel = facet.getGradleModuleModel();
        if (gradleModuleModel == null) {
            continue;
        }
        gradleTasks.addAll(gradleModuleModel.getTaskNames());
    }
    return gradleTasks;
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) GradleFacet(com.android.tools.idea.gradle.project.facet.gradle.GradleFacet) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module)

Example 38 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class ThemeEditorUtils method findAndroidModules.

@NotNull
public static ImmutableList<Module> findAndroidModules(@NotNull Project project) {
    final ModuleManager manager = ModuleManager.getInstance(project);
    final ImmutableList.Builder<Module> builder = ImmutableList.builder();
    for (Module module : manager.getModules()) {
        final AndroidFacet facet = AndroidFacet.getInstance(module);
        if (facet != null) {
            builder.add(module);
        }
    }
    return builder.build();
}
Also used : ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 39 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class ConflictSet method findConflicts.

@NotNull
public static ConflictSet findConflicts(@NotNull Project project) {
    Map<String, Conflict> selectionConflicts = Maps.newHashMap();
    Map<String, Conflict> structureConflicts = Maps.newHashMap();
    ModuleManager moduleManager = ModuleManager.getInstance(project);
    for (Module module : moduleManager.getModules()) {
        AndroidModuleModel currentAndroidModel = AndroidModuleModel.get(module);
        if (currentAndroidModel == null || currentAndroidModel.getProjectType() == PROJECT_TYPE_APP) {
            continue;
        }
        String gradlePath = GradleUtil.getGradlePath(module);
        if (gradlePath == null) {
            continue;
        }
        String selectedVariant = currentAndroidModel.getSelectedVariant().getName();
        for (Module dependent : ModuleUtilCore.getAllDependentModules(module)) {
            AndroidModuleModel dependentAndroidModel = AndroidModuleModel.get(dependent);
            if (dependentAndroidModel == null) {
                continue;
            }
            String expectedVariant = getExpectedVariant(dependentAndroidModel, gradlePath);
            if (StringUtil.isEmpty(expectedVariant)) {
                continue;
            }
            addConflict(structureConflicts, module, selectedVariant, dependent, expectedVariant);
            if (!selectedVariant.equals(expectedVariant)) {
                addConflict(selectionConflicts, module, selectedVariant, dependent, expectedVariant);
            }
        }
    }
    // Structural conflicts are the ones that have more than one group of modules depending on different variants of another module.
    List<Conflict> filteredStructureConflicts = Lists.newArrayList();
    for (Conflict conflict : structureConflicts.values()) {
        if (conflict.getVariants().size() > 1) {
            filteredStructureConflicts.add(conflict);
        }
    }
    return new ConflictSet(project, selectionConflicts.values(), filteredStructureConflicts);
}
Also used : ConflictResolution.solveSelectionConflict(com.android.tools.idea.gradle.variant.conflict.ConflictResolution.solveSelectionConflict) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleManager(com.intellij.openapi.module.ModuleManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 40 with ModuleManager

use of com.intellij.openapi.module.ModuleManager in project android by JetBrains.

the class ModuleVariantsInfoDialog method createDependentsTree.

@NotNull
private static JTree createDependentsTree(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    VariantCheckboxTreeCellRenderer renderer = new VariantCheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (value instanceof DefaultMutableTreeNode) {
                Object data = ((DefaultMutableTreeNode) value).getUserObject();
                if (data instanceof String) {
                    appendVariant((String) data);
                } else if (data instanceof DependentTreeElement) {
                    DependentTreeElement dependent = (DependentTreeElement) data;
                    String variant = null;
                    if (!dependent.myVariants.isEmpty()) {
                        variant = Joiner.on(", ").join(dependent.myVariants);
                    }
                    appendModule(dependent.myModule, variant);
                }
            }
        }
    };
    //noinspection ConstantConditions
    CheckedTreeNode root = new CheckedTreeNode(null);
    AndroidProject androidProject = GradleUtil.getAndroidProject(module);
    assert androidProject != null;
    String gradlePath = GradleUtil.getGradlePath(module);
    assert gradlePath != null;
    Multimap<String, DependentTreeElement> dependentsByVariant = HashMultimap.create();
    ModuleManager moduleManager = ModuleManager.getInstance(module.getProject());
    for (Module dependent : moduleManager.getModuleDependentModules(module)) {
        AndroidProject dependentProject = GradleUtil.getAndroidProject(dependent);
        if (dependentProject == null) {
            continue;
        }
        DependentTreeElement element = new DependentTreeElement(dependent);
        for (Variant variant : dependentProject.getVariants()) {
            for (AndroidLibrary library : GradleUtil.getDirectLibraryDependencies(variant, androidModel)) {
                if (gradlePath.equals(library.getProject())) {
                    element.addVariant(variant.getName());
                    String projectVariant = library.getProjectVariant();
                    if (StringUtil.isNotEmpty(projectVariant)) {
                        dependentsByVariant.put(projectVariant, element);
                    }
                }
            }
        }
    }
    List<String> variantNames = Lists.newArrayList(dependentsByVariant.keySet());
    Collections.sort(variantNames);
    for (String variantName : variantNames) {
        Collection<DependentTreeElement> dependents = dependentsByVariant.get(variantName);
        if (!dependents.isEmpty()) {
            List<DependentTreeElement> sortedDependents = Lists.newArrayList(dependents);
            Collections.sort(sortedDependents);
            DefaultMutableTreeNode variantNode = new DefaultMutableTreeNode(variantName);
            for (DependentTreeElement dependent : dependents) {
                variantNode.add(new DefaultMutableTreeNode(dependent));
            }
            root.add(variantNode);
        }
    }
    CheckboxTree tree = new CheckboxTree(renderer, root);
    tree.setRootVisible(false);
    TreeUtil.expandAll(tree);
    return tree;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CheckboxTree(com.intellij.ui.CheckboxTree) CheckedTreeNode(com.intellij.ui.CheckedTreeNode) AndroidProject(com.android.builder.model.AndroidProject) ModuleManager(com.intellij.openapi.module.ModuleManager) Variant(com.android.builder.model.Variant) AndroidLibrary(com.android.builder.model.AndroidLibrary) Module(com.intellij.openapi.module.Module) VariantCheckboxTreeCellRenderer(com.android.tools.idea.gradle.variant.ui.VariantCheckboxTreeCellRenderer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModuleManager (com.intellij.openapi.module.ModuleManager)51 Module (com.intellij.openapi.module.Module)40 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 Project (com.intellij.openapi.project.Project)10 NotNull (org.jetbrains.annotations.NotNull)8 ModifiableModuleModel (com.intellij.openapi.module.ModifiableModuleModel)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)7 File (java.io.File)7 GradleFacet (com.android.tools.idea.gradle.project.facet.gradle.GradleFacet)3 IOException (java.io.IOException)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 Variant (com.android.builder.model.Variant)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 BuildMode (com.android.tools.idea.gradle.util.BuildMode)2 AccessToken (com.intellij.openapi.application.AccessToken)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ContentEntry (com.intellij.openapi.roots.ContentEntry)2 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)2