Search in sources :

Example 96 with AndroidModuleModel

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

the class TestArtifactSearchScopes method getSourceScope.

@NotNull
private FileRootSearchScope getSourceScope(@NotNull String artifactName) {
    Set<File> roots = Collections.emptySet();
    AndroidModuleModel androidModel = getAndroidModel();
    if (androidModel != null) {
        roots = new HashSet<>();
        // TODO consider generated source
        for (SourceProvider sourceProvider : androidModel.getTestSourceProviders(artifactName)) {
            roots.addAll(getAllSourceFolders(sourceProvider));
        }
    }
    return new FileRootSearchScope(myModule.getProject(), roots);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) SourceProvider(com.android.builder.model.SourceProvider) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with AndroidModuleModel

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

the class TestArtifactSearchScopes method initializeScope.

/**
   * Initialize the test scopes in the given module if the module is Gradle-based Android.
   *
   * @param module the given module.
   */
public static void initializeScope(@NotNull Module module) {
    AndroidModuleModel androidModel = AndroidModuleModel.get(module);
    TestArtifactSearchScopes scopes = androidModel != null ? new TestArtifactSearchScopes(module) : null;
    module.putUserData(SEARCH_SCOPES_KEY, scopes);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel)

Example 98 with AndroidModuleModel

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

the class AndroidRootUtil method getApkPath.

@Nullable
public static String getApkPath(@NotNull AndroidFacet facet) {
    if (facet.requiresAndroidModel()) {
        AndroidModuleModel androidModuleModel = AndroidModuleModel.get(facet);
        if (androidModuleModel != null) {
            // For Android-Gradle projects, AndroidModel is not null.
            AndroidArtifact mainArtifact = androidModuleModel.getMainArtifact();
            AndroidArtifactOutput output = getOutput(mainArtifact);
            File outputFile = output.getMainOutputFile().getOutputFile();
            return outputFile.getAbsolutePath();
        } else {
            return null;
        }
    }
    String path = facet.getProperties().APK_PATH;
    if (path.length() == 0) {
        return getOutputPackage(facet.getModule());
    }
    String moduleDirPath = getModuleDirPath(facet.getModule());
    return moduleDirPath != null ? toSystemDependentName(moduleDirPath + path) : null;
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidArtifactOutput(com.android.builder.model.AndroidArtifactOutput) AndroidArtifact(com.android.builder.model.AndroidArtifact) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 99 with AndroidModuleModel

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

the class AndroidGradleProjectResolverIdeaTest method testPopulateModuleContentRootsWithAndroidProject.

public void testPopulateModuleContentRootsWithAndroidProject() {
    when(myVariantSelector.findVariantToSelect(myAndroidProject)).thenReturn(myAndroidProject.getFirstVariant());
    ProjectData project = myProjectResolver.createProject();
    DataNode<ProjectData> projectNode = new DataNode<>(PROJECT, project, null);
    DataNode<ModuleData> moduleDataNode = myProjectResolver.createModule(myAndroidModuleModel, projectNode);
    myProjectResolver.populateModuleContentRoots(myAndroidModuleModel, moduleDataNode);
    // Verify module has AndroidGradleModel.
    Collection<DataNode<AndroidModuleModel>> androidModelNodes = getChildren(moduleDataNode, ANDROID_MODEL);
    assertThat(androidModelNodes).hasSize(1);
    DataNode<AndroidModuleModel> androidModelNode = getFirstItem(androidModelNodes);
    assertNotNull(androidModelNode);
    assertSame(myAndroidProject, androidModelNode.getData().getAndroidProject());
    // Verify module has IdeaGradleProject.
    Collection<DataNode<GradleModuleModel>> gradleModelNodes = getChildren(moduleDataNode, GRADLE_MODULE_MODEL);
    assertThat(gradleModelNodes).hasSize(1);
    DataNode<GradleModuleModel> gradleModelNode = getFirstItem(gradleModelNodes);
    assertNotNull(gradleModelNode);
    assertEquals(myAndroidModuleModel.getGradleProject().getPath(), gradleModelNode.getData().getGradlePath());
}
Also used : GradleModuleModel(com.android.tools.idea.gradle.project.model.GradleModuleModel) DataNode(com.intellij.openapi.externalSystem.model.DataNode) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 100 with AndroidModuleModel

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

the class AndroidModuleModelDataServiceTest method testImportData.

public void testImportData() throws Exception {
    loadSimpleApplication();
    Module appModule = myModules.getAppModule();
    AndroidModuleModel androidModel = AndroidModuleModel.get(appModule);
    assertNotNull(androidModel);
    DataNode<AndroidModuleModel> dataNode = new DataNode<>(ANDROID_MODEL, androidModel, null);
    Project project = getProject();
    IdeModifiableModelsProvider modelsProvider = new IdeModifiableModelsProviderImpl(project);
    myService.importData(Lists.newArrayList(dataNode), mock(ProjectData.class), project, modelsProvider);
    verify(myModuleSetup).setUpModule(appModule, modelsProvider, androidModel, null, null);
    verify(myValidator).validate(appModule, androidModel);
    verify(myValidator).fixAndReportFoundIssues();
}
Also used : Project(com.intellij.openapi.project.Project) DataNode(com.intellij.openapi.externalSystem.model.DataNode) IdeModifiableModelsProviderImpl(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) IdeModifiableModelsProvider(com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

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