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;
}
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);
}
}
}
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());
}
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());
}
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);
}
Aggregations