Search in sources :

Example 6 with AndroidProject

use of com.android.builder.model.AndroidProject 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 7 with AndroidProject

use of com.android.builder.model.AndroidProject 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 8 with AndroidProject

use of com.android.builder.model.AndroidProject 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)

Example 9 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class AndroidModelViewTest method testProductFlavorsNodeCustomization.

public void testProductFlavorsNodeCustomization() throws Exception {
    AndroidProject androidProject = mock(AndroidProject.class);
    ProductFlavorContainer flavorContainer = mock(ProductFlavorContainer.class);
    when(androidProject.getProductFlavors()).thenReturn(ImmutableList.of(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 productFlavorsNode = (DefaultMutableTreeNode) node.getChildAt(node.getChildCount() - 1);
    assertEquals("ProductFlavors", productFlavorsNode.getUserObject().toString());
    assertEquals(1, productFlavorsNode.getChildCount());
    DefaultMutableTreeNode productFlavorNode = (DefaultMutableTreeNode) productFlavorsNode.getChildAt(0);
    assertEquals("dummyFlavor", productFlavorNode.getUserObject().toString());
    assertTrue(productFlavorNode.getChildCount() > 0);
    DefaultMutableTreeNode sourceProvidersNode = (DefaultMutableTreeNode) productFlavorNode.getChildAt(productFlavorNode.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) productFlavorNode.getChildAt(productFlavorNode.getChildCount() - 2);
    assertEquals("SdkVersions", sdkVersionsNode.getUserObject().toString());
    // Min, Max and Target Sdk versions.
    assertEquals(3, sdkVersionsNode.getChildCount());
}
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 10 with AndroidProject

use of com.android.builder.model.AndroidProject in project android by JetBrains.

the class EncodingValidationStrategy method validate.

@Override
void validate(@NotNull Module module, @NotNull AndroidModuleModel androidModel) {
    GradleVersion modelVersion = (androidModel.getModelVersion());
    if (modelVersion != null) {
        boolean isOneDotTwoOrNewer = modelVersion.compareIgnoringQualifiers(myOneDotTwoPluginVersion) >= 0;
        // Verify that the encoding in the model is the same as the encoding in the IDE's project settings.
        Charset modelEncoding = null;
        if (isOneDotTwoOrNewer) {
            try {
                AndroidProject androidProject = androidModel.getAndroidProject();
                modelEncoding = Charset.forName(androidProject.getJavaCompileOptions().getEncoding());
            } catch (UnsupportedCharsetException ignore) {
            // It's not going to happen.
            }
        }
        if (myMismatchingEncoding == null && modelEncoding != null && myProjectEncoding.compareTo(modelEncoding) != 0) {
            myMismatchingEncoding = modelEncoding.displayName();
        }
    }
}
Also used : UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) Charset(java.nio.charset.Charset) AndroidProject(com.android.builder.model.AndroidProject) GradleVersion(com.android.ide.common.repository.GradleVersion)

Aggregations

AndroidProject (com.android.builder.model.AndroidProject)35 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)12 NativeAndroidProject (com.android.builder.model.NativeAndroidProject)7 File (java.io.File)7 Variant (com.android.builder.model.Variant)6 Module (com.intellij.openapi.module.Module)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)6 NotNull (org.jetbrains.annotations.NotNull)6 ModuleNodeBuilder (com.android.tools.idea.gradle.AndroidModelView.ModuleNodeBuilder)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 NonNull (com.android.annotations.NonNull)3 NdkModuleModel (com.android.tools.idea.gradle.project.model.NdkModuleModel)3 Project (com.intellij.openapi.project.Project)3 IOException (java.io.IOException)3 AndroidLibrary (com.android.builder.model.AndroidLibrary)2 LintOptions (com.android.builder.model.LintOptions)2 ProductFlavorContainer (com.android.builder.model.ProductFlavorContainer)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)2 GradleUtil.getAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject)2 GradleUtil.getNativeAndroidProject (com.android.tools.idea.gradle.util.GradleUtil.getNativeAndroidProject)2