Search in sources :

Example 11 with AndroidModuleModel

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

the class DynamicResourceValueRepository method getMap.

@Override
@NonNull
protected Map<ResourceType, ListMultimap<String, ResourceItem>> getMap() {
    if (mItems.isEmpty()) {
        // TODO: b/23032391
        AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
        if (androidModel == null) {
            return mItems;
        }
        Variant selectedVariant = androidModel.getSelectedVariant();
        // Reverse overlay order because when processing lower order ones, we ignore keys already processed
        BuildTypeContainer buildType = androidModel.findBuildType(selectedVariant.getBuildType());
        if (buildType != null) {
            addValues(buildType.getBuildType().getResValues());
        }
        // flavors and default config:
        addValues(selectedVariant.getMergedFlavor().getResValues());
    }
    return mItems;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) BuildTypeContainer(com.android.builder.model.BuildTypeContainer) NonNull(com.android.annotations.NonNull)

Example 12 with AndroidModuleModel

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

the class AppResourceRepository method findAarLibraries.

@NotNull
public static Collection<AndroidLibrary> findAarLibraries(@NotNull AndroidFacet facet) {
    List<AndroidLibrary> libraries = Lists.newArrayList();
    if (facet.requiresAndroidModel()) {
        AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
        if (androidModel != null) {
            List<AndroidFacet> dependentFacets = AndroidUtils.getAllAndroidDependencies(facet.getModule(), true);
            addGradleLibraries(libraries, androidModel);
            for (AndroidFacet dependentFacet : dependentFacets) {
                AndroidModuleModel dependentGradleModel = AndroidModuleModel.get(dependentFacet);
                if (dependentGradleModel != null) {
                    addGradleLibraries(libraries, dependentGradleModel);
                }
            }
        }
    }
    return libraries;
}
Also used : AndroidLibrary(com.android.builder.model.AndroidLibrary) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with AndroidModuleModel

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

the class AttributeProcessingUtil method processMenuItemAttributes.

