Search in sources :

Example 71 with AndroidModuleModel

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

the class AppResourceRepository method getResourceVisibility.

@NotNull
public ResourceVisibilityLookup getResourceVisibility(@NotNull AndroidFacet facet) {
    // TODO: b/23032391
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (androidModel != null) {
        ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
        if (provider != null) {
            AndroidProject androidProject = androidModel.getAndroidProject();
            Variant variant = androidModel.getSelectedVariant();
            return provider.get(androidProject, variant);
        }
    }
    return ResourceVisibilityLookup.NONE;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup) AndroidProject(com.android.builder.model.AndroidProject) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with AndroidModuleModel

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

the class AppResourceRepository method isPrivate.

/**
   * Returns true if the given resource is private
   *
   * @param type the type of the resource
   * @param name the name of the resource
   * @return true if the given resource is private
   */
public boolean isPrivate(@NotNull ResourceType type, @NotNull String name) {
    if (myResourceVisibility == null) {
        ResourceVisibilityLookup.Provider provider = getResourceVisibilityProvider();
        if (provider == null) {
            return false;
        }
        // TODO: b/23032391
        AndroidModuleModel androidModel = AndroidModuleModel.get(myFacet);
        if (androidModel == null) {
            // but can be triggered during a sync (b/22523040)
            return false;
        }
        myResourceVisibility = provider.get(androidModel.getAndroidProject(), androidModel.getSelectedVariant());
    }
    return myResourceVisibility.isPrivate(type, name);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ResourceVisibilityLookup(com.android.ide.common.repository.ResourceVisibilityLookup)

Example 73 with AndroidModuleModel

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

the class AppResourceRepository method findAarLibraries.

@NotNull
private static Map<File, String> findAarLibraries(@NotNull AndroidFacet facet, @NotNull List<AndroidFacet> dependentFacets) {
    // Use the gradle model if available, but if not, fall back to using plain IntelliJ library dependencies
    // which have been persisted since the most recent sync
    AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
    if (androidModuleModel != null) {
        List<AndroidLibrary> libraries = Lists.newArrayList();
        addGradleLibraries(libraries, androidModuleModel);
        for (AndroidFacet dependentFacet : dependentFacets) {
            AndroidModuleModel dependentGradleModel = AndroidModuleModel.get(dependentFacet);
            if (dependentGradleModel != null) {
                addGradleLibraries(libraries, dependentGradleModel);
            }
        }
        return findAarLibrariesFromGradle(androidModuleModel.getModelVersion(), dependentFacets, libraries);
    }
    return findAarLibrariesFromIntelliJ(facet, dependentFacets);
}
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 74 with AndroidModuleModel

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

the class LintIdeClient method getBuildTools.

@Override
@Nullable
public BuildToolInfo getBuildTools(@NonNull com.android.tools.lint.detector.api.Project project) {
    if (project.isGradleProject()) {
        Module module = getModule();
        if (module != null) {
            AndroidModuleModel model = AndroidModuleModel.get(module);
            if (model != null) {
                GradleVersion version = model.getModelVersion();
                if (version != null && version.isAtLeast(2, 1, 0)) {
                    String buildToolsVersion = model.getAndroidProject().getBuildToolsVersion();
                    AndroidSdkHandler sdk = getSdk();
                    if (sdk != null) {
                        try {
                            Revision revision = Revision.parseRevision(buildToolsVersion);
                            BuildToolInfo buildToolInfo = sdk.getBuildToolInfo(revision, getRepositoryLogger());
                            if (buildToolInfo != null) {
                                return buildToolInfo;
                            }
                        } catch (NumberFormatException ignore) {
                        // Fall through and use the latest
                        }
                    }
                }
            }
        }
    }
    return super.getBuildTools(project);
}
Also used : Revision(com.android.repository.Revision) BuildToolInfo(com.android.sdklib.BuildToolInfo) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidSdkHandler(com.android.sdklib.repository.AndroidSdkHandler) Module(com.intellij.openapi.module.Module) GradleVersion(com.android.ide.common.repository.GradleVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 75 with AndroidModuleModel

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

the class MoveToDebugManifestQuickFix method apply.

@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
    final XmlAttribute attribute = PsiTreeUtil.getParentOfType(startElement, XmlAttribute.class);
    if (attribute != null) {
        XmlTag parent = attribute.getParent();
        if (parent != null && parent.getName().equals(TAG_USES_PERMISSION)) {
            Module module = getModule(parent);
            assert MOCK_LOCATION_PERMISSION.equals(parent.getAttributeValue(ATTR_NAME, ANDROID_URI));
            parent.delete();
            if (module != null) {
                AndroidFacet facet = AndroidFacet.getInstance(module);
                if (facet != null) {
                    VirtualFile mainManifest = facet.getMainIdeaSourceProvider().getManifestFile();
                    // TODO: b/22928250
                    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
                    if (androidModel != null && mainManifest != null && mainManifest.getParent() != null && mainManifest.getParent().getParent() != null) {
                        final VirtualFile src = mainManifest.getParent().getParent();
                        for (BuildTypeContainer container : androidModel.getAndroidProject().getBuildTypes()) {
                            BuildType buildType = container.getBuildType();
                            if (buildType.isDebuggable()) {
                                addManifest(module, src, buildType.getName());
                                return;
                            }
                        }
                        Messages.showErrorDialog(module.getProject(), "Did not find a debug build type", "Move Permission");
                    }
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) BuildType(com.android.builder.model.BuildType) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) XmlTag(com.intellij.psi.xml.XmlTag) BuildTypeContainer(com.android.builder.model.BuildTypeContainer)

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