Search in sources :

Example 86 with AndroidModuleModel

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

the class BuildVariantUpdater method ensureVariantIsSelected.

private void ensureVariantIsSelected(@NotNull Project project, @NotNull String moduleGradlePath, @NotNull String variant, @NotNull List<AndroidFacet> affectedFacets) {
    Module module = findModuleByGradlePath(project, moduleGradlePath);
    if (module == null) {
        logAndShowUpdateFailure(variant, String.format("Cannot find module with Gradle path '%1$s'.", moduleGradlePath));
        return;
    }
    AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        logAndShowUpdateFailure(variant, String.format("Cannot find 'Android' facet in module '%1$s'.", module.getName()));
        return;
    }
    AndroidModuleModel androidModel = getAndroidModel(facet, variant);
    if (androidModel == null) {
        return;
    }
    if (!updateSelectedVariant(facet, androidModel, variant, affectedFacets)) {
        return;
    }
    affectedFacets.add(facet);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 87 with AndroidModuleModel

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

the class BuildVariantView method getVariantNames.

@Nullable
private static Collection<String> getVariantNames(@NotNull Module module) {
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    if (androidModel != null) {
        return androidModel.getVariantNames();
    }
    NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
    if (ndkModuleModel != null) {
        return ndkModuleModel.getVariantNames();
    }
    return null;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) Nullable(org.jetbrains.annotations.Nullable)

Example 88 with AndroidModuleModel

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

the class AndroidTestRunConfiguration method findInstrumentationRunner.

@Nullable
public static String findInstrumentationRunner(@NotNull AndroidFacet facet) {
    String runner = getRunnerFromManifest(facet);
    // TODO: Resolve direct AndroidGradleModel dep (b/22596984)
    AndroidModuleModel androidModel = AndroidModuleModel.get(facet);
    if (runner == null && androidModel != null) {
        Variant selectedVariant = androidModel.getSelectedVariant();
        String testRunner = selectedVariant.getMergedFlavor().getTestInstrumentationRunner();
        if (testRunner != null) {
            runner = testRunner;
        }
    }
    return runner;
}
Also used : Variant(com.android.builder.model.Variant) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Nullable(org.jetbrains.annotations.Nullable)

Example 89 with AndroidModuleModel

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

the class AndroidGradleClassJarProvider method findModuleClassFile.

@Override
@Nullable
public VirtualFile findModuleClassFile(@NotNull String className, @NotNull Module module) {
    AndroidModuleModel model = AndroidModuleModel.get(module);
    if (model == null) {
        return null;
    }
    VirtualFile outputDir = getCompilerOutputRoot(model);
    if (outputDir == null) {
        return null;
    }
    return ClassJarProvider.findClassFileInPath(outputDir, className);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Nullable(org.jetbrains.annotations.Nullable)

Example 90 with AndroidModuleModel

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

the class PsAndroidModuleAnalyzer method doAnalyze.

@Override
protected void doAnalyze(@NotNull PsAndroidModule module, @NotNull PsIssueCollection issueCollection) {
    Multimap<String, SyncIssue> issuesByData = ArrayListMultimap.create();
    AndroidModuleModel gradleModel = module.getGradleModel();
    Collection<SyncIssue> syncIssues = gradleModel.getAndroidProject().getSyncIssues();
    for (SyncIssue syncIssue : syncIssues) {
        String data = nullToEmpty(syncIssue.getData());
        issuesByData.put(data, syncIssue);
    }
    PsModulePath modulePath = new PsModulePath(module);
    module.forEachDependency(dependency -> {
        if (dependency instanceof PsLibraryDependency && dependency.isDeclared()) {
            PsLibraryDependency libraryDependency = (PsLibraryDependency) dependency;
            PsPath path = new PsLibraryDependencyNavigationPath(getContext(), libraryDependency);
            PsArtifactDependencySpec resolvedSpec = libraryDependency.getResolvedSpec();
            String issueKey = resolvedSpec.group + GRADLE_PATH_SEPARATOR + resolvedSpec.name;
            Collection<SyncIssue> librarySyncIssues = issuesByData.get(issueKey);
            for (SyncIssue syncIssue : librarySyncIssues) {
                PsIssue issue = createIssueFrom(syncIssue, path, modulePath);
                issueCollection.add(issue);
            }
            analyzeDeclaredDependency(libraryDependency, modulePath, issueCollection);
        }
    });
}
Also used : SyncIssue(com.android.builder.model.SyncIssue) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) XmlStringUtil.escapeString(com.intellij.xml.util.XmlStringUtil.escapeString) PsLibraryDependencyNavigationPath(com.android.tools.idea.gradle.structure.navigation.PsLibraryDependencyNavigationPath)

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