Search in sources :

Example 16 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 17 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 18 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 19 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)

Example 20 with AndroidModuleModel

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

the class AndroidModelViewTest method testVariantsNodeCustomization.

public void testVariantsNodeCustomization() throws Exception {
    AndroidProject androidProject = mock(AndroidProject.class);
    Variant variant = mock(Variant.class);
    when(variant.getName()).thenReturn("dummyVariant");
    when(androidProject.getVariants()).thenReturn(ImmutableList.of(createProxyInstance(Variant.class, variant)));
    AndroidArtifact mainArtifact = mock(AndroidArtifact.class);
    when(mainArtifact.getName()).thenReturn(ARTIFACT_MAIN);
    when(variant.getMainArtifact()).thenReturn(createProxyInstance(AndroidArtifact.class, mainArtifact));
    AndroidArtifact extraAndroidArtifact = mock(AndroidArtifact.class);
    when(extraAndroidArtifact.getName()).thenReturn(ARTIFACT_ANDROID_TEST);
    when(variant.getExtraAndroidArtifacts()).thenReturn(ImmutableList.of(createProxyInstance(AndroidArtifact.class, extraAndroidArtifact)));
    JavaArtifact extraJavaArtifact = mock(JavaArtifact.class);
    when(extraJavaArtifact.getName()).thenReturn(ARTIFACT_UNIT_TEST);
    when(variant.getExtraJavaArtifacts()).thenReturn(ImmutableList.of(createProxyInstance(JavaArtifact.class, extraJavaArtifact)));
    AndroidProject reproxyProject = ProxyUtil.reproxy(AndroidProject.class, createProxyInstance(AndroidProject.class, androidProject));
    assertNotNull(reproxyProject);
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.waitForAndGetProxyAndroidProject()).thenReturn(reproxyProject);
    when(androidModel.getVariantNames()).thenReturn(ImmutableList.of("dummyVariant"));
    List<SourceProvider> mockSourceProviders = ImmutableList.of(createMockSourceProvider("src1"), createMockSourceProvider("src2"), createMockSourceProvider("src3"));
    when(androidModel.getMainSourceProviders("dummyVariant")).thenReturn(mockSourceProviders);
    when(androidModel.getTestSourceProviders("dummyVariant", ARTIFACT_ANDROID_TEST)).thenReturn(mockSourceProviders);
    when(androidModel.getTestSourceProviders("dummyVariant", ARTIFACT_UNIT_TEST)).thenReturn(mockSourceProviders);
    ModuleNodeBuilder nodeBuilder = new ModuleNodeBuilder("test", androidModel, projectBasePath);
    DefaultMutableTreeNode node = nodeBuilder.getNode();
    assertTrue(node.getChildCount() > 0);
    DefaultMutableTreeNode variantsNode = (DefaultMutableTreeNode) node.getChildAt(node.getChildCount() - 1);
    assertEquals("Variants", variantsNode.getUserObject().toString());
    assertEquals(1, variantsNode.getChildCount());
    DefaultMutableTreeNode variantNode = (DefaultMutableTreeNode) variantsNode.getChildAt(0);
    assertEquals("dummyVariant", variantNode.getUserObject().toString());
    assertTrue(variantNode.getChildCount() > 0);
    DefaultMutableTreeNode artifactsNode = (DefaultMutableTreeNode) variantNode.getChildAt(variantNode.getChildCount() - 1);
    assertEquals("Artifacts", artifactsNode.getUserObject().toString());
    assertEquals(3, artifactsNode.getChildCount());
    DefaultMutableTreeNode androidTestNode = (DefaultMutableTreeNode) artifactsNode.getChildAt(0);
    assertEquals(ARTIFACT_ANDROID_TEST, androidTestNode.getUserObject().toString());
    DefaultMutableTreeNode sourcesNode = (DefaultMutableTreeNode) androidTestNode.getChildAt(androidTestNode.getChildCount() - 1);
    verifySourcesNode(sourcesNode);
    DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) artifactsNode.getChildAt(1);
    assertEquals(ARTIFACT_MAIN, mainNode.getUserObject().toString());
    sourcesNode = (DefaultMutableTreeNode) mainNode.getChildAt(mainNode.getChildCount() - 1);
    verifySourcesNode(sourcesNode);
    DefaultMutableTreeNode unitTestNode = (DefaultMutableTreeNode) artifactsNode.getChildAt(2);
    assertEquals(ARTIFACT_UNIT_TEST, unitTestNode.getUserObject().toString());
    sourcesNode = (DefaultMutableTreeNode) unitTestNode.getChildAt(unitTestNode.getChildCount() - 1);
    verifySourcesNode(sourcesNode);
}
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