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