private static void processMenuItemAttributes(@NotNull AndroidFacet facet, @NotNull DomElement element, @NotNull Collection<XmlName> skippedAttributes, @NotNull AttributeProcessor callback) {
    ResourceManager manager = facet.getSystemResourceManager();
    if (manager == null) {
        return;
    }
    AttributeDefinitions styleables = manager.getAttributeDefinitions();
    if (styleables == null) {
        return;
    }
    StyleableDefinition styleable = styleables.getStyleableByName("MenuItem");
    if (styleable == null) {
        getLog().warn("No StyleableDefinition for MenuItem");
        return;
    }
    for (AttributeDefinition attribute : styleable.getAttributes()) {
        String name = attribute.getName();
        // .lint.checks.AppCompatResourceDetector.
        if (name.equals(ATTR_SHOW_AS_ACTION)) {
            AndroidModuleModel model = AndroidModuleModel.get(facet);
            if (model != null && GradleUtil.dependsOn(model, APPCOMPAT_LIB_ARTIFACT)) {
                if (skippedAttributes.add(new XmlName(name, AUTO_URI))) {
                    registerAttribute(attribute, "MenuItem", AUTO_URI, element, callback);
                }
                continue;
            }
        }
        if (skippedAttributes.add(new XmlName(name, ANDROID_URI))) {
            registerAttribute(attribute, "MenuItem", ANDROID_URI, element, callback);
        }
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) XmlName(com.intellij.util.xml.XmlName) ResourceManager(org.jetbrains.android.resourceManagers.ResourceManager) SystemResourceManager(org.jetbrains.android.resourceManagers.SystemResourceManager)

Example 14 with AndroidModuleModel

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

the class AndroidModelViewTest method testBuildTypesNodeCustomization.

public void testBuildTypesNodeCustomization() throws Exception {
    AndroidProject androidProject = mock(AndroidProject.class);
    BuildTypeContainer buildTypeContainer = mock(BuildTypeContainer.class);
    when(androidProject.getBuildTypes()).thenReturn(ImmutableList.of(createProxyInstance(BuildTypeContainer.class, buildTypeContainer)));
    BuildType buildtype = mock(BuildType.class);
    when(buildtype.getName()).thenReturn("dummyBuildType");
    when(buildTypeContainer.getBuildType()).thenReturn(createProxyInstance(BuildType.class, buildtype));
    SourceProvider mainSourceProvider = mock(SourceProvider.class);
    when(mainSourceProvider.getName()).thenReturn("dummySourceProvider");
    when(buildTypeContainer.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, mainSourceProvider));
    SourceProviderContainer extraSourceProviderContainer1 = mock(SourceProviderContainer.class);
    SourceProvider extraSourceProvider1 = mock(SourceProvider.class);
    when(extraSourceProvider1.getName()).thenReturn("extraSourceProvider1");
    when(extraSourceProviderContainer1.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, extraSourceProvider1));
    SourceProviderContainer extraSourceProviderContainer2 = mock(SourceProviderContainer.class);
    SourceProvider extraSourceProvider2 = mock(SourceProvider.class);
    when(extraSourceProvider2.getName()).thenReturn("extraSourceProvider2");
    when(extraSourceProviderContainer2.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, extraSourceProvider2));
    when(buildTypeContainer.getExtraSourceProviders()).thenReturn(ImmutableList.of(createProxyInstance(SourceProviderContainer.class, extraSourceProviderContainer1), createProxyInstance(SourceProviderContainer.class, extraSourceProviderContainer2)));
    AndroidProject reproxyProject = ProxyUtil.reproxy(AndroidProject.class, createProxyInstance(AndroidProject.class, androidProject));
    assertNotNull(reproxyProject);
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.waitForAndGetProxyAndroidProject()).thenReturn(reproxyProject);
    ModuleNodeBuilder nodeBuilder = new ModuleNodeBuilder("test", androidModel, projectBasePath);
    DefaultMutableTreeNode node = nodeBuilder.getNode();
    assertTrue(node.getChildCount() > 0);
    DefaultMutableTreeNode buildTypesNode = (DefaultMutableTreeNode) node.getChildAt(node.getChildCount() - 1);
    assertEquals("BuildTypes", buildTypesNode.getUserObject().toString());
    assertEquals(1, buildTypesNode.getChildCount());
    DefaultMutableTreeNode buildTypeNode = (DefaultMutableTreeNode) buildTypesNode.getChildAt(0);
    assertEquals("dummyBuildType", buildTypeNode.getUserObject().toString());
    assertTrue(buildTypeNode.getChildCount() > 0);
    DefaultMutableTreeNode sourceProvidersNode = (DefaultMutableTreeNode) buildTypeNode.getChildAt(buildTypeNode.getChildCount() - 1);
    assertEquals("SourceProviders", sourceProvidersNode.getUserObject().toString());
    assertEquals(3, sourceProvidersNode.getChildCount());
    assertEquals("dummySourceProvider", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(0)).getUserObject().toString());
    assertEquals("extraSourceProvider1", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(1)).getUserObject().toString());
    assertEquals("extraSourceProvider2", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(2)).getUserObject().toString());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ModuleNodeBuilder(com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject)

Example 15 with AndroidModuleModel

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

the class AndroidModelViewTest method testDefaultConfigNodeCustomization.

