Search in sources :

Example 61 with AndroidModuleModel

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

the class ProjectSetupImplTest method SetUpProjectWithAndroidModule.

// Test fails in build server, but not locally.
public void SetUpProjectWithAndroidModule() throws Exception {
    // Obtain models for 'simpleApplication' from Gradle.
    prepareProjectForImport(SIMPLE_APPLICATION);
    Project project = getProject();
    // Sync with Gradle.
    NewGradleSync gradleSync = new NewGradleSync();
    CountDownLatch latch = new CountDownLatch(1);
    NewGradleSync.Callback sync = gradleSync.sync(project);
    sync.doWhenRejected(() -> {
        latch.countDown();
        Throwable error = sync.getSyncError();
        if (error != null) {
            rethrowAllAsUnchecked(error);
        }
        throw new RuntimeException("Sync failed");
    });
    sync.doWhenDone(latch::countDown);
    if (!sync.isProcessed()) {
        latch.await();
    }
    SyncAction.ProjectModels projectModels = sync.getModels();
    assertNotNull("Gradle models", projectModels);
    Map<String, IdeaModule> moduleModelsByName = getModuleModelsByName(projectModels);
    // 2 modules: root and "app"
    assertThat(moduleModelsByName).hasSize(2);
    // Simulate ModuleFactory create root module from Gradle models.
    Module rootModule = simulateModelCreation(projectModels, moduleModelsByName.get(project.getName()));
    // Simulate ModuleFactory create "app" module from Gradle models.
    Module appModule = simulateModelCreation(projectModels, moduleModelsByName.get("app"));
    Module[] modules = { rootModule, appModule };
    when(myModelsProvider.getModules()).thenReturn(modules);
    // Add AndroidFacet and AndroidGradleModel to "app" module, to ensure that the validator gets invoked.
    AndroidModuleModel appAndroidModel = mock(AndroidModuleModel.class);
    AndroidFacet appAndroidFacet = createAndAddAndroidFacet(appModule);
    appAndroidFacet.setAndroidModel(appAndroidModel);
    // This happens before AndroidModuleValidator gets invoked. AndroidFacet and AndroidGradleModel need to be set in the module to
    // participate in validation.
    simulateAndroidFacetLookup(rootModule, null);
    simulateAndroidFacetLookup(appModule, appAndroidFacet);
    myProjectSetup.setUpProject(projectModels, myProgressIndicator);
    verify(myModuleSetup).setUpModule(rootModule, projectModels.getModels(":"), myProgressIndicator);
    verify(myModuleSetup).setUpModule(appModule, projectModels.getModels(":app"), myProgressIndicator);
    verify(myAndroidModuleValidator).validate(appModule, appAndroidModel);
    verify(myAndroidModuleValidator).fixAndReportFoundIssues();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) Facets.createAndAddAndroidFacet(com.android.tools.idea.testing.Facets.createAndAddAndroidFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Project(com.intellij.openapi.project.Project) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) IdeaModule(org.gradle.tooling.model.idea.IdeaModule) Module(com.intellij.openapi.module.Module)

Example 62 with AndroidModuleModel

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

the class PluginVersionUpgradeTest method simulateAndroidModule.

private static void simulateAndroidModule(@NotNull Module module, int pluginGeneration) {
    AndroidProject androidProject = mock(AndroidProject.class);
    when(androidProject.getPluginGeneration()).thenReturn(pluginGeneration);
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.getAndroidProject()).thenReturn(androidProject);
    AndroidFacet facet = createAndAddAndroidFacet(module);
    facet.setAndroidModel(androidModel);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) AndroidProject(com.android.builder.model.AndroidProject) Facets.createAndAddAndroidFacet(com.android.tools.idea.testing.Facets.createAndAddAndroidFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 63 with AndroidModuleModel

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

the class JavaLanguageLevelModuleSetupStepTest method createAndroidModule.

private void createAndroidModule(@NotNull String name, @NotNull LanguageLevel languageLevel) {
    AndroidModuleModel androidModel = mock(AndroidModuleModel.class);
    when(androidModel.getJavaLanguageLevel()).thenReturn(languageLevel);
    Module module = createModule(name);
    AndroidFacet facet = createAndAddAndroidFacet(module);
    facet.setAndroidModel(androidModel);
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) Facets.createAndAddAndroidFacet(com.android.tools.idea.testing.Facets.createAndAddAndroidFacet) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 64 with AndroidModuleModel

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

the class ProjectSubset method containsSourceFile.

/**
   * Checks in the Android and Java models to see if the module contains the given file.
   *
   * @param moduleInfos represents the module that is not included yet in the IDE.
   * @param file        the given file.
   * @param selected    indicates whether the module is included in the project.
   * @return the result of the search, or {@code null} if this module does not contain the given file.
   */
@Nullable
private static ModuleSearchResult containsSourceFile(@NotNull DataNode<ModuleData> moduleInfos, @NotNull File file, boolean selected) {
    DataNode<AndroidModuleModel> androidProjectNode = find(moduleInfos, ANDROID_MODEL);
    if (androidProjectNode != null) {
        AndroidModuleModel androidModel = androidProjectNode.getData();
        SourceFileContainerInfo result = androidModel.containsSourceFile(file);
        if (result != null) {
            return new ModuleSearchResult(moduleInfos, result, selected);
        }
    }
    DataNode<JavaModuleModel> javaProjectNode = find(moduleInfos, JAVA_MODULE_MODEL);
    if (javaProjectNode != null) {
        JavaModuleModel javaModuleModel = javaProjectNode.getData();
        if (javaModuleModel.containsSourceFile(file)) {
            return new ModuleSearchResult(moduleInfos, null, selected);
        }
    }
    return null;
}
Also used : SourceFileContainerInfo(com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo) JavaModuleModel(com.android.tools.idea.gradle.project.model.JavaModuleModel) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Nullable(org.jetbrains.annotations.Nullable)

Example 65 with AndroidModuleModel

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

the class PsAndroidDependencyCollection method collectDependencies.

private void collectDependencies(@NotNull PsAndroidArtifact artifact) {
    BaseArtifact resolvedArtifact = artifact.getResolvedModel();
    if (resolvedArtifact == null) {
        return;
    }
    AndroidModuleModel gradleModel = artifact.getGradleModel();
    Dependencies dependencies = GradleUtil.getDependencies(resolvedArtifact, gradleModel.getModelVersion());
    for (AndroidLibrary androidLibrary : dependencies.getLibraries()) {
        String gradlePath = androidLibrary.getProject();
        if (gradlePath != null) {
            String projectVariant = androidLibrary.getProjectVariant();
            addModule(gradlePath, artifact, projectVariant);
        } else {
            // This is an AAR
            addLibrary(androidLibrary, artifact);
        }
    }
    for (JavaLibrary javaLibrary : dependencies.getJavaLibraries()) {
        addLibrary(javaLibrary, artifact);
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) PsParsedDependencies(com.android.tools.idea.gradle.structure.model.PsParsedDependencies)

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