public void testDefaultConfigNodeCustomization() throws Exception {
    AndroidProject androidProject = mock(AndroidProject.class);
    ProductFlavorContainer flavorContainer = mock(ProductFlavorContainer.class);
    when(androidProject.getDefaultConfig()).thenReturn(createProxyInstance(ProductFlavorContainer.class, flavorContainer));
    ProductFlavor flavor = mock(ProductFlavor.class);
    when(flavor.getName()).thenReturn("dummyFlavor");
    when(flavorContainer.getProductFlavor()).thenReturn(createProxyInstance(ProductFlavor.class, flavor));
    SourceProvider mainSourceProvider = mock(SourceProvider.class);
    when(mainSourceProvider.getName()).thenReturn("dummySourceProvider");
    when(flavorContainer.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, mainSourceProvider));
    SourceProviderContainer extraSourceProviderContainer1 = mock(SourceProviderContainer.class);
    SourceProvider extraSourceProvider1 = mock(SourceProvider.class);
    when(extraSourceProvider1.getName()).thenReturn("extraSourceProvider1");
    when(extraSourceProviderContainer1.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, extraSourceProvider1));
    SourceProviderContainer extraSourceProviderContainer2 = mock(SourceProviderContainer.class);
    SourceProvider extraSourceProvider2 = mock(SourceProvider.class);
    when(extraSourceProvider2.getName()).thenReturn("extraSourceProvider2");
    when(extraSourceProviderContainer2.getSourceProvider()).thenReturn(createProxyInstance(SourceProvider.class, extraSourceProvider2));
    when(flavorContainer.getExtraSourceProviders()).thenReturn(ImmutableList.of(createProxyInstance(SourceProviderContainer.class, extraSourceProviderContainer1), createProxyInstance(SourceProviderContainer.class, extraSourceProviderContainer2)));
    AndroidProject reproxyProject = ProxyUtil.reproxy(AndroidProject.class, createProxyInstance(AndroidProject.class, androidProject));
    assertNotNull(reproxyProject);
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.waitForAndGetProxyAndroidProject()).thenReturn(reproxyProject);
    ModuleNodeBuilder nodeBuilder = new ModuleNodeBuilder("test", androidModel, projectBasePath);
    DefaultMutableTreeNode node = nodeBuilder.getNode();
    assertTrue(node.getChildCount() > 0);
    DefaultMutableTreeNode defaultConfigNode = (DefaultMutableTreeNode) node.getChildAt(node.getChildCount() - 1);
    assertEquals("DefaultConfig", defaultConfigNode.getUserObject().toString());
    assertTrue(defaultConfigNode.getChildCount() > 0);
    DefaultMutableTreeNode sourceProvidersNode = (DefaultMutableTreeNode) defaultConfigNode.getChildAt(defaultConfigNode.getChildCount() - 1);
    assertEquals("SourceProviders", sourceProvidersNode.getUserObject().toString());
    assertEquals(3, sourceProvidersNode.getChildCount());
    assertEquals("dummySourceProvider", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(0)).getUserObject().toString());
    assertEquals("extraSourceProvider1", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(1)).getUserObject().toString());
    assertEquals("extraSourceProvider2", ((DefaultMutableTreeNode) sourceProvidersNode.getChildAt(2)).getUserObject().toString());
    DefaultMutableTreeNode sdkVersionsNode = (DefaultMutableTreeNode) defaultConfigNode.getChildAt(defaultConfigNode.getChildCount() - 2);
    assertEquals("SdkVersions", sdkVersionsNode.getUserObject().toString());
    // Min, Max and Target Sdk versions.
    assertEquals(3, sdkVersionsNode.getChildCount());
    DefaultMutableTreeNode nameNode = null;
    for (int i = 0; i < defaultConfigNode.getChildCount(); i++) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) defaultConfigNode.getChildAt(i);
        if (child.getUserObject().toString().startsWith("Name ->")) {
            nameNode = child;
            break;
        }
    }
    assertNotNull(nameNode);
    // Verifies that the flavor node is inlined under default config.
    assertEquals("Name -> dummyFlavor", nameNode.getUserObject().toString());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ModuleNodeBuilder(com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject)

Aggregations

AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)117 Module (com.intellij.openapi.module.Module)54 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)26 File (java.io.File)24 NotNull (org.jetbrains.annotations.NotNull)21 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Nullable (org.jetbrains.annotations.Nullable)18 AndroidProject (com.android.builder.model.AndroidProject)12 GradleVersion (com.android.ide.common.repository.GradleVersion)11 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)10 Project (com.intellij.openapi.project.Project)9 Variant (com.android.builder.model.Variant)8 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 AndroidLibrary (com.android.builder.model.AndroidLibrary)5 PsiFile (com.intellij.psi.PsiFile)5 AndroidArtifact (com.android.builder.model.AndroidArtifact)4 AndroidArtifactOutput (com.android.builder.model.AndroidArtifactOutput)4 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)4 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 AndroidVersion (com.android.sdklib.AndroidVersion)3